Ë
    ÜÓ^ju{  ã                   óÄ  — d Z ddlZddlmZ ddlmZmZmZ ddlmZ	 ddl
mZ ddlmZ ddlmZmZmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'  ejP                  e)«      Z* G d„ de"«      Z+ G d„ de%«      Z, G d„ de!«      Z- G d„ de#«      Z.e G d„ de«      «       Z/ G d„ de$«      Z0 ed¬«       G d„ d e/e«      «       Z1e G d!„ d"e/«      «       Z2 G d#„ d$ejf                  «      Z4 ed%¬«       G d&„ d'e/«      «       Z5e G d(„ d)e/«      «       Z6e G d*„ d+e/«      «       Z7 G d,„ d-ejf                  «      Z8e G d.„ d/e/«      «       Z9g d0¢Z:y)1zPyTorch RoBERTa model.é    N)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )Úinitialization)Úgelu)ÚGenerationMixin)Ú,BaseModelOutputWithPoolingAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚMaskedLMOutputÚMultipleChoiceModelOutputÚQuestionAnsweringModelOutputÚSequenceClassifierOutputÚTokenClassifierOutput)ÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚlogging)Úcan_return_tupleé   )ÚBertCrossAttentionÚBertEmbeddingsÚ	BertLayerÚ	BertModelÚBertSelfAttentioné   )ÚRobertaConfigc                   óÐ   ‡ — e Zd Zˆ fd„Z	 	 	 	 	 ddej
                  dz  dej
                  dz  dej
                  dz  dej                  dz  def
d„Ze	d	„ «       Z
e	dd
„«       Zˆ xZS )ÚRobertaEmbeddingsc                 óÄ   •— t         ‰| �  |«       | `| `|j                  | _        t        j                  |j                  |j                  | j                  ¬«      | _        y )N)Úpadding_idx)	ÚsuperÚ__init__Úpad_token_idÚposition_embeddingsr"   ÚnnÚ	EmbeddingÚmax_position_embeddingsÚhidden_size©ÚselfÚconfigÚ	__class__s     €úv/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/roberta/modular_roberta.pyr$   zRobertaEmbeddings.__init__-   sT   ø€ Ü‰Ñ˜Ô àÐØÐ$à!×.Ñ.ˆÔÜ#%§<¡<Ø×*Ñ*¨F×,>Ñ,>ÈD×L\ÑL\ô$
ˆÕ ó    NÚ	input_idsÚtoken_type_idsÚposition_idsÚinputs_embedsÚpast_key_values_lengthc                 ó  — |€<|�| j                  || j                  |«      }n| j                  || j                  «      }|�|j                  «       }n|j                  «       d d }|\  }}|€³t	        | d«      rm| j
                  j                  |j                  «      j                  |j                  d   d«      }	t        j                  |	d|¬«      }	|	j                  ||«      }n:t        j                  |t        j                  | j                  j                  ¬«      }|€| j                  |«      }| j!                  |«      }
||
z   }| j#                  |«      }||z   }| j%                  |«      }| j'                  |«      }|S )Néÿÿÿÿr2   r   r   )ÚdimÚindex©ÚdtypeÚdevice)Ú"create_position_ids_from_input_idsr"   Ú&create_position_ids_from_inputs_embedsÚsizeÚhasattrr2   Útor<   ÚexpandÚshapeÚtorchÚgatherÚzerosÚlongr3   Úword_embeddingsÚtoken_type_embeddingsr&   Ú	LayerNormÚdropout)r,   r1   r2   r3   r4   r5   Úinput_shapeÚ
batch_sizeÚ
seq_lengthÚbuffered_token_type_idsrI   Ú
embeddingsr&   s                r/   ÚforwardzRobertaEmbeddings.forward8   s€  € ð ÐØÐ$à#×FÑFØ˜t×/Ñ/Ð1Gó ‘ð  $×JÑJÈ=ÐZ^×ZjÑZjÓk�àÐ Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà!,Ñˆ
�Jð
 Ð!Ü�tÐ-Ô.à*.×*=Ñ*=×*@Ñ*@À×ATÑATÓ*U×*\Ñ*\Ð]i×]oÑ]oÐpqÑ]rÐtvÓ*wÐ'Ü*/¯,©,Ð7NÐTUÐ]iÔ*jÐ'Ø!8×!?Ñ!?À
