Ë
    l^(h›  ã                  óV   — d dl mZ d dlmZmZ d dlmZ  G d„ dej                  «      Zy)é    )Úannotations)ÚTensorÚnn)ÚCrossEncoderc                  óJ   ‡ — e Zd Z ej                  «       fdˆ fd„Zdd„Zˆ xZS )ÚCrossEntropyLossc                ó  •— t         ‰| �  «        || _        || _        t	        j
                  di |¤Ž| _        t        | j                  t        «      s8t        | j                  j                  › dt        | j                  «      › d�«      ‚y)aø	  
        Computes the Cross Entropy Loss for a CrossEncoder model. This loss is used to train a model to predict the
        correct class label for a given pair of sentences. The number of classes should be equal to the number of model
        output labels.

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

        References:
            - :class:`torch.nn.CrossEntropyLoss`
            - `Cross Encoder > Training Examples > Natural Language Inference <../../../examples/cross_encoder/training/nli/README.html>`_

        Requirements:
            1. Your model can be initialized with `num_labels > 1` to predict multiple classes.
            2. The number of dataset classes should be equal to the number of model output labels (`model.num_labels`).

        Inputs:
            +-------------------------------------------------+--------+-------------------------------+
            | Texts                                           | Labels | Number of Model Output Labels |
            +=================================================+========+===============================+
            | (sentence_A, sentence_B) pairs                  | class  | `num_classes`                 |
            +-------------------------------------------------+--------+-------------------------------+

        Example:
            ::

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

                model = CrossEncoder("microsoft/mpnet-base", num_labels=2)
                train_dataset = Dataset.from_dict({
                    "sentence1": ["How can I be a good geologist?", "What is the capital of France?"],
                    "sentence2": ["What should I do to be a great geologist?", "What is the capital of Germany?"],
                    "label": [1, 0],  # 1: duplicate, 0: not duplicate
                })
                loss = losses.CrossEntropyLoss(model)

                trainer = CrossEncoderTrainer(
                    model=model,
                    train_dataset=train_dataset,
                    loss=loss,
                )
                trainer.train()
        z? expects a model of type CrossEncoder, but got a model of type ú.N© )ÚsuperÚ__init__ÚmodelÚactivation_fnr   r   Úce_lossÚ
isinstancer   Ú
ValueErrorÚ	__class__Ú__name__Útype)Úselfr   r   Úkwargsr   s       €úy/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sentence_transformers/cross_encoder/losses/CrossEntropyLoss.pyr   zCrossEntropyLoss.__init__	   s€   ø€ ô^ 	‰ÑÔØˆŒ
Ø*ˆÔÜ×*Ñ*Ñ4¨VÑ4ˆŒä˜$Ÿ*™*¤lÔ3ÜØ—>‘>×*Ñ*Ð+ð ,+Ü+/°·
±
Ó+;Ð*<¸Að?óð ð 4ó    c                ó€  — t        |«      dk7  rt        dt        |«      › d�«      ‚t        t        |d   |d   «      «      }| j                  j                  |ddd¬«      }|j                  | j                  j                  «        | j                  d	i |¤Žd   }| j                  |«      }| j                  ||«      }|S )
Né   zVCrossEntropyLoss expects a dataset with two non-label columns, but got a dataset with z	 columns.r   é   TÚpt)ÚpaddingÚ
truncationÚreturn_tensorsr   )
Úlenr   ÚlistÚzipr   Ú	tokenizerÚtoÚdevicer   r   )r   ÚinputsÚlabelsÚpairsÚtokensÚlogitsÚlosss          r   ÚforwardzCrossEntropyLoss.forwardC   sÅ   € Üˆv‹;˜!ÒÜØhÔilÐmsÓitÐhuÐu~Ðóð ô ”S˜ ™ F¨1¡IÓ.Ó/ˆØ—‘×%Ñ%ØØØØð	 &ó 
ˆð 	�	‰	�$—*‘*×#Ñ#Ô$Ø�—‘Ñ%˜fÑ% aÑ(ˆØ×#Ñ# FÓ+ˆØ�|‰|˜F FÓ+ˆØˆr   )r   r   r   z	nn.ModuleÚreturnÚNone)r'   zlist[list[str]]r(   r   r.   r   )r   Ú
__module__Ú__qualname__r   ÚIdentityr   r-   Ú__classcell__)r   s   @r   r   r      s   ø„ ØGRÀrÇ{Á{Ã}ö 8÷tr   r   N)	Ú
__future__r   Útorchr   r   Ú0sentence_transformers.cross_encoder.CrossEncoderr   ÚModuler   r   r   r   ú<module>r8      s    ðÝ "ç å IôL�r—y‘yõ Lr   