ó
    ‡Ž¡jéŒ  ã                   óÚ  • S r SSKrSSKJr  SSKJrJrJr  SSKJr	  SSK
JrJrJr  SSKJrJrJrJrJrJrJrJr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJ r J!r!  SSK"J#r#  SSK$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7  \Rp                  " \95      r: " S S\&5      r; " S S\55      r< " S S\%5      r= " S S\05      r> " S S\45      r? " S S\25      r@ " S S\'5      rA\ " S S \5      5       rB " S! S"\35      rC " S# S$\,5      rD " S% S&\+5      rE " S' S(\15      rF " S) S*\(5      rG " S+ S,\*5      rH " S- S.\.5      rI " S/ S0\)5      rJ " S1 S2\/5      rK " S3 S4\-5      rL/ S5QrMg)6zPyTorch ERNIE model.é    N)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )Úinitialization)ÚCacheÚDynamicCacheÚEncoderDecoderCache)Ú,BaseModelOutputWithPoolingAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚMaskedLMOutputÚMultipleChoiceModelOutputÚNextSentencePredictorOutputÚQuestionAnsweringModelOutputÚSequenceClassifierOutputÚTokenClassifierOutput)ÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚlogging)Úcan_return_tupleÚmerge_with_config_defaults)Úcapture_outputsé   )ÚBertCrossAttentionÚBertEmbeddingsÚBertEncoderÚBertForMaskedLMÚBertForMultipleChoiceÚBertForNextSentencePredictionÚBertForPreTrainingÚBertForPreTrainingOutputÚBertForQuestionAnsweringÚBertForSequenceClassificationÚBertForTokenClassificationÚ	BertLayerÚBertLMHeadModelÚBertLMPredictionHeadÚ	BertModelÚ
BertPoolerÚBertSelfAttentioné   )ÚErnieConfigc                   óø   ^ • \ rS rSrSrU 4S jr      SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\	S\R                  4S jjrSrU =r$ )ÚErnieEmbeddingsé>   zGConstruct the embeddings from word, position and token_type embeddings.c                 óÊ   >• [         TU ]  U5        UR                  U l        UR                  (       a1  [        R                  " UR
                  UR                  5      U l        g g )N)ÚsuperÚ__init__Úuse_task_idÚnnÚ	EmbeddingÚtask_type_vocab_sizeÚhidden_sizeÚtask_type_embeddings)ÚselfÚconfigÚ	__class__s     €ÚµC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/models/ernie/modular_ernie.pyr4   ÚErnieEmbeddings.__init__A   sL   ø€ Ü‰Ñ˜Ô à!×-Ñ-ˆÔØ××Ü(*¯ª°V×5PÑ5PÐRX×RdÑRdÓ(eˆDÕ%ð ó    NÚ	input_idsÚtoken_type_idsÚtask_type_idsÚposition_idsÚinputs_embedsÚpast_key_values_lengthÚreturnc                 ó‚  • Ub  UR                  5       nOUR                  5       S S nUu  p‰Uc  U R                  S S 2XiU-   24   nUcš  [        U S5      (       aQ  U R                  R	                  UR
                  S   S5      n
[        R                  " U
SUS9n
U
R	                  X‰5      nO8[        R                  " U[        R                  U R                  R                  S9nUc  U R                  U5      nU R                  U5      nUR                  UR                  5      nX[-   nU R                  U5      nXÍ-   nU R                  (       aP  Uc8  [        R                  " U[        R                  U R                  R                  S9nU R!                  U5      nXÎ-  nU R#                  U5      nU R%                  U5      nU$ )NéÿÿÿÿrB   r   r-   )ÚdimÚindex)ÚdtypeÚdevice)ÚsizerD   ÚhasattrrB   ÚexpandÚshapeÚtorchÚgatherÚzerosÚlongrM   Úword_embeddingsÚtoken_type_embeddingsÚtoÚposition_embeddingsr5   r:   Ú	LayerNormÚdropout)r;   rA   rB   rC   rD   rE   rF   Úinput_shapeÚ
batch_sizeÚ
seq_lengthÚbuffered_token_type_idsrW   Ú
embeddingsrY   r:   s                  r>   ÚforwardÚErnieEmbeddings.forwardH   s­  € ð Ñ Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà!,Ñˆ
àÑØ×,Ñ,ªQÐ0FÐVlÑIlÐ0lÐ-lÑmˆLð
 Ñ!Ü�tÐ-×.Ñ.à*.×*=Ñ*=×*DÑ*DÀ\×EWÑEWÐXYÑEZÐ\^Ó*_Ð'Ü*/¯,ª,Ð7NÐTUÐ]iÑ*jÐ'Ø!8×!?Ñ!?À
Ó!W‘ä!&§¢¨[ÄÇ
Á
ÐSW×SdÑSd×SkÑSkÑ!l�àÑ Ø ×0Ñ0°Ó;ˆMØ $× :Ñ :¸>Ó JÐð &×(Ñ(Ð)>×)EÑ)EÓFˆØ"Ñ:ˆ
à"×6Ñ6°|ÓDÐØÑ5ˆ
ð ××ØÑ$Ü %§¢¨K¼u¿z¹zÐRV×RcÑRc×RjÑRjÑ k�Ø#'×#<Ñ#<¸]Ó#KÐ ØÑ.ˆJà—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr@   )r:   r5   )NNNNNr   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r4   rR   Ú
LongTensorÚFloatTensorÚintÚTensorra   Ú__static_attributes__Ú__classcell__©r=   s   @r>   r0   r0   >   s©   ø† ÙQõfð .2Ø26Ø15Ø04Ø26Ø&'ñ3à×#Ñ# dÑ*ð3ð ×(Ñ(¨4Ñ/ð3ð ×'Ñ'¨$Ñ.ð	3ð
 ×&Ñ&¨Ñ-ð3ð ×(Ñ(¨4Ñ/ð3ð !$ð3ð 
�‰÷3ó 3r@   r0   c                   ó   • \ rS rSrSrg)ÚErnieSelfAttentioné~   © N©rc   rd   re   rf   rl   rr   r@   r>   rp   rp   ~   ó   † Úr@   rp   c                   ó   • \ rS rSrSrg)ÚErnieCrossAttentioné‚   rr   Nrs   rr   r@   r>   rv   rv   ‚   rt   r@   rv   c                   ó   • \ rS rSrSrg)Ú
ErnieLayeré†   rr   Nrs   rr   r@   r>   ry   ry   †   rt   r@   ry   c                   ó   • \ rS rSrSrg)ÚErniePooleréŠ   rr   Nrs   rr   r@   r>   r|   r|   Š   rt   r@   r|   c                   ó   • \ rS rSrSrg)ÚErnieLMPredictionHeadéŽ   rr   Nrs   rr   r@   r>   r   r   Ž   rt   r@   r   c                   ó   • \ rS rSrSrg)ÚErnieEncoderé’   rr   Nrs   rr   r@   r>   r‚   r‚   ’   rt   r@   r‚   c                   óx   ^ • \ rS rSr\rSrSrSrSr	Sr
Sr\\\S.r\R"                  " 5       U 4S j5       rSrU =r$ )ÚErniePreTrainedModelé–   ÚernieT)Úhidden_statesÚ
attentionsÚcross_attentionsc                 ó²  >• [         TU ]  U5        [        U[        5      (       a!  [        R
                  " UR                  5        g[        U[        5      (       a|  [        R                  " UR                  [        R                  " UR                  R                  S   5      R                  S5      5        [        R
                  " UR                  5        gg)zInitialize the weightsrI   )r-   rI   N)r3   Ú_init_weightsÚ
isinstancer   ÚinitÚzeros_Úbiasr0   Úcopy_rD   rR   ÚarangerQ   rP   rB   )r;   Úmoduler=   s     €r>   rŒ   Ú"ErniePreTrainedModel._init_weights¥   s�   ø€ ô 	‰Ñ˜fÔ%Ü�fÔ3×4Ñ4Ü�KŠK˜Ÿ™Õ$Ü˜¤×0Ñ0Ü�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÑ9VÓ,W×,^Ñ,^Ð_fÓ,gÔhÜ�KŠK˜×-Ñ-Õ.ð 1r@   rr   )rc   rd   re   rf   r.   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_supports_flash_attnÚ_supports_sdpaÚ_supports_flex_attnÚ_supports_attention_backendry   rp   rv   Ú_can_record_outputsrR   Úno_gradrŒ   rl   rm   rn   s   @r>   r…   r…   –   sV   ø† à€LØÐØ&*Ð#ØÐØ€NØÐØ"&Ðà#Ø(Ø/ñÐð ‡]‚]ƒ_ô/ó ö/r@   r…   c                   ó¤  ^ • \ rS rSrS/rSU 4S jjr\\\          SS\	R                  S-  S\	R                  S-  S\	R                  S-  S\	R                  S-  S	\	R                  S-  S
\	R                  S-  S\	R                  S-  S\	R                  S-  S\S-  S\S-  S\\   S\\	R                     \-  4S jj5       5       5       rSrU =r$ )Ú
ErnieModelé°   ry   c                 óÐ   >• [         TU ]  X5        Xl        SU l        [	        U5      U l        [        U5      U l        U(       a  [        U5      OS U l	        U R                  5         g )NF)r3   r4   r<   Úgradient_checkpointingr0   r`   r‚   Úencoderr|   ÚpoolerÚ	post_init)r;   r<   Úadd_pooling_layerr=   s      €r>   r4   ÚErnieModel.__init__³   sQ   ø€ Ü‰Ñ˜Ô&ØŒØ&+ˆÔ#ä)¨&Ó1ˆŒÜ# FÓ+ˆŒæ->”k &Ô)ÀDˆŒð 	�‰Õr@   NrA   Úattention_maskrB   rC   rD   rE   Úencoder_hidden_statesÚencoder_attention_maskÚpast_key_valuesÚ	use_cacheÚkwargsrG   c           
      óœ  • USL USL-  (       a  [        S5      eU R                  R                  (       a  U
b  U
OU R                  R                  n
OSn
U
(       ab  U	c_  Uc  U R                  R                  (       a.  [        [        U R                  S9[        U R                  S95      O[        U R                  S9n	U	b  U	R                  5       OSnU R                  UUUUUUS9nU R                  UUUUU	S9u  p(U R                  " U4UUUU	U
US.UD6nUS   nU R                  b  U R                  U5      OSn[        UUUR                  S	9$ )
áª  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
Nz:You must specify exactly one of input_ids or inputs_embedsF)r<   r   )rA   rD   rB   rC   rE   rF   )r¨   rª   Úembedding_outputr©   r«   )r¨   r©   rª   r«   r¬   rD   )Úlast_hidden_stateÚpooler_outputr«   )Ú
ValueErrorr<   Ú
is_decoderr¬   Úis_encoder_decoderr
   r	   Úget_seq_lengthr`   Ú_create_attention_masksr£   r¤   r   r«   )r;   rA   r¨   rB   rC   rD   rE   r©   rª   r«   r¬   r­   rF   r°   Úencoder_outputsÚsequence_outputÚpooled_outputs                    r>   ra   ÚErnieModel.forwardÀ   sy  € ð0 ˜Ð -°tÐ";×<ÜÐYÓZÐZà�;‰;×!×!Ø%.Ñ%:™	ÀÇÁ×@UÑ@U‰IàˆIæ˜Ñ0ð )Ñ4¸¿¹×8V×8Vô $¤L¸¿¹Ñ$DÄlÐZ^×ZeÑZeÑFfÔgä!¨¯©Ñ5ð ð FUÑE` ×!?Ñ!?Ô!AÐfgÐØŸ?™?ØØ%Ø)à'Ø'Ø#9ð +ð 
Ðð 26×1MÑ1MØ)Ø#9Ø-Ø"7Ø+ð 2Nð 2
Ñ.ˆð Ÿ,š,Øð	
à)Ø"7Ø#9Ø+ØØ%ñ	
ð ñ	
ˆð *¨!Ñ,ˆØ8<¿¹Ñ8O˜Ÿ™ OÔ4ÐUYˆä;Ø-Ø'Ø+×;Ñ;ñ
ð 	
r@   )r<   r`   r£   r¢   r¤   )T)
NNNNNNNNNN)rc   rd   re   rf   Ú_no_split_modulesr4   r   r   r   rR   rk   r   Úboolr   r   Útupler   ra   rl   rm   rn   s   @r>   rŸ   rŸ   °   s=  ø† Ø%˜Ð÷ð  ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø59Ø6:Ø(,Ø!%ñH
à—<‘< $Ñ&ðH
ð Ÿ™ tÑ+ðH
ð Ÿ™ tÑ+ð	H
ð
 —|‘| dÑ*ðH
ð —l‘l TÑ)ðH
ð —|‘| dÑ*ðH
ð  %Ÿ|™|¨dÑ2ðH
ð !&§¡¨tÑ 3ðH
ð  ™ðH
ð ˜$‘;ðH
ð Ð+Ñ,ðH
ð 
ˆu�|‰|Ñ	ÐKÑ	KôH
ó ó ó  öH
r@   rŸ   c                   ó   • \ rS rSrSrg)ÚErnieForPreTrainingOutputi  rr   Nrs   rr   r@   r>   rÀ   rÀ     rt   r@   rÀ   c                   ón  • \ rS rSrSSS.r\\        SS\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\	\
   S\\R                     \-  4S jj5       5       rSrg)ÚErnieForPreTrainingi  úcls.predictions.biasú'ernie.embeddings.word_embeddings.weight©zcls.predictions.decoder.biaszcls.predictions.decoder.weightNrA   r¨   rB   rC   rD   rE   ÚlabelsÚnext_sentence_labelr­   rG   c	           
      ó¢  • U R                   " U4UUUUUSS.U	D6n
U
SS u  p¼U R                  X¼5      u  pÞSnUbv  Ubs  [        5       nU" UR                  SU R                  R
                  5      UR                  S5      5      nU" UR                  SS5      UR                  S5      5      nUU-   n[        UUUU
R                  U
R                  S9$ )aj  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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]`
next_sentence_label (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the next sequence prediction (classification) loss. Input should be a sequence
    pair (see `input_ids` docstring) Indices should be in `[0, 1]`:

    - 0 indicates sequence B is a continuation of sequence A,
    - 1 indicates sequence B is a random sequence.

Example:

```python
>>> from transformers import AutoTokenizer, ErnieForPreTraining
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("nghuyong/ernie-1.0-base-zh")
>>> model = ErnieForPreTraining.from_pretrained("nghuyong/ernie-1.0-base-zh")

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

>>> prediction_logits = outputs.prediction_logits
>>> seq_relationship_logits = outputs.seq_relationship_logits
```
T©r¨   rB   rC   rD   rE   Úreturn_dictNr   rI   )ÚlossÚprediction_logitsÚseq_relationship_logitsrˆ   r‰   )	r‡   Úclsr   Úviewr<   Ú
vocab_sizerÀ   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   rÆ   rÇ   r­   Úoutputsr¹   rº   Úprediction_scoresÚseq_relationship_scoreÚ
total_lossÚloss_fctÚmasked_lm_lossÚnext_sentence_losss                      r>   ra   ÚErnieForPreTraining.forward  sþ   € ð^ —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð *1°°!¨Ñ&ˆØ48·H±H¸_Ó4\Ñ1Ðàˆ
ØÑÐ"5Ñ"AÜ'Ó)ˆHÙ%Ð&7×&<Ñ&<¸RÀÇÁ×AWÑAWÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNÙ!)Ð*@×*EÑ*EÀbÈ!Ó*LÐNa×NfÑNfÐgiÓNjÓ!kÐØ'Ð*<Ñ<ˆJä(ØØ/Ø$:Ø!×/Ñ/Ø×)Ñ)ñ
ð 	
r@   rr   ©NNNNNNNN)rc   rd   re   rf   Ú_tied_weights_keysr   r   rR   rk   r   r   r¾   rÀ   ra   rl   rr   r@   r>   rÂ   rÂ     s  † à(>Ø*SñÐð
 Øð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø&*Ø37ñH
à—<‘< $Ñ&ðH
ð Ÿ™ tÑ+ðH
ð Ÿ™ tÑ+ð	H
ð
 —|‘| dÑ*ðH
ð —l‘l TÑ)ðH
ð —|‘| dÑ*ðH
ð —‘˜tÑ#ðH
ð #Ÿ\™\¨DÑ0ðH
ð Ð+Ñ,ðH
ð 
ˆu�|‰|Ñ	Ð8Ñ	8ôH
ó ó óH
r@   rÂ   c                    óÖ  • \ rS rSr\\            SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\R                  S-  S\\R                     S-  S\	S-  S\
\R                  -  S\\   S\\R                     \-  4S jj5       5       rSrg)ÚErnieForCausalLMie  NrA   r¨   rB   rC   rD   rE   r©   rª   rÆ   r«   r¬   Úlogits_to_keepr­   rG   c                 ó¦  • U	b  SnU R                   " U4UUUUUUUU
USS.
UD6nUR                  n[        U[        5      (       a  [	        U* S5      OUnU R                  USS2USS24   5      nSnU	b)  U R                  " SUX�R                  R                  S.UD6n[        UUUR                  UR                  UR                  UR                  S9$ )aA  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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]`
NFT)
r¨   rB   rC   rD   rE   r©   rª   r«   r¬   rÊ   )ÚlogitsrÆ   rÐ   )rË   rß   r«   rˆ   r‰   rŠ   rr   )r‡   r±   r�   rj   ÚslicerÎ   Úloss_functionr<   rÐ   r   r«   rˆ   r‰   rŠ   )r;   rA   r¨   rB   rC   rD   rE   r©   rª   rÆ   r«   r¬   rÝ   r­   rÑ   rˆ   Úslice_indicesrß   rË   s                      r>   ra   ÚErnieForCausalLM.forwardf  sü   € ð: ÑØˆIà@DÇ
Â
ØðA
à)Ø)Ø'Ø%Ø'Ø"7Ø#9Ø+ØØñA
ð ñA
ˆð  ×1Ñ1ˆä8BÀ>ÔSV×8WÑ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜-ª¨=º!Ð(;Ñ<Ó=ˆàˆØÑØ×%Ò%Ðp¨V¸FÏ{É{×OeÑOeÑpÐioÑpˆDä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ñ
ð 	
r@   rr   )NNNNNNNNNNNr   )rc   rd   re   rf   r   r   rR   rk   Úlistr½   rj   r   r   r¾   r   ra   rl   rr   r@   r>   rÜ   rÜ   e  sM  † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø59Ø6:Ø&*Ø59Ø!%Ø-.ñ=
à—<‘< $Ñ&ð=
ð Ÿ™ tÑ+ð=
ð Ÿ™ tÑ+ð	=
ð
 —|‘| dÑ*ð=
ð —l‘l TÑ)ð=
ð —|‘| dÑ*ð=
ð  %Ÿ|™|¨dÑ2ð=
ð !&§¡¨tÑ 3ð=
ð —‘˜tÑ#ð=
ð ˜eŸl™lÑ+¨dÑ2ð=
ð ˜$‘;ð=
ð ˜eŸl™lÑ*ð=
ð Ð+Ñ,ð=
ð 
ˆu�|‰|Ñ	Ð@Ñ	@ô=
ó ó ó=
r@   rÜ   c                   óŽ  • \ rS rSrSSS.r\\         SS\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\	\
   S\\R                     \-  4S jj5       5       rSrg)ÚErnieForMaskedLMi¨  rÃ   rÄ   rÅ   NrA   r¨   rB   rC   rD   rE   r©   rª   rÆ   r­   rG   c
                 ó<  • U R                   " U4UUUUUUUSS.U
