Ë
    T^(h‡l ã                   óÊ  — d Z ddlZddlmZ ddlmZmZmZm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mZmZmZmZ ddlmZ ddlmZmZmZmZm Z m!Z! ddl"m#Z#  e jH                  e%«      Z&dZ'dZ(d@d„Z)d„ Z* G d„ de
jV                  «      Z, G d„ de
jV                  «      Z- G d„ de
jV                  «      Z. G d„ de«      Z/e G d„ de«      «       Z0e G d„ de«      «       Z1e G d„ d e«      «       Z2e G d!„ d"e«      «       Z3e G d#„ d$e«      «       Z4e G d%„ d&e«      «       Z5e G d'„ d(e«      «       Z6d)Z7d*Z8 ed+e7«       G d,„ d-e/«      «       Z9 ed.e7«       G d/„ d0e/e«      «       Z: ed1e7«       G d2„ d3e/«      «       Z; ed4e7«       G d5„ d6e/«      «       Z< ed7e7«       G d8„ d9e/«      «       Z= ed:e7«       G d;„ d<e/«      «       Z> ed:e7«       G d=„ d>e/«      «       Z?g d?¢Z@y)Az
PyTorch XLNet model.
é    N)Ú	dataclass)ÚListÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚGenerationMixin)ÚPoolerAnswerClassÚPoolerEndLogitsÚPoolerStartLogitsÚPreTrainedModelÚSequenceSummary)Úapply_chunking_to_forward)ÚModelOutputÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚXLNetConfigzxlnet/xlnet-base-casedr   c                 ó"  — i }t        | d«      rÿt        | d«      r| j                  j                  |d<   t        | d«      rJd|v rF| j                  j                  j
                  |d<   | j                  j                  j                  |d<   t        | d«      rl|j                  �`d|j                  › d	�|v rN| j                  j
                  |d|j                  › d	�<   | j                  j                  |d|j                  › d
�<   | j                  } |j                  | j                  j
                  | j                  dœ«       t        | j                  «      D �]²  \  }}d|› d�}|j                  |dz   |j                  j                  j
                  |dz   |j                  j                  j                  |dz   |j                  j                   |dz   |j                  j"                  |dz   |j                  j$                  |dz   |j                  j&                  |dz   |j                  j(                  |dz   |j*                  j                  j
                  |dz   |j*                  j                  j                  |dz   |j*                  j,                  j
                  |dz   |j*                  j,                  j                  |dz   |j*                  j.                  j
                  |dz   |j*                  j.                  j                  i«       �Œµ |j0                  r®g }g }g }	g }
| j                  D ]–  }|j3                  |j                  j4                  «       |j3                  |j                  j6                  «       |	j3                  |j                  j8                  «       |
j3                  |j                  j:                  «       Œ˜ n4| j4                  g}| j6                  g}| j8                  g}	| j:                  g}
|j                  |||	|
dœ«       |S )z�
    A map of modules from TF to PyTorch. I use a map to keep the PyTorch model as identical to the original PyTorch
    model as possible.
    ÚtransformerÚlm_losszmodel/lm_loss/biasÚsequence_summaryz%model/sequnece_summary/summary/kernelz#model/sequnece_summary/summary/biasÚlogits_projzmodel/regression_z/logit/kernelz/logit/bias)z-model/transformer/word_embedding/lookup_tablez#model/transformer/mask_emb/mask_embzmodel/transformer/layer_ú/zrel_attn/LayerNorm/gammazrel_attn/LayerNorm/betazrel_attn/o/kernelzrel_attn/q/kernelzrel_attn/k/kernelzrel_attn/r/kernelzrel_attn/v/kernelzff/LayerNorm/gammazff/LayerNorm/betazff/layer_1/kernelzff/layer_1/biaszff/layer_2/kernelzff/layer_2/bias)zmodel/transformer/r_r_biaszmodel/transformer/r_w_biaszmodel/transformer/r_s_biaszmodel/transformer/seg_embed)Úhasattrr   Úbiasr    ÚsummaryÚweightÚfinetuning_taskr!   r   ÚupdateÚword_embeddingÚmask_embÚ	enumerateÚlayerÚrel_attnÚ
layer_normÚoÚqÚkÚrÚvÚffÚlayer_1Úlayer_2Úuntie_rÚappendÚr_r_biasÚr_w_biasÚr_s_biasÚ	seg_embed)ÚmodelÚconfigÚ
tf_weightsÚtf_to_pt_mapÚiÚbÚ	layer_strÚr_r_listÚr_w_listÚr_s_listÚseg_embed_lists              úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/xlnet/modeling_xlnet.pyÚbuild_tf_xlnet_to_pytorch_maprI   1   s�  € ð €Läˆu�mÔ$Ü�5˜)Ô$à16·±×1CÑ1CˆLÐ-Ñ.Ü�5Ð,Ô-Ð2YÐ]gÑ2gàDI×DZÑDZ×DbÑDb×DiÑDiˆLÐ@ÑAØBG×BXÑBX×B`ÑB`×BeÑBeˆLÐ>Ñ?ä�E˜=Ô)Ø×&Ñ&Ð2Ø# F×$:Ñ$:Ð#;¸=ÐIÈZÑWàV[×VgÑVg×VnÑVnˆLÐ,¨V×-CÑ-CÐ,DÀMÐRÑSØTY×TeÑTe×TjÑTjˆLÐ,¨V×-CÑ-CÐ,DÀKÐPÑQð ×!Ñ!ˆð ×Ñà=B×=QÑ=Q×=XÑ=XØ38·>±>ñ	
ôô ˜%Ÿ+™+Ó&ó 
‰ˆˆ1Ø.¨q¨c°Ð3ˆ	Ø×ÑàÐ6Ñ6¸¿
¹
×8MÑ8M×8TÑ8TØÐ5Ñ5°q·z±z×7LÑ7L×7QÑ7QØÐ/Ñ/°·±·±ØÐ/Ñ/°·±·±ØÐ/Ñ/°·±·±ØÐ/Ñ/°·±·±ØÐ/Ñ/°·±·±ØÐ0Ñ0°!·$±$·/±/×2HÑ2HØÐ/Ñ/°·±·±×1EÑ1EØÐ/Ñ/°·±·±×1DÑ1DØÐ-Ñ-¨q¯t©t¯|©|×/@Ñ/@ØÐ/Ñ/°·±·±×1DÑ1DØÐ-Ñ-¨q¯t©t¯|©|×/@Ñ/@ðö	
ð
ð* ‡~‚~ØˆØˆØˆØˆØ—‘ò 	8ˆAØ�O‰O˜AŸJ™J×/Ñ/Ô0Ø�O‰O˜AŸJ™J×/Ñ/Ô0Ø�O‰O˜AŸJ™J×/Ñ/Ô0Ø×!Ñ! !§*¡*×"6Ñ"6Õ7ñ		8ð —N‘NÐ#ˆØ—N‘NÐ#ˆØ—N‘NÐ#ˆØŸ/™/Ð*ˆØ×Ñà*2Ø*2Ø*2Ø+9ñ		
ôð Ðó    c                 ó¾  — 	 ddl }ddl}|j
                  j                  |«      }i }|D ]A  \  }}t        j                  d|› d|› �«       |j
                  j                  ||«      }	|	||<   ŒC t        | ||«      }
|
j                  «       D �]ý  \  }}t        j                  d|› �«       ||vrt        j                  |› d�«       Œ<||   }	d|v r2d	|v sd
|v sd|v r&t        j                  d«       |j                  |	«      }	t        |t        «      rÌt        |«      |	j                  d   k(  s$J dt        |«      › d|	j                  d   › d�«       ‚t!        |«      D ]~  \  }}|	|df   }	 |j                  |j                  k(  s"J d|j                  › d|j                  › d�«       ‚	 t        j                  d|› d|› �«       t'        j(                  |«      |_        Œ€ no	 |j                  |	j                  k(  s"J d|j                  › d|	j                  › d�«       ‚	 t        j                  d|› �«       t'        j(                  |	«      |_        |j-                  |d«       |j-                  |dz   d«       |j-                  |dz   d«       �Œ  t        j                  ddj/                  |j1                  «       «      › �«       | S # t        $ r t        j	                  d«       ‚ w xY w# t"        $ r1}|xj$                  |j                  |j                  fz  c_        ‚ d}~ww xY w# t"        $ r1}|xj$                  |j                  |	j                  fz  c_        ‚ d}~ww xY w)z&Load tf checkpoints in a pytorch modelr   NzšLoading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.zLoading TF weight z with shape z
Importing z( not in tf pre-trained weights, skippingÚkernelr4   r%   ÚlogitÚTransposingzPointer length z and array length z mismatched.zPointer shape z and array shape zInitialize PyTorch weight z for layer z/Adamz/Adam_1z%Weights not copied to PyTorch model: z, )ÚnumpyÚ
tensorflowÚImportErrorÚloggerÚerrorÚtrainÚlist_variablesÚinfoÚload_variablerI   ÚitemsÚ	transposeÚ
isinstanceÚlistÚlenÚshaper+   ÚAssertionErrorÚargsÚtorchÚ
from_numpyÚdataÚpopÚjoinÚkeys)r=   r>   Útf_pathÚnpÚtfÚ	init_varsr?   Únamer]   Úarrayr@   ÚpointerrA   Úp_iÚarr_iÚes                   rH   Úload_tf_weights_in_xlnetrp   „   sC  € ðÛÛð —‘×'Ñ'¨Ó0€IØ€JØ ò !‰ˆˆeÜ�‰Ð(¨¨¨l¸5¸'ÐBÔCØ—‘×&Ñ& w°Ó5ˆØ ˆ
�4Òð!ô 1°¸À
ÓK€Là%×+Ñ+Ó-ó '/‰ˆˆgÜ�‰�j  Ð'Ô(Ø�zÑ!Ü�K‰K˜4˜&Ð HÐIÔJØØ˜4Ñ ˆð �tÑ ¨¡°¸dÑ1BÀgÐQUÁoÜ�K‰K˜Ô&Ø—L‘L Ó'ˆEÜ�gœtÔ$ä�w“< 5§;¡;¨q¡>Ò1ð Ø!¤# g£, Ð/AÀ%Ç+Á+ÈaÁ.ÐAQÐQ\Ð]óÐ1ô $ GÓ,ò 
3‘��3Ø˜a ˜f™�ðØŸ9™9¨¯©Ò3ð Ø(¨¯©¨Ð3DÀUÇ[Á[ÀMÐQ\Ð]óÑ3ô —‘Ð8¸¸¸kÈ!ÈÐMÔNÜ ×+Ñ+¨EÓ2�•ñ
3ðØ—}‘}¨¯©Ò3ð Ø$ W§]¡] OÐ3DÀUÇ[Á[ÀMÐQ\Ð]óÑ3ô �K‰KÐ4°T°FÐ;Ô<Ü ×+Ñ+¨EÓ2ˆGŒLØ�‰�t˜TÔ"Ø�‰�t˜g‘~ tÔ,Ø�‰�t˜iÑ'¨Ö.ðO'/ôR ‡K�KÐ7¸¿	¹	À*Ç/Á/ÓBSÓ8TÐ7UÐVÔWØ€Løôw ò Ü�‰ðQô	
ð 	ðûôN &ò Ø—F’F˜sŸy™y¨%¯+©+Ð6Ñ6•FØûðûô "ò Ø—’˜7Ÿ=™=¨%¯+©+Ð6Ñ6•Øûðús;   ‚K Å);K%Ç;L"Ë K"Ë%	LË.,LÌLÌ"	MÌ+,MÍMc                   óp   ‡ — e Zd Zˆ fd„Zd„ Zedd„«       Zedd„«       Z	 	 	 	 d	d„Zd
d„Z		 	 	 	 d	d„Z
ˆ xZS )ÚXLNetRelativeAttentionc                 óô  •— t         ‰| �  «        |j                  |j                  z  dk7  r%t	        d|j                  › d|j                  › �«      ‚|j                  | _        |j
                  | _        |j                  | _        d|j
                  dz  z  | _        t        j                  t        j                  |j                  | j                  | j
                  «      «      | _        t        j                  t        j                  |j                  | j                  | j
                  «      «      | _        t        j                  t        j                  |j                  | j                  | j
                  «      «      | _        t        j                  t        j                  |j                  | j                  | j
                  «      «      | _        t        j                  t        j                  |j                  | j                  | j
                  «      «      | _        t        j                  t        j                  | j                  | j
                  «      «      | _        t        j                  t        j                  | j                  | j
                  «      «      | _        t        j                  t        j                  | j                  | j
                  «      «      | _        t        j                  t        j                  d| j                  | j
                  «      «      | _        t        j(                  |j                  |j*                  ¬«      | _        t        j.                  |j0                  «      | _        y )Nr   zThe hidden size (z6) is not a multiple of the number of attention heads (r   ç      à?é   ©Úeps)ÚsuperÚ__init__Úd_modelÚn_headÚ
ValueErrorÚd_headÚscaler   Ú	Parameterr`   ÚFloatTensorr0   r1   r3   r/   r2   r9   r;   r:   r<   Ú	LayerNormÚlayer_norm_epsr.   ÚDropoutÚdropout©Úselfr>   Ú	__class__s     €rH   ry   zXLNetRelativeAttention.__init__È   s$  ø€ Ü‰ÑÔà�>‰>˜FŸM™MÑ)¨QÒ.ÜØ# F§N¡NÐ#3ð 4Ø Ÿ-™-˜ð*óð ð
 —m‘mˆŒØ—m‘mˆŒØ—~‘~ˆŒØ˜&Ÿ-™-¨Ñ,Ñ-ˆŒ
