o
    7ti	                  
   @   s   d dl Zzd dlZedZedZedZejddddZW n" ee	fy.   ed	 e
yC Z z
ed
ee ddZ[ww defddZdefddZdd ZdS )    Nbleurouge	bertscorebleurtzbleurt-base-512metric)module_typezPlease install evaluation metrics via pip install evaluate bert-score rouge_score>=0.1.2 nltk absl-py git+https://github.com/google-research/bleurt.gitz"Error loading evaluation metrics: z!. Please check your installation.returnc                 C   s.   | d }| d}|dkr||d d  S |S )NCHQMESSAGE	   )find)doctextidx r   N/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/tasks/meqsum/utils.pydoc_to_text   s
   
r   c                 C   s   | d S )NSummaryr   )r   r   r   r   doc_to_target!   s   r   c           	   
   C   s  |d gt | g}}t|d dk st|d dk r*tjtjtjtjtjtjdS z	tj||d}W n tyQ } ztd|  dtji}W Y d }~nd }~ww z	tj||d}W n" ty} } ztd|  tjtjtjd}W Y d }~nd }~ww zt	j||dd	 }W n ty } ztd
|  tjg}W Y d }~nd }~ww zt
j||ddd }W n ty } ztd|  tjg}W Y d }~nd }~ww |d dkr|d  d7  < |d |d |d |d t|t|dS )Nr      )r   rouge1rouge2rougeLr   
bert_score)predictions
referenceszBleu error: r   zRouge error: )r   r   r   scoreszBleurt error: en)r   r   langf1zBert error: gh㈵>r   r   r   )r   lennpNANr   compute	Exceptionprintr   r   r   mean)	r   resultspredrefsbleu_resultserouge_resultsbleurt_scoresbert_scoresr   r   r   process_results_gen%   s`    	r0   )numpyr"   evaluateloadr   r   r   r   ModuleNotFoundErrorImportErrorr%   r,   RuntimeErrorstrr   r   r0   r   r   r   r   <module>   s(    


	