ÈJÓ!W‘ä!&§¡¨[ÄÇ
Á
ÐSW×SdÑSd×SkÑSkÔ!l�àÐ Ø ×0Ñ0°Ó;ˆMØ $× :Ñ :¸>Ó JÐØ"Ð%:Ñ:ˆ
à"×6Ñ6°|ÓDÐØÐ"5Ñ5ˆ
à—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr0   c                 óæ   — | j                  «       dd }|d   }t        j                  |dz   ||z   dz   t        j                  | j                  ¬«      }|j                  d«      j                  |«      S )z×
        We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.

        Args:
            inputs_embeds: torch.Tensor

        Returns: torch.Tensor
        Nr7   r   r:   r   )r?   rD   ÚarangerG   r<   Ú	unsqueezerB   )r4   r"   rL   Úsequence_lengthr3   s        r/   r>   z8RobertaEmbeddings.create_position_ids_from_inputs_embedsh   sp   € ð $×(Ñ(Ó*¨3¨BÐ/ˆØ% a™.ˆä—|‘|Ø˜!‰O˜_¨{Ñ:¸QÑ>ÄeÇjÁjÐYf×YmÑYmô
ˆð ×%Ñ% aÓ(×/Ñ/°Ó<Ð<r0   c                 ó¾   — | j                  |«      j                  «       }t        j                  |d¬«      j	                  |«      |z   |z  }|j                  «       |z   S )a  
        Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
        are ignored. This is modified from fairseq's `utils.make_positions`.

        Args:
            x: torch.Tensor x:

        Returns: torch.Tensor
        r   ©r8   )ÚneÚintrD   ÚcumsumÚtype_asrG   )r1   r"   r5   ÚmaskÚincremental_indicess        r/   r=   z4RobertaEmbeddings.create_position_ids_from_input_idsz   sW   € ð �|‰|˜KÓ(×,Ñ,Ó.ˆÜ$Ÿ|™|¨D°aÔ8×@Ñ@ÀÓFÐI_Ñ_ÐcgÑgÐØ"×'Ñ'Ó)¨KÑ7Ð7r0   )NNNNr   )r   )Ú__name__Ú
__module__Ú__qualname__r$   rD   Ú
LongTensorÚFloatTensorrY   rQ   Ústaticmethodr>   r=   Ú__classcell__©r.   s   @r/   r    r    ,   s£   ø„ ô	
ð .2Ø26Ø04Ø26Ø&'ñ.à×#Ñ# dÑ*ð.ð ×(Ñ(¨4Ñ/ð.ð ×&Ñ&¨Ñ-ð	.ð
 ×(Ñ(¨4Ñ/ð.ð !$ó.ð` ñ=ó ð=ð" ò8ó ô8r0   r    c                   ó   — e Zd Zy)ÚRobertaSelfAttentionN©r^   r_   r`   © r0   r/   rg   rg   ‹   ó   „ Ør0   rg   c                   ó   — e Zd Zy)ÚRobertaCrossAttentionNrh   ri   r0   r/   rl   rl   �   rj   r0   rl   c                   ó   — e Zd Zy)ÚRobertaLayerNrh   ri   r0   r/   rn   rn   “   rj   r0   rn   c                   ón   ‡ — e Zd ZeZdZdZdZdZdZ	dZ
eeedœZ ej                   «       ˆ fd„«       Zˆ xZS )ÚRobertaPreTrainedModelÚrobertaT)Úhidden_statesÚ
attentionsÚcross_attentionsc                 ó–  •— t         ‰| �  |«       t        |t        «      r t	        j
                  |j                  «       yt        |t        «      ryt	        j                  |j                  t        j                  |j                  j                  d   «      j                  d«      «       t	        j
                  |j                  «       yy)zInitialize the weightsr7   )r   r7   N)r#   Ú_init_weightsÚ