ä—‘œe×/Ñ/°·±ÀÇÁÈTÏ[É[ÓYÓZˆŒÜ—‘œe×/Ñ/°·±ÀÇÁÈTÏ[É[ÓYÓZˆŒÜ—‘œe×/Ñ/°·±ÀÇÁÈTÏ[É[ÓYÓZˆŒÜ—‘œe×/Ñ/°·±ÀÇÁÈTÏ[É[ÓYÓZˆŒÜ—‘œe×/Ñ/°·±ÀÇÁÈTÏ[É[ÓYÓZˆŒäŸ™¤U×%6Ñ%6°t·{±{ÀDÇKÁKÓ%PÓQˆŒÜŸ™¤U×%6Ñ%6°t·{±{ÀDÇKÁKÓ%PÓQˆŒÜŸ™¤U×%6Ñ%6°t·{±{ÀDÇKÁKÓ%PÓQˆŒÜŸ™¤e×&7Ñ&7¸¸4¿;¹;ÈÏÉÓ&TÓUˆŒäŸ,™, v§~¡~¸6×;PÑ;PÔQˆŒÜ—z‘z &§.¡.Ó1ˆ�rJ   c                 ó   — t         ‚©N©ÚNotImplementedError)r†   Úheadss     rH   Úprune_headsz"XLNetRelativeAttention.prune_headsä   ó   € Ü!Ð!rJ   c           	      ó@  — | j                   }| j                  |d   |d   |d   |d   «      } | dd…df   } | j                  |d   |d   dz
  |d   |d   «      } t        j                  | dt        j                  || j
                  t        j                  ¬«      «      } | S )z<perform relative shift to form the relative attention score.r   r   ru   r   N.©ÚdeviceÚdtype©r]   Úreshaper`   Úindex_selectÚaranger‘   Úlong©ÚxÚklenÚx_sizes      rH   Ú	rel_shiftz XLNetRelativeAttention.rel_shiftç   s–   € ð —‘ˆà�I‰I�f˜Q‘i ¨¡¨F°1©I°v¸a±yÓAˆØˆa‰b�#ˆg‰JˆØ�I‰I�f˜Q‘i ¨¡¨Q¡°°q±	¸6À!¹9ÓEˆä×Ñ˜q !¤U§\¡\°$¸q¿x¹xÌuÏzÉzÔ%ZÓ[ˆàˆrJ   c           	      óP  — | j                   }| j                  |d   |d   |d   |d   «      } | d d …d d …dd …d d …f   } | j                  |d   |d   |d   |d   dz
  «      } t        j                  | dt        j                  || j
                  t        j                  ¬«      «      } | S )Nr   r   r   ru   r�   r“   r˜   s      rH   Úrel_shift_bnijz%XLNetRelativeAttention.rel_shift_bnijô   sœ   € à—‘ˆà�I‰I�f˜Q‘i ¨¡¨F°1©I°v¸a±yÓAˆØŠa’�A‘Bšˆk‰NˆØ�I‰I�f˜Q‘i ¨¡¨F°1©I°v¸a±yÀ1±}ÓEˆô ×Ñ˜q !¤U§\¡\°$¸q¿x¹xÌuÏzÉzÔ%ZÓ[ˆð ˆrJ   c	                 ó@  — t        j                  d|| j                  z   |«      }	t        j                  d|| j                  z   |«      }
| j	                  |
|	j
                  d   ¬«      }
|€d}nEt        j                  d|| j                  z   | j                  «      }t        j                  d||«      }|	|
z   |z   | j                  z  }|�V|j                  t         j                  k(  r|dt        j                  d|«      z  z
  }n|d	t        j                  d|«      z  z
  }t        j                  j                  |d¬
«      }| j                  |«      }|�|t        j                  d|«      z  }t        j                  d||«      }|r|t        j                  d|«      fS |S )z.Core relative positional attention operations.zibnd,jbnd->bnijr   )rš   r   zibnd,snd->ibnszijbs,ibns->bnijiÜÿ  z
ijbn->bnijgêŒ 9Y>)F©Údimzbnij,jbnd->ibndz
bnij->ijbn)r`   Úeinsumr:   r9   rž   r]   r;   r<   r~   r’   Úfloat16r   Ú
functionalÚsoftmaxr„   )r†   Úq_headÚk_head_hÚv_head_hÚk_head_rÚseg_matÚ	attn_maskÚ	head_maskÚoutput_attentionsÚacÚbdÚefÚ
attn_scoreÚ	attn_probÚattn_vecs                  rH   Úrel_attn_corez$XLNetRelativeAttention.rel_attn_core  su  € ô �\‰\Ð+¨V°d·m±mÑ-CÀXÓNˆô �\‰\Ð+¨V°d·m±mÑ-CÀXÓNˆØ× Ñ  ¨"¯(©(°1©+Ð Ó6ˆð ˆ?Ø‰Bä—‘Ð.°¸¿¹Ñ0FÈÏÉÓWˆBÜ—‘Ð/°¸"Ó=ˆBð ˜2‘g ‘l d§j¡jÑ0ˆ
ØÐ à�‰¤%§-¡-Ò/Ø'¨%´%·,±,¸|ÈYÓ2WÑ*WÑW‘
à'¨$´·±¸lÈIÓ1VÑ*VÑV�
ô —M‘M×)Ñ)¨*¸!Ð)Ó<ˆ	Ø—L‘L Ó+ˆ	ð Ð Ø!¤E§L¡L°¸yÓ$IÑIˆIô —<‘<Ð 1°9¸hÓGˆáØœUŸ\™\¨,¸	ÓBÐBÐBàˆrJ   c                 óš   — t        j                  d|| j                  «      }| j                  |«      }|r||z   }| j	                  |«      }|S )zPost-attention processing.zibnd,hnd->ibh)r`   r¢   r/   r„   r.   )r†   Úhr³   ÚresidualÚattn_outÚoutputs         rH   Úpost_attentionz%XLNetRelativeAttention.post_attention7  sG   € ô —<‘< °¸4¿6¹6ÓBˆà—<‘< Ó)ˆÙØ !‘|ˆHØ—‘ Ó*ˆàˆrJ   c           
      ód  — |��”|�-|j                  «       dkD  rt        j                  ||gd¬«      }n|}t        j                  d|| j                  «      }t        j                  d|| j
                  «      }t        j                  d|| j                  «      }t        j                  d|| j                  «      }| j                  |||||||	|
¬«      }|
r|\  }}| j                  ||«      }t        j                  d|| j                  «      }|�Ot        j                  d||«      }| j                  |||||||	|
¬«      }|
r|\  }}t        j                  d||«      }n | j                  |||||||	|
¬«      }|
r|\  }}| j                  ||«      }|
�rf}�n|�-|j                  «       dkD  rt        j                  ||gd¬«      }n|}t        j                  d|| j                  «      }t        j                  d|| j                  «      }t        j                  d|| j
                  «      }t        j                  d|j                  | j                  j                  «      | j                  «      }| j                  |||||||	|
¬«      }|
r|\  }}| j                  ||«      }d }||f}|
r|fz   }|S )Nr   r   r    zibh,hnd->ibnd)rª   r«   r¬   r­   zmbnd,mlb->lbndzlbnd,mlb->mbnd)r¡   r`   Úcatr¢   r1   r3   r2   r0   r´   rº   Útyper’   )r†   r¶   ÚgÚattn_mask_hÚattn_mask_gr2   rª   ÚmemsÚtarget_mappingr¬   r­   r¼   r§   r¨   r©   Úq_head_hÚ
attn_vec_hÚattn_prob_hÚoutput_hÚq_head_gÚ
attn_vec_gÚattn_prob_gÚoutput_gr²   r³   Úoutputss                             rH   ÚforwardzXLNetRelativeAttention.forwardC  sÖ  € ð ‰=ð Ð D§H¡H£J°¢NÜ—i‘i  q 	¨qÔ1‘à�ô —|‘| O°S¸$¿&¹&ÓAˆHô —|‘| O°S¸$¿&¹&ÓAˆHô —|‘| O°Q¸¿¹Ó?ˆHô —|‘| O°Q¸¿¹Ó?ˆHð ×+Ñ+ØØØØØØ%Ø#Ø"3ð ,ó 	ˆJñ !Ø*4Ñ'�
˜Kð ×*Ñ*¨1¨jÓ9ˆHô —|‘| O°Q¸¿¹Ó?ˆHð Ð)Ü Ÿ<™<Ð(8¸(ÀNÓS�Ø!×/Ñ/ØØØØØ#Ø)Ø'Ø&7ð 0ó 	�
ñ %Ø.8Ñ+�J ä"Ÿ\™\Ð*:¸JÈÓW‘
à!×/Ñ/ØØØØØ#Ø)Ø'Ø&7ð 0ó 	�
ñ %Ø.8Ñ+�J ð ×*Ñ*¨1¨jÓ9ˆHâ Ø'¨Ð4’	ð Ð D§H¡H£J°¢NÜ—i‘i  q 	¨qÔ1‘à�ô —|‘| O°Q¸¿¹Ó?ˆHÜ—|‘| O°S¸$¿&¹&ÓAˆHÜ—|‘| O°S¸$¿&¹&ÓAˆHô —|‘| O°Q·V±V¸D¿F¹F¿L¹LÓ5IÈ4Ï6É6ÓRˆHð ×)Ñ)ØØØØØØ%Ø#Ø"3ð *ó 	ˆHñ !Ø&.Ñ#�˜)ð ×*Ñ*¨1¨hÓ7ˆHØˆHà˜XÐ&ˆÙØ  Ñ,ˆGØˆrJ   )éÿÿÿÿ©NNNF)T)Ú__name__Ú
__module__Ú__qualname__ry   r�   Ústaticmethodrœ   rž   r´   rº   rÌ   Ú__classcell__©r‡   s   @rH   rr   rr   Ç   sb   ø„ ô2ò8"ð ò
ó ð
ð òó ðð( ØØØó2óh
ð( ØØØ÷ErJ   rr   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚXLNetFeedForwardc                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  ¬«      | _        t        j                  |j                  |j                  «      | _	        t        j                  |j                  |j                  «      | _
        t        j                  |j                  «      | _        t        |j                  t        «      rt         |j                     | _        y |j                  | _        y )Nrv   )rx   ry   r   r�   rz   r‚   r.   ÚLinearÚd_innerr5   r6   rƒ   r„   rZ   Úff_activationÚstrr   Úactivation_functionr…   s     €rH   ry   zXLNetFeedForward.__init__Ì  s£   ø€ Ü‰ÑÔÜŸ,™, v§~¡~¸6×;PÑ;PÔQˆŒÜ—y‘y §¡°·±Ó@ˆŒÜ—y‘y §¡°·±Ó@ˆŒÜ—z‘z &§.¡.Ó1ˆŒÜ�f×*Ñ*¬CÔ0Ü'-¨f×.BÑ.BÑ'CˆDÕ$à'-×';Ñ';ˆDÕ$rJ   c                 óÜ   — |}| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }| j	                  ||z   «      }|S r‰   )r5   rÜ   r„   r6   r.   )r†   Úinpr¹   s      rH   rÌ   zXLNetFeedForward.forward×  sf   € ØˆØ—‘˜fÓ%ˆØ×)Ñ)¨&Ó1ˆØ—‘˜fÓ%ˆØ—‘˜fÓ%ˆØ—‘˜fÓ%ˆØ—‘ ¨#¡Ó.ˆØˆrJ   )rÏ   rÐ   rÑ   ry   rÌ   rÓ   rÔ   s   @rH   rÖ   rÖ   Ë  s   ø„ ô	<örJ   rÖ   c                   ó4   ‡ — e Zd Zˆ fd„Z	 	 	 	 dd„Zd„ Zˆ xZS )Ú
XLNetLayerc                 óÚ   •— t         ‰| �  «        t        |«      | _        t	        |«      | _        t        j                  |j                  «      | _        |j                  | _	        d| _
        y ©Nr   )rx   ry   rr   r-   rÖ   r4   r   rƒ   r„   Úchunk_size_feed_forwardÚseq_len_dimr…   s     €rH   ry   zXLNetLayer.__init__ã  sP   ø€ Ü‰ÑÔÜ.¨vÓ6ˆŒÜ" 6Ó*ˆŒÜ—z‘z &§.¡.Ó1ˆŒØ'-×'EÑ'EˆÔ$ØˆÕrJ   c                 ó  — | j                  |||||||||	|
¬«
      }|d d \  }}|�,t        | j                  | j                  | j                  |«      }t        | j                  | j                  | j                  |«      }||f|dd  z   }|S )N)rÁ   rÂ   r¬   r­   ru   )r-   r   Úff_chunkrã   rä   )r†   rÆ   rÊ   r¿   rÀ   r2   rª   rÁ   rÂ   r¬   r­   rË   s               rH   rÌ   zXLNetLayer.forwardë  s®   € ð —-‘-ØØØØØØØØ)ØØ/ð  ó 
