
    uj                     @    d dl mZmZmZ ddlmZ  G d d          ZdS )    )absolute_importdivisionprint_function   )CiderScorerc                   &    e Zd ZdZd	dZd Zd ZdS )
CiderDz1
    Main Class to compute the CIDEr metric

             @corpusc                 p    || _         || _        || _        t          | j         | j                  | _        d S )N)ndf_mode)_n_sigma_dfr   cider_scorer)selfr   sigmadfs       p/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/metrics/ciderD/ciderD.py__init__zCiderD.__init__   s6    '$'48DDD    c                    | j                                         }|                                 |D ]}|d         }||d                  }t          |          t          u sJ t          |          dk    sJ t          |          t          u sJ t          |          dk    sJ ||d         |fz  }|                                \  }}||fS )ab  
        Main function to compute CIDEr score
        :param  hypo_for_image (dict) : dictionary with key <image> and value <tokenized hypothesis / candidate sentence>
                ref_for_image (dict)  : dictionary with key <image> and value <tokenized reference sentence>
        :return: cider (float) : computed CIDEr score for the corpus
        captionimage_idr   r   )r   
copy_emptycleartypelistlencompute_score)	r   gtsrestmp_cider_scorerres_idhyporefscorescoress	            r   r"   zCiderD.compute_score   s      ,7799    
	/ 
	/F)$DfZ()C JJ$&&&&IINNNNII%%%%HHqLLLLa#.*88::f}r   c                     dS )NzCIDEr-D )r   s    r   methodzCiderD.method8   s    yr   N)r
   r   r   )__name__
__module____qualname____doc__r   r"   r-   r,   r   r   r	   r	      sT         
E E E E  6    r   r	   N)
__future__r   r   r   ciderD_scorerr   r	   r,   r   r   <module>r4      sj    A @ @ @ @ @ @ @ @ @ & & & & & &+ + + + + + + + + +r   