o
    .wÖi%   ã                   @   s€  d dl mZ d dl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 ))é    )ÚSequence)ÚAnyÚLiteralÚOptional)Ú	BLEUScore)ÚCharErrorRate)Ú	CHRFScore)ÚExtendedEditDistance)ÚMatchErrorRate)Ú
Perplexity)ÚSacreBLEUScore)ÚSQuAD)ÚTranslationEditRate)ÚWordErrorRate)ÚWordInfoLost)ÚWordInfoPreserved)Ú_deprecated_root_import_classc                       sF   e Zd ZdZ			ddededeee  de	d	df
‡ fd
d„Z
‡  ZS )Ú
_BLEUScorezâWrapper 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d|||dœ|¤Ž d S )Nr   Útext)r   r   r   © ©r   ÚsuperÚ__init__)Úselfr   r   r   r   ©Ú	__class__r   úZ/home/ubuntu/sommelier/.venv/lib/python3.10/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                       ó*   e Zd ZdZdeddf‡ fdd„Z‡  ZS )Ú_CharErrorRatezüWrapper 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)

    r   r   Nc                    ó    t ddƒ tƒ jdi |¤Ž d S )Nr   r   r   r   ©r   r   r    r   r"   r   4   ó   
z_CharErrorRate.__init__©r#   r$   r%   r&   r   r   r*   r   r   r    r"   r,   )   ó    
þýr,   c                       sP   e Zd ZdZ						ddededed	ed
edededdf‡ fdd„Z‡  Z	S )Ú
_CHRFScorezâWrapper 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)

    é   é   ç       @FÚn_char_orderÚn_word_orderÚbetaÚ	lowercaseÚ
whitespaceÚreturn_sentence_level_scorer   r   Nc              	      ó.   t ddƒ tƒ jd||||||dœ|¤Ž d S )Nr   r   )r6   r7   r8   r9   r:   r;   r   r   )r   r6   r7   r8   r9   r:   r;   r   r    r   r"   r   G   ó   

ú
ùz_CHRFScore.__init__)r3   r4   r5   FFF)
r#   r$   r%   r&   r'   r)   r(   r   r   r*   r   r   r    r"   r2   <   s2    ùþýüûúùø	÷r2   c                       sT   e Zd ZdZ						dded	 d
ededededededdf‡ 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)

    ÚenFr5   ç333333Ó?çš™™™™™É?ç      ð?Úlanguage)r?   Újar;   ÚalphaÚrhoÚdeletionÚ	insertionr   r   Nc              	      r<   )Nr	   r   )rC   r;   rE   rF   rG   rH   r   r   )r   rC   r;   rE   rF   rG   rH   r   r    r   r"   r   h   r=   z_ExtendedEditDistance.__init__)r?   Fr5   r@   rA   rB   )
r#   r$   r%   r&   r   r(   r)   r   r   r*   r   r   r    r"   r>   ]   s2    ùþýüûúùø	÷r>   c                       r+   )Ú_MatchErrorRatezýWrapper 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)

    r   r   Nc                    r-   )Nr
   r   r   r   r.   r    r   r"   r   ‰   r/   z_MatchErrorRate.__init__r0   r   r   r    r"   rI   ~   r1   rI   c                       s6   e Zd ZdZ	ddee deddf‡ fdd„Z‡  ZS )	Ú_Perplexitya	  Wrapper for deprecated import.

    >>> from torch import rand, randint
    >>> preds = rand(2, 8, 5)
    >>> target = randint(5, (2, 8))
    >>> 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dd|i|¤Ž d S )Nr   r   rK   r   r   )r   rK   r   r    r   r"   r   ž   s   
z_Perplexity.__init__)N)	r#   r$   r%   r&   r   r'   r   r   r*   r   r   r    r"   rJ   ‘   s    þþýürJ   c                       sV   e Zd ZdZ					ddededed	 d
edeee	  de
ddf‡ fdd„Z‡  ZS )Ú_SacreBLEUScorezóWrapper 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Ú13aNr   r   Útokenize)ÚnonerM   ÚzhÚintlÚcharr9   r   r   r   c                    ó,   t ddƒ tƒ jd|||||dœ|¤Ž d S )Nr   r   )r   r   rN   r9   r   r   r   )r   r   r   rN   r9   r   r   r    r   r"   r   ²   s   
	
ÿ
ÿz_SacreBLEUScore.__init__)r   FrM   FN)r#   r$   r%   r&   r'   r(   r   r   r   r)   r   r   r*   r   r   r    r"   rL   §   s,    úþýüû
úùørL   c                       r+   )Ú_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.)}

    r   r   Nc                    r-   )Nr   r   r   r   r.   r    r   r"   r   Ì   ó   
z_SQuAD.__init__r0   r   r   r    r"   rT   Á   ó    
rT   c                       sJ   e Zd ZdZ					ddededededed	ed
df‡ fdd„Z‡  ZS )Ú_TranslationEditRatezêWrapper 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)

    FTÚ	normalizeÚno_punctuationr9   Úasian_supportr;   r   r   Nc                    rS   )Nr   r   )rX   rY   r9   rZ   r;   r   r   )r   rX   rY   r9   rZ   r;   r   r    r   r"   r   Ü   s   
	û
úz_TranslationEditRate.__init__)FFTFF)r#   r$   r%   r&   r(   r   r   r*   r   r   r    r"   rW   Ñ   s,    úþýüûúùørW   c                       r+   )Ú_WordErrorRatezüWrapper 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)

    r   r   Nc                    r-   )Nr   r   r   r   r.   r    r   r"   r   û   rU   z_WordErrorRate.__init__r0   r   r   r    r"   r[   ð   rV   r[   c                       r+   )Ú_WordInfoLostzûWrapper 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)

    r   r   Nc                    r-   )Nr   r   r   r   r.   r    r   r"   r     rU   z_WordInfoLost.__init__r0   r   r   r    r"   r\      rV   r\   c                       r+   )Ú_WordInfoPreservedzÿWrapper 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)

    r   r   Nc                    r-   )Nr   r   r   r   r.   r    r   r"   r     rU   z_WordInfoPreserved.__init__r0   r   r   r    r"   r]     rV   r]   N),Úcollections.abcr   Útypingr   r   r   Útorchmetrics.text.bleur   Útorchmetrics.text.cerr   Útorchmetrics.text.chrfr   Útorchmetrics.text.eedr	   Útorchmetrics.text.merr
   Útorchmetrics.text.perplexityr   Útorchmetrics.text.sacre_bleur   Útorchmetrics.text.squadr   Útorchmetrics.text.terr   Útorchmetrics.text.werr   Útorchmetrics.text.wilr   Útorchmetrics.text.wipr   Útorchmetrics.utilities.printsr   r   r,   r2   r>   rI   rJ   rL   rT   rW   r[   r\   r]   r   r   r   r"   Ú<module>   s6    !!