+
    œ°³j·Ÿ  ã                   óú  € R t ^ RIHt ^ RIt^ RIHt ^ RIHtHtHt ^RI	H
t ^RIHt ^RIHt ^RIHtHtHtHtHtHt ^R	IHtHt ^R
IHt ^RIHt ^RIHtH t H!t!H"t" ^RI#H$t$ ^RI%H&t& ^RI'H(t( ]"PR                  ! ]*4      t+]PX                  t- ! R R]P\                  4      t/R9R R llt0 ! R R]P\                  4      t1 ! R R]P\                  4      t2 ! R R]P\                  4      t3 ! R R]P\                  4      t4 ! R R]P\                  4      t5 ! R R]4      t6 ! R  R!]P\                  4      t7 ! R" R#]P\                  4      t8 ! R$ R%]P\                  4      t9 ! R& R']P\                  4      t: ! R( R)]P\                  4      t;]  ! R* R+]4      4       t<]  ! R, R-]<4      4       t=]  ! R. R/]<4      4       t>] ! R0R17       ! R2 R3]<4      4       t?] ! R4R17       ! R5 R6]<4      4       t@]  ! R7 R8]<4      4       tA. R:OtBR# );zPyTorch LayoutLM model.)ÚCallableN)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELoss)Úinitialization)ÚACT2FN)ÚGradientCheckpointingLayer)ÚBaseModelOutputÚBaseModelOutputWithPoolingÚMaskedLMOutputÚQuestionAnsweringModelOutputÚSequenceClassifierOutputÚTokenClassifierOutput)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)Úapply_chunking_to_forward)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚlogging)Úmerge_with_config_defaults)Úcapture_outputs©ÚLayoutLMConfigc                   ó@   a a€ ] tR t^0t oRtV 3R ltRR ltRtVtV ;t	# )ÚLayoutLMEmbeddingszGConstruct the embeddings from word, position and token_type embeddings.c                ó  <€ \         SV `  4        \        P                  ! VP                  VP
                  VP                  R 7      V n        \        P                  ! VP                  VP
                  4      V n	        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP                  VP
                  4      V n        \#        VP
                  VP$                  R7      V n        \        P(                  ! VP*                  4      V n        \        P.                  ! \0        P2                  ! VP                  4      P5                  R4      RR7      V n        R# ))Úpadding_idx©ÚepsF)Ú
persistentN©é   éÿÿÿÿ)ÚsuperÚ__init__r   Ú	EmbeddingÚ
vocab_sizeÚhidden_sizeÚpad_token_idÚword_embeddingsÚmax_position_embeddingsÚposition_embeddingsÚmax_2d_position_embeddingsÚx_position_embeddingsÚy_position_embeddingsÚh_position_embeddingsÚw_position_embeddingsÚtype_vocab_sizeÚtoken_type_embeddingsÚLayoutLMLayerNormÚlayer_norm_epsÚ	LayerNormÚDropoutÚhidden_dropout_probÚdropoutÚBufferÚtorchÚarangeÚexpandÚposition_ids©ÚselfÚconfigÚ	__class__s   &&€Úo/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/layoutlm/modeling_layoutlm.pyr'   ÚLayoutLMEmbeddings.__init__3   sT  ø€ Ü‰ÑÔÜ!Ÿ|š|¨F×,=Ñ,=¸v×?QÑ?QÐ_e×_rÑ_rÔsˆÔÜ#%§<¢<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ Ü%'§\¢\°&×2SÑ2SÐU[×UgÑUgÓ%hˆÔ"Ü%'§\¢\°&×2SÑ2SÐU[×UgÑUgÓ%hˆÔ"Ü%'§\¢\°&×2SÑ2SÐU[×UgÑUgÓ%hˆÔ"Ü%'§\¢\°&×2SÑ2SÐU[×UgÑUgÓ%hˆÔ"Ü%'§\¢\°&×2HÑ2HÈ&×J\ÑJ\Ó%]ˆÔ"ä*¨6×+=Ñ+=À6×CXÑCXÔYˆŒÜ—z’z &×"<Ñ"<Ó=ˆŒäŸIšI¤e§l¢l°6×3QÑ3QÓ&R×&YÑ&YÐZaÓ&bÐotÔuˆÖó    c                óî  € Ve   VP                  4       pMVP                  4       R R pV^,          pVe   VP                  MVP                  pVf   V P                  RR V13,          pVf(   \        P                  ! V\        P
                  VR7      pVf   V P                  V4      pTp	V P                  V4      p
 V P                  VR,          4      pV P                  VR,          4      pV P                  VR,          4      pV P                  VR,          4      pT P                  TR,          TR,          ,
          4      pT P                  TR,          TR,          ,
          4      pT P                  T4      pT	T
,           T,           T,           T,           T,           T,           T,           T,           pT P                  T4      pT P                  T4      pT#   \         d   p\        R4      ThR p?ii ; i)	NºNNN©ÚdtypeÚdevicez:The `bbox`coordinate values should be within 0-1000 range.r%   )rI   rI   é    )rI   rI   r$   )rI   rI   é   )rI   rI   é   )ÚsizerL   r@   r=   ÚzerosÚlongr,   r.   r0   r1   Ú
IndexErrorr2   r3   r5   r8   r;   )rB   Ú	input_idsÚbboxÚtoken_type_idsr@   Úinputs_embedsÚinput_shapeÚ
seq_lengthrL   Úwords_embeddingsr.   Úleft_position_embeddingsÚupper_position_embeddingsÚright_position_embeddingsÚlower_position_embeddingsÚer2   r3   r5   Ú
embeddingss   &&&&&&              rE   ÚforwardÚLayoutLMEmbeddings.forwardB   sû  € ð Ò Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà  •^ˆ
à%.Ò%:�×!Ò!À×@TÑ@TˆàÒØ×,Ñ,¨Q°°°¨^Õ<ˆLàÒ!Ü"Ÿ[š[¨¼E¿J¹JÈvÔVˆNàÒ Ø ×0Ñ0°Ó;ˆMà(ÐØ"×6Ñ6°|ÓDÐð	bØ'+×'AÑ'AÀ$ÀwÅ-Ó'PÐ$Ø(,×(BÑ(BÀ4ÈÅ=Ó(QÐ%Ø(,×(BÑ(BÀ4ÈÅ=Ó(QÐ%Ø(,×(BÑ(BÀ4ÈÅ=Ó(QÐ%ð !%× :Ñ :¸4À½=È4ÐPWÍ=Õ;XÓ YÐØ $× :Ñ :¸4À½=È4ÐPWÍ=Õ;XÓ YÐØ $× :Ñ :¸>Ó JÐð Ø!õ"à&õ'ð (õ(ð (õ	(ð
 (õ(ð $õ$ð $õ$ð $õ$ð 	ð —^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐøô) ô 	bÜÐYÓZÐ`aÐaûð	bús   Â=A G ÇG4Ç#G/Ç/G4)
r8   r;   r2   r.   r@   r5   r3   r,   r0   r1   )NNNNN)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r'   ra   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rD   Ú__classdict__s   @@rE   r   r   0   s   ù‡ € ÙQõv÷5ô 5rG   r   c                óÞ   € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R\        /# )	rN   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskNÚscalingr;   )r   ÚModuler=   ÚTensorÚfloat)Úformats   "rE   Ú__annotate__rx   {   sg   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô ð%ô ñ%rG   c                 óÎ  € \         P                  ! WP                  ^^4      4      V,          pVe	   W„,           p\        P                  P                  VR\         P                  R7      P                  VP                  4      p\        P                  P                  W†V P                  R7      p\         P                  ! Wƒ4      p	V	P                  ^^4      P                  4       p	W˜3# )rN   )ÚdimrK   )ÚpÚtrainingr%   )r=   ÚmatmulÚ	transposer   Ú
functionalÚsoftmaxÚfloat32ÚtorK   r;   r|   Ú
contiguous)
rn   ro   rp   rq   rr   rs   r;   ÚkwargsÚattn_weightsÚattn_outputs
   &&&&&&&,  rE   Úeager_attention_forwardr‡   {   s°   € ô —<’< §}¡}°Q¸Ó':Ó;¸gÕE€LØÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KØÐ$Ð$rG   c                   óH   a a€ ] tR t^’t oV 3R ltRV3R lR lltRtVtV ;t# )ÚLayoutLMSelfAttentionc                ó\  <€ \         SV `  4        VP                  VP                  ,          ^ 8w  d9   \	        VR4      '       g'   \        RVP                   RVP                   R24      hWn        VP                  V n        \        VP                  VP                  ,          4      V n        V P                  V P                  ,          V n	        \        P                  ! VP                  V P                  4      V n        \        P                  ! VP                  V P                  4      V n        \        P                  ! VP                  V P                  4      V n        \        P                  ! VP                   4      V n        VP                   V n        V P                  R,          V n        R# )rM   Úembedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads (Ú)Ng      à¿)r&   r'   r*   Únum_attention_headsÚhasattrÚ
ValueErrorrC   ÚintÚattention_head_sizeÚall_head_sizer   ÚLinearro   rp   rq   r9   Úattention_probs_dropout_probr;   Úattention_dropoutrs   rA   s   &&€rE   r'   ÚLayoutLMSelfAttention.__init__“   sD  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Õ:¸aÔ?ÌÐPVÐXh×HiÒHiÜØ# F×$6Ñ$6Ð#7ð 8Ø ×4Ñ4Ð5°Qð8óð ð
 ŒØ#)×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÕ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÕPˆÔä—Y’Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
Ü—9’9˜V×/Ñ/°×1CÑ1CÓDˆŒÜ—Y’Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
ä—z’z &×"EÑ"EÓFˆŒØ!'×!DÑ!DˆÔØ×/Ñ/°Õ5ˆŽrG   c                óÄ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[S[ P                  S[ P                  R,          3,          /# ©rN   Úhidden_statesrr   Nr„   Úreturn)r=   ru   ÚFloatTensorr   r   Útuple)rw   rl   s   "€rE   rx   Ú"LayoutLMSelfAttention.__annotate__¨   s_   ø€ ÷ )ñ )á—|‘|ð)ñ ×)Ñ)¨DÕ0ð)ñ Ñ+Õ,ð	)ñ
 
‰u�|‰|™UŸ\™\¨DÕ0Ð0Õ	1ñ)rG   c                ó†  € VP                   R R p. VORNV P                  N5pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      p\        P                  ! V P                  P                  \        4      p	T	! V VVVV3RV P                  '       g   RMV P                  RV P                  /VB w  r«V
P                  ! . VORN5!  P!                  4       p
W«3# )Nr;   ç        rs   r%   )Úshaper‘   ro   Úviewr~   rp   rq   r   Úget_interfacerC   Ú_attn_implementationr‡   r|   r•   rs   Úreshaperƒ   )rB   r™   rr   r„   rX   Úhidden_shapeÚquery_statesÚ
key_statesÚvalue_statesÚattention_interfacer†   r…   s   &&&,        rE   ra   ÚLayoutLMSelfAttention.forward¨   sA  € ð $×)Ñ)¨#¨2Ð.ˆØC˜ÐC bÐC¨$×*BÑ*BÑCˆà—z‘z -Ó0×5Ñ5°lÓC×MÑMÈaÐQRÓSˆØ—X‘X˜mÓ,×1Ñ1°,Ó?×IÑIÈ!ÈQÓOˆ
Ø—z‘z -Ó0×5Ñ5°lÓC×MÑMÈaÐQRÓSˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØñ	%
ð  $Ÿ}Ÿ}˜}‘C°$×2HÑ2Hð	%
ð —L‘Lð	%
ð ñ	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØÐ(Ð(rG   )
r’   r•   r‘   rC   r;   rp   r�   ro   rs   rq   ©N©	rc   rd   re   rf   r'   ra   rh   ri   rj   rk   s   @@rE   r‰   r‰   ’   s   ù‡ € õ6÷*)÷ )ò )rG   r‰   c                   óD   a a€ ] tR t^Ét oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMSelfOutputc                ó0  <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        P                  ! VP                  VP                  R 7      V n        \        P                  ! VP                  4      V n
        R# ©r    N)r&   r'   r   r“   r*   Údenser8   r7   r9   r:   r;   rA   s   &&€rE   r'   ÚLayoutLMSelfOutput.__init__Ê   s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŽrG   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# ©rN   r™   Úinput_tensorrš   ©r=   ru   )rw   rl   s   "€rE   rx   ÚLayoutLMSelfOutput.__annotate__Ð   ó1   ø€ ÷ ñ ¡U§\¡\ð ÁÇÁð ÑRW×R^ÑR^ñ rG   c                óx   € V P                  V4      pV P                  V4      pV P                  W,           4      pV# r«   ©r±   r;   r8   ©rB   r™   rµ   s   &&&rE   ra   ÚLayoutLMSelfOutput.forwardÐ   ó5   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ }Õ'CÓDˆØÐrG   ©r8   r±   r;   r¬   rk   s   @@rE   r®   r®   É   ó   ù‡ € õ>÷÷ ð rG   r®   c                   óH   a a€ ] tR t^Øt oV 3R ltRV3R lR lltRtVtV ;t# )ÚLayoutLMAttentionc                ód   <€ \         SV `  4        \        V4      V n        \	        V4      V n        R # r«   )r&   r'   r‰   rB   r®   ÚoutputrA   s   &&€rE   r'   ÚLayoutLMAttention.__init__Ù   s&   ø€ Ü‰ÑÔÜ)¨&Ó1ˆŒ	Ü(¨Ó0ˆŽrG   c                óŒ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[ P                  /# r˜   ©r=   ru   r›   r   r   )rw   rl   s   "€rE   rx   ÚLayoutLMAttention.__annotate__Þ   sL   ø€ ÷ ñ á—|‘|ðñ ×)Ñ)¨DÕ0ðñ Ñ+Õ,ð	ñ
 
�‰ñrG   c                óZ   € TpV P                   ! V3R V/VB w  rV P                  W4      pV# ©rr   )rB   rÃ   )rB   r™   rr   r„   ÚresidualÚ_s   &&&,  rE   ra   ÚLayoutLMAttention.forwardÞ   sE   € ð !ˆØŸ9š9Øñ
à)ð
ð ñ
Ñˆð
 Ÿ™ MÓ<ˆØÐrG   )rÃ   rB   r«   r¬   rk   s   @@rE   rÁ   rÁ   Ø   s   ù‡ € õ1÷
÷ ò rG   rÁ   c                   óD   a a€ ] tR t^ït oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMIntermediatec                ó"  <€ \         SV `  4        \        P                  ! VP                  VP
                  4      V n        \        VP                  \        4      '       d   \        VP                  ,          V n        R # VP                  V n        R # r«   )r&   r'   r   r“   r*   Úintermediate_sizer±   Ú
isinstanceÚ
hidden_actÚstrr   Úintermediate_act_fnrA   s   &&€rE   r'   ÚLayoutLMIntermediate.__init__ð   s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬×-Ò-Ü'-¨f×.?Ñ.?Õ'@ˆDÖ$à'-×'8Ñ'8ˆDÖ$rG   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©rN   r™   rš   r¶   )rw   rl   s   "€rE   rx   Ú!LayoutLMIntermediate.__annotate__ø   s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ rG   c                óJ   € V P                  V4      pV P                  V4      pV# r«   ©r±   rÔ   ©rB   r™   s   &&rE   ra   ÚLayoutLMIntermediate.forwardø   s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐrG   rÚ   r¬   rk   s   @@rE   rÎ   rÎ   ï   s   ù‡ € õ9÷÷ ð rG   rÎ   c                   óD   a a€ ] tR t^ÿt oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMOutputc                ó0  <€ \         SV `  4        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP
                  VP                  R 7      V n        \        P                  ! VP                  4      V n        R# r°   )r&   r'   r   r“   rÐ   r*   r±   r8   r7   r9   r:   r;   rA   s   &&€rE   r'   ÚLayoutLMOutput.__init__   s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŽrG   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# r´   r¶   )rw   rl   s   "€rE   rx   ÚLayoutLMOutput.__annotate__  r¸   rG   c                óx   € V P                  V4      pV P                  V4      pV P                  W,           4      pV# r«   rº   r»   s   &&&rE   ra   ÚLayoutLMOutput.forward  r½   rG   r¾   r¬   rk   s   @@rE   rÞ   rÞ   ÿ   r¿   rG   rÞ   c                   óN   a a€ ] tR tRt oV 3R ltRV3R lR lltR tRtVtV ;t	# )ÚLayoutLMLayeri  c                ó´   <€ \         SV `  4        VP                  V n        ^V n        \	        V4      V n        \        V4      V n        \        V4      V n	        R# )r$   N)
r&   r'   Úchunk_size_feed_forwardÚseq_len_dimrÁ   Ú	attentionrÎ   ÚintermediaterÞ   rÃ   rA   s   &&€rE   r'   ÚLayoutLMLayer.__init__  sI   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ*¨6Ó2ˆŒÜ0°Ó8ˆÔÜ$ VÓ,ˆŽrG   c                óŒ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[ P                  /# r˜   rÆ   )rw   rl   s   "€rE   rx   ÚLayoutLMLayer.__annotate__  sL   ø€ ÷ ñ á—|‘|ðñ ×)Ñ)¨DÕ0ðñ Ñ+Õ,ð	ñ
 
�‰ñrG   c                óˆ   € V P                   ! V3R V/VB p\        V P                  V P                  V P                  V4      pV# rÉ   )rê   r   Úfeed_forward_chunkrè   ré   )rB   r™   rr   r„   s   &&&,rE   ra   ÚLayoutLMLayer.forward  sW   € ð ŸšØñ
à)ð
ð ñ
ˆô 2Ø×#Ñ# T×%AÑ%AÀ4×CSÑCSÐUbó
ˆð ÐrG   c                óJ   € V P                  V4      pV P                  W!4      pV# r«   )rë   rÃ   )rB   Úattention_outputÚintermediate_outputÚlayer_outputs   &&  rE   rð   Ú LayoutLMLayer.feed_forward_chunk)  s)   € Ø"×/Ñ/Ð0@ÓAÐØ—{‘{Ð#6ÓIˆØÐrG   )rê   rè   rë   rÃ   ré   r«   )
rc   rd   re   rf   r'   ra   rð   rh   ri   rj   rk   s   @@rE   ræ   ræ     s   ù‡ € õ-÷ò ÷$ò rG   ræ   c                   óH   a a€ ] tR tRt oV 3R ltRV3R lR lltRtVtV ;t# )ÚLayoutLMEncoderi0  c                óÖ   <€ \         SV `  4        Wn        \        P                  ! \        VP                  4       Uu. uF  p\        V4      NK  	  up4      V n        R V n	        R# u upi )FN)
r&   r'   rC   r   Ú
ModuleListÚrangeÚnum_hidden_layersræ   ÚlayerÚgradient_checkpointing)rB   rC   ÚirD   s   && €rE   r'   ÚLayoutLMEncoder.__init__1  sR   ø€ Ü‰ÑÔØŒÜ—]’]Ä5È×IaÑIaÔCbÓ#cÑCb¸a¤M°&Ö$9ÑCbÑ#cÓdˆŒ
Ø&+ˆÖ#ùò $ds   ½A&c                óx   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[,          RS[/# r˜   )r=   ru   r›   r   r   r
   )rw   rl   s   "€rE   rx   ÚLayoutLMEncoder.__annotate__7  sH   ø€ ÷ 
ñ 
á—|‘|ð
ñ ×)Ñ)¨DÕ0ð
ñ Ñ+Õ,ð	
ñ
 
ñ
rG   c                óT   € V P                    F  pV! VV3/ VB pK  	  \        VR 7      # ))Úlast_hidden_state)rý   r
   )rB   r™   rr   r„   Úlayer_modules   &&&, rE   ra   ÚLayoutLMEncoder.forward7  s>   € ð !ŸJœJˆLÙ(ØØñð ñŠMñ 'ô Ø+ô
ð 	
rG   )rC   rþ   rý   r«   r¬   rk   s   @@rE   rø   rø   0  s   ù‡ € õ,÷
÷ 
ò 
rG   rø   c                   óD   a a€ ] tR tRt oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMPooleriJ  c                ó¸   <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        P                  ! 4       V n        R # r«   )r&   r'   r   r“   r*   r±   ÚTanhÚ
activationrA   s   &&€rE   r'   ÚLayoutLMPooler.__init__K  s9   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ'š'›)ˆŽrG   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r×   r¶   )rw   rl   s   "€rE   rx   ÚLayoutLMPooler.__annotate__P  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ rG   c                ó\   € VR,          pV P                  V4      pV P                  V4      pV# )rI   )rI   rM   )r±   r  )rB   r™   Úfirst_token_tensorÚpooled_outputs   &&  rE   ra   ÚLayoutLMPooler.forwardP  s2   € ð +¨4Õ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐrG   )r  r±   r¬   rk   s   @@rE   r  r  J  s   ù‡ € õ$÷
÷ ð rG   r  c                   óD   a a€ ] tR tRt oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMPredictionHeadTransformiZ  c                ó‚  <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        VP                  \        4      '       d   \        VP                  ,          V n
        MVP                  V n
        \        P                  ! VP                  VP                  R 7      V n        R# r°   )r&   r'   r   r“   r*   r±   rÑ   rÒ   rÓ   r   Útransform_act_fnr8   r7   rA   s   &&€rE   r'   Ú(LayoutLMPredictionHeadTransform.__init__[  s~   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