isinstanceÚRobertaLMHeadÚinitÚzeros_Úbiasr    Úcopy_r3   rD   rS   rC   rB   r2   )r,   Úmoduler.   s     €r/   rv   z$RobertaPreTrainedModel._init_weights¦   s‰   ø€ ô 	‰Ñ˜fÔ%Ü�fœmÔ,Ü�K‰K˜Ÿ™Õ$Ü˜Ô 1Ô2Ü�J‰J�v×*Ñ*¬E¯L©L¸×9LÑ9L×9RÑ9RÐSUÑ9VÓ,W×,^Ñ,^Ð_fÓ,gÔhÜ�K‰K˜×-Ñ-Õ.ð 3r0   )r^   r_   r`   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_supports_flash_attnÚ_supports_sdpaÚ_supports_flex_attnÚ_supports_attention_backendrn   rg   rl   Ú_can_record_outputsrD   Úno_gradrv   rd   re   s   @r/   rp   rp   —   sX   ø„ à €LØ!ÐØ&*Ð#ØÐØ€NØÐØ"&Ðà%Ø*Ø1ñÐð €U‡]�]ƒ_ó/ó ô/r0   rp   c                   ó    ‡ — e Zd Zdˆ fd„	Zˆ xZS )ÚRobertaModelc                 ó&   •— t         ‰| �  | |«       y ©N)r#   r$   )r,   r-   Úadd_pooling_layerr.   s      €r/   r$   zRobertaModel.__init__²   s   ø€ Ü‰Ñ˜˜vÕ&r0   )T)r^   r_   r`   r$   rd   re   s   @r/   rˆ   rˆ   ±   s   ø„ ÷'ñ 'r0   rˆ   zS
    RoBERTa Model with a `language modeling` head on top for CLM fine-tuning.
    )Úcustom_introc                   óØ  ‡ — e Zd ZdddœZˆ fd„Zd„ Zd„ Zee	 	 	 	 	 	 	 	 	 	 	 dde	j                  dz  d	e	j                  dz  d
e	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  deee	j                        dz  dedz  dee	j                  z  dee   dee	j                     ez  fd„«       «       Zˆ xZS )ÚRobertaForCausalLMú)roberta.embeddings.word_embeddings.weightúlm_head.bias©zlm_head.decoder.weightzlm_head.decoder.biasc                 óÊ   •— t         ‰| �  |«       |j                  st        j	                  d«       t        |d¬«      | _        t        |«      | _        | j                  «        y )NzOIf you want to use `RobertaLMHeadModel` as a standalone, add `is_decoder=True.`F©r‹   ©
r#   r$   Ú
is_decoderÚloggerÚwarningrˆ   rq   rx   Úlm_headÚ	post_initr+   s     €r/   r$   zRobertaForCausalLM.__init__Á   sL   ø€ Ü‰Ñ˜Ô à× Ò Ü�N‰NÐlÔmä# F¸eÔDˆŒÜ$ VÓ,ˆŒð 	�‰Õr0   c                 ó.   — | j                   j                  S rŠ   ©r˜   Údecoder©r,   s    r/   Úget_output_embeddingsz(RobertaForCausalLM.get_output_embeddingsÍ   ó   € Ø�|‰|×#Ñ#Ð#r0   c                 ó&   — || j                   _        y rŠ   r›   ©r,   Únew_embeddingss     r/   Úset_output_embeddingsz(RobertaForCausalLM.set_output_embeddingsÐ   ó   € Ø-ˆ�‰Õr0   Nr1   Úattention_maskr2   r3   r4   Úencoder_hidden_statesÚencoder_attention_maskÚlabelsÚpast_key_valuesÚ	use_cacheÚlogits_to_keepÚkwargsÚreturnc                 óž  — |�d}
 | j                   |f|||||||	|
ddœ	|¤Ž}|j                  }t        |t        «      rt	        | d«      n|}| j                  |dd…|dd…f   «      }d}|�* | j                  d||| j                  j                  dœ|¤Ž}t        |||j                  |j                  |j                  |j                  ¬«      S )am  
        token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
            `[-100, 0, ..., config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are
            ignored (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`

        Example:

        ```python
        >>> from transformers import AutoTokenizer, RobertaForCausalLM, AutoConfig
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base")
        >>> config = AutoConfig.from_pretrained("FacebookAI/roberta-base")
        >>> config.is_decoder = True
        >>> model = RobertaForCausalLM.from_pretrained("FacebookAI/roberta-base", config=config)

        >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
        >>> outputs = model(**inputs)

        >>> prediction_logits = outputs.logits
        ```NFT)	r¥   r2   r3   r4   r¦   r§   r©   rª   Úreturn_dict)Úlogitsr¨   Ú
