§
    ÑìNg   ã                  óT   — d dl mZ d dlZd dlmZmZ erd dlmZ  G d„ d¦  «        ZdS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAny)ÚSentenceTransformerc                  óL   — e Zd ZdZd„ Z	 ddd„Zdd„Zdd„Zed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    ún/var/www/html/ai-engine/env/lib/python3.11/site-packages/sentence_transformers/evaluation/SentenceEvaluator.pyÚ__init__zSentenceEvaluator.__init__   s   € ð "&ˆÔØ"ˆÔÐÐó    NéÿÿÿÿÚmodelr   Úoutput_pathÚstrÚepochÚintÚstepsÚreturnúfloat | dict[str, float]c                ó   — 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údict[str, float]Ú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ÐM©z¨s°E4˜#‘: Ñ# UÐMÐMÐMr   r   r!   )ÚitemsÚhasattrr   Ú
startswith)r   r   r   s     `r   Úprefix_name_to_metricsz(SentenceEvaluator.prefix_name_to_metrics9   s~   ø€ Øð 	ØˆNØMÐMÐMÐM¸W¿]º]¹_¼_ÐMÑMÔMˆÝ4Ð)Ñ*Ô*ð 	C°4Ô3F×3QÒ3QÐRVÐY\ÑR\Ñ3]Ô3]ð 	CØ"&¨¡*¨tÔ/BÑ"BˆDÔØˆr   údict[str, Any]ÚNonec                ó<   — |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_dataA   s!   € ØÔ×4Ò4°T¸7Ñ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_namer4   s      r   ÚdescriptionzSentenceEvaluator.descriptionD   sm   € ð ”^Ô,ˆ
ð	Ø×$Ò$ [Ñ1Ô1ˆEØ# F U FÔ+ˆJˆJøÝð 	ð 	ð 	ØˆDð	øøøõ ŒvÐ'¨¸ÑDÔDÐDs   Ž. ®
;º;)Nr   r   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r*   r   r+   )r   r   )
r3   Ú
__module__Ú__qualname__Ú__doc__r   r   r)   r/   Úpropertyr9   r   r   r   r   r   
   sŸ   € € € € € ðð ð#ð #ð #ð bdðð ð ð ð ð6ð ð ð ðDð Dð Dð Dð ðEð Eð Eñ „XðEð Eð Er   r   )	Ú
__future__r   r6   Útypingr   r   Ú)sentence_transformers.SentenceTransformerr   r   r   r   r   ú<module>rA      s™   ðØ "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %àð NØMÐMÐMÐMÐMÐMðIEð IEð IEð IEð IEñ IEô IEð IEð IEð IEr   