o
    7ti                     @   s0   d dl Z d dlZd dlmZ dd Zdd ZdS )    N)Counterc                 C   s4   dd }dd }dd }dd }||||| S )	z
    Taken from the official evaluation script for v1.1 of the SQuAD dataset.
    Lower text and remove punctuation, articles and extra whitespace.
    c                 S   s   t dd| S )Nz\b(a|an|the)\b )resubtext r   P/home/ubuntu/.local/lib/python3.10/site-packages/lm_eval/tasks/qasper/metrics.pyremove_articles      z)normalize_answer.<locals>.remove_articlesc                 S   s   d |  S )Nr   )joinsplitr   r   r   r	   white_space_fix   r   z)normalize_answer.<locals>.white_space_fixc                    s"   t tj d fdd| D S )N c                 3   s    | ]	}| vr|V  qd S Nr   ).0chexcluder   r	   	<genexpr>   s    z8normalize_answer.<locals>.remove_punc.<locals>.<genexpr>)setstringpunctuationr   r   r   r   r	   remove_punc   s   
z%normalize_answer.<locals>.remove_puncc                 S   s   |   S r   )lowerr   r   r   r	   r      s   znormalize_answer.<locals>.lowerr   )sr
   r   r   r   r   r   r	   normalize_answer   s
   r   c           	      C   s   t | d  }t |d  }t|t|@ }t| }|dkr$dS d| t| }d| t| }d| | ||  }|S )zR
    Taken from the official evaluation script for v1.1 of the SQuAD dataset.
    r   g      ?   )r   r   r   sumvalueslen)	predictions
referencesprediction_tokensreferences_tokenscommonnum_same	precisionrecallf1r   r   r	   f1_abstractive   s   r*   )r   r   collectionsr   r   r*   r   r   r   r	   <module>   s
    