vocab_size)Úlossr°   r©   rr   rs   rt   ri   )rq   Úlast_hidden_staterw   rY   Úslicer˜   Úloss_functionr-   r±   r   r©   rr   rs   rt   )r,   r1   r¥   r2   r3   r4   r¦   r§   r¨   r©   rª   r«   r¬   Úoutputsrr   Úslice_indicesr°   r²   s                     r/   rQ   zRobertaForCausalLM.forwardÓ   sý   € ð` ÐØˆIà@LÀÇÁØðA
à)Ø)Ø%Ø'Ø"7Ø#9Ø+ØØñA
ð ñA
ˆð  ×1Ñ1ˆä8BÀ>ÔSVÔ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜mªA¨}ºaÐ,?Ñ@ÓAˆàˆØÐØ%�4×%Ñ%Ðp¨V¸FÈtÏ{É{×OeÑOeÑpÐioÑpˆDä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
r0   )NNNNNNNNNNr   )r^   r_   r`   Ú_tied_weights_keysr$   rž   r£   r   r   rD   ra   rb   ÚtupleÚboolrY   ÚTensorr   r   r   rQ   rd   re   s   @r/   rŽ   rŽ   ¶   s€  ø„ ð #NØ .ñÐô

ò$ò.ð Øð .2Ø37Ø26Ø04Ø26Ø:>Ø;?Ø*.ØBFØ!%Ø-.ñO
à×#Ñ# dÑ*ðO
ð ×)Ñ)¨DÑ0ðO
ð ×(Ñ(¨4Ñ/ð	O
ð
 ×&Ñ&¨Ñ-ðO
ð ×(Ñ(¨4Ñ/ðO
ð  %×0Ñ0°4Ñ7ðO
ð !&× 1Ñ 1°DÑ 8ðO
ð × Ñ  4Ñ'ðO
ð ˜u U×%6Ñ%6Ñ7Ñ8¸4Ñ?ðO
ð ˜$‘;ðO
ð ˜eŸl™lÑ*ðO
ð Ð+Ñ,ðO
ð 
ˆu�|‰|Ñ	Ð@Ñ	@òO
ó ó ôO
r0   rŽ   c                   ó€  ‡ — e Zd ZdddœZˆ fd„Zd„ Zd„ Zee	 	 	 	 	 	 	 	 dde	j                  dz  d	e	j                  dz  d
e	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  de	j                  dz  dee   dee	j                     ez  fd„«       «       Zˆ xZS )ÚRobertaForMaskedLMr�   r�   r‘   c                 óÊ   •— t         ‰| �  |«       |j                  rt        j	                  d«       t        |d¬«      | _        t        |«      | _        | j                  «        y )NznIf you want to use `RobertaForMaskedLM` make sure `config.is_decoder=False` for bi-directional self-attention.Fr“   r”   r+   s     €r/   r$   zRobertaForMaskedLM.__init__.  sR   ø€ Ü‰Ñ˜Ô à×ÒÜ�N‰Nð1ôô
 $ F¸eÔDˆŒÜ$ VÓ,ˆŒð 	�‰Õr0   c                 ó.   — | j                   j                  S rŠ   r›   r�   s    r/   rž   z(RobertaForMaskedLM.get_output_embeddings=  rŸ   r0   c                 ó&   — || j                   _        y rŠ   r›   r¡   s     r/   r£   z(RobertaForMaskedLM.set_output_embeddings@  r¤   r0   Nr1   r¥   r2   r3   r4   r¦   r§   r¨   r¬   r­   c	                 ót  —  | j                   |f||||||ddœ|	¤Ž}
|
d   }| j                  |«      }d}|�a|j                  |j                  «      }t	        «       } ||j                  d| j                  j                  «      |j                  d«      «      }t        |||
j                  |
j                  ¬«      S )aô  
        token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
            config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
            loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`
        T)r¥   r2   r3   r4   r¦   r§   r¯   r   Nr7   ©r²   r°   rr   rs   )rq   r˜   rA   r<   r   Úviewr-   r±   r   rr   rs   )r,   r1   r¥   r2   r3   r4   r¦   r§   r¨   r¬   r¶   Úsequence_outputÚprediction_scoresÚmasked_lm_lossÚloss_fcts                  r/   rQ   zRobertaForMaskedLM.forwardC  sÓ   € ð: �$—,‘,Øð

à)Ø)Ø%Ø'Ø"7Ø#9Øñ

ð ñ

ˆð " !™*ˆØ ŸL™L¨Ó9ÐàˆØÐà—Y‘YÐ0×7Ñ7Ó8ˆFÜ'Ó)ˆHÙ%Ð&7×&<Ñ&<¸RÀÇÁ×AWÑAWÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNäØØ$Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r0   )NNNNNNNN)r^   r_   r`   r¸   r$   rž   r£   r   r   rD   ra   rb   r   r   r¹   r»   r   rQ   rd   re   s   @r/   r½   r½   '  s'  ø„ ð #NØ .ñÐô
ò$ò.ð Øð .2Ø37Ø26Ø04Ø26Ø:>Ø;?Ø*.ñ5
à×#Ñ# dÑ*ð5
ð ×)Ñ)¨DÑ0ð5
ð ×(Ñ(¨4Ñ/ð	5
ð
 ×&Ñ&¨Ñ-ð5
ð ×(Ñ(¨4Ñ/ð5
ð  %×0Ñ0°4Ñ7ð5
ð !&× 1Ñ 1°DÑ 8ð5
ð × Ñ  4Ñ'ð5
ð Ð+Ñ,ð5
ð 
ˆu�|‰|Ñ	˜~Ñ	-ò5
ó ó ô5
r0   r½   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )rx   z*Roberta Head for masked language modeling.c                 ó¬  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  |j                  «      | _
        t        j                  t        j                  |j                  «      «      | _        y )N)Úeps)r#   r$   r'   ÚLinearr*   ÚdenserJ   Úlayer_norm_epsÚ
