a
    dE                      @   sx  d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ G dd deZG dd deZ G dd de
Z!G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd  d eZ'G d!d" d"eZ(G d#d$ d$eZ)G d%d& d&eZ*d'S )(    )AnyLiteralOptionalSequence)	BLEUScore)CharErrorRate)	CHRFScore)ExtendedEditDistance)MatchErrorRate)
Perplexity)SacreBLEUScore)SQuAD)TranslationEditRate)WordErrorRate)WordInfoLost)WordInfoPreserved)_deprecated_root_import_classc                       s8   e Zd ZdZdeeeee  e	dd fddZ
  ZS )	
_BLEUScorezWrapper for deprecated import.

    >>> preds = ['the cat is on the mat']
    >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
    >>> bleu = _BLEUScore()
    >>> bleu(preds, target)
    tensor(0.7598)

       FN)n_gramsmoothweightskwargsreturnc                    s(   t dd t jf |||d| d S )Nr   text)r   r   r   r   super__init__)selfr   r   r   r   	__class__ f/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/text/_deprecated.pyr      s    
z_BLEUScore.__init__)r   FN)__name__
__module____qualname____doc__intboolr   r   floatr   r   __classcell__r!   r!   r   r"   r      s      
r   c                       s(   e Zd ZdZedd fddZ  ZS )_CharErrorRatezWrapper for deprecated import.

    >>> preds = ["this is the prediction", "there is an other sample"]
    >>> target = ["this is the reference", "there is another one"]
    >>> cer = _CharErrorRate()
    >>> cer(preds, target)
    tensor(0.3415)

    Nr   r   c                    s    t dd t jf i | d S )Nr   r   r   r   r   r   r!   r"   r   3   s    
z_CharErrorRate.__init__r#   r$   r%   r&   r   r   r*   r!   r!   r   r"   r+   (   s   r+   c                
       s6   e Zd ZdZd
eeeeeeedd fdd	Z  Z	S )
_CHRFScorezWrapper for deprecated import.

    >>> preds = ['the cat is on the mat']
    >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
    >>> chrf = _CHRFScore()
    >>> chrf(preds, target)
    tensor(0.8640)

                 @FN)n_char_ordern_word_orderbeta	lowercase
whitespacereturn_sentence_level_scorer   r   c              	      s.   t dd t jf ||||||d| d S )Nr   r   )r3   r4   r5   r6   r7   r8   r   )r   r3   r4   r5   r6   r7   r8   r   r   r!   r"   r   F   s    

z_CHRFScore.__init__)r0   r1   r2   FFF)
r#   r$   r%   r&   r'   r)   r(   r   r   r*   r!   r!   r   r"   r/   ;   s"         r/   c                
       s:   e Zd ZdZded eeeeeed	d
 fddZ  Z	S )_ExtendedEditDistancea  Wrapper for deprecated import.

    >>> preds = ["this is the prediction", "here is an other sample"]
    >>> target = ["this is the reference", "here is another one"]
    >>> eed = _ExtendedEditDistance()
    >>> eed(preds=preds, target=target)
    tensor(0.3078)

    enFr2   333333?皙?      ?)r:   jaN)languager8   alpharhodeletion	insertionr   r   c              	      s.   t dd t jf ||||||d| d S )Nr	   r   )r?   r8   r@   rA   rB   rC   r   )r   r?   r8   r@   rA   rB   rC   r   r   r!   r"   r   g   s    

z_ExtendedEditDistance.__init__)r:   Fr2   r;   r<   r=   )
r#   r$   r%   r&   r   r(   r)   r   r   r*   r!   r!   r   r"   r9   \   s"         r9   c                       s(   e Zd ZdZedd fddZ  ZS )_MatchErrorRatezWrapper for deprecated import.

    >>> preds = ["this is the prediction", "there is an other sample"]
    >>> target = ["this is the reference", "there is another one"]
    >>> mer = _MatchErrorRate()
    >>> mer(preds, target)
    tensor(0.4444)

    Nr,   c                    s    t dd t jf i | d S )Nr
   r   r   r-   r   r!   r"   r      s    
z_MatchErrorRate.__init__r.   r!   r!   r   r"   rD   }   s   rD   c                       s0   e Zd ZdZdee edd fddZ  ZS )_PerplexityaD  Wrapper for deprecated import.

    >>> import torch
    >>> gen = torch.manual_seed(42)
    >>> preds = torch.rand(2, 8, 5, generator=gen)
    >>> target = torch.randint(5, (2, 8), generator=gen)
    >>> target[0, 6:] = -100
    >>> perp = _Perplexity(ignore_index=-100)
    >>> perp(preds, target)
    tensor(5.8540)

    N)ignore_indexr   r   c                    s$   t dd t jf d|i| d S )Nr   r   rF   r   )r   rF   r   r   r!   r"   r      s    