ˆð % R a˜[Ñˆ�(àÐÜ0Ø—‘˜t×;Ñ;¸T×=MÑ=MÈxóˆHô -¨T¯]©]¸D×<XÑ<XÐZ^×ZjÑZjÐltÓuˆà˜XÐ&¨°°¨Ñ4ˆØˆrJ   c                 ó(   — | j                  |«      }|S r‰   )r4   )r†   Úoutput_xs     rH   ræ   zXLNetLayer.ff_chunk  s   € Ø—7‘7˜8Ó$ˆØˆrJ   rÎ   )rÏ   rÐ   rÑ   ry   rÌ   ræ   rÓ   rÔ   s   @rH   rà   rà   â  s!   ø„ ôð  ØØØó"öHrJ   rà   c                   ó"   — e Zd ZdZeZeZdZd„ Z	y)ÚXLNetPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    r   c           	      óò  — t        |t        j                  «      rm|j                  j                  j                  d| j                  j                  ¬«       |j                  �%|j                  j                  j                  «        yyt        |t        j                  «      rz|j                  j                  j                  d| j                  j                  ¬«       |j                  �2|j                  j                  |j                     j                  «        yyt        |t        j                  «      rJ|j                  j                  j                  «        |j                  j                  j                  d«       yt        |t        «      rœ|j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  f	D ]3  }|j                  j                  d| j                  j                  ¬«       Œ5 yt        |t0        «      r<|j2                  j                  j                  d| j                  j                  ¬«       yy)zInitialize the weights.g        )ÚmeanÚstdNç      ð?)rZ   r   rØ   r&   rb   Únormal_r>   Úinitializer_ranger$   Úzero_Ú	EmbeddingÚpadding_idxr�   Úfill_rr   r0   r1   r3   r/   r2   r9   r;   r:   r<   Ú
XLNetModelr*   )r†   ÚmoduleÚparams      rH   Ú_init_weightsz"XLNetPreTrainedModel._init_weights  s»  € ä�fœbŸi™iÔ(ð �M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)Ü˜Ô 6Ô7à—‘Ø—‘Ø—‘Ø—‘Ø—‘Ø—‘Ø—‘Ø—‘Ø× Ñ ð
ò P�ð —
‘
×"Ñ"¨°·±×1NÑ1NÐ"ÕOñPô ˜¤
Ô+Ø�O‰O× Ñ ×(Ñ(¨c°t·{±{×7TÑ7TÐ(ÕUð ,rJ   N)
rÏ   rÐ   rÑ   Ú__doc__r   Úconfig_classrp   Úload_tf_weightsÚbase_model_prefixrø   © rJ   rH   rê   rê     s   „ ñð
 €LØ.€OØ%ÐóVrJ   rê   c                   óÂ   — e Zd ZU dZej
                  ed<   dZee	ej
                        ed<   dZ
eeej
                  df      ed<   dZeeej
                  df      ed<   y)ÚXLNetModelOutputa@  
    Output type of [`XLNetModel`].

    Args:
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_predict, hidden_size)`):
            Sequence of hidden-states at the last layer of the model.

            `num_predict` corresponds to `target_mapping.shape[1]`. If `target_mapping` is `None`, then `num_predict`
            corresponds to `sequence_length`.
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Úlast_hidden_stateNrÁ   .Úhidden_statesÚ
attentions)rÏ   rÐ   rÑ   rù   r`   r€   Ú__annotations__rÁ   r   r   r  r   r  rý   rJ   rH   rÿ   rÿ   >  sm   … ñð4 ×(Ñ(Ó(Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   rÿ   c                   óô   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                        ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚXLNetLMHeadModelOutputa  
    Output type of [`XLNetLMHeadModel`].

    Args:
        loss (`torch.FloatTensor` of shape *(1,)*, *optional*, returned when `labels` is provided)
            Language modeling loss (for next-token prediction).
        logits (`torch.FloatTensor` of shape `(batch_size, num_predict, config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).

            `num_predict` corresponds to `target_mapping.shape[1]`. If `target_mapping` is `None`, then `num_predict`
            corresponds to `sequence_length`.
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    NÚlossÚlogitsrÁ   .r  r  ©rÏ   rÐ   rÑ   rù   r  r   r`   r€   r  r  rÁ   r   r  r   r  rý   rJ   rH   r  r  `  s‹   … ñð8 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   r  c                   óô   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                        ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	Ú$XLNetForSequenceClassificationOutputa_  
    Output type of [`XLNetForSequenceClassification`].

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `label` is provided):
            Classification (or regression if config.num_labels==1) loss.
        logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
            Classification (or regression if config.num_labels==1) scores (before SoftMax).
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr  r  rÁ   .r  r  r  rý   rJ   rH   r
  r
  …  ó‹   … ñð2 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   r
  c                   óô   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                        ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	Ú!XLNetForTokenClassificationOutputa%  
    Output type of [`XLNetForTokenClassificationOutput`].

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) :
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_labels)`):
            Classification scores (before SoftMax).
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr  r  rÁ   .r  r  r  rý   rJ   rH   r  r  §  r  rJ   r  c                   óô   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                        ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚXLNetForMultipleChoiceOutputad  
    Output type of [`XLNetForMultipleChoice`].

    Args:
        loss (`torch.FloatTensor` of shape *(1,)*, *optional*, returned when `labels` is provided):
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, num_choices)`):
            *num_choices* is the second dimension of the input tensors. (see *input_ids* above).

            Classification scores (before SoftMax).
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr  r  rÁ   .r  r  r  rý   rJ   rH   r  r  É  s‹   … ñð6 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   r  c                   ó  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeeej                        ed<   dZeeej                  df      ed<   dZeeej                  df      ed	<   y)
Ú%XLNetForQuestionAnsweringSimpleOutputaÙ  
    Output type of [`XLNetForQuestionAnsweringSimple`].

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.
        start_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length,)`):
            Span-start scores (before SoftMax).
        end_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length,)`):
            Span-end scores (before SoftMax).
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr  Ústart_logitsÚ
end_logitsrÁ   .r  r  )rÏ   rÐ   rÑ   rù   r  r   r`   r€   r  r  r  rÁ   r   r  r   r  rý   rJ   rH   r  r  í  s    … ñð6 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø04€L�(˜5×,Ñ,Ñ-Ó4Ø.2€J�˜×*Ñ*Ñ+Ó2Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   r  c                   ó”  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeeej                        ed	<   dZeeej                  d
f      ed<   dZeeej                  d
f      ed<   y)ÚXLNetForQuestionAnsweringOutputam  
    Output type of [`XLNetForQuestionAnswering`].

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned if both `start_positions` and `end_positions` are provided):
            Classification loss as the sum of start token, end token (and is_impossible if provided) classification
            losses.
        start_top_log_probs (`torch.FloatTensor` of shape `(batch_size, config.start_n_top)`, *optional*, returned if `start_positions` or `end_positions` is not provided):
            Log probabilities for the top config.start_n_top start token possibilities (beam-search).
        start_top_index (`torch.LongTensor` of shape `(batch_size, config.start_n_top)`, *optional*, returned if `start_positions` or `end_positions` is not provided):
            Indices for the top config.start_n_top start token possibilities (beam-search).
        end_top_log_probs (`torch.FloatTensor` of shape `(batch_size, config.start_n_top * config.end_n_top)`, *optional*, returned if `start_positions` or `end_positions` is not provided):
            Log probabilities for the top `config.start_n_top * config.end_n_top` end token possibilities
            (beam-search).
        end_top_index (`torch.LongTensor` of shape `(batch_size, config.start_n_top * config.end_n_top)`, *optional*, returned if `start_positions` or `end_positions` is not provided):
            Indices for the top `config.start_n_top * config.end_n_top` end token possibilities (beam-search).
        cls_logits (`torch.FloatTensor` of shape `(batch_size,)`, *optional*, returned if `start_positions` or `end_positions` is not provided):
            Log probabilities for the `is_impossible` label of the answers.
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states. Can be used (see `mems` input) to speed up sequential decoding. The
            token ids which have their past given to this model should not be passed as `input_ids` as they have
            already been computed.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr  Ústart_top_log_probsÚstart_top_indexÚend_top_log_probsÚend_top_indexÚ
cls_logitsrÁ   .r  r  )rÏ   rÐ   rÑ   rù   r  r   r`   r€   r  r  r  Ú
LongTensorr  r  r  rÁ   r   r  r   r  rý   rJ   rH   r  r    sâ   … ñ!ðF )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø7;Ð˜ %×"3Ñ"3Ñ4Ó;Ø26€O�X˜e×.Ñ.Ñ/Ó6Ø59Ð�x × 1Ñ 1Ñ2Ó9Ø04€M�8˜E×,Ñ,Ñ-Ó4Ø.2€J�˜×*Ñ*Ñ+Ó2Ø.2€Dˆ(�4˜×)Ñ)Ñ*Ñ
+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>rJ   r  a?  

    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`XLNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