layer_normr±   rœ   Ú	ParameterrD   rF   r{   r+   s     €r/   r$   zRobertaLMHead.__init__€  s‡   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ,™, v×'9Ñ'9¸v×?TÑ?TÔUˆŒä—y‘y ×!3Ñ!3°V×5FÑ5FÓGˆŒÜ—L‘L¤§¡¨V×->Ñ->Ó!?Ó@ˆ�	r0   c                 ó‚   — | j                  |«      }t        |«      }| j                  |«      }| j                  |«      }|S rŠ   )rÌ   r   rÎ   rœ   ©r,   Úfeaturesr¬   Úxs       r/   rQ   zRobertaLMHead.forwardˆ  s;   € Ø�J‰J�xÓ ˆÜ�‹GˆØ�O‰O˜AÓˆð �L‰L˜‹Oˆàˆr0   ©r^   r_   r`   Ú__doc__r$   rQ   rd   re   s   @r/   rx   rx   }  s   ø„ Ù4ôAör0   rx   zŸ
    RoBERTa Model transformer with a sequence classification/regression head on top (a linear layer on top of the
    pooled output) e.g. for GLUE tasks.
    c                   ó*  ‡ — e Zd Zˆ fd„Zee	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  d	e	e
   d
eej                     ez  fd„«       «       Zˆ xZS )Ú RobertaForSequenceClassificationc                 ó¸   •— t         ‰| �  |«       |j                  | _        || _        t	        |d¬«      | _        t        |«      | _        | j                  «        y ©NFr“   )	r#   r$   Ú
num_labelsr-   rˆ   rq   ÚRobertaClassificationHeadÚ
classifierr™   r+   s     €r/   r$   z)RobertaForSequenceClassification.__init__š  sJ   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒØˆŒä# F¸eÔDˆŒÜ3°FÓ;ˆŒð 	�‰Õr0   Nr1   r¥   r2   r3   r4   r¨   r¬   r­   c           	      óô  —  | j                   |f||||ddœ|¤Ž}|d   }	| j                  |	«      }
d}|��¢|j                  |
j                  «      }| j                  j
                  €�| j                  dk(  rd| j                  _        nl| j                  dkD  rL|j                  t        j                  k(  s|j                  t        j                  k(  rd| j                  _        nd| j                  _        | j                  j
                  dk(  rIt        «       }| j                  dk(  r& ||
j                  «       |j                  «       «      }nŒ ||
|«      }n‚| j                  j
                  dk(  r=t        «       } ||
j                  d	| j                  «      |j                  d	«      «      }n,| j                  j
                  dk(  rt        «       } ||
|«      }t!        ||
|j"                  |j$                  ¬
«      S )aß  
        token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        T©r¥   r2   r3   r4   r¯   r   Nr   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationr7   rÂ   )rq   rÜ   rA   r<   r-   Úproblem_typerÚ   r;   rD   rG   rY   r   Úsqueezer   rÃ   r   r   rr   rs   ©r,   r1   r¥   r2   r3   r4   r¨   r¬   r¶   rÄ   r°   r²   rÇ   s                r/   rQ   z(RobertaForSequenceClassification.forward¥  s­  € ð6 �$—,‘,Øð
à)Ø)Ø%Ø'Øñ
ð ñ
ˆð " !™*ˆØ—‘ Ó1ˆàˆØÑà—Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�ä'ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r0   ©NNNNNN)r^   r_   r`   r$   r   r   rD   ra   rb   r   r   r¹   r»   r   rQ   rd   re   s   @r/   r×   r×   “  sç   ø„ ô	ð Øð .2Ø37Ø26Ø04Ø26Ø*.ñC
à×#Ñ# dÑ*ðC
ð ×)Ñ)¨DÑ0ðC
ð ×(Ñ(¨4Ñ/ð	C
ð
 ×&Ñ&¨Ñ-ðC
ð ×(Ñ(¨4Ñ/ðC
ð × Ñ  4Ñ'ðC
ð Ð+Ñ,ðC
ð 
ˆu�|‰|Ñ	Ð7Ñ	7òC
ó ó ôC
r0   r×   c                   ó*  ‡ — e Zd Zˆ fd„Zee	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  d	e	e
   d
eej                     ez  fd„«       «       Zˆ xZS )ÚRobertaForMultipleChoicec                 óö   •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  «      | _        t	        j                  |j                  d«      | _
        | j                  «        y )Nr   )r#   r$   rˆ   rq   r'   ÚDropoutÚhidden_dropout_probrK   rË   r*   rÜ   r™   r+   s     €r/   r$   z!RobertaForMultipleChoice.__init__ï  sV   ø€ Ü‰Ñ˜Ô ä# FÓ+ˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒÜŸ)™) F×$6Ñ$6¸Ó:ˆŒð 	�‰Õr0   Nr1   r2   r¥   r¨   r3   r4   r¬   r­   c           	      ó"  — |�|j                   d   n|j                   d   }|�!|j                  d|j                  d«      «      nd}	|�!|j                  d|j                  d«      «      nd}
|�!|j                  d|j                  d«      «      nd}|�!|j                  d|j                  d«      «      nd}|�1|j                  d|j                  d«      |j                  d«      «      nd} | j                  |	f|
|||ddœ|¤Ž}|d   }| j	                  |«      }| j                  |«      }|j                  d|«      }d}|�.|j                  |j                  «      }t        «       } |||«      }t        |||j                  |j                  ¬«      S )a  
        input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        token_type_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
            num_choices-1]` where `num_choices` is the size of the second dimension of the input tensors. (See
            `input_ids` above)
        position_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

            [What are position IDs?](../glossary#position-ids)
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, num_choices, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        Nr   r7   éþÿÿÿT)r3   r2   r¥   r4   r¯   rÂ   )rC   rÃ   r?   rq   rK   rÜ   rA   r<   r   r   rr   rs   )r,   r1   r2   r¥   r¨   r3   r4   r¬   Únum_choicesÚflat_input_idsÚflat_position_idsÚflat_token_type_idsÚflat_attention_maskÚflat_inputs_embedsr¶   Úpooled_outputr°   Úreshaped_logitsr²   rÇ   s                       r/   rQ   z RobertaForMultipleChoice.forwardù  sµ  € ðV -6Ð,A�i—o‘o aÒ(À}×GZÑGZÐ[\ÑG]ˆàCLÐCX˜Ÿ™¨¨I¯N©N¸2Ó,>Ô?Ð^bˆØLXÐLd˜L×-Ñ-¨b°,×2CÑ2CÀBÓ2GÔHÐjnÐØR`ÐRl˜n×1Ñ1°"°n×6IÑ6IÈ"Ó6MÔNÐrvÐØR`ÐRl˜n×1Ñ1°"°n×6IÑ6IÈ"Ó6MÔNÐrvÐð Ð(ð ×Ñ˜r =×#5Ñ#5°bÓ#9¸=×;MÑ;MÈbÓ;QÔRàð 	ð �$—,‘,Øð
à*Ø.Ø.Ø,Øñ
ð ñ
ˆð   ™
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆØ Ÿ+™+ b¨+Ó6ˆàˆØÐà—Y‘Y˜×5Ñ5Ó6ˆFÜ'Ó)ˆHÙ˜O¨VÓ4ˆDä(ØØ"Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r0   rå   )r^   r_   r`   r$   r   r   rD   ra   rb   r   r   r¹   r»   r   rQ   rd   re   s   @r/   rç   rç   í  sç   ø„ ôð Øð .2Ø26Ø37Ø*.Ø04Ø26ñP
à×#Ñ# dÑ*ðP
ð ×(Ñ(¨4Ñ/ðP
ð ×)Ñ)¨DÑ0ð	P
ð
 × Ñ  4Ñ'ðP