z_Perplexity.__init__)N)	r#   r$   r%   r&   r   r'   r   r   r*   r!   r!   r   r"   rE      s    rE   c                	       s@   e Zd ZdZd
eeed eeee	  e
dd fdd	Z  ZS )_SacreBLEUScorezWrapper for deprecated import.

    >>> preds = ['the cat is on the mat']
    >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
    >>> sacre_bleu = _SacreBLEUScore()
    >>> sacre_bleu(preds, target)
    tensor(0.7598)

    r   F13aN)nonerH   zhZintlchar)r   r   tokenizer6   r   r   r   c                    s,   t dd t jf |||||d| d S )Nr   r   )r   r   rL   r6   r   r   )r   r   r   rL   r6   r   r   r   r!   r"   r      s    	

z_SacreBLEUScore.__init__)r   FrH   FN)r#   r$   r%   r&   r'   r(   r   r   r   r)   r   r   r*   r!   r!   r   r"   rG      s        
rG   c                       s(   e Zd ZdZedd fddZ  ZS )_SQuADaL  Wrapper for deprecated import.

    >>> preds = [{"prediction_text": "1976", "id": "56e10a3be3433e1400422b22"}]
    >>> target = [{"answers": {"answer_start": [97], "text": ["1976"]}, "id": "56e10a3be3433e1400422b22"}]
    >>> squad = _SQuAD()
    >>> squad(preds, target)
    {'exact_match': tensor(100.), 'f1': tensor(100.)}

    Nr,   c                    s    t dd t jf i | d S )Nr   r   r   r-   r   r!   r"   r      s    
z_SQuAD.__init__r.   r!   r!   r   r"   rM      s   
rM   c                	       s4   e Zd ZdZdeeeeeedd fddZ  ZS )	_TranslationEditRatezWrapper for deprecated import.

    >>> preds = ['the cat is on the mat']
    >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
    >>> ter = _TranslationEditRate()
    >>> ter(preds, target)
    tensor(0.1538)

    FTN)	normalizeno_punctuationr6   asian_supportr8   r   r   c                    s,   t dd t jf |||||d| d S )Nr   r   )rO   rP   r6   rQ   r8   r   )r   rO   rP   r6   rQ   r8   r   r   r!   r"   r      s    	
z_TranslationEditRate.__init__)FFTFF)r#   r$   r%   r&   r(   r   r   r*   r!   r!   r   r"   rN      s        rN   c                       s(   e Zd ZdZedd fddZ  ZS )_WordErrorRatezWrapper for deprecated import.

    >>> preds = ["this is the prediction", "there is an other sample"]
    >>> target = ["this is the reference", "there is another one"]
    >>> wer = _WordErrorRate()
    >>> wer(preds, target)
    tensor(0.5000)

    Nr,   c                    s    t dd t jf i | d S )Nr   r   r   r-   r   r!   r"   r      s    
z_WordErrorRate.__init__r.   r!   r!   r   r"   rR      s   
rR   c                       s(   e Zd ZdZedd fddZ  ZS )_WordInfoLostzWrapper for deprecated import.

    >>> preds = ["this is the prediction", "there is an other sample"]
    >>> target = ["this is the reference", "there is another one"]
    >>> wil = _WordInfoLost()
    >>> wil(preds, target)
    tensor(0.6528)

    Nr,   c                    s    t dd t jf i | d S )Nr   r   r   r-   r   r!   r"   r     s    
z_WordInfoLost.__init__r.   r!   r!   r   r"   rS      s   
rS   c                       s(   e Zd ZdZedd fddZ  ZS )_WordInfoPreservedzWrapper for deprecated import.

    >>> preds = ["this is the prediction", "there is an other sample"]
    >>> target = ["this is the reference", "there is another one"]
    >>> wip = WordInfoPreserved()
    >>> wip(preds, target)
    tensor(0.3472)

    Nr,   c                    s    t dd t jf i | d S )Nr   r   r   r-   r   r!   r"   r     s    
z_WordInfoPreserved.__init__r.   r!   r!   r   r"   rT     s   
rT   N)+typingr   r   r   r   Ztorchmetrics.text.bleur   Ztorchmetrics.text.cerr   Ztorchmetrics.text.chrfr   Ztorchmetrics.text.eedr	   Ztorchmetrics.text.merr
   Ztorchmetrics.text.perplexityr   Ztorchmetrics.text.sacre_bleur   Ztorchmetrics.text.squadr   Ztorchmetrics.text.terr   Ztorchmetrics.text.werr   Ztorchmetrics.text.wilr   Ztorchmetrics.text.wipr   Ztorchmetrics.utilities.printsr   r   r+   r/   r9   rD   rE   rG   rM   rN   rR   rS   rT   r!   r!   r!   r"   <module>   s2   !!