aP  
    Args:
        input_ids (`torch.LongTensor` of shape `({0})`):
            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)
        attention_mask (`torch.FloatTensor` of shape `({0})`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        mems (`List[torch.FloatTensor]` of length `config.n_layers`):
            Contains pre-computed hidden-states (see `mems` output below) . Can be used to speed up sequential
            decoding. The token ids which have their past given to this model should not be passed as `input_ids` as
            they have already been computed.

            `use_mems` has to be set to `True` to make use of `mems`.
        perm_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length, sequence_length)`, *optional*):
            Mask to indicate the attention pattern for each input token with values selected in `[0, 1]`:

            - if `perm_mask[k, i, j] = 0`, i attend to j in batch k;
            - if `perm_mask[k, i, j] = 1`, i does not attend to j in batch k.

            If not set, each token attends to all the others (full bidirectional attention). Only used during
            pretraining (to define factorization order) or for sequential decoding (generation).
        target_mapping (`torch.FloatTensor` of shape `(batch_size, num_predict, sequence_length)`, *optional*):
            Mask to indicate the output tokens to use. If `target_mapping[k, i, j] = 1`, the i-th predict in batch k is
            on the j-th token. Only used during pretraining for partial prediction or for sequential decoding
            (generation).
        token_type_ids (`torch.LongTensor` of shape `({0})`, *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)
        input_mask (`torch.FloatTensor` of shape `{0}`, *optional*):
            Mask to avoid performing attention on padding token indices. Negative of `attention_mask`, i.e. with 0 for
            real tokens and 1 for padding which is kept for compatibility with the original code base.

            Mask values selected in `[0, 1]`:

            - 1 for tokens that are **masked**,
            - 0 for tokens that are **not masked**.

            You can only uses one of `input_mask` and `attention_mask`.
        head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        inputs_embeds (`torch.FloatTensor` of shape `({0}, 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.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
z_The bare XLNet Model transformer outputting raw hidden-states without any specific head on top.c            !       ó  ‡ — e Zd Zˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Ze	dd„«       Z
dd„Z eej                  d	«      «       eeee¬
«      	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej*                     deej*                     deej*                     deej*                     deej*                     deej*                     deej*                     deej*                     deej*                     dee   dee   dee   dee   deeef   fd„«       «       Zˆ xZS )rõ   c                 óþ  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _	        t        j                  |j                  |j                  «      | _        t        j                  t        j                   dd|j                  «      «      | _        t        j$                  t'        |j                  «      D �cg c]  }t)        |«      ‘Œ c}«      | _        t        j,                  |j.                  «      | _        | j1                  «        y c c}w râ   )rx   ry   Úmem_lenÚ	reuse_lenrz   Úsame_lengthÚ	attn_typeÚbi_dataÚ	clamp_lenÚn_layerr   rò   Ú
vocab_sizer)   r   r`   r€   r*   Ú
ModuleListÚrangerà   r,   rƒ   r„   Ú	post_init)r†   r>   Ú_r‡   s      €rH   ry   zXLNetModel.__init__   s   ø€ Ü‰Ñ˜Ô à—~‘~ˆŒØ×)Ñ)ˆŒØ—~‘~ˆŒØ!×-Ñ-ˆÔØ×)Ñ)ˆŒØ—~‘~ˆŒØ×)Ñ)ˆŒØ—~‘~ˆŒä Ÿl™l¨6×+<Ñ+<¸f¿n¹nÓMˆÔÜŸ™¤U×%6Ñ%6°q¸!¸V¿^¹^Ó%LÓMˆŒÜ—]‘]ÄÀfÇnÁnÓ@UÖ#V¸1¤J¨vÕ$6Ò#VÓWˆŒ
Ü—z‘z &§.¡.Ó1ˆŒð 	�‰Õùò	 $Ws   Ä'E:c                 ó   — | j                   S r‰   ©r)   ©r†   s    rH   Úget_input_embeddingszXLNetModel.get_input_embeddings´  s   € Ø×"Ñ"Ð"rJ   c                 ó   — || _         y r‰   r+  ©r†   Únew_embeddingss     rH   Úset_input_embeddingszXLNetModel.set_input_embeddings·  s
   € Ø,ˆÕrJ   c                 ó   — t         ‚r‰   rŠ   )r†   Úheads_to_prunes     rH   Ú_prune_headszXLNetModel._prune_headsº  rŽ   rJ   c                 ó  — t        j                  |||z   f| j                  ¬«      }| j                  rC|dd…d|…f   j	                  d«      }|j                  |dz   «       |dd…d|…fxx   |z  cc<   |S |j                  |dz   «       |S )aD  
        Creates causal attention mask. Float mask where 1.0 indicates masked, 0.0 indicates not-masked.

        Args:
            qlen: Sequence length
            mlen: Mask length

        ::

                  same_length=False: same_length=True: <mlen > < qlen > <mlen > < qlen >
               ^ [0 0 0 0 0 1 1 1 1] [0 0 0 0 0 1 1 1 1]
                 [0 0 0 0 0 0 1 1 1] [1 0 0 0 0 0 1 1 1]
            qlen [0 0 0 0 0 0 0 1 1] [1 1 0 0 0 0 0 1 1]
                 [0 0 0 0 0 0 0 0 1] [1 1 1 0 0 0 0 0 1]
               v [0 0 0 0 0 0 0 0 0] [1 1 1 1 0 0 0 0 0]

        )r‘   NrÍ   r   )r`   Úonesr‘   r   ÚtrilÚtriu_)r†   ÚqlenÚmlenÚmaskÚmask_los        rH   Úcreate_maskzXLNetModel.create_mask½  sŠ   € ô$ �z‰z˜4 ¨¡Ð-°d·k±kÔBˆØ×ÒØš1˜e˜t˜e˜8‘n×)Ñ)¨"Ó-ˆGØ�J‰J�t˜a‘xÔ Ø’�E�T�E�‹N˜gÑ%‹Nð ˆð �J‰J�t˜a‘xÔ àˆrJ   c                 ó2  — | j                   �| j                   dkD  r|d | j                    }| j                  �| j                  dk(  rd}n| j                   }|€||d  }|j	                  «       S t        j                  ||gd¬«      |d  }|j	                  «       S )Nr   r    )r  r  r`   r¼   Údetach)r†   Úcurr_outÚprev_memÚcutoffÚnew_mems        rH   Ú	cache_memzXLNetModel.cache_memÙ  s�   € à�>‰>Ð%¨$¯.©.¸1Ò*<ØÐ 0 $§.¡.Ð1ˆHà�<‰<Ð 4§<¡<°1Ò#4ð ‰Fð —l‘l�]ˆFØÐà˜v˜wÐ'ˆGð �~‰~ÓÐô —i‘i ¨8Ð 4¸!Ô<¸V¸WÐEˆGà�~‰~ÓÐrJ   c                 óô   — t        j                  d| |«      }t        j                  t        j                  |«      t        j                  |«      gd¬«      }|d d …d d d …f   }|�|j                  d|d«      }|S )Nzi,d->idrÍ   r    )r`   r¢   r¼   ÚsinÚcosÚexpand)Úpos_seqÚinv_freqÚbszÚsinusoid_inpÚpos_embs        rH   Úpositional_embeddingzXLNetModel.positional_embeddingî  sh   € ä—|‘| I¨w¸ÓAˆÜ—)‘)œUŸY™Y |Ó4´e·i±iÀÓ6MÐNÐTVÔWˆØš!˜T¢1˜*Ñ%ˆàˆ?Ø—n‘n R¨¨bÓ1ˆGàˆrJ   c                 óØ  — t        j                  d| j                  dt         j                  ¬«      j	                  «       }dt        j
                  d|| j                  z  «      z  }| j                  dk(  r|| }}n-| j                  dk(  r|d}}nt        d	| j                  › d