Ü�f×'Ñ'¬×-Ò-Ü$*¨6×+<Ñ+<Õ$=ˆDÕ!à$*×$5Ñ$5ˆDÔ!ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŽrG   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r×   r¶   )rw   rl   s   "€rE   rx   Ú,LayoutLMPredictionHeadTransform.__annotate__d  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ rG   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r«   )r±   r  r8   rÛ   s   &&rE   ra   Ú'LayoutLMPredictionHeadTransform.forwardd  s4   € ØŸ
™
 =Ó1ˆØ×-Ñ-¨mÓ<ˆØŸ™ }Ó5ˆØÐrG   )r8   r±   r  r¬   rk   s   @@rE   r  r  Z  s   ù‡ € õU÷÷ ð rG   r  c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚLayoutLMLMPredictionHeadil  c                ó  <€ \         SV `  4        \        V4      V n        \        P
                  ! VP                  VP                  R R7      V n        \        P                  ! \        P                  ! VP                  4      4      V n        R# )T)ÚbiasN)r&   r'   r  Ú	transformr   r“   r*   r)   ÚdecoderÚ	Parameterr=   rQ   r  rA   s   &&€rE   r'   Ú!LayoutLMLMPredictionHead.__init__m  s[   ø€ Ü‰ÑÔÜ8¸Ó@ˆŒô —y’y ×!3Ñ!3°V×5FÑ5FÈTÔRˆŒÜ—L’L¤§¢¨V×->Ñ->Ó!?Ó@ˆŽ	rG   c                óJ   € V P                  V4      pV P                  V4      pV# r«   )r   r!  rÛ   s   &&rE   ra   Ú LayoutLMLMPredictionHead.forwardv  s$   € ØŸ™ }Ó5ˆØŸ™ ]Ó3ˆØÐrG   )r  r!  r   r¬   rk   s   @@rE   r  r  l  s   ù‡ € õA÷ò rG   r  c                   óD   a a€ ] tR tRt oV 3R ltV3R lR ltRtVtV ;t# )ÚLayoutLMOnlyMLMHeadi}  c                óD   <€ \         SV `  4        \        V4      V n        R # r«   )r&   r'   r  ÚpredictionsrA   s   &&€rE   r'   ÚLayoutLMOnlyMLMHead.__init__~  s   ø€ Ü‰ÑÔÜ3°FÓ;ˆÖrG   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )rN   Úsequence_outputrš   r¶   )rw   rl   s   "€rE   rx   Ú LayoutLMOnlyMLMHead.__annotate__‚  s#   ø€ ÷ !ñ !¡u§|¡|ð !¹¿¹ñ !rG   c                ó(   € V P                  V4      pV# r«   ©r)  )rB   r,  Úprediction_scoress   && rE   ra   ÚLayoutLMOnlyMLMHead.forward‚  s   € Ø ×,Ñ,¨_Ó=ÐØ Ð rG   r/  r¬   rk   s   @@rE   r'  r'  }  s   ù‡ € õ<÷!÷ !ð !rG   r'  c                   óz   a a€ ] tR tRt oRtRtR]R]/t]	P                  ! 4       V 3R l4       tV3R ltRtVtV ;t# )	ÚLayoutLMPreTrainedModeli‡  ÚlayoutlmTr™   Ú