D6nUS   nU R                  U5      nSnU	bF  [        5       nU" UR                  SU R                  R
                  5      U	R                  S5      5      n[        UUUR                  UR                  S9$ )a#  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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¨   rB   rC   rD   rE   r©   rª   rÊ   r   NrI   ©rË   rß   rˆ   r‰   )	r‡   rÎ   r   rÏ   r<   rÐ   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   r©   rª   rÆ   r­   rÑ   r¹   rÒ   rÖ   rÕ   s                   r>   ra   ÚErnieForMaskedLM.forward®  s¿   € ð4 —*’*Øð
à)Ø)Ø'Ø%Ø'Ø"7Ø#9Øñ
ð ñ
ˆð " !™*ˆØ ŸH™H _Ó5ÐàˆØÑÜ'Ó)ˆHÙ%Ð&7×&<Ñ&<¸RÀÇÁ×AWÑAWÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNäØØ$Ø!×/Ñ/Ø×)Ñ)ñ	
ð 	
r@   rr   )	NNNNNNNNN)rc   rd   re   rf   rÚ   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   ræ   ræ   ¨  s  † à(>Ø*SñÐð
 Øð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø59Ø6:Ø&*ñ2
à—<‘< $Ñ&ð2
ð Ÿ™ tÑ+ð2
ð Ÿ™ tÑ+ð	2
ð
 —|‘| dÑ*ð2
ð —l‘l TÑ)ð2
ð —|‘| dÑ*ð2
ð  %Ÿ|™|¨dÑ2ð2
ð !&§¡¨tÑ 3ð2
ð —‘˜tÑ#ð2
ð Ð+Ñ,ð2
ð 
ˆu�|‰|Ñ	˜~Ñ	-ô2
ó ó ó2
r@   ræ   c                   óD  • \ rS rSr\\       SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\\	   S\
\R                     \-  4S jj5       5       rSrg)ÚErnieForNextSentencePredictioniå  NrA   r¨   rB   rC   rD   rE   rÆ   r­   rG   c           
      ó  • U R                   " U4UUUUUSS.UD6n	U	S   n