�«      ‚| j                  �r7t        j                  ||dt         j                  ¬«      j	                  «       }t        j                  | | dt         j                  ¬«      j	                  «       }	| j                  dkD  rN|j                  | j                   | j                  «      }|	j                  | j                   | j                  «      }	|�-| j                  |||dz  «      }
| j                  |	||dz  «      }n$| j                  ||«      }
| j                  |	|«      }t        j                  |
|gd¬«      }|S t        j                  ||dt         j                  ¬«      j	                  «       }| j                  dkD  r'|j                  | j                   | j                  «      }| j                  |||«      }|S )Nr   g       @©r’   r   i'  ÚbiÚunirÍ   zUnknown `attn_type` ú.g      ð¿rî   ru   r    )r`   r–   rz   Úint64ÚfloatÚpowr!  r|   r"  r#  ÚclamprN  r¼   )r†   r9  rš   rK  Úfreq_seqrJ  ÚbegÚendÚfwd_pos_seqÚbwd_pos_seqÚfwd_pos_embÚbwd_pos_embrM  s                rH   Úrelative_positional_encodingz'XLNetModel.relative_positional_encodingù  s÷  € ä—<‘<  4§<¡<°¼E¿K¹KÔH×NÑNÓPˆØ”u—y‘y ¨°D·L±LÑ)@ÓBÑBˆà�>‰>˜TÒ!à˜d˜U�‰CØ�^‰^˜uÒ$à˜R�‰CäÐ3°D·N±NÐ3CÀ1ÐEÓFÐFà�<‹<ÜŸ,™, s¨C°¼U¿[¹[ÔI×OÑOÓQˆKÜŸ,™,¨ t¨c¨T°3¼e¿k¹kÔJ×PÑPÓRˆKà�~‰~ Ò!Ø)×/Ñ/°·±°ÀÇÁÓP�Ø)×/Ñ/°·±°ÀÇÁÓP�àˆØ"×7Ñ7¸ÀXÈsÐVWÉxÓX�Ø"×7Ñ7¸ÀXÈsÐVWÉxÓX‘à"×7Ñ7¸ÀXÓN�Ø"×7Ñ7¸ÀXÓN�ä—i‘i ¨kÐ :ÀÔBˆGð ˆô  Ÿ,™, s¨C°¼U¿[¹[ÔI×OÑOÓQˆKØ�~‰~ Ò!Ø)×/Ñ/°·±°ÀÇÁÓP�Ø×/Ñ/°¸XÀsÓKˆGàˆrJ   úbatch_size, sequence_length©Ú
checkpointÚoutput_typerú   Ú	input_idsÚattention_maskrÁ   Ú	perm_maskrÂ   Útoken_type_idsÚ
input_maskr¬   Úinputs_embedsÚuse_memsr­   Úoutput_hidden_statesÚreturn_dictÚreturnc                 óF  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }d|v rt	        j
                  dt        «       |d   }
| j                  r|
�|
n| j                   j                  }
n|
�|
n| j                   j                  }
|�|	�t        d«      ‚|�?|j                  dd«      j                  «       }|j                  d   |j                  d   }}nL|	�?|	j                  dd«      j                  «       }	|	j                  d   |	j                  d   }}nt        d«      ‚|� |j                  dd«      j                  «       nd }|� |j                  dd«      j                  «       nd }|� |j                  dd«      j                  «       nd }|�!|j                  ddd«      j                  «       nd }|�!|j                  ddd«      j                  «       nd }|�|d   �|d   j                  d   nd}||z   }| j                  }| j                   }| j"                  dk(  r | j%                  ||«      }|d d …d d …d d f   }n*| j"                  d	k(  rd }nt        d
| j"                  › �«      ‚|�	|�J d«       ‚	 |€|�d|z
  }|�|�	|d    |z   }n|�|€|d    }n	|€|�|}nd }|�v|dkD  rMt'        j(                  |j                  d   ||g«      j+                  |«      }t'        j,                  ||gd¬«      }|€|d d …d d …d d …d f   }n||d d …d d …d d …d f   z  }|�|dkD  j+                  |«      }|�Št'        j.                  |«      j+                  |«       }|dkD  r=t'        j,                  t'        j(                  ||g«      j+                  |«      |gd¬«      }||d d …d d …d d f   z   dkD  j+                  |«      }nd }|	�|	}n| j1                  |«      }| j3                  |«      }|�<| j4                  j7                  |j                  d   |d«      }| j3                  |«      }nd }|�›|dkD  rBt'        j(                  ||gt&        j8                  |¬«      }t'        j,                  ||gd¬«      }n|}|d d …d f   |d d d …f   k7  j9                  «       }t:        j<                  j?                  |d¬«      j+                  |«      }nd }| jA                  |||¬«      } | j+                  |j                   «      } | j3                  | «      } |�ç|jC                  «       dk(  r^|jE                  d«      jE                  d«      jE                  d«      jE                  d«      }|j7                  | jF                  dddd«      }nB|jC                  «       dk(  r/|jE                  d«      jE                  d«      jE                  d«      }|j+                  tI        | jK                  «       «      j                  ¬«      }nd g| jF                  z  }d}!|€d gtM        | jN                  «      z  }|rg nd }"|rg nd }#tQ        | jN                  «      D ]p  \  }$}%|
r|!| jS                  |||$   «      fz   }!|r|#jU                  |�||fn|«        |%||||| |||$   |||$   |¬«
      }&|&d d \  }}|sŒ]|"jU                  |&d   «       Œr |r|#jU                  |�||fn|«       | j3                  |�|n|«      }'|'j                  ddd«      j                  «       }'|
sd }!|r'|�tW        d„ |#D «       «      }#ntW        d„ |#D «       «      }#|r'|�tW        d„ |"D «       «      }"ntW        d„ |"D «       «      }"|stW        d„ |'|!|#|"fD «       «      S tY        |'|!|#|"¬«      S )NÚ	use_cachezgThe `use_cache` argument is deprecated and will be removed in a future version, use `use_mems` instead.zDYou cannot specify both input_ids and inputs_embeds at the same timer   r   z5You have to specify either input_ids or inputs_embedsru   rR  rQ  zUnsupported attention type: z8You can only use one of input_mask (uses 1 for padding) rî   r    rÍ   ©r’   r‘   )Únum_classes)rK  rP  rý   )r¿   rÀ   r2   rª   rÁ   rÂ   r¬   r­   c              3   ól   K  — | ],  }|D ]%  }|j                  d dd«      j                  «       –— Œ' Œ. y­w©r   r   ru   N©ÚpermuteÚ
contiguous)Ú.0Úhsr¶   s      rH   ú	<genexpr>z%XLNetModel.forward.<locals>.<genexpr>ï  s5   è ø€ Ò%jÈ"ÐgiÒ%jÐbc a§i¡i°°1°aÓ&8×&CÑ&C×&EÐ%jÐ&EÑ%jùs   ‚24c              3   ó^   K  — | ]%  }|j                  d dd«      j                  «       –— Œ' y­wrs  rt  )rw  rx  s     rH   ry  z%XLNetModel.forward.<locals>.<genexpr>ñ  s&   è ø€ Ò%_È2 b§j¡j°°A°qÓ&9×&DÑ&D×&FÑ%_ùs   ‚+-c              3   ó@   K  — | ]  }t        d „ |D «       «      –— Œ y­w)c              3   ó`   K  — | ]&  }|j                  d ddd«      j                  «       –— Œ( y­w©ru   r   r   r   Nrt  )rw  Ú
att_streams     rH   ry  z/XLNetModel.forward.<locals>.<genexpr>.<genexpr>÷  s*   è ø€ ÒZÈ*˜*×,Ñ,¨Q°°1°aÓ8×CÑC×EÑZùó   ‚,.N)Útuple©rw  Úts     rH   ry  z%XLNetModel.forward.<locals>.<genexpr>ö  s!   è ø€ ò #Ø_`”EÑZÐXYÔZ×Zñ#ùs   ‚c              3   ó`   K  — | ]&  }|j                  d ddd«      j                  «       –— Œ( y­wr}  rt  r�  s     rH   ry  z%XLNetModel.forward.<locals>.<genexpr>ú  s(   è ø€ Ò"ZÈ! 1§9¡9¨Q°°1°aÓ#8×#CÑ#C×#EÑ"Zùr  c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr‰   rý   )rw  r3   s     rH   ry  z%XLNetModel.forward.<locals>.<genexpr>ý  s   è ø€ Òc˜qÐUVÑUbœÑcùs   ‚Š)r   rÁ   r  r  )-r>   r­   rk  Úuse_return_dictÚwarningsÚwarnÚFutureWarningÚtrainingÚuse_mems_trainÚuse_mems_evalr|   rY   rv  r]   ru  r’   r‘   r!  r=  r`   ÚzerosÚtor¼   Úeyer)   r„   r*   rH  r—   r   r¤   Úone_hotr_  r¡   Ú	unsqueezer$  ÚnextÚ
parametersr\   r,   r+   rD  r8   r€  rÿ   )(r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  rj  r­   rk  rl  Úkwargsr9  rK  r:  rš   Údtype_floatr‘   r«   Ú	data_maskÚ	mems_maskÚnon_tgt_maskÚ
word_emb_krÆ   Ú
word_emb_qrÊ   Úmem_padÚcat_idsrª   rM  Únew_memsr  r  rA   Úlayer_modulerË   r¹   s(                                           rH   rÌ   zXLNetModel.forward  sû  € ð. 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà˜&Ñ Ü�M‰Mðäôð
 ˜kÑ*ˆHà�=Š=Ø#+Ð#7‘x¸T¿[¹[×=WÑ=W‰Hà#+Ð#7‘x¸T¿[¹[×=VÑ=VˆHð
 Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ø!×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆIØ!Ÿ™¨Ñ*¨I¯O©O¸AÑ,>�#‰DØÐ&Ø)×3Ñ3°A°qÓ9×DÑDÓFˆMØ%×+Ñ+¨AÑ.°×0CÑ0CÀAÑ0F�#‰DäÐTÓUÐUàHVÐHb˜×1Ñ1°!°QÓ7×BÑBÔDÐhlˆØ@JÐ@V�Z×)Ñ)¨!¨QÓ/×:Ñ:Ô<Ð\`ˆ
ØHVÐHb˜×1Ñ1°!°QÓ7×BÑBÔDÐhlˆØ?HÐ?T�I×%Ñ% a¨¨AÓ.×9Ñ9Ô;ÐZ^ˆ	ØIWÐIc˜×/Ñ/°°1°aÓ8×CÑCÔEÐimˆà#'Ð#3¸¸Q¹Ð8Kˆt�A‰w�}‰}˜QÒÐQRˆØ�d‰{ˆà—j‘jˆØ—‘ˆð �>‰>˜UÒ"Ø×(Ñ(¨¨tÓ4ˆIØ!¢!¢Q¨¨dÐ"2Ñ3‰IØ�^‰^˜tÒ#Ø‰IäÐ;¸D¿N¹NÐ;KÐLÓMÐMð Ð! ^Ð%;ÐwÐ=wÓwÐ;ØgØÐ .Ð"<Ø˜~Ñ-ˆJØÐ! iÐ&;Ø" 4Ñ(¨9Ñ4‰IØÐ#¨	Ð(9Ø" 4Ñ(‰IØÐ IÐ$9Ø!‰IàˆIàÐ à�aŠxÜ!ŸK™K¨¯©¸Ñ);¸TÀ3Ð(GÓH×KÑKÈIÓV�	Ü!ŸI™I y°)Ð&<À!ÔD�	ØÐ Ø%¢aªªA¨t mÑ4‘	à˜Y¢qª!ªQ° }Ñ5Ñ5�	àÐ Ø" Q™×*Ñ*¨;Ó7ˆIàÐ Ü!ŸI™I d›O×.Ñ.¨yÓ9Ð9ˆLØ�aŠxÜ$Ÿy™y¬%¯+©+°t¸T°lÓ*C×*FÑ*FÀyÓ*QÐS_Ð)`ÐfhÔi�Ø&¨²aº¸DÀ$Ð6FÑ)GÑGÈ1ÑL×PÑPÐQZÓ[‰LàˆLð Ð$Ø&‰Jà×,Ñ,¨YÓ7ˆJØ—<‘< 
Ó+ˆØÐ%ØŸ™×-Ñ-¨n×.BÑ.BÀ1Ñ.EÀsÈBÓOˆJð —|‘| JÓ/‰HàˆHð Ð%à�aŠxÜŸ+™+ t¨S k¼¿¹ÈFÔS�ÜŸ)™) W¨nÐ$=À1ÔE‘à(�ð &¢a¨ gÑ.°'¸$Â¸'Ñ2BÑB×HÑHÓJˆGÜ—m‘m×+Ñ+¨GÀÐ+ÓC×FÑFÀ{ÓS‰GàˆGð ×3Ñ3°D¸$ÀCÐ3ÓHˆØ—*‘*˜XŸ_™_Ó-ˆØ—,‘,˜wÓ'ˆð Ð Ø�}‰}‹ !Ò#Ø%×/Ñ/°Ó2×<Ñ<¸QÓ?×IÑIÈ!ÓL×VÑVÐWXÓY�	Ø%×,Ñ,¨T¯\©\¸2¸rÀ2ÀrÓJ‘	Ø—‘“ AÒ%Ø%×/Ñ/°Ó2×<Ñ<¸QÓ?×IÑIÈ!ÓL�	Ø!Ÿ™Ü˜4Ÿ?™?Ó,Ó-×3Ñ3ð %ó ‰Ið ˜ §¡Ñ-ˆIàˆØˆ<Ø�6œC §
¡
›OÑ+ˆDá,‘R°$ˆ
Ù2™¸ˆÜ(¨¯©Ó4ò 	.‰OˆAˆ|Ùà# t§~¡~°hÀÀQÁÓ'HÐ&JÑJ�Ù#Ø×$Ñ$¸XÐ=Q h°Ñ%9ÐW_Ô`á"ØØØ(Ø%ØØØ˜!‘WØ-Ø# A™,Ø"3ôˆGð ")¨¨! ÑˆH�hÚ Ø×!Ñ! '¨!¡*Õ-ð+	.ñ0  Ø× Ñ ¸Ð9M (¨HÑ!5ÐS[Ô\à—‘¨(Ð*>™hÀHÓMˆð —‘  1 aÓ(×3Ñ3Ó5ˆáØˆHáØÐ#Ü %Ñ%jÐP]Ô%jÓ j‘ä %Ñ%_ÐQ^Ô%_Ó _�áØÐ)ä"ñ #Ødnô#ó ‘
ô #Ñ"ZÈzÔ"ZÓZ�
áÜÑc V¨X°}ÀjÐ$QÔcÓcÐcäØ$¨8À=Ð]gô
ð 	
rJ   r‰   )NNNNNNNNNNNNN)rÏ   rÐ   rÑ   ry   r-  r1  r4  r=  rD  rÒ   rN  r_  r   ÚXLNET_INPUTS_DOCSTRINGÚformatr   Ú_CHECKPOINT_FOR_DOCrÿ   Ú_CONFIG_FOR_DOCr   r`   ÚTensorÚboolr   r   rÌ   rÓ   rÔ   s   @rH   rõ   rõ   ›  s§  ø„ ô
ò(#ò-ò"òò8 ð* òó ðó$ñL +Ð+A×+HÑ+HÐIfÓ+gÓhÙØ&Ø$Ø$ôð -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø#'Ø,0Ø/3Ø&*ñ\
à˜EŸL™LÑ)ð\
ð ! §¡Ñ.ð\
ð �u—|‘|Ñ$ð	\
ð
 ˜EŸL™LÑ)ð\
ð ! §¡Ñ.ð\
ð ! §¡Ñ.ð\
ð ˜UŸ\™\Ñ*ð\
ð ˜EŸL™LÑ)ð\
ð   §¡Ñ-ð\
ð ˜4‘.ð\
ð $ D™>ð\
ð ' t™nð\
ð ˜d‘^ð\
ð  
ˆuÐ&Ð&Ñ	'ò!\
óó iô\
rJ   rõ   zt
    XLNet Model with a language modeling head on top (linear layer with weights tied to the input embeddings).
    c            #       ót  ‡ — e Zd ZdgZˆ fd„Zd„ Zd„ Zdd„Z ee	j                  d«      «       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                      d	eej                      d
eej                      deej                      deej                      deej                      deej                      deej                      deej                      deej                      dee   dee   dee   dee   deeef   fd„«       «       Zed
eej                      dej                   deej                      fd„«       Zˆ xZS )ÚXLNetLMHeadModelzlm_loss.weightc                 ó
  •— t         ‰| �  |«       |j                  | _        |j                  | _        t	        |«      | _        t        j                  |j                  |j                  d¬«      | _
        | j                  «        y )NT)r$   )rx   ry   r!  r   rõ   r   r   rØ   rz   r%  r   r(  r…   s     €rH   ry   zXLNetLMHeadModel.__init__  sb   ø€ Ü‰Ñ˜Ô Ø×)Ñ)ˆŒØ!×-Ñ-ˆÔä% fÓ-ˆÔÜ—y‘y §¡°×1BÑ1BÈÔNˆŒð 	�‰ÕrJ   c                 ó   — | j                   S r‰   ©r   r,  s    rH   Úget_output_embeddingsz&XLNetLMHeadModel.get_output_embeddings  s   € Ø�|‰|ÐrJ   c                 ó   — || _         y r‰   r¨  r/  s     rH   Úset_output_embeddingsz&XLNetLMHeadModel.set_output_embeddings  s	   € Ø%ˆ�rJ   c                 ób  ‡— |j                   d   }t        j                  |dft        j                  |j                  ¬«      }dŠ|r$t        j
                  |d d …‰ d …f   |gd¬«      }nt        j
                  ||gd¬«      }|j                   d   }t        j                  |||ft        j                  |j                  ¬«      }d|d d …d d …df<   t        j                  |d|ft        j                  |j                  ¬«      }	d|	d d …ddf<   |||	|dœ}
|rt        ˆfd	„|D «       «      |
d
<   |
S )Nr   r   rp  ru   r    rî   rÍ   )rd  rf  rÂ   rj  c              3   ó<   •K  — | ]  }|d ‰ …d d …d d …f   –— Œ y ­wr‰   rý   )rw  Ú
layer_pastÚoffsets     €rH   ry  zAXLNetLMHeadModel.prepare_inputs_for_generation.<locals>.<genexpr>F  s"   øè ø€ Ò"`À* :¨h°¨w¨hºº1¨nÕ#=Ñ"`ùs   ƒrÁ   )r]   r`   rŒ  r—   r‘   r¼   rU  r€  )r†   rd  Úpast_key_valuesrj  r“  Úeffective_batch_sizeÚdummy_tokenÚsequence_lengthrf  rÂ   Úinputsr¯  s              @rH   Úprepare_inputs_for_generationz.XLNetLMHeadModel.prepare_inputs_for_generation  s0  ø€ ð
  )Ÿ™¨qÑ1ÐÜ—k‘kÐ#7¸Ð";Ä5Ç:Á:ÐV_×VfÑVfÔgˆð
 ˆáÜŸ	™	 9ªQ°°±¨[Ñ#9¸;Ð"GÈQÔO‰IäŸ	™	 9¨kÐ":ÀÔBˆIð $Ÿ/™/¨!Ñ,ˆÜ—K‘KØ! ?°OÐDÌEÏKÉKÐ`i×`pÑ`pô
ˆ	ð "ˆ	’!’Q˜�(Ñô Ÿ™Ø! 1 oÐ6¼e¿k¹kÐR[×RbÑRbô
ˆð $'ˆ’q˜!˜R�xÑ ð #Ø"Ø,Ø ñ	
ˆñ Ü"Ó"`ÐP_Ô"`Ó`ˆF�6‰NàˆrJ   r`  ©rc  rú   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  Úlabelsrj  r­   rk  rl  rm  c                 ó®  — |�|n| j                   j                  } | j                  |f||||||||	||||dœ|¤Ž}| j                  |d   «      }d}|
�At	        «       } ||j                  d|j                  d«      «      |
j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  ¬«      S )aI  
        labels (`torch.LongTensor` of shape `(batch_size, num_predict)`, *optional*):
            Labels for masked language modeling. `num_predict` corresponds to `target_mapping.shape[1]`. If
            `target_mapping` is `None`, then `num_predict` corresponds to `sequence_length`.

            The labels should correspond to the masked input words that should be predicted and depends on
            `target_mapping`. Note in order to perform standard auto-regressive language modeling a *<mask>* token has
            to be added to the `input_ids` (see the `prepare_inputs_for_generation` function and examples below)

            Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100` are ignored, the loss
            is only computed for labels in `[0, ..., config.vocab_size]`

        Return:

        Examples:

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

        >>> tokenizer = AutoTokenizer.from_pretrained("xlnet/xlnet-large-cased")
        >>> model = XLNetLMHeadModel.from_pretrained("xlnet/xlnet-large-cased")

        >>> # We show how to setup inputs to predict a next token using a bi-directional context.
        >>> input_ids = torch.tensor(
        ...     tokenizer.encode("Hello, my dog is very <mask>", add_special_tokens=False)
        ... ).unsqueeze(
        ...     0
        ... )  # We will predict the masked token
        >>> perm_mask = torch.zeros((1, input_ids.shape[1], input_ids.shape[1]), dtype=torch.float)
        >>> perm_mask[:, :, -1] = 1.0  # Previous tokens don't see last token
        >>> target_mapping = torch.zeros(
        ...     (1, 1, input_ids.shape[1]), dtype=torch.float
        ... )  # Shape [1, 1, seq_length] => let's predict one token
        >>> target_mapping[
        ...     0, 0, -1
        ... ] = 1.0  # Our first (and only) prediction will be the last token of the sequence (the masked token)

        >>> outputs = model(input_ids, perm_mask=perm_mask, target_mapping=target_mapping)
        >>> next_token_logits = outputs[
        ...     0
        ... ]  # Output has shape [target_mapping.size(0), target_mapping.size(1), config.vocab_size]

        >>> # The same way can the XLNetLMHeadModel be used to be trained by standard auto-regressive language modeling.
        >>> input_ids = torch.tensor(
        ...     tokenizer.encode("Hello, my dog is very <mask>", add_special_tokens=False)
        ... ).unsqueeze(
        ...     0
        ... )  # We will predict the masked token
        >>> labels = torch.tensor(tokenizer.encode("cute", add_special_tokens=False)).unsqueeze(0)
        >>> assert labels.shape[0] == 1, "only one word will be predicted"
        >>> perm_mask = torch.zeros((1, input_ids.shape[1], input_ids.shape[1]), dtype=torch.float)
        >>> perm_mask[
        ...     :, :, -1
        ... ] = 1.0  # Previous tokens don't see last token as is done in standard auto-regressive lm training
        >>> target_mapping = torch.zeros(
        ...     (1, 1, input_ids.shape[1]), dtype=torch.float
        ... )  # Shape [1, 1, seq_length] => let's predict one token
        >>> target_mapping[
        ...     0, 0, -1
        ... ] = 1.0  # Our first (and only) prediction will be the last token of the sequence (the masked token)

        >>> outputs = model(input_ids, perm_mask=perm_mask, target_mapping=target_mapping, labels=labels)
        >>> loss = outputs.loss
        >>> next_token_logits = (
        ...     outputs.logits
        ... )  # Logits have shape [target_mapping.size(0), target_mapping.size(1), config.vocab_size]
        ```N©re  rÁ   rf  rÂ   rg  rh  r¬   ri  rj  r­   rk  rl  r   rÍ   r   ©r  r  rÁ   r  r  )r>   r…  r   r   r
   ÚviewÚsizer  rÁ   r  r  )r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  r·  rj  r­   rk  rl  r“  Útransformer_outputsr  r  Úloss_fctr¹   s                        rH   rÌ   zXLNetLMHeadModel.forwardJ  s  € ðp &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà.˜d×.Ñ.Øð
