§
    æ˜ºhs  ã                   óX   — d dl mZ ddlmZmZ ddlmZmZ  G d„ dej        ¦  «        Z	dS )é   )Úutilé    )ÚnnÚTensor)ÚIterableÚDictc                   ó\   ‡ — e Zd ZdZej        fˆ fd„	Zdeee	e
f                  de
fd„Zˆ xZS )ÚMarginMSELosszû
    Compute the MSE loss between the ``|sim(Query, Pos) - sim(Query, Neg)|`` and ``|gold_sim(Query, Pos) - gold_sim(Query, Neg)|``.
    By default, sim() is the dot-product.
    For more details, please refer to https://arxiv.org/abs/2010.02666.
    c                 ó¢   •— t          t          | ¦  «                             ¦   «          || _        || _        t          j        ¦   «         | _        dS )zz
        :param model: SentenceTransformerModel
        :param similarity_fct:  Which similarity function to use.
        N)Úsuperr
   Ú__init__ÚmodelÚsimilarity_fctr   ÚMSELossÚloss_fct)Úselfr   r   Ú	__class__s      €úr/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/sentence_transformers/losses/MarginMSELoss.pyr   zMarginMSELoss.__init__   sA   ø€ õ
 	�m˜TÑ"Ô"×+Ò+Ñ-Ô-Ð-ØˆŒ
Ø,ˆÔÝœ
™œˆŒˆˆó    Úsentence_featuresÚlabelsc                 óÞ   ‡ — ˆ fd„|D ¦   «         }|d         }|d         }|d         }‰                       ||¦  «        }‰                       ||¦  «        }||z
  }	‰                      |	|¦  «        S )Nc                 óF   •— g | ]}‰                      |¦  «        d          ‘ŒS )Úsentence_embedding)r   )Ú.0Úsentence_featurer   s     €r   ú
<listcomp>z)MarginMSELoss.forward.<locals>.<listcomp>   s-   ø€ ÐmÐmÐmÐGW�—
’
Ð+Ñ,Ô,Ð-AÔBÐmÐmÐmr   r   é   r   )r   r   )
r   r   r   ÚrepsÚembeddings_queryÚembeddings_posÚembeddings_negÚ
scores_posÚ
scores_negÚmargin_preds
   `         r   ÚforwardzMarginMSELoss.forward   sƒ   ø€ àmÐmÐmÐmÐ[lÐmÑmÔmˆØ œ7ÐØ˜aœˆØ˜aœˆà×(Ò(Ð)9¸>ÑJÔJˆ
Ø×(Ò(Ð)9¸>ÑJÔJˆ
Ø  :Ñ-ˆà�}Š}˜[¨&Ñ1Ô1Ð1r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpairwise_dot_scorer   r   r   Ústrr   r&   Ú__classcell__)r   s   @r   r
   r
      s   ø€ € € € € ðð ð .2Ô-Dð %ð %ð %ð %ð %ð %ð2¨°$°s¸F°{Ô2CÔ)Dð 2Èfð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2r   r
   N)
Ú r   Útorchr   r   Útypingr   r   ÚModuler
   © r   r   ú<module>r3      s}   ðØ Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !ð2ð 2ð 2ð 2ð 2�B”Iñ 2ô 2ð 2ð 2ð 2r   