Ë
    l^(hä  ã                  óL   — 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y)é    )ÚannotationsN)ÚTYPE_CHECKINGÚAny)ÚSentenceTransformerc                  ót   — 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
y)ÚSentenceEvaluatoraÀ  
    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 | _        y )NT)Úgreater_is_betterÚprimary_metric©Úselfs    úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sentence_transformers/evaluation/SentenceEvaluator.pyÚ__init__zSentenceEvaluator.__init__   s   € Ø!%ˆÔØ"ˆÕó    Nc                 ó   — y)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   ÚmodelÚoutput_pathÚepochÚstepss        r   Ú__call__zSentenceEvaluator.__call__   s   € ð2 	r   c                ó^  — dd„}|s*|j                  «       D ��ci c]  \  }}| ||«      “Œ c}}S |j                  «       D ��ci c]  \  }}|dz   |z    ||«      “Œ }}}t        | d«      r5| j                  j                  |dz   «      s|dz   | j                  z   | _        |S c c}}w c c}}w )Nc                ó<   — 	 t        | «      S # t        $ r | cY S w xY w©N)ÚfloatÚ
ValueError)Úvalues    r   Úmaybe_to_floatz@SentenceEvaluator.prefix_name_to_metrics.<locals>.maybe_to_float7   s%   € ðÜ˜U“|Ð#øÜò Ø’ðús   ‚
 �šÚ_r   )r   r   Úreturnr   )ÚitemsÚhasattrr   Ú
startswith)r   ÚmetricsÚnamer   Úkeyr   s         r   Úprefix_name_to_metricsz(SentenceEvaluator.prefix_name_to_metrics6   s«   € ó	ñ ØAHÇÁÃ×Q±:°3¸�C™¨Ó.Ñ.ÓQÐQØMTÏ]É]Ë_×]¹z¸sÀE�4˜#‘: Ñ#¡^°EÓ%:Ñ:Ð]ˆÑ]Ü�4Ð)Ô*°4×3FÑ3F×3QÑ3QÐRVÐY\ÑR\Ô3]Ø"&¨¡*¨t×/BÑ/BÑ"BˆDÔØˆùó	 RùÛ]s   šB#ÁB)c                ó@   — |j                   j                  | |||«       y r   )Úmodel_card_dataÚset_evaluation_metrics)r   r   r$   r   Ústeps        r   Ú store_metrics_in_model_card_dataz2SentenceEvaluator.store_metrics_in_model_card_dataD   s   € ð 	×Ñ×4Ñ4°T¸7ÀEÈ4ÕPr   c                óÚ   — | j                   j                  }|j                  d«      rd|dd z   }	 |j                  d«      }|d| }t        j                  dd|«      S # t        $ r Y Œ"w xY w)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__r#   ÚindexÚ
IndexErrorÚreÚsub)r   Ú
class_namer4   s      r   ÚdescriptionzSentenceEvaluator.descriptionI   s|   € ð —^‘^×,Ñ,ˆ
à× Ñ  Ô&Ø'¨*°Q°R¨.Ñ8ˆJð	Ø×$Ñ$ [Ó1ˆEØ# F UÐ+ˆJô �v‰vÐ'¨¸ÓDÐDøô ò 	Ùð	ús   ±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!SentenceEvaluator.get_config_dict_   s	   € ð ˆ	r   )Néÿÿÿÿr<   )
r   r   r   Ústrr   Úintr   r>   r    zfloat | dict[str, float])r$   údict[str, float]r%   r=   r    r?   )r   r   )
r   r   r$   údict[str, Any]r   r>   r+   r>   r    ÚNone)r    r=   )r    r@   )r3   Ú
__module__Ú__qualname__Ú__doc__r   r   r'   r,   Úpropertyr9   r;   r   r   r   r   r   
   sš   „ ñ
ò#ð
 bdðØ(ðØ7:ðØJMðØ[^ðà	!óó6ð `aðQØ(ðQØ3AðQØJMðQØY\ðQà	óQð
 òEó ðEô*r   r   )	Ú
__future__r   r6   Útypingr   r   Ú)sentence_transformers.SentenceTransformerr   r   r   r   r   ú<module>rI      s    ðÝ "ã 	ß %áÝM÷Yò Yr   