§
    *�’j"  ã                  óX   — 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eZ	dS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAny)Ú	BaseModelc                  óX   — e Zd ZdZd„ Z	 ddd„Zdd„Z	 ddd„Zed d„¦   «         Z	d!d„Z
dS )"ÚBaseEvaluatoraÀ  
    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.

    Extend this class and implement __call__ for custom evaluators.
    c                ó"   — d| _         d | _        d S )NT)Úgreater_is_betterÚprimary_metric©Úselfs    ú]C:\Projects\DSCons\.venv\Lib\site-packages\sentence_transformers\base\evaluation\evaluator.pyÚ__init__zBaseEvaluator.__init__   s   € Ø!%ˆÔØ"ˆÔÐÐó    NéÿÿÿÿÚmodelr   Úoutput_pathú
str | NoneÚepochÚintÚstepsÚreturnúfloat | dict[str, float]c                ó   — t           ‚)aw  
        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
        )ÚNotImplementedError)r   r   r   r   r   s        r   Ú__call__zBaseEvaluator.__call__   s
   € õ& "Ð!r   Úmetricsúdict[str, float]ÚnameÚstrc                ó$  ‡‡— d	d„Š‰s ˆfd„|                      ¦   «         D ¦   «         S ˆˆfd„|                      ¦   «         D ¦   «         }t          | d¦  «        r6| j        �/| j                             ‰dz   ¦  «        s‰dz   | j        z   | _        |S )
NÚvaluer   r   c                óF   — 	 t          | ¦  «        S # t          $ r | cY S w xY w©N)ÚfloatÚ
ValueError)r"   s    r   Úmaybe_to_floatz<BaseEvaluator.prefix_name_to_metrics.<locals>.maybe_to_float1   s7   € ðÝ˜U‘|”|Ð#øÝð ð ð Ø���ðøøøs   ‚ ‘ Ÿ c                ó.   •— i | ]\  }}| ‰|¦  «        “ŒS © r)   )Ú.0Úkeyr"   r'   s      €r   ú
<dictcomp>z8BaseEvaluator.prefix_name_to_metrics.<locals>.<dictcomp>8   s)   ø€ ÐQÐQÐQ±:°3¸�C˜˜¨Ñ.Ô.ÐQÐQÐQr   c                ó:   •— i | ]\  }}‰d z   |z    ‰|¦  «        “ŒS )Ú_r)   )r*   r+   r"   r'   r   s      €€r   r,   z8BaseEvaluator.prefix_name_to_metrics.<locals>.<dictcomp>9   s2   ø€ Ð]Ð]Ð]¹z¸sÀE�4˜#‘: Ñ# ^ ^°EÑ%:Ô%:Ð]Ð]Ð]r   r   r.   )r"   r   r   r   )ÚitemsÚhasattrr   Ú
startswith)r   r   r   r'   s     `@r   Úprefix_name_to_metricsz$BaseEvaluator.prefix_name_to_metrics0   s¾   øø€ ð	ð 	ð 	ð 	ð ð 	RØQÐQÐQÐQÀÇÂÁÄÐQÑQÔQÐQØ]Ð]Ð]Ð]Ð]ÈWÏ]Ê]É_Ì_Ð]Ñ]Ô]ˆå�DÐ*Ñ+Ô+ð	CàÔ#Ð/ØÔ'×2Ò2°4¸#±:Ñ>Ô>ð 0ð #'¨¡*¨tÔ/BÑ"BˆDÔØˆr   r   údict[str, Any]ÚstepÚNonec                ó@   — |j                              | |||¦  «         d S r$   )Úmodel_card_dataÚset_evaluation_metrics)r   r   r   r   r4   s        r   Ú store_metrics_in_model_card_dataz.BaseEvaluator.store_metrics_in_model_card_dataB   s'   € ð 	Ô×4Ò4°T¸7ÀEÈ4ÑPÔPÐPÐPÐPr   c                óì   — | j         j        }|                     d¦  «        rd|dd…         z   }	 |                     d¦  «        }|d|…         }n# t          $ r Y nw xY wt          j        dd|¦  «        S )a  
        Returns a human-readable description of the evaluator: BinaryClassificationEvaluator -> Binary Classification

        1. Replace "CE" prefix with "CrossEncoder"
        2. Remove "Evaluator" from the class name
        3. Add a space before every capital letter
        ÚCEÚCrossEncoderé   NÚ	Evaluatorz([a-z])([A-Z])z\g<1> \g<2>)Ú	__class__Ú__name__r1   Úindexr&   ÚreÚsub)r   Ú
class_namerA   s      r   ÚdescriptionzBaseEvaluator.descriptionG   s•   € ð ”^Ô,ˆ
à× Ò  Ñ&Ô&ð 	9Ø'¨*°Q°R°R¬.Ñ8ˆJð	Ø×$Ò$ [Ñ1Ô1ˆEØ# F U FÔ+ˆJˆJøÝð 	ð 	ð 	ØˆDð	øøøõ ŒvÐ'¨¸ÑDÔDÐDs   °A Á
AÁAc                ó   — i S )z{
        Return a dictionary with all meaningful configuration values of the evaluator to store in the model card.
        r)   r   s    r   Úget_config_dictzBaseEvaluator.get_config_dict]   s	   € ð ˆ	r   )Nr   r   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r    r   r   )r   r   )
r   r   r   r3   r   r   r4   r   r   r5   )r   r    )r   r3   )r@   Ú
__module__Ú__qualname__Ú__doc__r   r   r2   r9   ÚpropertyrE   rG   r)   r   r   r   r   
   s¾   € € € € € ð
ð 
ð#ð #ð #ð
 _að"ð "ð "ð "ð "ð*ð ð ð ð& VWðQð Qð Qð Qð Qð
 ðEð Eð Eñ „XðEð*ð ð ð ð ð r   r   )
Ú
__future__r   rB   Útypingr   r   Ú sentence_transformers.base.modelr   r   ÚSentenceEvaluatorr)   r   r   ú<module>rP      s‘   ðØ "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %àð ;Ø:Ð:Ð:Ð:Ð:Ð:ðWð Wð Wð Wð Wñ Wô Wð Wðv "Ð Ð Ð r   