ð ×&Ñ&¨Ñ-ðP
ð ×(Ñ(¨4Ñ/ðP
ð Ð+Ñ,ðP
ð 
ˆu�|‰|Ñ	Ð8Ñ	8òP
ó ó ôP
r0   rç   c                   ó*  ‡ — e Zd Zˆ fd„Zee	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  d	e	e
   d
eej                     ez  fd„«       «       Zˆ xZS )ÚRobertaForTokenClassificationc                 ód  •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        |j
                  �|j
                  n|j                  }t        j                  |«      | _	        t        j                  |j                  |j                  «      | _        | j                  «        y rÙ   )r#   r$   rÚ   rˆ   rq   Úclassifier_dropoutrê   r'   ré   rK   rË   r*   rÜ   r™   ©r,   r-   rø   r.   s      €r/   r$   z&RobertaForTokenClassification.__init__P  sŠ   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä# F¸eÔDˆŒà)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnð 	ô —z‘zÐ"4Ó5ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr0   Nr1   r¥   r2   r3   r4   r¨   r¬   r­   c           	      ó~  —  | j                   |f||||ddœ|¤Ž}|d   }	| j                  |	«      }	| j                  |	«      }
d}|�W|j                  |
j                  «      }t        «       } ||
j                  d| j                  «      |j                  d«      «      }t        ||
|j                  |j                  ¬«      S )a-  
        token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        TrÞ   r   Nr7   rÂ   )rq   rK   rÜ   rA   r<   r   rÃ   rÚ   r   rr   rs   rä   s                r/   rQ   z%RobertaForTokenClassification.forward^  sÉ   € ð2 �$—,‘,Øð