à)ØØØ)Ø)Ø!ØØ'ØØ/Ø!5Ø#ñ
ð ñ
Ðð" —‘Ð1°!Ñ4Ó5ˆàˆØÐä'Ó)ˆHÙ˜FŸK™K¨¨F¯K©K¸«OÓ<¸f¿k¹kÈ"»oÓNˆDáØ�YÐ!4°Q°RÐ!8Ñ8ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä%ØØØ$×)Ñ)Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
rJ   Úbeam_idxc           	      ó~   — | D �cg c]-  }|j                  d|j                  |j                  «      «      ‘Œ/ c}S c c}w )zü
        This function is used to re-order the `mems` cache if [`~PreTrainedModel.beam_search`] or
        [`~PreTrainedModel.beam_sample`] is called. This is required to match `mems` with the correct beam_idx at every
        generation step.
        r   )r•   r�  r‘   )rÁ   r¿  r®  s      rH   Ú_reorder_cachezXLNetLMHeadModel._reorder_cacheÉ  s6   € ð ^bÖbÈz�
×'Ñ'¨¨8¯;©;°z×7HÑ7HÓ+IÕJÒbÐbùÒbs   …2:)NN©NNNNNNNNNNNNNN)rÏ   rÐ   rÑ   Ú_tied_weights_keysry   r©  r«  rµ  r   rž  rŸ  r   r  r¡  r   r`   r¢  r£  r   r   rÌ   rÒ   r   rÁ  rÓ   rÔ   s   @rH   r¥  r¥    sê  ø„ ð +Ð+Ðô	òò&ó*ñX +Ð+A×+HÑ+HÐIfÓ+gÓhÙÐ+AÐP_Ô`ð -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø)-Ø#'Ø,0Ø/3Ø&*ñ{
à˜EŸL™LÑ)ð{
ð ! §¡Ñ.ð{
ð �u—|‘|Ñ$ð	{
ð
 ˜EŸL™LÑ)ð{
ð ! §¡Ñ.ð{
ð ! §¡Ñ.ð{
ð ˜UŸ\™\Ñ*ð{
ð ˜EŸL™LÑ)ð{
ð   §¡Ñ-ð{
ð ˜Ÿ™Ñ&ð{
ð ˜4‘.ð{
ð $ D™>ð{
ð ' t™nð{
ð ˜d‘^ð{
ð" 
ˆuÐ,Ð,Ñ	-ò#{
ó aó ið{
ðz ðc˜T %§,¡,Ñ/ð c¸5¿<¹<ð cÈDÐQV×Q]ÑQ]ÑL^ò có ôcrJ   r¥  z‘
    XLNet Model 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j                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     dee   dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚXLNetForSequenceClassificationc                 ó  •— t         ‰| �  |«       |j                  | _        || _        t	        |«      | _        t        |«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r‰   )rx   ry   Ú
num_labelsr>   rõ   r   r   r    r   rØ   rz   r!   r(  r…   s     €rH   ry   z'XLNetForSequenceClassification.__init__Û  sg   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒØˆŒä% fÓ-ˆÔÜ /°Ó 7ˆÔÜŸ9™9 V§^¡^°V×5FÑ5FÓGˆÔð 	�‰ÕrJ   r`  ra  rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  r·  rj  r­   rk  rl  rm  c                 ób  — |�|n| j                   j                  } | j                  |f||||||||	||||dœ|¤Ž}|d   }| j                  |«      }| j	                  |«      }d}|
��‡| 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        «       } |||
«      }|s|f|dd z   }|�|f|z   S |S t!        |||j"                  |j$                  |j&                  ¬	«      S )
a�  
        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).
        Nr¹  r   r   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrÍ   rº  )r>   r…  r   r    r!   Úproblem_typerÇ  r’   r`   r—   Úintr   Úsqueezer
   r»  r	   r
  rÁ   r  r  )r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  r·  rj  r­   rk  rl  r“  r½  r¹   r  r  r¾  s                        rH   rÌ   z&XLNetForSequenceClassification.forwardç  s  € ð< &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà.˜d×.Ñ.Øð
à)ØØØ)Ø)Ø!ØØ'ØØ/Ø!5Ø#ñ
ð ñ
Ðð  % QÑ'ˆà×&Ñ& vÓ.ˆØ×!Ñ! &Ó)ˆàˆØÑØ�{‰{×'Ñ'Ð/Ø—?‘? 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Ü,Ó.�Ù ¨Ó/�áØ�YÐ!4°Q°RÐ!8Ñ8ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä3ØØØ$×)Ñ)Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
rJ   rÂ  )rÏ   rÐ   rÑ   ry   r   rž  rŸ  r   r   r
  r¡  r   r`   r¢  r£  r   r   rÌ   rÓ   rÔ   s   @rH   rÅ  rÅ  Ó  s‹  ø„ ô
ñ +Ð+A×+HÑ+HÐIfÓ+gÓhÙØ&Ø8Ø$ôð -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø)-Ø#'Ø,0Ø/3Ø&*ñP
à˜EŸL™LÑ)ðP
ð ! §¡Ñ.ðP
ð �u—|‘|Ñ$ð	P
ð
 ˜EŸL™LÑ)ðP
ð ! §¡Ñ.ðP
ð ! §¡Ñ.ðP
ð ˜UŸ\™\Ñ*ðP
ð ˜EŸL™LÑ)ðP
ð   §¡Ñ-ðP
ð ˜Ÿ™Ñ&ðP
ð ˜4‘.ðP
ð $ D™>ðP
ð ' t™nðP
ð ˜d‘^ðP
ð" 
ˆuÐ:Ð:Ñ	;ò#P
óó iôP
rJ   rÅ  z¤
    XLNet Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
    Named-Entity-Recognition (NER) tasks.
    c            #       óö  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     dee   dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚXLNetForTokenClassificationc                 óä   •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r‰   )
rx   ry   rÇ  rõ   r   r   rØ   Úhidden_sizeÚ
classifierr(  r…   s     €rH   ry   z$XLNetForTokenClassification.__init__H  óT   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä% fÓ-ˆÔÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰ÕrJ   r`  ra  rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  r·  rj  r­   rk  rl  rm  c                 ó¤  — |�|n| j                   j                  }| j                  |||||||||	||||¬«      }|d   }| j                  |«      }d}|
�<t	        «       } ||j                  d| j                  «      |
j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  ¬«      S )a<  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the multiple choice classification loss. Indices should be in `[0, ..., num_choices]`
            where *num_choices* is the size of the second dimension of the input tensors. (see *input_ids* above)
        Nr¹  r   rÍ   r   rº  )r>   r…  r   rÓ  r
   r»  rÇ  r  rÁ   r  r  )r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  r·  rj  r­   rk  rl  r“  rË   Úsequence_outputr  r  r¾  r¹   s                         rH   rÌ   z#XLNetForTokenClassification.forwardR  sý   € ð: &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà×"Ñ"ØØ)ØØØ)Ø)Ø!ØØ'ØØ/Ø!5Ø#ð #ó 
ˆð  " !™*ˆà—‘ Ó1ˆàˆØÐÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä0ØØØ—‘Ø!×/Ñ/Ø×)Ñ)ô
ð 	
rJ   rÂ  )rÏ   rÐ   rÑ   ry   r   rž  rŸ  r   r   r  r¡  r   r`   r¢  r£  r   r   rÌ   rÓ   rÔ   s   @rH   rÐ  rÐ  @  sz  ø„ ôñ +Ð+A×+HÑ+HÐIfÓ+gÓhÙØ&Ø5Ø$ôð -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø)-Ø#'Ø,0Ø/3Ø&*ñ<
à˜EŸL™LÑ)ð<
ð ! §¡Ñ.ð<
ð �u—|‘|Ñ$ð	<
ð
 ˜EŸL™LÑ)ð<