attentionsc                ó„  <€ \         SV `  V4       \        V\        4      '       d#   \        P
                  ! VP                  4       R# \        V\        4      '       db   \        P                  ! VP                  \        P                  ! VP                  P                  R,          4      P                  R4      4       R# R# )zInitialize the weightsNr%   r#   )r&   Ú_init_weightsrÑ   r  ÚinitÚzeros_r  r   Úcopy_r@   r=   r>   r    r?   )rB   rn   rD   s   &&€rE   r7  Ú%LayoutLMPreTrainedModel._init_weights‘  s~   ø€ ô 	‰Ñ˜fÔ%Ü�fÔ6×7Ò7Ü�KŠK˜Ÿ™Ö$Ü˜Ô 2×3Ò3Ü�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÕ9VÓ,W×,^Ñ,^Ð_fÓ,gÖhñ 4rG   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )rN   rC   r   )rw   rl   s   "€rE   rx   Ú$LayoutLMPreTrainedModel.__annotate__‡  s   ø‡ ‚ áÑò rG   © )rc   rd   re   rf   Úbase_model_prefixÚsupports_gradient_checkpointingræ   r‰   Ú_can_record_outputsr=   Úno_gradr7  Ú__annotate_func__rh   ri   rj   rk   s   @@rE   r3  r3  ‡  sI   ù‡ € ð #ÐØ&*Ð#à˜ØÐ+ðÐð
 ‡]‚]ƒ_ôió ði÷ … rG   r3  c                   ór   a a€ ] tR tRt oV 3R ltR tR t]]]	RV3R lR ll4       4       4       t
RtVtV ;t# )	ÚLayoutLMModeli›  c                ó²   <€ \         SV `  V4       Wn        \        V4      V n        \        V4      V n        \        V4      V n        V P                  4        R # r«   )
r&   r'   rC   r   r`   rø   Úencoderr  ÚpoolerÚ	post_initrA   s   &&€rE   r'   ÚLayoutLMModel.__init__�  sE   ø€ Ü‰Ñ˜Ô ØŒä,¨VÓ4ˆŒÜ& vÓ.ˆŒÜ$ VÓ,ˆŒð 	�‰ÖrG   c                ó.   € V P                   P                  # r«   ©r`   r,   ©rB   s   &rE   Úget_input_embeddingsÚ"LayoutLMModel.get_input_embeddings¨  s   € Ø�‰×.Ñ.Ð.rG   c                ó&   € WP                   n        R # r«   rL  )rB   rq   s   &&rE   Úset_input_embeddingsÚ"LayoutLMModel.set_input_embeddings«  s   € Ø*/�‰Ö'rG   c                ó6  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[S[,          R	S[S[,          /# )
rN   rT   NrU   rr   rV   r@   rW   r„   rš   )r=   Ú
LongTensorr›   r   r   rœ   r   )rw   rl   s   "€rE   rx   ÚLayoutLMModel.__annotate__±  s³   ø€ ÷ [
ñ [
á×#Ñ# dÕ*ð[
ñ ×Ñ Õ%ð[
ñ ×)Ñ)¨DÕ0ð	[
ñ
 ×(Ñ(¨4Õ/ð[
ñ ×&Ñ&¨Õ-ð[
ñ ×(Ñ(¨4Õ/ð[
ñ Ñ+Õ,ð[
ñ 
Ñ+Õ	+ñ[
rG   c                ól  € Ve   Ve   \        R4      hVe#   V P                  W4       VP                  4       pM#Ve   VP                  4       RR
 pM\        R4      hVe   VP                  MVP                  p	Vf   \        P
                  ! W‰R7      pVf(   \        P                  ! V\        P                  V	R7      pVf/   \        P                  ! VR,           \        P                  V	R7      pVP                  ^4      P                  ^4      p
V
P                  V P                  R7      p
RV
,
          \        P                  ! V P                  4      P                  ,          p
V P                  VVVVVR7      pV P                  ! VV
3/ VB pV^ ,          pV P                  V4      p\!        VVR	7      # )a  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner. See [Overview](#Overview) for normalization.

Examples:

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

>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
>>> model = LayoutLMModel.from_pretrained("microsoft/layoutlm-base-uncased")

>>> words = ["Hello", "world"]
>>> normalized_word_boxes = [637, 773, 693, 782], [698, 773, 733, 782]

>>> token_boxes = []
>>> for word, box in zip(words, normalized_word_boxes):
...     word_tokens = tokenizer.tokenize(word)
...     token_boxes.extend([box] * len(word_tokens))
>>> # add bounding boxes of cls + sep tokens
>>> token_boxes = [[0, 0, 0, 0]] + token_boxes + [[1000, 1000, 1000, 1000]]

>>> encoding = tokenizer(" ".join(words), return_tensors="pt")
>>> input_ids = encoding["input_ids"]
>>> attention_mask = encoding["attention_mask"]
>>> token_type_ids = encoding["token_type_ids"]
>>> bbox = torch.tensor([token_boxes])

>>> outputs = model(
...     input_ids=input_ids, bbox=bbox, attention_mask=attention_mask, token_type_ids=token_type_ids
... )

>>> last_hidden_states = outputs.last_hidden_state
```NzDYou cannot specify both input_ids and inputs_embeds at the same timez5You have to specify either input_ids or inputs_embeds)rL   rJ   )rK   g      ð?)rT   rU   r@   rV   rW   )r  Úpooler_outputr%   )é   )r�   Ú%warn_if_padding_and_no_attention_maskrP   rL   r=   ÚonesrQ   rR   Ú	unsqueezer‚   rK   ÚfinfoÚminr`   rG  rH  r   )rB   rT   rU   rr   rV   r@   rW   r„   rX   rL   Úextended_attention_maskÚembedding_outputÚencoder_outputsr,  r  s   &&&&&&&,       rE   ra   ÚLayoutLMModel.forward®  s–  € ðf Ò  ]Ò%>ÜÐcÓdÐdØÒ"Ø×6Ñ6°yÔQØ#Ÿ.™.Ó*‰KØÒ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUà%.Ò%:�×!Ò!À×@TÑ@TˆàÒ!Ü"ŸZšZ¨ÔCˆNØÒ!Ü"Ÿ[š[¨¼E¿J¹JÈvÔVˆNàŠ<Ü—;’;˜{¨TÕ1¼¿¹ÈFÔSˆDà"0×":Ñ":¸1Ó"=×"GÑ"GÈÓ"JÐà"9×"<Ñ"<À4Ç:Á:Ð"<Ó"NÐØ#&Ð)@Õ#@ÄEÇKÂKÐPT×PZÑPZÓD[×D_ÑD_Õ"_ÐàŸ?™?ØØØ%Ø)Ø'ð +ó 
Ðð Ÿ,š,ØØ#ñ
ð ñ
ˆð
 *¨!Õ,ˆØŸ™ OÓ4ˆä)Ø-Ø'ô
ð 	
rG   )rC   r`   rG  rH  )NNNNNN)rc   rd   re   rf   r'   rN  rQ  r   r   r   ra   rh   ri   rj   rk   s   @@rE   rE  rE  ›  sF   ù‡ € õ	ò/ò0ð  ØØ÷[
ñ [
ó ó ó  ÷[
ð [
rG   rE  c                   óz   a a€ ] tR tRt oRRRR/tV 3R ltR tR tR	 t]	]
RV3R
 lR ll4       4       tRtVtV ;t# )ÚLayoutLMForMaskedLMi  zcls.predictions.decoder.biaszcls.predictions.biaszcls.predictions.decoder.weightz*layoutlm.embeddings.word_embeddings.weightc                ó†   <€ \         SV `  V4       \        V4      V n        \	        V4      V n        V P                  4        R # r«   )r&   r'   rE  r4  r'  ÚclsrI  rA   s   &&€rE   r'   ÚLayoutLMForMaskedLM.__init__  s4   ø€ Ü‰Ñ˜Ô ä% fÓ-ˆŒÜ& vÓ.ˆŒð 	�‰ÖrG   c                óB   € V P                   P                  P                  # r«   ©r4  r`   r,   rM  s   &rE   rN  Ú(LayoutLMForMaskedLM.get_input_embeddings  ó   € Ø�}‰}×'Ñ'×7Ñ7Ð7rG   c                óB   € V P                   P                  P                  # r«   )re  r)  r!  rM  s   &rE   Úget_output_embeddingsÚ)LayoutLMForMaskedLM.get_output_embeddings"  s   € Ø�x‰x×#Ñ#×+Ñ+Ð+rG   c                ó„   € WP                   P                  n        VP                  V P                   P                  n        R # r«   )re  r)  r!  r  )rB   Únew_embeddingss   &&rE   Úset_output_embeddingsÚ)LayoutLMForMaskedLM.set_output_embeddings%  s*   € Ø'5�‰×ÑÔ$Ø$2×$7Ñ$7ˆ�‰×ÑÖ!rG   c                ó^  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[S[,          R
S[S[,          /	# ©rN   rT   NrU   rr   rV   r@   rW   Úlabelsr„   rš   )r=   rT  r›   r   r   rœ   r   )rw   rl   s   "€rE   rx   Ú LayoutLMForMaskedLM.__annotate__+  sÈ   ø€ ÷ U
ñ U
á×#Ñ# dÕ*ðU
ñ ×Ñ Õ%ðU
ñ ×)Ñ)¨DÕ0ð	U
ñ
 ×(Ñ(¨4Õ/ðU
ñ ×&Ñ&¨Õ-ðU
ñ ×(Ñ(¨4Õ/ðU
ñ × Ñ  4Õ'ðU
ñ Ñ+Õ,ðU
ñ 
‘Õ	ñU
rG   c                óL  € V P                   ! VV3RVRVRVRV/VB p	V	^ ,          p
V P                  V
4      pRpVeG   \        4       pV! VP                  RV P                  P
                  4      VP                  R4      4      p\        VVV	P                  V	P                  R7      # )a  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner. See [Overview](#Overview) for normalization.
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
    config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
    loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`

Examples:

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

>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
>>> model = LayoutLMForMaskedLM.from_pretrained("microsoft/layoutlm-base-uncased")

>>> words = ["Hello", "[MASK]"]
>>> normalized_word_boxes = [637, 773, 693, 782], [698, 773, 733, 782]

>>> token_boxes = []
>>> for word, box in zip(words, normalized_word_boxes):
...     word_tokens = tokenizer.tokenize(word)
...     token_boxes.extend([box] * len(word_tokens))
>>> # add bounding boxes of cls + sep tokens
>>> token_boxes = [[0, 0, 0, 0]] + token_boxes + [[1000, 1000, 1000, 1000]]

>>> encoding = tokenizer(" ".join(words), return_tensors="pt")
>>> input_ids = encoding["input_ids"]
>>> attention_mask = encoding["attention_mask"]
>>> token_type_ids = encoding["token_type_ids"]
>>> bbox = torch.tensor([token_boxes])

>>> labels = tokenizer("Hello world", return_tensors="pt")["input_ids"]

>>> outputs = model(
...     input_ids=input_ids,
...     bbox=bbox,
...     attention_mask=attention_mask,
...     token_type_ids=token_type_ids,
...     labels=labels,
... )

>>> loss = outputs.loss
```rr   rV   r@   rW   N©ÚlossÚlogitsr™   r5  r%   )	r4  re  r   r¡   rC   r)   r   r™   r5  )rB   rT   rU   rr   rV   r@   rW   rt  r„   Úoutputsr,  r0  Úmasked_lm_lossÚloss_fcts   &&&&&&&&,     rE   ra   ÚLayoutLMForMaskedLM.forward)  sÎ   € ðz —-’-ØØñ
ð *ð
ð *ð	
ð
 &ð
ð (ð
ð ñ
ˆð " !�*ˆØ ŸH™H _Ó5ÐàˆØÒÜ'Ó)ˆHÙ%Ø!×&Ñ& r¨4¯;©;×+AÑ+AÓBØ—‘˜B“óˆNô
 ØØ$Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
rG   )re  r4  ©NNNNNNN)rc   rd   re   rf   Ú_tied_weights_keysr'   rN  rl  rp  r   r   ra   rh   ri   rj   rk   s   @@rE   rc  rc    sY   ù‡ € ð 	'Ð(>Ø(Ð*VðÐõ
ò8ò,ò8ð Ø÷U
ñ U
ó ó ÷U
ð U
rG   rc  zì
    LayoutLM Model with a sequence classification head on top (a linear layer on top of the pooled output) e.g. for
    document image classification tasks such as the [RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/) dataset.
    )Úcustom_introc                   ób   a a€ ] tR tRt oV 3R ltR t]]RV3R lR ll4       4       tRt	Vt
V ;t# )Ú!LayoutLMForSequenceClassificationiƒ  c                ó2  <€ \         SV `  V4       VP                  V n        \        V4      V n        \
        P                  ! VP                  4      V n        \
        P                  ! VP                  VP                  4      V n        V P                  4        R # r«   ©r&   r'   Ú
num_labelsrE  r4  r   r9   r:   r;   r“   r*   Ú
classifierrI  rA   s   &&€rE   r'   Ú*LayoutLMForSequenceClassification.__init__Š  ói   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ% fÓ-ˆŒÜ—z’z &×"<Ñ"<Ó=ˆŒÜŸ)š) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰ÖrG   c                óB   € V P                   P                  P                  # r«   rh  rM  s   &rE   rN  Ú6LayoutLMForSequenceClassification.get_input_embeddings”  rj  rG   c                ó^  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[S[,          R
S[S[,          /	# rs  )r=   rT  r›   r   r   rœ   r   )rw   rl   s   "€rE   rx   Ú.LayoutLMForSequenceClassification.__annotate__™  sÉ   ø€ ÷ f
ñ f
á×#Ñ# dÕ*ðf
ñ ×Ñ Õ%ðf
ñ ×)Ñ)¨DÕ0ð	f
ñ
 ×(Ñ(¨4Õ/ðf
ñ ×&Ñ&¨Õ-ðf
ñ ×(Ñ(¨4Õ/ðf
ñ × Ñ  4Õ'ðf
ñ Ñ+Õ,ðf
ñ 
Ñ)Õ	)ñf
rG   c                ó  € V P                   ! RRVRVRVRVRVRV/VB p	V	^,          p
V P                  V
4      p
V P                  V
4      pRpVEe˜   V P                  P                  f–   V P
                  ^8X  d   RV P                  n        MrV P
                  ^8”  dQ   VP                  \        P                  8X  g    VP                  \        P                  8X  d   R	V P                  n        MR
V P                  n        V P                  P                  R8X  dK   \        4       pV P
                  ^8X  d'   V! VP                  4       VP                  4       4      pMŽV! W·4      pM…V P                  P                  R	8X  d>   \        4       pV! VP                  RV P
                  4      VP                  R4      4      pM-V P                  P                  R
8X  d   \        4       pV! W·4      p\        VVV	P                   V	P"                  R7      # )a
  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner. See [Overview](#Overview) for normalization.
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).

Examples:

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

>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
>>> model = LayoutLMForSequenceClassification.from_pretrained("microsoft/layoutlm-base-uncased")

>>> words = ["Hello", "world"]
>>> normalized_word_boxes = [637, 773, 693, 782], [698, 773, 733, 782]

>>> token_boxes = []
>>> for word, box in zip(words, normalized_word_boxes):
...     word_tokens = tokenizer.tokenize(word)
...     token_boxes.extend([box] * len(word_tokens))
>>> # add bounding boxes of cls + sep tokens
>>> token_boxes = [[0, 0, 0, 0]] + token_boxes + [[1000, 1000, 1000, 1000]]

>>> encoding = tokenizer(" ".join(words), return_tensors="pt")
>>> input_ids = encoding["input_ids"]
>>> attention_mask = encoding["attention_mask"]
>>> token_type_ids = encoding["token_type_ids"]
>>> bbox = torch.tensor([token_boxes])
>>> sequence_label = torch.tensor([1])

>>> outputs = model(
...     input_ids=input_ids,
...     bbox=bbox,
...     attention_mask=attention_mask,
...     token_type_ids=token_type_ids,
...     labels=sequence_label,
... )

>>> loss = outputs.loss
>>> logits = outputs.logits
```rT   rU   rr   rV   r@   rW   NÚ
regressionÚsingle_label_classificationÚmulti_label_classificationrw  r>  r%   )r4  r;   r†  rC   Úproblem_typer…  rK   r=   rR   r�   r   Úsqueezer   r¡   r   r   r™   r5  )rB   rT   rU   rr   rV   r@   rW   rt  r„   rz  r  ry  rx  r|  s   &&&&&&&&,     rE   ra   Ú)LayoutLMForSequenceClassification.forward—  sÅ  € ðz —-’-ñ 
Øð
àð
ð *ð
ð *ð	
ð
 &ð
ð (ð
ð ñ
ˆð   �
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÓØ�{‰{×'Ñ'Ò/Ø—?‘? aÔ'Ø/;�D—K‘KÕ,Ø—_‘_ qÔ(¨f¯l©l¼e¿j¹jÔ.HÈFÏLÉLÔ\a×\eÑ\eÔLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ô7Ü"›9�Ø—?‘? aÔ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# FÓ3‘DØ—‘×)Ñ)Ð-JÔJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÔIÜ,Ó.�Ù Ó/�ä'ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
rG   ©r†  r;   r4  r…  r~  ©rc   rd   re   rf   r'   rN  r   r   ra   rh   ri   rj   rk   s   @@rE   r‚  r‚  ƒ  s9   ù‡ € õò8ð Ø÷f
ñ f
ó ó ÷f
ð f
rG   r‚  a3  
    LayoutLM Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
    sequence labeling (information extraction) tasks such as the [FUNSD](https://guillaumejaume.github.io/FUNSD/)
    dataset and the [SROIE](https://rrc.cvc.uab.es/?ch=13) dataset.
    c                   ób   a a€ ] tR tRt oV 3R ltR t]]RV3R lR ll4       4       tRt	Vt
V ;t# )ÚLayoutLMForTokenClassificationi  c                ó2  <€ \         SV `  V4       VP                  V n        \        V4      V n        \
        P                  ! VP                  4      V n        \
        P                  ! VP                  VP                  4      V n        V P                  4        R # r«   r„  rA   s   &&€rE   r'   Ú'LayoutLMForTokenClassification.__init__
  rˆ  rG   c                óB   € V P                   P                  P                  # r«   rh  rM  s   &rE   rN  Ú3LayoutLMForTokenClassification.get_input_embeddings  rj  rG   c                ó^  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[S[,          R
S[S[,          /	# rs  )r=   rT  r›   r   r   rœ   r   )rw   rl   s   "€rE   rx   Ú+LayoutLMForTokenClassification.__annotate__  sÉ   ø€ ÷ R
ñ R
á×#Ñ# dÕ*ðR
ñ ×Ñ Õ%ðR
ñ ×)Ñ)¨DÕ0ð	R
ñ
 ×(Ñ(¨4Õ/ðR
ñ ×&Ñ&¨Õ-ðR
ñ ×(Ñ(¨4Õ/ðR
ñ × Ñ  4Õ'ðR
ñ Ñ+Õ,ðR
ñ 
Ñ&Õ	&ñR
rG   c                ó^  € V P                   ! R	RVRVRVRVRVRV/VB p	V	^ ,          p
V P                  V
4      p
V P                  V
4      pRpVe=   \        4       pV! VP	                  R
V P
                  4      VP	                  R
4      4      p\        VVV	P                  V	P                  R7      # )a‡  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner. See [Overview](#Overview) for normalization.
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.

Examples:

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

>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")
>>> model = LayoutLMForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased")

>>> words = ["Hello", "world"]
>>> normalized_word_boxes = [637, 773, 693, 782], [698, 773, 733, 782]

>>> token_boxes = []
>>> for word, box in zip(words, normalized_word_boxes):
...     word_tokens = tokenizer.tokenize(word)
...     token_boxes.extend([box] * len(word_tokens))
>>> # add bounding boxes of cls + sep tokens
>>> token_boxes = [[0, 0, 0, 0]] + token_boxes + [[1000, 1000, 1000, 1000]]

>>> encoding = tokenizer(" ".join(words), return_tensors="pt")
>>> input_ids = encoding["input_ids"]
>>> attention_mask = encoding["attention_mask"]
>>> token_type_ids = encoding["token_type_ids"]
>>> bbox = torch.tensor([token_boxes])
>>> token_labels = torch.tensor([1, 1, 0, 0]).unsqueeze(0)  # batch size of 1

>>> outputs = model(
...     input_ids=input_ids,
...     bbox=bbox,
...     attention_mask=attention_mask,
...     token_type_ids=token_type_ids,
...     labels=token_labels,
... )

>>> loss = outputs.loss
>>> logits = outputs.logits
```rT   rU   rr   rV   r@   rW   Nrw  r>  r%   )	r4  r;   r†  r   r¡   r…  r   r™   r5  )rB   rT   rU   rr   rV   r@   rW   rt  r„   rz  r,  ry  rx  r|  s   &&&&&&&&,     rE   ra   Ú&LayoutLMForTokenClassification.forward  s×   € ðv —-’-ñ 
Øð
àð
ð *ð
ð *ð	
ð
 &ð
ð (ð
ð ñ
ˆð " !�*ˆàŸ,™, Ó7ˆØ—‘ Ó1ˆàˆØÒÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
rG   r”  r~  r•  rk   s   @@rE   r—  r—    s9   ù‡ € õò8ð Ø÷R
ñ R
ó ó ÷R
ð R
rG   r—  c                   óf   a a€ ] tR tRt oRV 3R lltR t]]RV3R lR ll4       4       tRt	Vt
V ;t# )	ÚLayoutLMForQuestionAnsweringin  c                óè   <€ \         SV `  V4       VP                  V n        \        V4      V n        \
        P                  ! VP                  VP                  4      V n        V P                  4        R# )z}
has_visual_segment_embedding (`bool`, *optional*, defaults to `True`):
    Whether or not to add visual segment embeddings.
N)
r&   r'   r…  rE  r4  r   r“   r*   Ú
qa_outputsrI  )rB   rC   Úhas_visual_segment_embeddingrD   s   &&&€rE   r'   Ú%LayoutLMForQuestionAnswering.__init__p  sU   ø€ ô
 	‰Ñ˜Ô Ø ×+Ñ+ˆŒä% fÓ-ˆŒÜŸ)š) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰ÖrG   c                óB   € V P                   P                  P                  # r«   rh  rM  s   &rE   rN  Ú1LayoutLMForQuestionAnswering.get_input_embeddings~  rj  rG   c                ó†  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[ P                  R,          R
S[S[,          RS[S[,          /
# )rN   rT   NrU   rr   rV   r@   rW   Ústart_positionsÚend_positionsr„   rš   )r=   rT  r›   r   r   rœ   r   )rw   rl   s   "€rE   rx   Ú)LayoutLMForQuestionAnswering.__annotate__ƒ  sß   ø€ ÷ e
ñ e
á×#Ñ# dÕ*ðe
ñ ×Ñ Õ%ðe
ñ ×)Ñ)¨DÕ0ð	e
ñ
 ×(Ñ(¨4Õ/ðe
ñ ×&Ñ&¨Õ-ðe
ñ ×(Ñ(¨4Õ/ðe
ñ ×)Ñ)¨DÕ0ðe
ñ ×'Ñ'¨$Õ.ðe
ñ Ñ+Õ,ðe
ñ 
Ñ-Õ	-ñe
rG   c	                óò  € V P                   ! RRVRVRVRVRVRV/V	B p
V
^ ,          pV P                  V4      pVP                  ^RR7      w  rÞVP                  R4      P	                  4       pVP                  R4      P	                  4       pRpVeÄ   VeÀ   \        VP                  4       4      ^8”  d   VP                  R4      p\        VP                  4       4      ^8”  d   VP                  R4      pVP                  ^4      pVP                  ^ V4      pVP                  ^ V4      p\        VR	7      pV! W×4      pV! Wè4      pVV,           ^,          p\        VVVV
P                  V
P                  R
7      # )aô  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner. See [Overview](#Overview) for normalization.

Example:

In the example below, we prepare a question + context pair for the LayoutLM model. It will give us a prediction
of what it thinks the answer is (the span of the answer within the texts parsed from the image).

```python
>>> from transformers import AutoTokenizer, LayoutLMForQuestionAnswering
>>> from datasets import load_dataset
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("impira/layoutlm-document-qa", add_prefix_space=True)
>>> model = LayoutLMForQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="1e3ebac")

>>> dataset = load_dataset("nielsr/funsd", split="train")
>>> example = dataset[0]
>>> question = "what's his name?"
>>> words = example["words"]
>>> boxes = example["bboxes"]

>>> encoding = tokenizer(
...     question.split(), words, is_split_into_words=True, return_token_type_ids=True, return_tensors="pt"
... )
>>> bbox = []
>>> for i, s, w in zip(encoding.input_ids[0], encoding.sequence_ids(0), encoding.word_ids(0)):
...     if s == 1:
...         bbox.append(boxes[w])
...     elif i == tokenizer.sep_token_id:
...         bbox.append([1000] * 4)
...     else:
...         bbox.append([0] * 4)
>>> encoding["bbox"] = torch.tensor([bbox])

>>> word_ids = encoding.word_ids(0)
>>> outputs = model(**encoding)
>>> loss = outputs.loss
>>> start_scores = outputs.start_logits
>>> end_scores = outputs.end_logits
>>> start, end = word_ids[start_scores.argmax(-1)], word_ids[end_scores.argmax(-1)]
>>> print(" ".join(words[start : end + 1]))
M. Hamann P. Harper, P. Martinez
```rT   rU   rr   rV   r@   rW   )rz   N)Úignore_index)rx  Ústart_logitsÚ
end_logitsr™   r5  r>  r%   )r4  r£  Úsplitr’  rƒ   ÚlenrP   Úclampr   r   r™   r5  )rB   rT   rU   rr   rV   r@   rW   r©  rª  r„   rz  r,  ry  r®  r¯  Ú
total_lossÚignored_indexr|  Ú
start_lossÚend_losss   &&&&&&&&&,          rE   ra   Ú$LayoutLMForQuestionAnswering.forward�  sš  € ð~ —-’-ñ 
Øð
àð
ð *ð
ð *ð	
ð
 &ð
ð (ð
ð ñ
ˆð " !�*ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆ
ØÒ&¨=Ò+Dä�?×'Ñ'Ó)Ó*¨QÔ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ô,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ-×3Ñ3°A°}ÓEˆOØ)×/Ñ/°°=ÓAˆMä'°]ÔCˆHÙ! ,Ó@ˆJÙ 
Ó:ˆHØ$ xÕ/°1Õ4ˆJä+ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ô
ð 	
rG   )r4  r…  r£  )T)NNNNNNNNr•  rk   s   @@rE   r¡  r¡  n  s9   ù‡ € ÷ò8ð Ø÷e
ñ e
ó ó ÷e
ð e
rG   r¡  )rŸ   )rc  r‚  r—  r¡  rE  r3  )Crg   Úcollections.abcr   r=   r   Útorch.nnr   r   r   Ú r   r8  Úactivationsr   Úmodeling_layersr	   Úmodeling_outputsr
   r   r   r   r   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úpytorch_utilsr   Úutilsr   r   r   r   Úutils.genericr   Úutils.output_capturingr   Úconfiguration_layoutlmr   Ú
get_loggerrc   Úloggerr8   r6   rt   r   r‡   r‰   r®   rÁ   rÎ   rÞ   ræ   rø   r  r  r  r'  r3  rE  rc  r‚  r—  r¡  Ú__all__r>  rG   rE   Ú<module>rÈ     s  ðñ å $ã Ý ß AÑ Aå &Ý !Ý 9÷÷ ÷ GÝ &Ý 6ß RÓ RÝ 7Ý 5Ý 2ð 
×	Ò	˜HÓ	%€ð —L‘LÐ ôG˜Ÿ™ô G÷V%ô.3)˜BŸI™Iô 3)ôn˜Ÿ™ô ô˜Ÿ	™	ô ô.˜2Ÿ9™9ô ô �R—Y‘Yô ôÐ.ô ôD
�b—i‘iô 
ô4�R—Y‘Yô ô  b§i¡iô ô$˜rŸy™yô ô"!˜"Ÿ)™)ô !ð ôi˜oó ió ðið& ôp
Ð+ó p
ó ðp
ðf ôp
Ð1ó p
ó ðp
ñf ðôôv
Ð(?ó v
óðv
ñr ðôôb
Ð%<ó b
óðb
ðJ ôy
Ð#:ó y
ó ðy
òx‚rG   