à)Ø)Ø%Ø'Øñ
ð ñ
ˆð " !™*ˆàŸ,™, Ó7ˆØ—‘ Ó1ˆàˆØÐà—Y‘Y˜vŸ}™}Ó-ˆFÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r0   rå   )r^   r_   r`   r$   r   r   rD   ra   rb   r   r   r¹   r»   r   rQ   rd   re   s   @r/   rö   rö   N  sÝ   ø„ ôð Øð .2Ø37Ø26Ø04Ø26Ø*.ñ2
à×#Ñ# dÑ*ð2
ð ×)Ñ)¨DÑ0ð2
ð ×(Ñ(¨4Ñ/ð	2
ð
 ×&Ñ&¨Ñ-ð2
ð ×(Ñ(¨4Ñ/ð2
ð × Ñ  4Ñ'ð2
ð Ð+Ñ,ð2
ð 
ˆu�|‰|Ñ	Ð4Ñ	4ò2
ó ó ô2
r0   rö   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )rÛ   z-Head for sentence-level classification tasks.c                 óZ  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        |j                  �|j                  n|j                  }t        j                  |«      | _	        t        j                  |j                  |j                  «      | _        y rŠ   )r#   r$   r'   rË   r*   rÌ   rø   rê   ré   rK   rÚ   Úout_projrù   s      €r/   r$   z"RobertaClassificationHead.__init__˜  s   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
à)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnð 	ô —z‘zÐ"4Ó5ˆŒÜŸ	™	 &×"4Ñ"4°f×6GÑ6GÓHˆ�r0   c                 óÐ   — |d d …dd d …f   }| j                  |«      }| j                  |«      }t        j                  |«      }| j                  |«      }| j	                  |«      }|S )Nr   )rK   rÌ   rD   Útanhrý   rÑ   s       r/   rQ   z!RobertaClassificationHead.forward¡  sY   € Ø’Q˜š1�WÑˆØ�L‰L˜‹OˆØ�J‰J�q‹MˆÜ�J‰J�q‹MˆØ�L‰L˜‹OˆØ�M‰M˜!ÓˆØˆr0   rÔ   re   s   @r/   rÛ   rÛ   •  s   ø„ Ù7ôIör0   rÛ   c                   óJ  ‡ — e Zd Zˆ fd„Zee	 	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  d	ej                  dz  d
e	e
   deej                     ez  fd„«       «       Zˆ xZS )ÚRobertaForQuestionAnsweringc                 óè   •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y rÙ   )