ð ! §¡Ñ.ð<
ð ! §¡Ñ.ð<
ð ˜UŸ\™\Ñ*ð<
ð ˜EŸL™LÑ)ð<
ð   §¡Ñ-ð<
ð ˜Ÿ™Ñ&ð<
ð ˜4‘.ð<
ð $ D™>ð<
ð ' t™nð<
ð ˜d‘^ð<
ð" 
ˆuÐ7Ð7Ñ	8ò#<
óó iô<
rJ   rÐ  z 
    XLNet Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
    softmax) e.g. for RACE/SWAG tasks.
    c            #       óö  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     dee   dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚXLNetForMultipleChoicec                 óÎ   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        t        j                  |j                  d«      | _	        | j                  «        y râ   )rx   ry   rõ   r   r   r    r   rØ   rz   r!   r(  r…   s     €rH   ry   zXLNetForMultipleChoice.__init__Ÿ  sM   ø€ Ü‰Ñ˜Ô ä% fÓ-ˆÔÜ /°Ó 7ˆÔÜŸ9™9 V§^¡^°QÓ7ˆÔð 	�‰ÕrJ   z(batch_size, num_choices, sequence_lengthra  rd  rg  rh  re  rÁ   rf  rÂ   r¬   ri  r·  rj  r­   rk  rl  rm  c                 óŒ  — |�|n| j                   j                  }|�|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   }| j                  |«      }| j                  |«      }|j                  d|«      }d}|
�"t        «       } |||
j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  ¬«      S )aJ  
        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   rÍ   éþÿÿÿ)rg  rh  re  rÁ   rf  rÂ   r¬   ri  rj  r­   rk  rl  r   rº  )r>   r…  r]   r»  r¼  r   r    r!   r
   r  rÁ   r  r  )r†   rd  rg  rh  re  rÁ   rf  rÂ   r¬   ri  r·  rj  r­   rk  rl  r“  Únum_choicesÚflat_input_idsÚflat_token_type_idsÚflat_attention_maskÚflat_input_maskÚflat_inputs_embedsr½  r¹   r  Úreshaped_logitsr  r¾  s                               rH   rÌ   zXLNetForMultipleChoice.forward©  s  € ð< &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà,5Ð,A�i—o‘o aÒ(À}×GZÑGZÐ[\ÑG]ˆàCLÐCX˜Ÿ™¨¨I¯N©N¸2Ó,>Ô?Ð^bˆØR`ÐRl˜n×1Ñ1°"°n×6IÑ6IÈ"Ó6MÔNÐrvÐØR`ÐRl˜n×1Ñ1°"°n×6IÑ6IÈ"Ó6MÔNÐrvÐØFPÐF\˜*Ÿ/™/¨"¨j¯o©o¸bÓ.AÔBÐbfˆð Ð(ð ×Ñ˜r =×#5Ñ#5°bÓ#9¸=×;MÑ;MÈbÓ;QÔRàð 	ð /˜d×.Ñ.Øð
à.Ø&Ø.ØØØ)ØØ,ØØ/Ø!5Ø#ñ
ð ñ
Ðð" % QÑ'ˆà×&Ñ& vÓ.ˆØ×!Ñ! &Ó)ˆØ Ÿ+™+ b¨+Ó6ˆàˆØÐÜ'Ó)ˆHÙ˜O¨V¯[©[¸«_Ó=ˆDáØ%Ð'Ð*=¸a¸bÐ*AÑAˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä+ØØ"Ø$×)Ñ)Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
rJ   rÂ  )rÏ   rÐ   rÑ   ry   r   rž  rŸ  r   r   r  r¡  r   r`   r¢  r£  r   r   rÌ   rÓ   rÔ   s   @rH   rØ  rØ  —  s‹  ø„ ôñ +Ð+A×+HÑ+HÐIsÓ+tÓuÙØ&Ø0Ø$ôð -1Ø15Ø-1Ø15Ø'+Ø,0Ø15Ø,0Ø04Ø)-Ø#'Ø,0Ø/3Ø&*ñL
à˜EŸL™LÑ)ðL
ð ! §¡Ñ.ðL
ð ˜UŸ\™\Ñ*ð	L
ð
 ! §¡Ñ.ðL
ð �u—|‘|Ñ$ðL
ð ˜EŸL™LÑ)ðL
ð ! §¡Ñ.ðL
ð ˜EŸL™LÑ)ðL
ð   §¡Ñ-ðL
ð ˜Ÿ™Ñ&ðL
ð ˜4‘.ðL
ð $ D™>ðL
ð ' t™nðL
ð ˜d‘^ðL
ð" 
ˆuÐ2Ð2Ñ	3ò#L
óó vôL
rJ   rØ  zÞ
    XLNet Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c            %       ó  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deej                     dee   dee   dee   dee   deee	f   f d„«       «       Zˆ xZS )ÚXLNetForQuestionAnsweringSimplec                 óä   •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r‰   )
rx   ry   rÇ  rõ   r   r   rØ   rÒ  Ú
qa_outputsr(  r…   s     €rH   ry   z(XLNetForQuestionAnsweringSimple.__init__  rÔ  rJ   r`  ra  rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  Ústart_positionsÚend_positionsrj  r­   rk  rl  rm  c                 óJ  — |�|n| j                   j                  } | j                  |f||||||||	||||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  }|s||f|dd z   }|�|f|z   S |S t        ||||j                  |j                  |j                  ¬	«      S )
a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        Nr¹  r   r   rÍ   r    )Úignore_indexru   )r  r  r  rÁ   r  r  )r>   r…  r   ræ  ÚsplitrÎ  rv  r\   r¼  rW  r
   r  rÁ   r  r  )r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  rç  rè  rj  r­   rk  rl  r“  rË   rÖ  r  r  r  Ú