U R                  U
5      nSnUb2  [        5       nU" UR                  SS5      UR                  S5      5      n[	        UUU	R
                  U	R                  S9$ )aÇ  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the next sequence prediction (classification) loss. Input should be a sequence pair
    (see `input_ids` docstring). Indices should be in `[0, 1]`:

    - 0 indicates sequence B is a continuation of sequence A,
    - 1 indicates sequence B is a random sequence.

Example:

```python
>>> from transformers import AutoTokenizer, ErnieForNextSentencePrediction
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("nghuyong/ernie-1.0-base-zh")
>>> model = ErnieForNextSentencePrediction.from_pretrained("nghuyong/ernie-1.0-base-zh")

>>> prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
>>> next_sentence = "The sky is blue due to the shorter wavelength of blue light."
>>> encoding = tokenizer(prompt, next_sentence, return_tensors="pt")

>>> outputs = model(**encoding, labels=torch.LongTensor([1]))
>>> logits = outputs.logits
>>> assert logits[0, 0] < logits[0, 1]  # next sentence was random
```
TrÉ   r-   NrI   r   rè   )r‡   rÎ   r   rÏ   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   rÆ   r­   rÑ   rº   Úseq_relationship_scoresr×   rÕ   s                 r>   ra   Ú&ErnieForNextSentencePrediction.forwardæ  s®   € ðZ —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð   ™
ˆà"&§(¡(¨=Ó"9Ðà!ÐØÑÜ'Ó)ˆHÙ!)Ð*A×*FÑ*FÀrÈ1Ó*MÈvÏ{É{Ð[]ËÓ!_Ðä*Ø#Ø*Ø!×/Ñ/Ø×)Ñ)ñ	
ð 	
r@   rr   ©NNNNNNN)rc   rd   re   rf   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   rë   rë   å  sê   † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø&*ñD
à—<‘< $Ñ&ðD
ð Ÿ™ tÑ+ðD
ð Ÿ™ tÑ+ð	D
ð
 —|‘| dÑ*ðD