r#   r$   rÚ   rˆ   rq   r'   rË   r*   Ú
qa_outputsr™   r+   s     €r/   r$   z$RobertaForQuestionAnswering.__init__­  sU   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä# F¸eÔDˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr0   Nr1   r¥   r2   r3   r4   Ústart_positionsÚend_positionsr¬   r­   c           	      óÆ  —  | j                   |f||||ddœ|¤Ž}	|	d   }
| j                  |
«      }|j                  dd¬«      \  }}|j                  d«      j	                  «       }|j                  d«      j	                  «       }d}|�·|�µt        |j                  «       «      dkD  r|j                  d«      }t        |j                  «       «      dkD  r|j                  d«      }|j                  d«      }|j                  d|«      }|j                  d|«      }t        |¬«      } |||«      } |||«      }||z   d	z  }t        ||||	j                  |	j                  ¬
«      S )a[  
        token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.
            This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
            >= 2. All the value in this tensor should be always < type_vocab_size.

            [What are token type IDs?](../glossary#token-type-ids)
        TrÞ   r   r   r7   rW   N)Úignore_indexr   )r²   Ústart_logitsÚ
end_logitsrr   rs   )rq   r  Úsplitrã   Ú
contiguousÚlenr?   Úclampr   r   rr   rs   )r,   r1   r¥   r2   r3   r4   r  r  r¬   r¶   rÄ   r°   r  r	  Ú
total_lossÚignored_indexrÇ   Ú
start_lossÚend_losss                      r/   rQ   z#RobertaForQuestionAnswering.forward·  s€  € ð0 �$—,‘,Øð
à)Ø)Ø%Ø'Øñ
ð ñ
ˆð " !™*ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ-×3Ñ3°A°}ÓEˆOØ)×/Ñ/°°=ÓAˆMä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJä+ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r0   )NNNNNNN)r^   r_   r`   r$   r   r   rD   ra   rb   r   r   r¹   r»   r   rQ   rd   re   s   @r/   r  r  «  sõ   ø„ ôð Øð .2Ø37Ø26Ø04Ø26Ø37Ø15ñ>
à×#Ñ# dÑ*ð>
ð ×)Ñ)¨DÑ0ð>
ð ×(Ñ(¨4Ñ/ð	>
ð
 ×&Ñ&¨Ñ-ð>
ð ×(Ñ(¨4Ñ/ð>
ð ×)Ñ)¨DÑ0ð>
ð ×'Ñ'¨$Ñ.ð>
ð Ð+Ñ,ð>
ð 
ˆu�|‰|Ñ	Ð;Ñ	;ò>
ó ó ô>
r0   r  )rŽ   r½   rç   r  r×   rö   rˆ   rp   );rÕ   rD   Útorch.nnr'   r   r   r   Ú r   ry   Úactivationsr   Ú
generationr	   Úmodeling_outputsr
   r   r   r   r   r   r   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   Úbert.modeling_bertr   r   r   r   r   Úconfiguration_robertar   Ú
get_loggerr^   r–   r    rg   rl   rn   rp   rˆ   rŽ   r½   ÚModulerx   r×   rç   rö   rÛ   r  Ú__all__ri   r0   r/   ú<module>r      sµ  ðñ ã Ý ß AÑ Aå &Ý Ý )÷÷ ñ õ .Ý &ß @Ñ @Ý -ß lÕ lÝ 0ð 
ˆ×	Ñ	˜HÓ	%€ô\8˜ô \8ô~	Ð,ô 	ô	Ð.ô 	ô	�9ô 	ð ô/˜_ó /ó ð/ô2'�9ô 'ñ
 ðôô
i
Ð/°ó i
óð
i
ðX ôR
Ð/ó R
ó ðR
ôj�B—I‘Iô ñ, ðôôQ
Ð'=ó Q
óðQ
ðh ô]
Ð5ó ]
ó ð]
ð@ ôC
Ð$:ó C
ó ðC
ôL §	¡	ô ð, ôK
Ð"8ó K
ó ðK
ò\	�r0   