total_lossÚignored_indexr¾  Ú
start_lossÚend_lossr¹   s                               rH   rÌ   z'XLNetForQuestionAnsweringSimple.forward  sä  € ðF &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà"�$×"Ñ"Øð
à)ØØØ)Ø)Ø!ØØ'ØØ/Ø!5Ø#ñ
ð ñ
ˆð" " !™*ˆà—‘ Ó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áØ" JÐ/°'¸!¸"°+Ñ=ˆFØ/9Ð/E�Z�M FÑ*ÐQÈ6ÐQä4ØØ%Ø!Ø—‘Ø!×/Ñ/Ø×)Ñ)ô
ð 	
rJ   )NNNNNNNNNNNNNNN)rÏ   rÐ   rÑ   ry   r   rž  rŸ  r   r   r  r¡  r   r`   r¢  r£  r   r   rÌ   rÓ   rÔ   s   @rH   rä  rä  þ  s¢  ø„ ôñ +Ð+A×+HÑ+HÐIfÓ+gÓhÙØ&Ø9Ø$ôð -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø26Ø04Ø#'Ø,0Ø/3Ø&*ñ!S
à˜EŸL™LÑ)ðS
ð ! §¡Ñ.ðS
ð �u—|‘|Ñ$ð	S
ð
 ˜EŸL™LÑ)ðS
ð ! §¡Ñ.ðS
ð ! §¡Ñ.ðS
ð ˜UŸ\™\Ñ*ðS
ð ˜EŸL™LÑ)ðS
ð   §¡Ñ-ðS
ð " %§,¡,Ñ/ðS
ð   §¡Ñ-ðS
ð ˜4‘.ðS
ð $ D™>ðS
ð ' t™nðS
ð  ˜d‘^ð!S
ð$ 
ˆuÐ;Ð;Ñ	<ò%S
óó iôS
rJ   rä  c            +       ót  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
e   de
e   de
e   de
e   deeef   f&d„«       «       Zˆ xZS )ÚXLNetForQuestionAnsweringc                 ó  •— t         ‰| �  |«       |j                  | _        |j                  | _        t	        |«      | _        t        |«      | _        t        |«      | _	        t        |«      | _        | j                  «        y r‰   )rx   ry   Ústart_n_topÚ	end_n_toprõ   r   r   r  r   r  r   Úanswer_classr(  r…   s     €rH   ry   z"XLNetForQuestionAnswering.__init__t  sj   ø€ Ü‰Ñ˜Ô Ø!×-Ñ-ˆÔØ×)Ñ)ˆŒä% fÓ-ˆÔÜ-¨fÓ5ˆÔÜ)¨&Ó1ˆŒÜ-¨fÓ5ˆÔð 	�‰ÕrJ   r`  r¶  rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  rç  rè  Úis_impossibleÚ	cls_indexÚp_maskrj  r­   rk  rl  rm  c                 ó€  — |�|n| j                   j                  } | j                  |f||||||||	||||dœ|¤Ž}|d   }| j                  ||¬«      }|dd }|
�â|�à|
|||fD ]*  }|€Œ|j	                  «       dkD  sŒ|j                  d«       Œ, | j                  ||
|¬«      }t        «       } |||
«      } |||«      }||z   dz  }|�;|�9| j                  ||
|¬	«      }t        j                  «       } |||«      } || d
z  z  }|s	|f|dd z   S t        ||j                  |j                  |j                  ¬«      S |j                  «       \  }!}"}#t        j                   j#                  |d¬«      }$t%        j&                  |$| j(                  d¬«      \  }%}&|&j+                  d«      j-                  dd|#«      }'t%        j.                  |d|'«      }(|(j+                  d«      j-                  d|"dd«      }(|j+                  d«      j1                  |(«      })|�|j+                  d«      nd}| j                  |)|(|¬«      }t        j                   j#                  |d¬«      }*t%        j&                  |*| j2                  d¬«      \  }+},|+j5                  d| j(                  | j2                  z  «      }+|,j5                  d| j(                  | j2                  z  «      },t%        j6                  d||$«      }(| j                  ||(|¬«      }|s|%|&|+|,|f}||dd z   S t        |%|&|+|,||j                  |j                  |j                  ¬«      S )aJ  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        is_impossible (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels whether a question has an answer or no answer (SQuAD 2.0)
        cls_index (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the classification token to use as input for computing plausibility of the
            answer.
        p_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Optional mask of tokens which can't be in answers (e.g. [CLS], [PAD], ...). 1.0 means token should be
            masked. 0.0 mean token is not masked.

        Returns:

        Example:

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

        >>> tokenizer = AutoTokenizer.from_pretrained("xlnet/xlnet-base-cased")
        >>> model = XLNetForQuestionAnswering.from_pretrained("xlnet/xlnet-base-cased")

        >>> input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True)).unsqueeze(
        ...     0
        ... )  # Batch size 1
        >>> start_positions = torch.tensor([1])
        >>> end_positions = torch.tensor([3])
        >>> outputs = model(input_ids, start_positions=start_positions, end_positions=end_positions)

        >>> loss = outputs.loss
        ```Nr¹  r   )rø  r   rÍ   )rç  rø  ru   )rç  r÷  rt   )r  rÁ   r  r  r    rÛ  )Ústart_statesrø  z
blh,bl->bh)rú  r÷  )r  r  r  r  r  rÁ   r  r  )r>   r…  r   r  r¡   Úsqueeze_r  r
   rõ  r   r	   r  rÁ   r  r  r¼  r¤   r¥   r`   Útopkró  r�  rH  ÚgatherÚ	expand_asrô  r»  r¢   )-r†   rd  re  rÁ   rf  rÂ   rg  rh  r¬   ri  rç  rè  rö  r÷  rø  rj  r­   rk  rl  r“  r½  r  r  rË   r™   r  r¾  rî  rï  rì  r  Úloss_fct_clsÚcls_lossrK  ÚslenÚhszÚstart_log_probsr  r  Ústart_top_index_exprú  Úhidden_states_expandedÚend_log_probsr  r  s-                                                rH   rÌ   z!XLNetForQuestionAnswering.forward�  s¬  € ð| &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà.˜d×.Ñ.Øð
à)ØØØ)Ø)Ø!ØØ'ØØ/Ø!5Ø#ñ
ð ñ
Ðð  ,¨AÑ.ˆØ×(Ñ(¨¸vÐ(ÓFˆà% a bÐ)ˆàÐ&¨=Ð+Dà% }°iÀÐOò #�Ø‘= Q§U¡U£W¨q£[Ø—J‘J˜r•Nð#ð
 Ÿ™¨ÈÐ`f˜ÓgˆJä'Ó)ˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJàÐ$¨Ð)Bà!×.Ñ.¨}ÈoÐirÐ.Ós�
Ü!×3Ñ3Ó5�Ù'¨
°MÓB�ð ˜h¨™nÑ,�
áØ"�}Ð':¸1¸2Ð'>Ñ>Ð>ä6Ø#Ø,×1Ñ1Ø"5×"CÑ"CØ2×=Ñ=ô	ð ð +×/Ñ/Ó1‰NˆC��sÜ Ÿm™m×3Ñ3°LÀbÐ3ÓIˆOä38·:±:Ø ×!1Ñ!1°rô4Ñ0Ð ð #2×";Ñ";¸BÓ"?×"FÑ"FÀrÈ2ÈsÓ"SÐÜ Ÿ<™<¨°rÐ;NÓOˆLØ'×1Ñ1°!Ó4×;Ñ;¸BÀÀbÈ"ÓMˆLà%2×%<Ñ%<¸QÓ%?×%IÑ%IØó&Ð"ð .4Ð-?�V×%Ñ% bÔ)ÀTˆFØŸ™Ð)?ÈlÐci˜ÓjˆJÜŸM™M×1Ñ1°*À!Ð1ÓDˆMä/4¯z©zØ˜tŸ~™~°1ô0Ñ,Ð˜}ð !2× 6Ñ 6°r¸4×;KÑ;KÈdÏnÉnÑ;\Ó ]ÐØ)×.Ñ.¨r°4×3CÑ3CÀdÇnÁnÑ3TÓUˆMä Ÿ<™<Ø˜m¨_óˆLð ×*Ñ*Ø¨LÀIð +ó ˆJñ Ø.°ÐARÐTaÐcmÐn�ØÐ!4°Q°RÐ!8Ñ8Ð8ä6Ø(;Ø$3Ø&7Ø"/Ø)Ø,×1Ñ1Ø"5×"CÑ"CØ2×=Ñ=ô	ð 	rJ   )NNNNNNNNNNNNNNNNNN)rÏ   rÐ   rÑ   ry   r   rž  rŸ  r   r  r¡  r   r`   r¢  r£  r   r   rÌ   rÓ   rÔ   s   @rH   rñ  rñ  l  sã  ø„ ôñ +Ð+A×+HÑ+HÐIfÓ+gÓhÙÐ+JÐYhÔið -1Ø15Ø'+Ø,0Ø15Ø15Ø-1Ø,0Ø04Ø26Ø04Ø04Ø,0Ø)-Ø#'Ø,0Ø/3Ø&*ñ'aà˜EŸL™LÑ)ðað ! §¡Ñ.ðað �u—|‘|Ñ$ð	að
 ˜EŸL™LÑ)ðað ! §¡Ñ.ðað ! §¡Ñ.ðað ˜UŸ\™\Ñ*ðað ˜EŸL™LÑ)ðað   §¡Ñ-ðað " %§,¡,Ñ/ðað   §¡Ñ-ðað   §¡Ñ-ðað ˜EŸL™LÑ)ðað ˜Ÿ™Ñ&ðað  ˜4‘.ð!að" $ D™>ð#að$ ' t™nð%að& ˜d‘^ð'að* 
ˆuÐ5Ð5Ñ	6ò+aó jó iôarJ   rñ  )	rØ  rñ  rä  rÅ  rÐ  r¥  rõ   rê   rp   r‰   )Arù   r†  Údataclassesr   Útypingr   r   r   r   r`   r   Útorch.nnr	   r
   r   Úactivationsr   Ú
generationr   Úmodeling_utilsr   r   r   r   r   Úpytorch_utilsr   Úutilsr   r   r   r   r   r   Úconfiguration_xlnetr   Ú
get_loggerrÏ   rR   r   r¡  rI   rp   ÚModulerr   rÖ   rà   rê   rÿ   r  r
  r  r  r  r  ÚXLNET_START_DOCSTRINGrž  rõ   r¥  rÅ  rÐ  rØ  rä  rñ  Ú__all__rý   rJ   rH   ú<module>r     sÙ  ðñ ó Ý !ß /Ó /ã Ý ß AÑ Aå !Ý )ß uÕ uÝ 6÷÷ õ -ð 
ˆ×	Ñ	˜HÓ	%€à.Ð Ø€óPòf@ôFA˜RŸY™Yô AôH�r—y‘yô ô./�—‘ô /ôd'V˜?ô 'VðT ô?�{ó ?ó ð?ðB ô!?˜[ó !?ó ð!?ðH ô?¨;ó ?ó ð?ðB ô?¨ó ?ó ð?ðB ô ? ;ó  ?ó ð ?ðF ô!?¨Kó !?ó ð!?ðH ô,? kó ,?ó ð,?ð^Ð ð FÐ ñR ØeØóôb
Ð%ó b
ó	ðb
ñJ ðð ó	ôFcÐ+¨_ó FcóðFcñR ðð óôc
Ð%9ó c
óðc
ñL ðð óôM
Ð"6ó M
óðM
ñ` ðð óô]
Ð1ó ]
óð]
ñ@ ðð óôd
Ð&:ó d
óðd
ñN ðð óôqÐ 4ó qóðqòh
�rJ   