a
    d6                     @   s  d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
 d dl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$ 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/m0Z0 d dl1m2Z2 ddgiZ3e0sDddgZ4ee5e
e5ee5e
ee5 ee6 f f f f Z7e
e7ee7 f Z8dVe
ee5 ee5ef f e
ee5 ee5ef f ee5 ee6 e9ee eeeeee5ef gef  e9e9ee
e5ej:f  e6e6e6e9e5e9ee5 ee5 ee5e
eee; e5f f d d!dZ<dWe
e5ee5 f ee
e5ee5 f  e6e9eee;  ed"d#d$Z=e
e5ee5 f e
e5ee5 f ed%d&d'Z>dXe
e5ee5 f ee
e5ee5 f  e6e6e;e9e9e9e
ee	eef f d+	d,d-Z?dYe
e5ee5 f ee
e5ee5 f  ed1 e9e;e;e;e;e
ee	eef f d2	d3d4Z@dZe
e5ee5 f e
e5ee5 f e
e5e jAf e;ee9ee; ee; ee
e5ej:f  ee6 e6e6e9e9e
ee	eef f d9d:dZBe
e5ee5 f e
e5ee5 f ed%d;d<ZCd[eeee6 ed=d>d?ZDd\e
e5ee5 f e
e5ee5 eee5  f edB e9eee5ge5f  eee5gee5 f  e
e5e	e5dCf f ee5ef dDdEdZEd]ee5 eee5  e6e9edG e9eee;  edHdIdJZFe
ee5e5f eee5e5f  f e8ee5ef d%dKdLZGd^e
e5ee5 f ee
e5ee5 f  e9e9e9e9e9e
ee	eee f f dMdNdOZHe
e5ee5 f e
e5ee5 f ed%dPdQZIe
e5ee5 f e
e5ee5 f ed%dRdSZJe
e5ee5 f e
e5ee5 f ed%dTdUZKdS )_    N)	AnyCallableDictListLiteralOptionalSequenceTupleUnion)Tensor)Module)
bert_score)
bleu_score)char_error_rate)
chrf_score)extended_edit_distance)$_ALLOWED_INFORMATION_MEASURE_LITERAL)infolm)match_error_rate)
perplexity)rouge_score)sacre_bleu_score)squad)translation_edit_rate)word_error_rate)word_information_lost)word_information_preserved)_TRANSFORMERS_GREATER_EQUAL_4_4)_deprecated_root_import_func_rouge_scoreZnltk_bert_score_infolmF   @      en)predstargetmodel_name_or_path
num_layers
all_layersmodeluser_tokenizeruser_forward_fnverboseidfdevice
max_length
batch_sizenum_threadsreturn_hashlangrescale_with_baselinebaseline_pathbaseline_urlreturnc                 C   s8   t dd t| |||||||||	|
||||||||dS )af  Wrapper for deprecated import.

    >>> preds = ["hello there", "general kenobi"]
    >>> target = ["hello there", "master kenobi"]
    >>> score = _bert_score(preds, target)
    >>> from pprint import pprint
    >>> pprint(score)
    {'f1': tensor([1.0000, 0.9961]),
     'precision': tensor([1.0000, 0.9961]),
     'recall': tensor([1.0000, 0.9961])}

    r   textr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   )r   r   r;    r<   q/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/functional/text/_deprecated.pyr    &   s,    !
)r&   r'   n_gramsmoothweightsr9   c                 C   s   t dd t| ||||dS )zWrapper 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_score(preds, target)
    tensor(0.7598)

    r   r:   r&   r'   r>   r?   r@   )r   r   rA   r<   r<   r=   _bleu_score_   s    
rB   )r&   r'   r9   c                 C   s   t dd t| |dS )zWrapper for deprecated import.

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

    r   r:   r&   r'   )r   r   rC   r<   r<   r=   _char_error_rater   s    	
rD                @)	r&   r'   n_char_ordern_word_orderbeta	lowercase
whitespacereturn_sentence_level_scorer9   c              
   C   s"   t dd t| |||||||dS )zWrapper 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_score(preds, target)
    tensor(0.8640)

    r   r:   r&   r'   rH   rI   rJ   rK   rL   rM   )r   r   rN   r<   r<   r=   _chrf_score   s    
rO   333333?皙?      ?)r%   ja)	r&   r'   languagerM   alpharhodeletion	insertionr9   c              
   C   s"   t dd t| |||||||dS )zWrapper for deprecated import.

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

    r   r:   r&   r'   rT   rM   rU   rV   rW   rX   )r   r   rY   r<   r<   r=   _extended_edit_distance   s    
rZ   bert-base-uncased      ?kl_divergenceT)r&   r'   r(   temperatureinformation_measurer/   rU   rJ   r0   r1   r2   r3   r.   rM   r9   c                 C   s.   t dd t| |||||||||	|
|||dS )a<  Wrapper for deprecated import.

    >>> preds = ['he read the book because he was interested in world history']
    >>> target = ['he was interested in world history because he read the book']
    >>> _infolm(preds, target, model_name_or_path='google/bert_uncased_L-2_H-128_A-2', idf=False)
    tensor(-0.1784)

    r   r:   r&   r'   r(   r^   r_   r/   rU   rJ   r0   r1   r2   r3   r.   rM   )r   r   r`   r<   r<   r=   r!      s"    