ð —l‘l TÑ)ðD
ð —|‘| dÑ*ðD
ð —‘˜tÑ#ðD
ð Ð+Ñ,ðD
ð 
ˆu�|‰|Ñ	Ð:Ñ	:ôD
ó ó óD
r@   rë   c                   óD  • \ rS rSr\\       SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\\	   S\
\R                     \-  4S jj5       5       rSrg)ÚErnieForSequenceClassificationi/  NrA   r¨   rB   rC   rD   rE   rÆ   r­   rG   c           
      óì  • U R                   " U4UUUUUSS.UD6n	U	S   n
U R                  U
5      n
U R                  U
5      nSnUGbŽ  U R                  R                  c‘  U R
                  S:X  a  SU R                  l        OoU R
                  S:”  aN  UR                  [        R                  :X  d  UR                  [        R                  :X  a  SU R                  l        OSU R                  l        U R                  R                  S:X  aI  [        5       nU R
                  S:X  a&  U" UR                  5       UR                  5       5      nOŒU" X·5      nOƒU R                  R                  S:X  a=  [        5       nU" UR                  SU R
                  5      UR                  S5      5      nO,U R                  R                  S:X  a  [        5       nU" X·5      n[        UUU	R                   U	R"                  S	9$ )
a  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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).
TrÉ   r-   NÚ
regressionÚsingle_label_classificationÚmulti_label_classificationrI   rè   )r‡   r[   Ú
classifierr<   Úproblem_typeÚ
num_labelsrL   rR   rU   rj   r   Úsqueezer   rÏ   r   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   rÆ   r­   rÑ   rº   rß   rË   rÕ   s                 r>   ra   Ú&ErnieForSequenceClassification.forward0  s¦  € ð0 —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð   ™
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÒØ�{‰{×'Ñ'Ñ/Ø—?‘? 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Ó3‘DØ—‘×)Ñ)Ð-JÓJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÓIÜ,Ó.�Ù Ó/�ä'ØØØ!×/Ñ/Ø×)Ñ)ñ	
ð 	
r@   rr   rï   )rc   rd   re   rf   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   rñ   rñ   /  sê   † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø&*ñB
à—<‘< $Ñ&ðB
ð Ÿ™ tÑ+ðB
ð Ÿ™ tÑ+ð	B
ð
 —|‘| dÑ*ðB
ð —l‘l TÑ)ðB
ð —|‘| dÑ*ðB
ð —‘˜tÑ#ðB
ð Ð+Ñ,ðB
ð 
ˆu�|‰|Ñ	Ð7Ñ	7ôB
ó ó óB
r@   rñ   c                   óD  • \ rS rSr\\       SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\\	   S\
\R                     \-  4S jj5       5       rSrg)ÚErnieForMultipleChoiceiw  NrA   r¨   rB   rC   rD   rE   rÆ   r­   rG   c           
      óô  • Ub  UR                   S   OUR                   S   n	Ub!  UR                  SUR                  S5      5      OSnUb!  UR                  SUR                  S5      5      OSnUb!  UR                  SUR                  S5      5      OSnUb!  UR                  SUR                  S5      5      OSnUb1  UR                  SUR                  S5      UR                  S5      5      OSnU R                  " U4UUUUUSS.UD6n
