ó
    >:jú  ã                  ób   • S SK Jr  S SKJrJr  S SKJr  S SKJr   " S S\R                  5      r
g)é    )Úannotations)ÚTensorÚnn)ÚCrossEncoder)Úfullnamec                  óx   ^ • \ rS rSr\R
                  " 5       4SU 4S jjjr S         SS jjrS rSr	U =r
$ )	ÚMSELossé	   c                óÄ  >• [         TU ]  5         Xl        X l        [        R
                  " S0 UD6U l        [        U R                  [        5      (       d8  [        U R                  R                   S[        U R                  5       S35      eU R                  R                  S:w  a9  [        U R                  R                   SU R                  R                   S35      eg)aG  
Computes the MSE loss between the computed query-passage score and a target query-passage score. This loss
is used to distill a cross-encoder model from a teacher cross-encoder model or gold labels.

Args:
    model (:class:`~sentence_transformers.cross_encoder.model.CrossEncoder`): A CrossEncoder model to be trained.
    activation_fn (:class:`~torch.nn.Module`): Activation function applied to the logits before computing the loss.
    **kwargs: Additional keyword arguments passed to the underlying :class:`torch.nn.MSELoss`.

.. note::

    Be mindful of the magnitude of both the labels and what the model produces. If the teacher model produces
    logits with Sigmoid to bound them to [0, 1], then you may wish to use a Sigmoid activation function in the loss.

References:
    - Improving Efficient Neural Ranking Models with Cross-Architecture Knowledge Distillation: https://huggingface.co/papers/2010.02666
    - `Cross Encoder > Training Examples > Distillation <../../../examples/cross_encoder/training/distillation/README.html>`_

Requirements:
    1. Your model must be initialized with `num_labels = 1` (a.k.a. the default) to predict one class.
    2. Usually uses a finetuned CrossEncoder teacher M in a knowledge distillation setup.

Inputs:
    +-----------------------------------------+-----------------------------+-------------------------------+
    | Texts                                   | Labels                      | Number of Model Output Labels |
    +=========================================+=============================+===============================+
    | (sentence_A, sentence_B) pairs          | similarity score            | 1                             |
    +-----------------------------------------+-----------------------------+-------------------------------+

Relations:
    - :class:`MarginMSELoss` is similar to this loss, but with a margin through a negative pair.

Example:
    ::

        from sentence_transformers.cross_encoder import CrossEncoder, CrossEncoderTrainer, losses
        from datasets import Dataset

        student_model = CrossEncoder("microsoft/mpnet-base")
        teacher_model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L12-v2")
        train_dataset = Dataset.from_dict({
            "query": ["What are pandas?", "What is the capital of France?"],
            "answer": ["Pandas are a kind of bear.", "The capital of France is Paris."],
        })

        def compute_labels(batch):
            return {
                "label": teacher_model.predict(list(zip(batch["query"], batch["answer"])))
            }

        train_dataset = train_dataset.map(compute_labels, batched=True)
        loss = losses.MSELoss(student_model)

        trainer = CrossEncoderTrainer(
            model=student_model,
            train_dataset=train_dataset,
            loss=loss,
        )
        trainer.train()
z? expects a model of type CrossEncoder, but got a model of type Ú.é   z; expects a model with 1 output label, but got a model with z output labels.N© )ÚsuperÚ__init__ÚmodelÚactivation_fnr   r	   Úloss_fctÚ
isinstancer   Ú
ValueErrorÚ	__class__Ú__name__ÚtypeÚ
num_labels)Úselfr   r   Úkwargsr   s       €Úk/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sentence_transformers/cross_encoder/losses/mse.pyr   ÚMSELoss.__init__
   sË   ø€ ôz 	‰ÑÔØŒ
Ø*ÔÜŸ
š
Ñ, VÑ,ˆŒä˜$Ÿ*™*¤l×3Ñ3ÜØ—>‘>×*Ñ*Ð+ð ,+Ü+/°·
±
Ó+;Ð*<¸Að?óð ð
 �:‰:× Ñ  AÓ%ÜØ—>‘>×*Ñ*Ð+ð ,(Ø(,¯
©
×(=Ñ(=Ð'>¸oðOóð ð &ó    c                ó®  • [        U5      S:w  a  [        S[        U5       S35      e[        [        US   US   5      5      nU R                  R                  XSUS9nUR                  U R                  R                  5      nU R	                  U5      S   R                  S5      nU R                  U5      nU R                  XbR                  5       5      nU$ )	Né   zMMSELoss expects a dataset with two non-label columns, but got a dataset with z	 columns.r   r   )ÚpromptÚtaskÚscoreséÿÿÿÿ)Úlenr   ÚlistÚzipr   Ú
preprocessÚtoÚdeviceÚviewr   r   Úfloat)r   ÚinputsÚlabelsr!   r"   ÚpairsÚlogitsÚlosss           r   ÚforwardÚMSELoss.forwardX   sÅ   € ô ˆv‹;˜!ÓÜØ_Ô`cÐdjÓ`kÐ_lÐluÐvóð ô ”S˜ ™ F¨1¡IÓ.Ó/ˆØ—‘×&Ñ& uÀ$Ð&ÐGˆØ—‘˜4Ÿ:™:×,Ñ,Ó-ˆØ—‘˜FÓ# HÑ-×2Ñ2°2Ó6ˆØ×#Ñ# FÓ+ˆØ�}‰}˜V§\¡\£^Ó4ˆØˆr   c                ó0   • S[        U R                  5      0$ )Nr   )r   r   )r   s    r   Úget_config_dictÚMSELoss.get_config_dicth   s   € àœX d×&8Ñ&8Ó9ð
ð 	
r   )r   r   r   )r   r   r   z	nn.ModuleÚreturnÚNone)NN)
r-   zlist[list[str]]r.   r   r!   ú
str | Noner"   r9   r7   r   )r   Ú
__module__Ú__qualname__Ú__firstlineno__r   ÚIdentityr   r2   r5   Ú__static_attributes__Ú__classcell__)r   s   @r   r	   r	   	   sW   ø† ØGIÇ{Â{Ã}÷ Lñ Lð^ fjðØ%ðØ/5ðØ?IðØXbðà	õ÷ 
ð 
r   r	   N)Ú
__future__r   Útorchr   r   Ú)sentence_transformers.cross_encoder.modelr   Úsentence_transformers.utilr   ÚModuler	   r   r   r   Ú<module>rE      s#   ðÝ "ç å BÝ /ôb
ˆb�i‰iõ b
r   