c                 C   s   t dd t| |dS )zWrapper for deprecated import.

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

    r   r:   rC   )r   r   rC   r<   r<   r=   _match_error_rate   s    	
ra   )r&   r'   ignore_indexr9   c                 C   s   t dd t| ||dS )a0  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
    >>> _perplexity(preds, target, ignore_index=-100)
    tensor(5.8540)

    r   r:   r&   r'   rb   )r   r   rc   r<   r<   r=   _perplexity   s    
rd   bestZrouge1Zrouge2ZrougeLZ	rougeLsum)avgre   .)r&   r'   
accumulateuse_stemmer
normalizer	tokenizer
rouge_keysr9   c              	   C   s    t dd t| ||||||dS )a  Wrapper for deprecated import.

    >>> preds = "My name is John"
    >>> target = "Is your name John"
    >>> from pprint import pprint
    >>> pprint(_rouge_score(preds, target))
    {'rouge1_fmeasure': tensor(0.7500),
        'rouge1_precision': tensor(0.7500),
        'rouge1_recall': tensor(0.7500),
        'rouge2_fmeasure': tensor(0.),
        'rouge2_precision': tensor(0.),
        'rouge2_recall': tensor(0.),
        'rougeL_fmeasure': tensor(0.5000),
        'rougeL_precision': tensor(0.5000),
        'rougeL_recall': tensor(0.5000),
        'rougeLsum_fmeasure': tensor(0.5000),
        'rougeLsum_precision': tensor(0.5000),
        'rougeLsum_recall': tensor(0.5000)}

    r   r:   r&   r'   rh   ri   rj   rk   rl   )r   r   rm   r<   r<   r=   r     s    
13a)nonern   zhZintlchar)r&   r'   r>   r?   tokenizerK   r@   r9   c              	   C   s    t dd t| ||||||dS )zWrapper 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_score(preds, target)
    tensor(0.7598)

    r   r:   r&   r'   r>   r?   rr   rK   r@   )r   r   rs   r<   r<   r=   _sacre_bleu_score.  s    
rt   c                 C   s   t dd t| |dS )a3  Wrapper for deprecated import.

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

    r   r:   rC   )r   r   rC   r<   r<   r=   _squadK  s    	
ru   )r&   r'   	normalizeno_punctuationrK   asian_supportrM   r9   c              	   C   s    t dd t| ||||||dS )zWrapper for deprecated import.

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

    r   r:   r&   r'   rv   rw   rK   rx   rM   )r   r   ry   r<   r<   r=   _translation_edit_rateX  s    
rz   c                 C   s   t dd t| |dS )zWrapper for deprecated import.

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

    r   r:   rC   )r   r   rC   r<   r<   r=   _word_error_rateu  s    	
r{   c                 C   s   t dd t| |dS )zWrapper for deprecated import.

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

    r   r:   rC   )r   r   rC   r<   r<   r=   _word_information_lost  s    	
r|   c                 C   s   t dd t| |dS )zWrapper for deprecated import.

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

    r   r:   rC   )r   r   rC   r<   r<   r=   _word_information_preserved  s    	
r}   )NNFNNNFFNr"   r#   r$   Fr%   FNN)r$   FN)rE   rF   rG   FFF)r%   FrG   rP   rQ   rR   )r[   r\   r]   TNNNNr#   r   TF)N)re   FNNrf   )r$   Frn   FN)FFTFF)Lostypingr   r   r   r   r   r   r   r	   r
   Ztorchr   Ztorch.nnr   Z!torchmetrics.functional.text.bertr   Z!torchmetrics.functional.text.bleur   Z torchmetrics.functional.text.cerr   Z!torchmetrics.functional.text.chrfr   Z torchmetrics.functional.text.eedr   Z#torchmetrics.functional.text.infolmr   Z+_INFOLM_ALLOWED_INFORMATION_MEASURE_LITERALr   Z torchmetrics.functional.text.merr   Z'torchmetrics.functional.text.perplexityr   Z"torchmetrics.functional.text.rouger   Z'torchmetrics.functional.text.sacre_bleur   Z"torchmetrics.functional.text.squadr   Z torchmetrics.functional.text.terr   Z torchmetrics.functional.text.werr   Z torchmetrics.functional.text.wilr   Z torchmetrics.functional.text.wipr   Ztorchmetrics.utilities.importsr   Ztorchmetrics.utilities.printsr   Z__doctest_requires__Z__doctest_skip__strintZSQUAD_SINGLE_TARGET_TYPEZSQUAD_TARGETS_TYPEboolr0   floatr    rB   rD   rO   rZ   PathLiker!   ra   rd   r   rt   ru   rz   r{   r|   r}   r<   r<   r<   r=   <module>   s  ,
,                 <   
*      "      "            +*     
,     

6     **