U
S   nU R	                  U5      nU R                  U5      nUR                  SU	5      nSnUb  [        5       nU" X×5      n[        UUU
R                  U
R                  S9$ )aQ  
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.

    [What are token type IDs?](../glossary#token-type-ids)
task_type_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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.
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)
Nr-   rI   éþÿÿÿTrÉ   rè   )
rQ   rÏ   rN   r‡   r[   rö   r   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   rÆ   r­   Únum_choicesrÑ   rº   rß   Úreshaped_logitsrË   rÕ   s                   r>   ra   ÚErnieForMultipleChoice.forwardx  s�  € ð` -6Ñ,A�i—o‘o aÒ(À}×GZÑGZÐ[\ÑG]ˆà>GÑ>S�I—N‘N 2 y§~¡~°bÓ'9Ô:ÐY]ˆ	ØM[ÑMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØM[ÑMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØGSÑG_�|×(Ñ(¨¨\×->Ñ->¸rÓ-BÔCÐeiˆð Ñ(ð ×Ñ˜r =×#5Ñ#5°bÓ#9¸=×;MÑ;MÈbÓ;QÔRàð 	ð —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð   ™
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆØ Ÿ+™+ b¨+Ó6ˆàˆØÑÜ'Ó)ˆHÙ˜OÓ4ˆDä(ØØ"Ø!×/Ñ/Ø×)Ñ)ñ	
ð 	
r@   rr   rï   )rc   rd   re   rf   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   rü   rü   w  sê   † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø&*ñU
à—<‘< $Ñ&ðU
ð Ÿ™ tÑ+ðU
ð Ÿ™ tÑ+ð	U
ð
 —|‘| dÑ*ðU
ð —l‘l TÑ)ðU
ð —|‘| dÑ*ðU
ð —‘˜tÑ#ðU
ð Ð+Ñ,ðU
ð 
ˆu�|‰|Ñ	Ð8Ñ	8ôU
ó ó óU
r@   rü   c                   óD  • \ rS rSr\\       SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\\	   S\
\R                     \-  4S jj5       5       rSrg)ÚErnieForTokenClassificationiÒ  NrA   r¨   rB   rC   rD   rE   rÆ   r­   rG   c           
      óF  • U R                   " U4UUUUUSS.UD6n	U	S   n
U R                  U
5      n
U R                  U
5      nSnUb<  [        5       nU" UR	                  SU R
                  5      UR	                  S5      5      n[        UUU	R                  U	R                  S9$ )al  
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Task type embedding is a special embedding to represent the characteristic of different tasks, such as
    word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training task. We
    assign a `task_type_id` to each task and the `task_type_id` is in the range `[0,
    config.task_type_vocab_size-1]
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   NrI   rè   )	r‡   r[   rö   r   rÏ   rø   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   rÆ   r­   rÑ   r¹   rß   rË   rÕ   s                 r>   ra   Ú#ErnieForTokenClassification.forwardÓ  s¸   € ð, —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð " !™*ˆàŸ,™, Ó7ˆØ—‘ Ó1ˆàˆØÑÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDä$ØØØ!×/Ñ/Ø×)Ñ)ñ	
ð 	
r@   rr   rï   )rc   rd   re   rf   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   r  r  Ò  sß   † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø&*ñ.
à—<‘< $Ñ&ð.
ð Ÿ™ tÑ+ð.
ð Ÿ™ tÑ+ð	.
ð
 —|‘| dÑ*ð.
