
    si                     P    d dl Z d dlmZmZmZmZ erd dlmZ  G d d          ZdS )    N)TYPE_CHECKINGAnyDictUnion)SentenceTransformerc                       e Zd ZdZd Z	 ddddeded	ed
eee	eef         f         f
dZ
de	eef         ded
e	eef         fdZddde	eef         d
dfdZed
efd            ZdS )SentenceEvaluatorzl
    Base class for all evaluators

    Extend this class and implement __call__ for custom evaluators.
    c                 "    d| _         d| _        dS )a  
        Base class for all evaluators. Notably, this class introduces the ``greater_is_better`` and ``primary_metric``
        attributes. The former is a boolean indicating whether a higher evaluation score is better, which is used
        for choosing the best checkpoint if ``load_best_model_at_end`` is set to ``True`` in the training arguments.

        The latter is a string indicating the primary metric for the evaluator. This has to be defined whenever
        the evaluator returns a dictionary of metrics, and the primary metric is the key pointing to the primary
        metric, i.e. the one that is used for model selection and/or logging.
        TN)greater_is_betterprimary_metric)selfs    e/var/www/icac/venv/lib/python3.11/site-packages/sentence_transformers/evaluation/SentenceEvaluator.py__init__zSentenceEvaluator.__init__   s     "&"    Nmodelr   output_pathepochstepsreturnc                     dS )a  
        This is called during training to evaluate the model.
        It returns a score for the evaluation with a higher score indicating a better result.

        Args:
            model: the model to evaluate
            output_path: path where predictions and metrics are written
                to
            epoch: the epoch where the evaluation takes place. This is
                used for the file prefixes. If this is -1, then we
                assume evaluation on test data.
            steps: the steps in the current epoch at time of the
                evaluation. This is used for the file prefixes. If this
                is -1, then we assume evaluation at the end of the
                epoch.

        Returns:
            Either a score for the evaluation with a higher score
            indicating a better result, or a dictionary with scores. If
            the latter is chosen, then `evaluator.primary_metric` must
            be defined
        N )r   r   r   r   r   s        r   __call__zSentenceEvaluator.__call__   s	    2 	r   metricsnamec                     s|S fd|                                 D             }t          | d          r/| j                            dz             sdz   | j        z   | _        |S )Nc                 (    i | ]\  }}d z   |z   |S )_r   ).0keyvaluer   s      r   
<dictcomp>z<SentenceEvaluator.prefix_name_to_metrics.<locals>.<dictcomp>:   s(    MMMzsE4#:#UMMMr   r   r   )itemshasattrr   
startswith)r   r   r   s     `r   prefix_name_to_metricsz(SentenceEvaluator.prefix_name_to_metrics7   s~     	NMMMMW]]__MMM4)** 	C43F3Q3QRVY\R\3]3] 	C"&*t/B"BDr   c                 <    |j                             | |           d S )N)model_card_dataset_evaluation_metrics)r   r   r   s      r    store_metrics_in_model_card_dataz2SentenceEvaluator.store_metrics_in_model_card_data?   s!    44T7CCCCCr   c                     | j         j        }	 |                    d          }|d|         }n# t          $ r Y nw xY wt	          j        dd|          S )z
        Returns a human-readable description of the evaluator: BinaryClassificationEvaluator -> Binary Classification

        1. Remove "Evaluator" from the class name
        2. Add a space before every capital letter
        	EvaluatorNz([a-z])([A-Z])z\g<1> \g<2>)	__class____name__index
IndexErrorresub)r   
class_namer/   s      r   descriptionzSentenceEvaluator.descriptionB   sm     ^,
	$$[11E#FUF+JJ 	 	 	D	 v'
CCCs   . 
;;)Nr   r   )r.   
__module____qualname____doc__r   strintr   floatr   r   r&   r   r*   propertyr4   r   r   r   r	   r	      s3        # # # df *9<LO]`	ud3:&&	'   6d3:.> c dSVX]S]N^    D6K DVZ[^`c[cVd Dim D D D D DS D D D XD D Dr   r	   )	r1   typingr   r   r   r   )sentence_transformers.SentenceTransformerr   r	   r   r   r   <module>r>      s    				 2 2 2 2 2 2 2 2 2 2 2 2 NMMMMMMID ID ID ID ID ID ID ID ID IDr   