ð —l‘l TÑ)ð.
ð —|‘| dÑ*ð.
ð —‘˜tÑ#ð.
ð Ð+Ñ,ð.
ð 
ˆu�|‰|Ñ	Ð4Ñ	4ô.
ó ó ó.
r@   r  c                   ód  • \ rS rSr\\        SS\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S\R                  S-  S	\R                  S-  S
\R                  S-  S\\	   S\
\R                     \-  4S jj5       5       rSrg)ÚErnieForQuestionAnsweringi  NrA   r¨   rB   rC   rD   rE   Ústart_positionsÚend_positionsr­   rG   c	           
      ó¸  • U R                   " U4UUUUUSS.U	D6n
U
S   nU R                  U5      nUR                  SSS9u  pÞUR                  S5      R	                  5       nUR                  S5      R	                  5       nSnUbµ  Ub²  [        UR                  5       5      S:”  a  UR                  S5      n[        UR                  5       5      S:”  a  UR                  S5      nUR                  S5      nUR                  SU5      nUR                  SU5      n[        US9nU" X×5      nU" Xè5      nUU-   S	-  n[        UUUU
R                  U
R                  S
9$ )r¯   TrÉ   r   r-   rI   )rJ   N)Úignore_indexr   )rË   Ústart_logitsÚ
end_logitsrˆ   r‰   )r‡   Ú
qa_outputsÚsplitrù   Ú
contiguousÚlenrN   Úclampr   r   rˆ   r‰   )r;   rA   r¨   rB   rC   rD   rE   r  r	  r­   rÑ   r¹   rß   r  r  rÔ   Úignored_indexrÕ   Ú
start_lossÚend_losss                       r>   ra   Ú!ErnieForQuestionAnswering.forward  s{  € ð* —*’*Øð	
à)Ø)Ø'Ø%Ø'Øñ	
ð ñ	
ˆð " !™*ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ð#:Ñ ˆØ#×+Ñ+¨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Ù 
Ó:ˆHØ$ xÑ/°1Ñ4ˆJä+ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ñ
ð 	
r@   rr   rÙ   )rc   rd   re   rf   r   r   rR   rk   r   r   r¾   r   ra   rl   rr   r@   r>   r  r    sõ   † ØØð *.Ø.2Ø.2Ø-1Ø,0Ø-1Ø/3Ø-1ñ<
à—<‘< $Ñ&ð<
ð Ÿ™ tÑ+ð<
ð Ÿ™ tÑ+ð	<
ð
 —|‘| dÑ*ð<
ð —l‘l TÑ)ð<
ð —|‘| dÑ*ð<
ð Ÿ™¨Ñ,ð<
ð —|‘| dÑ*ð<
ð Ð+Ñ,ð<
ð 
ˆu�|‰|Ñ	Ð;Ñ	;ô<
ó ó ó<
r@   r  )
rÜ   ræ   rü   rë   rÂ   r  rñ   r  rŸ   r…   )Nrg   rR   Útorch.nnr6   r   r   r   Ú r   rŽ   Úcache_utilsr   r	   r
   Úmodeling_outputsr   r   r   r   r   r   r   r   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   r   Úutils.output_capturingr   Úbert.modeling_bertr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   Úconfiguration_ernier.   Ú
get_loggerrc   Úloggerr0   rp   rv   ry   r|   r   r‚   r…   rŸ   rÀ   rÂ   rÜ   ræ   rë   rñ   rü   r  r  Ú__all__rr   r@   r>   Ú<module>r%     s€  ðñ ã Ý ß AÑ Aå &ß CÑ C÷	÷ 	ó 	õ .Ý &ß @Ñ @ß IÝ 5÷÷ ÷ ÷ õ õ& -ð 
×	Ò	˜HÓ	%€ô=�nô =ô@	Ð*ô 	ô	Ð,ô 	ô	�ô 	ô	�*ô 	ô	Ð0ô 	ô	�;ô 	ð ô/˜?ó /ó ð/ô2[
�ô [
ô|	Ð 8ô 	ôP
Ð,ô P
ôf@
�ô @
ôF:
�ô :
ôzG
Ð%Bô G
ôTE
Ð%Bô E
ôPX
Ð2ô X
ôv1
Ð"<ô 1
ôh?
Ð 8ô ?
òD�r@   