+
    œ°³jìy ã                   óØ  € R t ^ RIt^ RI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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"H#t#H$t$ ^RI%H&t& ]$PN                  ! ](4      t)Rt*RQt+]#! RR7      ] ! R R]"4      4       4       t, ! R R]PZ                  4      t. ! R R]PZ                  4      t/ ! R R]PZ                  4      t0 ! R R]PZ                  4      t1 ! R R]PZ                  4      t2 ! R R]PZ                  4      t3 ! R  R!]4      t4 ! R" R#]PZ                  4      t5 ! R$ R%]PZ                  4      t6 ! R& R']PZ                  4      t7 ! R( R)]PZ                  4      t8 ! R* R+]PZ                  4      t9]# ! R, R-]4      4       t:]# ! R. R/]:4      4       t;]# ! R0 R1]:4      4       t<]#! R2R7       ! R3 R4]:4      4       t=]#! R5R7       ! R6 R7]:4      4       t>  ! R8 R9]?]P€                  4      tA ! R: R;4      tB ! R< R=]B4      tCRRR> ltDRSR? ltERTR@ ltFRA tGRURB ltHRVRC ltIRWRD ltJRXRE ltKRF tLRG tMRH tNRI tORJ tPRK tQRL tRRM tSRYRN RO lltTRP tU. RZOtVR# )[zPyTorch TAPAS model.N)Ú	dataclass)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELoss)Úinitialization)ÚACT2FN)ÚCacheÚDynamicCacheÚEncoderDecoderCache)Úcreate_bidirectional_mask)ÚGradientCheckpointingLayer)ÚBaseModelOutputÚBaseModelOutputWithPoolingÚMaskedLMOutputÚSequenceClassifierOutput)ÚPreTrainedModel)Úapply_chunking_to_forward)ÚModelOutputÚauto_docstringÚlogging©ÚTapasConfigg»½×Ùß|Û=z7
    Output type of [`TapasForQuestionAnswering`].
    )Úcustom_introc                   óD   a € ] tR t^+t o RtRtRtRtRtRt	V 3R lt
RtV tR# )ÚTableQuestionAnsweringOutputa¶  
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` (and possibly `answer`, `aggregation_labels`, `numeric_values` and `numeric_values_scale` are provided)):
    Total loss as the sum of the hierarchical cell selection log-likelihood loss and (optionally) the
    semi-supervised regression loss and (optionally) supervised loss for aggregations.
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
    Prediction scores of the cell selection head, for every token.
logits_aggregation (`torch.FloatTensor`, *optional*, of shape `(batch_size, num_aggregation_labels)`):
    Prediction scores of the aggregation head, for every aggregation operator.
Nc                ó   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )é   NÚlossÚlogitsÚlogits_aggregationÚhidden_statesÚ
attentions)ÚtorchÚFloatTensorÚtuple)ÚformatÚ__classdict__s   "€Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/tapas/modeling_tapas.pyÚ__annotate__Ú)TableQuestionAnsweringOutput.__annotate__+   s‡   ø‡ ‚ ñ" ×
Ñ
˜dÕ
"Ñ)ñ# ñ$ ×Ñ Õ$Ñ+ñ% ñ& ×)Ñ)¨DÕ0Ñ7ñ' ñ( ™×*Ñ*Õ+¨dÕ2Ñ9ñ) ñ* ‘e×'Ñ'Õ(¨4Õ/Ñ6ò+ ó    © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r    r!   r"   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r'   s   @r(   r   r   +   s-   ø‡ € ñð &*€DØ'+€FØ37ÐØ59€MØ26€J÷+ ƒ r+   r   c                   ó@   a a€ ] tR t^Ct oRtV 3R ltRR ltRtVtV ;t	# )ÚTapasEmbeddingsz³
Construct the embeddings from word, position and token_type embeddings. Same as BertEmbeddings but with a number of
additional token type embeddings to encode tabular structure.
c           	     ó‚  <€ \         SV `  4        \        P                  ! VP                  VP
                  VP                  R 7      V n        \        P                  ! VP                  VP
                  4      V n	        \        VP                  4       F4  w  r#RV 2p\        W\        P                  ! W1P
                  4      4       K6  	  \        VP                  4      V n        \        P                  ! VP
                  VP                   R7      V n        \        P"                  ! VP$                  4      V n        Wn        R# ))Úpadding_idxÚtoken_type_embeddings_©ÚepsN)ÚsuperÚ__init__r   Ú	EmbeddingÚ
vocab_sizeÚhidden_sizeÚpad_token_idÚword_embeddingsÚmax_position_embeddingsÚposition_embeddingsÚ	enumerateÚtype_vocab_sizesÚsetattrÚlenÚnumber_of_token_type_embeddingsÚ	LayerNormÚlayer_norm_epsÚDropoutÚhidden_dropout_probÚdropoutÚconfig)ÚselfrP   ÚirG   ÚnameÚ	__class__s   &&   €r(   r>   ÚTapasEmbeddings.__init__I   så   ø€ Ü‰ÑÔô  "Ÿ|š|¨F×,=Ñ,=¸v×?QÑ?QÐ_e×_rÑ_rÔsˆÔä#%§<¢<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ ä#,¨V×-DÑ-DÖ#EÑˆAØ+¨A¨3Ð/ˆDÜ�D¤§¢Ð-=×?QÑ?QÓ RÖSñ $Fô 03°6×3JÑ3JÓ/KˆÔ,äŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŒàŽr+   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Efq   \        P                  ! V\        P                  VR7      pVP                  ^ 4      P                  V4      pV P                  P                  '       Ed   \        VR,          V P                  P                  ^,          ^R7      p\        VR,          V P                  P                  ^,          ^R7      p	\        W‰4      p
\        W:4      ^ ,          p\        Wº4      p\        P                  ! V\        P                  VR7      P                  ^ 4      p\        P                  ! \        P                  ! V P                  P                   ^,
          VR7      WÜ,
          4      pVf8   \        P"                  ! WPP$                  ,           \        P                  VR7      pVf   V P'                  V4      pV P)                  V4      pWN,           p\+        V P$                  4       F+  pRV 2pV\-        V V4      ! VRRV3,          4      ,          pK-  	  V P/                  V4      pV P1                  V4      pV# )	N©ÚdtypeÚdeviceºNNN)Ú
batch_dims©rY   r:   éÿÿÿÿ)rZ   rZ   é   )rZ   rZ   r   )ÚsizerY   r#   ÚarangeÚlongÚ	unsqueezeÚexpandrP   Úreset_position_index_per_cellÚIndexMaprG   ÚProductIndexMapÚ
reduce_minÚgatherÚminÚ	as_tensorrD   ÚzerosrJ   rC   rE   ÚrangeÚgetattrrK   rO   )rQ   Ú	input_idsÚtoken_type_idsÚposition_idsÚinputs_embedsÚinput_shapeÚ
seq_lengthrY   Ú	col_indexÚ	row_indexÚ
full_indexÚfirst_position_per_segmentÚfirst_positionÚpositionrE   Ú
embeddingsrR   rS   s   &&&&&             r(   ÚforwardÚTapasEmbeddings.forward\   s  € ØÒ Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà  •^ˆ
Ø%.Ò%:�×!Ò!À×@TÑ@TˆàÓä Ÿ<š<¨
¼%¿*¹*ÈVÔTˆLØ'×1Ñ1°!Ó4×;Ñ;¸KÓHˆLà�{‰{×8×8Ñ8ä$ ^°GÕ%<¸d¿k¹k×>ZÑ>ZÐ[\Õ>]ÐjkÔl�	ä$ ^°GÕ%<¸d¿k¹k×>ZÑ>ZÐ[\Õ>]ÐjkÔl�	ä,¨YÓB�
ä-7¸Ó-QÐRSÕ-TÐ*ä!'Ð(BÓ!O�ä Ÿ<š<¨
¼%¿*¹*ÈVÔT×^Ñ^Ð_`Óa�Ü$ŸyšyÜ—O’O D§K¡K×$GÑ$GÈ!Õ$KÐTZÔ[Ð]eÕ]vó �ð Ò!Ü"Ÿ[š[Ø×CÑCÕCÌEÏJÉJÐ_eôˆNð Ò Ø ×0Ñ0°Ó;ˆMà"×6Ñ6°|ÓDÐà"Õ8ˆ
ä�t×;Ñ;Ö<ˆAØ+¨A¨3Ð/ˆDØœ' $¨Ô-¨n¸QÀÀ1¸WÕ.EÓFÕFŠJñ =ð —^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr+   )rK   rP   rO   rJ   rE   rC   )NNNN)
r-   r.   r/   r0   r1   r>   r{   r3   r4   Ú__classcell__©rT   r'   s   @@r(   r7   r7   C   s   ù‡ € ñõ
÷&1ô 1r+   r7   c                   ó@   a a€ ] tR t^�t oRV 3R lltRR ltRtVtV ;t# )ÚTapasSelfAttentionc                ó*  <€ \         SV `  4        VP                  VP                  ,          ^ 8w  d8   \	        VR4      '       g&   \        RVP                   RVP                   24      h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        W n        R# )é    Úembedding_sizezThe hidden size z4 is not a multiple of the number of attention heads N)r=   r>   rA   Únum_attention_headsÚhasattrÚ
ValueErrorÚintÚattention_head_sizeÚall_head_sizer   ÚLinearÚqueryÚkeyÚvaluerM   Úattention_probs_dropout_probrO   Ú
is_decoderÚ	layer_idx©rQ   rP   r�   rT   s   &&&€r(   r>   ÚTapasSelfAttention.__init__‘   s/  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Õ:¸aÔ?ÌÐPVÐXh×HiÒHiÜØ" 6×#5Ñ#5Ð"6ð 7Ø×3Ñ3Ð4ð6óð ð
 $*×#=Ñ#=ˆÔ Ü#& 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ˆŒØ ×+Ñ+ˆŒØ"Žr+   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	Rp
VR JpVe`   \        V\        4      '       dH   VP                  P                  V P                  4      p
V'       d   VP                  pMVP                  pMTpV'       d   TMTpV'       d\   VeX   V
'       dP   XP                  V P                  ,          P                  pVP                  V P                  ,          P                  pM¹V P                  V4      P                  V4      P	                  ^^4      pV P!                  V4      P                  V4      P	                  ^^4      pVeV   XP#                  WïV P                  4      w  rïV'       d0   \        V\        4      '       d   RVP                  V P                  &   \$        P&                  ! WžP	                  RR4      4      pV\(        P*                  ! V P                  4      ,          pVe
   VV,           p\,        P.                  P1                  VRR7      pV P3                  V4      p\$        P&                  ! VV4      pVP5                  ^ ^^^4      P7                  4       pVP9                  4       R R V P:                  3,           pVP                  ! V!  pV'       d   VV3MV3pV P<                  '       d   VV3,           pV# )NFT©Údimr]   éþÿÿÿ)Úshaperˆ   r‹   ÚviewÚ	transposeÚ
isinstancer   Ú
is_updatedÚgetr�   Úcross_attention_cacheÚself_attention_cacheÚlayersÚkeysÚvaluesrŒ   r�   Úupdater#   ÚmatmulÚmathÚsqrtr   Ú
functionalÚsoftmaxrO   ÚpermuteÚ
contiguousr_   r‰   r�   )rQ   r!   Úattention_maskÚencoder_hidden_statesÚpast_key_valuesÚoutput_attentionsÚkwargsrr   Úhidden_shapeÚquery_layerr›   Úis_cross_attentionÚcurr_past_key_valuesÚcurrent_statesÚ	key_layerÚvalue_layerÚattention_scoresÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutputss   &&&&&&,              r(   r{   ÚTapasSelfAttention.forward¥   s˜  € ð $×)Ñ)¨#¨2Ð.ˆØC˜ÐC bÐC¨$×*BÑ*BÑCˆØ—j‘j Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆàˆ
Ø2¸$Ð>ÐØÒ&Ü˜/Ô+>×?Ò?Ø,×7Ñ7×;Ñ;¸D¿N¹NÓK�
ß%à+:×+PÑ+PÑ(à+:×+OÑ+OÑ(à'6Ð$ç2DÑ.È-ˆß /Ò"=Ç*à,×3Ñ3°D·N±NÕC×HÑHˆIØ.×5Ñ5°d·n±nÕE×LÑL‰KàŸ™ Ó0×5Ñ5°lÓC×MÑMÈaÐQRÓSˆIØŸ*™* ^Ó4×9Ñ9¸,ÓG×QÑQÐRSÐUVÓWˆKàÒ*à)=×)DÑ)DÀYÐ]a×]kÑ]kÓ)lÑ&�	ç%¬*°_ÔFY×*ZÒ*ZØAE�O×.Ñ.¨t¯~©~Ñ>ô !Ÿ<š<¨×5HÑ5HÈÈRÓ5PÓQÐØ+¬d¯iªi¸×8PÑ8PÓ.QÕQÐØÒ%à/°.Õ@Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆäŸš _°kÓBˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÕ"SÐØ%×*Ò*Ð,CÑDˆç6G�= /Ñ2ÈmÐM]ˆØ�?�?ˆ?Ø Ð 2Õ2ˆGØˆr+   )	r‰   rˆ   rO   r�   rŒ   r�   r„   r‹   r�   ©N©NNNF©	r-   r.   r/   r0   r>   r{   r3   r4   r}   r~   s   @@r(   r€   r€   �   s   ù‡ € ÷#÷(Aô Ar+   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# )ÚTapasSelfOutputc                ó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Š   rA   ÚdenserK   rL   rM   rN   rO   ©rQ   rP   rT   s   &&€r(   r>   ÚTapasSelfOutput.__init__ë   s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŽr+   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# ©r   r!   Úinput_tensorÚreturn©r#   ÚTensor)r&   r'   s   "€r(   r)   ÚTapasSelfOutput.__annotate__ñ   ó1   ø€ ÷ ñ ¡U§\¡\ð ÁÇÁð ÑRW×R^ÑR^ñ r+   c                óx   € V P                  V4      pV P                  V4      pV P                  W,           4      pV# r¼   ©rÃ   rO   rK   ©rQ   r!   rÈ   s   &&&r(   r{   ÚTapasSelfOutput.forwardñ   ó5   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ }Õ'CÓDˆØÐr+   ©rK   rÃ   rO   r¾   r~   s   @@r(   rÀ   rÀ   ê   ó   ù‡ € õ>÷÷ ð r+   rÀ   c                   óL   a a€ ] tR t^øt oRV 3R lltRV3R lR lltRtVtV ;t# )ÚTapasAttentionc                óf   <€ \         SV `  4        \        WR 7      V n        \	        V4      V n        R# )©r�   N)r=   r>   r€   rQ   rÀ   Úoutputr‘   s   &&&€r(   r>   ÚTapasAttention.__init__ù   s&   ø€ Ü‰ÑÔÜ& vÔCˆŒ	Ü% fÓ-ˆŽr+   c                óÖ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[ P                  ,          /# )r   r!   rª   Nr«   r¬   r­   rÉ   ©r#   rË   r$   r	   Úboolr%   )r&   r'   s   "€r(   r)   ÚTapasAttention.__annotate__ÿ   sr   ø€ ÷ ñ á—|‘|ðñ ×)Ñ)¨DÕ0ðñ  %×0Ñ0°4Õ7ð	ñ
  �ðñ   $�;ðñ 
‰u�|‰|Õ	ñr+   c                ó†   € V P                  VVVVVR 7      pV P                  V^ ,          V4      pV3VR,          ,           p	V	# )©rª   r«   r¬   r­   ºr^   NN)rQ   rÙ   )
rQ   r!   rª   r«   r¬   r­   r®   Úself_outputsÚattention_outputrº   s
   &&&&&&,   r(   r{   ÚTapasAttention.forwardÿ   sT   € ð —y‘yØØ)Ø"7Ø+Ø/ð !ó 
ˆð  Ÿ;™; |°A¥¸ÓFÐØ#Ð%¨°RÕ(8Õ8ˆØˆr+   )rÙ   rQ   r¼   r½   r¾   r~   s   @@r(   rÖ   rÖ   ø   s   ù‡ € ÷.÷÷ ò r+   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# )ÚTapasIntermediatei  c                ó"  <€ \         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Š   rA   Úintermediate_sizerÃ   rš   Ú
hidden_actÚstrr   Úintermediate_act_fnrÄ   s   &&€r(   r>   ÚTapasIntermediate.__init__  s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬×-Ò-Ü'-¨f×.?Ñ.?Õ'@ˆDÖ$à'-×'8Ñ'8ˆDÖ$r+   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r!   rÉ   rÊ   )r&   r'   s   "€r(   r)   ÚTapasIntermediate.__annotate__  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r+   c                óJ   € V P                  V4      pV P                  V4      pV# r¼   ©rÃ   rë   ©rQ   r!   s   &&r(   r{   ÚTapasIntermediate.forward  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐr+   rñ   r¾   r~   s   @@r(   ræ   ræ     s   ù‡ € õ9÷÷ ð r+   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# )ÚTapasOutputi%  c                ó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è   rA   rÃ   rK   rL   rM   rN   rO   rÄ   s   &&€r(   r>   ÚTapasOutput.__init__&  s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŽr+   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# rÇ   rÊ   )r&   r'   s   "€r(   r)   ÚTapasOutput.__annotate__,  rÍ   r+   c                óx   € V P                  V4      pV P                  V4      pV P                  W,           4      pV# r¼   rÏ   rÐ   s   &&&r(   r{   ÚTapasOutput.forward,  rÒ   r+   rÓ   r¾   r~   s   @@r(   rõ   rõ   %  rÔ   r+   rõ   c                   óR   a a€ ] tR tRt oRV 3R lltRV3R lR lltR tRtVtV ;t	# )	Ú
TapasLayeri3  c                ó€  <€ \         SV `  4        VP                  V n        ^V n        \	        WR7      V n        VP                  V n        VP                  V n        V P                  '       d2   V P                  '       g   \        V  R24      h\	        WR7      V n	        \        V4      V n        \        V4      V n        R# )r^   rØ   z> should be used as a decoder model if cross attention is addedN)r=   r>   Úchunk_size_feed_forwardÚseq_len_dimrÖ   Ú	attentionr�   Úadd_cross_attentionr†   Úcrossattentionræ   Úintermediaterõ   rÙ   r‘   s   &&&€r(   r>   ÚTapasLayer.__init__4  s™   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ'¨ÔDˆŒØ ×+Ñ+ˆŒØ#)×#=Ñ#=ˆÔ Ø×#×#Ð#Ø—?—?�?Ü  D 6Ð)gÐ!hÓiÐiÜ"0°Ô"MˆDÔÜ-¨fÓ5ˆÔÜ! &Ó)ˆŽr+   c                óþ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[S[ P                  ,          /# )	r   r!   rª   Nr«   Úencoder_attention_maskr¬   r­   rÉ   rÜ   )r&   r'   s   "€r(   r)   ÚTapasLayer.__annotate__C  s‡   ø€ ÷ )ñ )á—|‘|ð)ñ ×)Ñ)¨DÕ0ð)ñ  %×0Ñ0°4Õ7ð	)ñ
 !&× 1Ñ 1°DÕ 8ð)ñ  �ð)ñ   $�;ð)ñ 
‰u�|‰|Õ	ñ)r+   c                óŠ  € V P                  VVVVR 7      pV^ ,          p	VR,          p
V P                  '       dT   VeP   \        V R4      '       g   \        RV  R24      hV P	                  V	VVVVR7      pV^ ,          p	W«R,          ,           p
\        V P                  V P                  V P                  V	4      pV3V
,           p
V
# ))rª   r­   r¬   rá   r  z'If `encoder_hidden_states` are passed, z` has to be instantiated with cross-attention layers by setting `config.add_cross_attention=True`rà   )	r  r�   r…   r†   r  r   Úfeed_forward_chunkrÿ   r   )rQ   r!   rª   r«   r  r¬   r­   r®   Úself_attention_outputsrã   rº   Úcross_attention_outputsÚlayer_outputs   &&&&&&&,     r(   r{   ÚTapasLayer.forwardC  só   € ð "&§¡ØØ)Ø/Ø+ð	 "0ó "
Ðð 2°!Õ4ÐØ(¨Õ,ˆà�?�?ˆ?Ð4Ò@Ü˜4Ð!1×2Ò2Ü Ø=¸d¸Vð DDð Dóð ð
 '+×&9Ñ&9Ø Ø5Ø&;Ø /Ø"3ð ':ó 'Ð#ð  7°qÕ9ÐØ¸Õ ;Õ;ˆGä0Ø×#Ñ# T×%AÑ%AÀ4×CSÑCSÐUeó
ˆð  �/ GÕ+ˆàˆr+   c                óJ   € V P                  V4      pV P                  W!4      pV# r¼   )r  rÙ   )rQ   rã   Úintermediate_outputr  s   &&  r(   r
  ÚTapasLayer.feed_forward_chunko  s)   € Ø"×/Ñ/Ð0@ÓAÐØ—{‘{Ð#6ÓIˆØÐr+   )r  r  rÿ   r  r  r�   rÙ   r   r¼   )NNNNF)
r-   r.   r/   r0   r>   r{   r
  r3   r4   r}   r~   s   @@r(   rý   rý   3  s   ù‡ € ÷*÷)ò )÷Xò r+   rý   c                   ó<   a a€ ] tR tRt oV 3R ltRR ltRtVtV ;t# )ÚTapasEncoderiu  c           
     óØ   <€ \         SV `  4        Wn        \        P                  ! \        VP                  4       Uu. uF  p\        WR 7      NK  	  up4      V n        RV n	        R# u upi )rØ   FN)
r=   r>   rP   r   Ú
ModuleListrl   Únum_hidden_layersrý   ÚlayerÚgradient_checkpointing)rQ   rP   rR   rT   s   && €r(   r>   ÚTapasEncoder.__init__v  sS   ø€ Ü‰ÑÔØŒÜ—]’]ÌUÐSY×SkÑSkÔMlÓ#mÑMlÈ¤J¨v×$CÑMlÑ#mÓnˆŒ
Ø&+ˆÖ#ùò $ns   ½A'c
           
     ó  € V'       d9   Vf5   \        \        V P                  R7      \        V P                  R7      4      pV'       d   RMR pV'       d   RMR p\        V P                  4       FG  w  rÞV'       d
   W±3,           pV! VVVVVVR7      pV^ ,          pV'       g   K7  WÏ^,          3,           pKI  	  V'       d
   W±3,           pV	'       g1   \
        ;QJ d    . R WV3 4       F  NK  	  5# ! R WV3 4       4      # \        WVR7      # )N)rP   )r  r¬   r­   c              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5ir¼   r,   )Ú.0Úvs   & r(   Ú	<genexpr>Ú'TapasEncoder.forward.<locals>.<genexpr>¢  s   é € ÐhÑ$V˜qŸšÓ$Vùs   ‚Œ
)Úlast_hidden_stater!   r"   r,   )r   r
   rP   rF   r  r%   r   )rQ   r!   rª   r«   r  r¬   Ú	use_cacher­   Úoutput_hidden_statesÚreturn_dictr®   Úall_hidden_statesÚall_attentionsrR   Úlayer_moduleÚlayer_outputss   &&&&&&&&&&,     r(   r{   ÚTapasEncoder.forward|  sö   € ÷ ˜Ò0Ü1´,ÀdÇkÁkÔ2RÔT`Ðhl×hsÑhsÔTtÓuˆOç"6™B¸DÐß0™°dˆÜ(¨¯©Ö4‰OˆAß#Ø$5Ð8HÕ$HÐ!á(ØØØ%Ø'=Ø /Ø"3ôˆMð *¨!Õ,ˆMß Ñ Ø!/ÀÕ3CÐ2EÕ!E’ñ  5÷   Ø 1Ð4DÕ DÐçß”5Ñh ]À~Ñ$VÓh—5Ðh�5Ñh ]À~Ñ$VÓhÓhÐhÜØ+ÐYgô
ð 	
r+   )rP   r  r  )NNNNNFFTr¾   r~   s   @@r(   r  r  u  s   ù‡ € õ,÷)
ô )
r+   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# )ÚTapasPooleri©  c                ó¸   <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        P                  ! 4       V n        R # r¼   )r=   r>   r   rŠ   rA   rÃ   ÚTanhÚ
activationrÄ   s   &&€r(   r>   ÚTapasPooler.__init__ª  s9   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ'š'›)ˆŽr+   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rî   rÊ   )r&   r'   s   "€r(   r)   ÚTapasPooler.__annotate__¯  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r+   c                ó\   € VR,          pV P                  V4      pV P                  V4      pV# )rZ   )rZ   r‚   )rÃ   r-  )rQ   r!   Úfirst_token_tensorÚpooled_outputs   &&  r(   r{   ÚTapasPooler.forward¯  s2   € ð +¨4Õ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐr+   )r-  rÃ   r¾   r~   s   @@r(   r*  r*  ©  s   ù‡ € õ$÷
÷ ð r+   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# )ÚTapasPredictionHeadTransformi¹  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Š   rA   rÃ   rš   ré   rê   r   Útransform_act_fnrK   rL   rÄ   s   &&€r(   r>   Ú%TapasPredictionHeadTransform.__init__º  s~   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
Ü�f×'Ñ'¬×-Ò-Ü$*¨6×+<Ñ+<Õ$=ˆDÕ!à$*×$5Ñ$5ˆDÔ!ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŽr+   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rî   rÊ   )r&   r'   s   "€r(   r)   Ú)TapasPredictionHeadTransform.__annotate__Ã  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r+   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r¼   )rÃ   r8  rK   rò   s   &&r(   r{   Ú$TapasPredictionHeadTransform.forwardÃ  s4   € ØŸ
™
 =Ó1ˆØ×-Ñ-¨mÓ<ˆØŸ™ }Ó5ˆØÐr+   )rK   rÃ   r8  r¾   r~   s   @@r(   r6  r6  ¹  s   ù‡ € õU÷÷ ð r+   r6  c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚTapasLMPredictionHeadiË  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>   r6  Ú	transformr   rŠ   rA   r@   ÚdecoderÚ	Parameterr#   rk   rA  rÄ   s   &&€r(   r>   ÚTapasLMPredictionHead.__init__Ì  s[   ø€ Ü‰ÑÔÜ5°fÓ=ˆŒô —y’y ×!3Ñ!3°V×5FÑ5FÈTÔRˆŒÜ—L’L¤§¢¨V×->Ñ->Ó!?Ó@ˆŽ	r+   c                óJ   € V P                  V4      pV P                  V4      pV# r¼   )rB  rC  rò   s   &&r(   r{   ÚTapasLMPredictionHead.forwardÕ  s$   € ØŸ™ }Ó5ˆØŸ™ ]Ó3ˆØÐr+   )rA  rC  rB  r¾   r~   s   @@r(   r?  r?  Ë  s   ù‡ € õA÷ò r+   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# )ÚTapasOnlyMLMHeadiÜ  c                óD   <€ \         SV `  4        \        V4      V n        R # r¼   )r=   r>   r?  ÚpredictionsrÄ   s   &&€r(   r>   ÚTapasOnlyMLMHead.__init__Ý  s   ø€ Ü‰ÑÔÜ0°Ó8ˆÖr+   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   Úsequence_outputrÉ   rÊ   )r&   r'   s   "€r(   r)   ÚTapasOnlyMLMHead.__annotate__á  s#   ø€ ÷ !ñ !¡u§|¡|ð !¹¿¹ñ !r+   c                ó(   € V P                  V4      pV# r¼   ©rK  )rQ   rN  Úprediction_scoress   && r(   r{   ÚTapasOnlyMLMHead.forwardá  s   € Ø ×,Ñ,¨_Ó=ÐØ Ð r+   rQ  r¾   r~   s   @@r(   rI  rI  Ü  s   ù‡ € õ9÷!÷ !ð !r+   rI  c                   ón   a a€ ] tR tRt oRtRt]P                  ! 4       V 3R l4       tV3R lt	Rt
VtV ;t# )ÚTapasPreTrainedModeliæ  ÚtapasTc                óÖ  <€ \         SV `  V4       \        V\        4      '       d!   \        P
                  ! VP                  4       \        V\        4      '       Ed   VP                  P                  '       dB   \        P
                  ! VP                  4       \        P
                  ! VP                  4       Ml\        P                  ! VP                  VP                  P                  R7       \        P                  ! VP                  VP                  P                  R7       \        P
                  ! VP                  4       \        P
                  ! VP                  4       R# R# )zInitialize the weights)ÚstdN)r=   Ú_init_weightsrš   r?  ÚinitÚzeros_rA  ÚTapasForQuestionAnsweringrP   Ú#init_cell_selection_weights_to_zeroÚoutput_weightsÚcolumn_output_weightsÚnormal_Úinitializer_rangeÚoutput_biasÚcolumn_output_bias)rQ   ÚmodulerT   s   &&€r(   rY  Ú"TapasPreTrainedModel._init_weightsì  s×   ø€ ô 	‰Ñ˜fÔ%Ü�fÔ3×4Ò4Ü�KŠK˜Ÿ™Ô$Ü�fÔ7×8Ó8Ø�}‰}×@×@Ð@Ü—’˜F×1Ñ1Ô2Ü—’˜F×8Ñ8Õ9ä—’˜V×2Ñ2¸¿¹×8WÑ8WÕXÜ—’˜V×9Ñ9¸v¿}¹}×?^Ñ?^Õ_Ü�KŠK˜×*Ñ*Ô+Ü�KŠK˜×1Ñ1Ö2ñ 9r+   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # ©r   rP   r   )r&   r'   s   "€r(   r)   Ú!TapasPreTrainedModel.__annotate__æ  s   ø‡ ‚ áÑò r+   r,   )r-   r.   r/   r0   Úbase_model_prefixÚsupports_gradient_checkpointingr#   Úno_gradrY  r2   r3   r4   r}   r~   s   @@r(   rU  rU  æ  s2   ù‡ € ð  ÐØ&*Ð#à
‡]‚]ƒ_ô3ó ð3÷ … r+   rU  c                   óf   a a€ ] tR tRt oRtR	V 3R lltR tR t]R
V3R lR ll4       t	Rt
VtV ;t# )Ú
TapasModeliý  a  
This class is a small change compared to [`BertModel`], taking into account the additional token type ids.

The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added between the self-attention layers, following the architecture described in [Attention is
all you need](https://huggingface.co/papers/1706.03762) by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit,
Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.

c                óÆ   <€ \         SV `  V4       Wn        \        V4      V n        \        V4      V n        V'       d   \        V4      MRV n        V P                  4        R# )z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
N)
r=   r>   rP   r7   rz   r  Úencoderr*  ÚpoolerÚ	post_init)rQ   rP   Úadd_pooling_layerrT   s   &&&€r(   r>   ÚTapasModel.__init__	  sK   ø€ ô
 	‰Ñ˜Ô ØŒä)¨&Ó1ˆŒÜ# FÓ+ˆŒç->”k &Ô)ÀDˆŒð 	�‰Ör+   c                ó.   € V P                   P                  # r¼   ©rz   rC   ©rQ   s   &r(   Úget_input_embeddingsÚTapasModel.get_input_embeddings  s   € Ø�‰×.Ñ.Ð.r+   c                ó&   € WP                   n        R # r¼   ru  )rQ   r�   s   &&r(   Úset_input_embeddingsÚTapasModel.set_input_embeddings  s   € Ø*/�‰Ö'r+   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[R,          R
S[R,          RS[R,          RS[S[,          /# )r   rn   Nrª   ro   rp   rq   r«   r  r­   r"  r#  rÉ   )r#   Ú
LongTensorr$   rÝ   r%   r   )r&   r'   s   "€r(   r)   ÚTapasModel.__annotate__   så   ø€ ÷ p
ñ p
á×#Ñ# dÕ*ðp
ñ ×)Ñ)¨DÕ0ðp
ñ ×(Ñ(¨4Õ/ð	p
ñ
 ×&Ñ&¨Õ-ðp
ñ ×(Ñ(¨4Õ/ðp
ñ  %×0Ñ0°4Õ7ðp
ñ !&× 1Ñ 1°DÕ 8ðp
ñ   $�;ðp
ñ # T�kðp
ñ ˜D•[ðp
ñ 
Ñ+Õ	+ñp
r+   c           
     óø  € Ve   TMV P                   P                  pV	e   T	MV P                   P                  p	V
e   T
MV P                   P                  p
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fJ   \        P                  ! . VO\        V P                   P                  4      N5\        P                  VR7      pV P                  WW5R7      p\        V P                   VVR7      pVe   \        V P                   VVVR7      pV P!                  VVVVVV	V
R	7      pV^ ,          pV P"                  e   V P#                  V4      MRpV
'       g   VV3VR
,          ,           # \%        VVVP&                  VP(                  R7      # )aŠ  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
    Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
    class for more info.

    [What are token type IDs?](../glossary#token-type-ids)
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. If
    `reset_position_index_per_cell` of [`TapasConfig`] is set to `True`, relative position embeddings will be
    used. Selected in the range `[0, config.max_position_embeddings - 1]`.

    [What are position IDs?](../glossary#position-ids)

Examples:

```python
>>> from transformers import AutoTokenizer, TapasModel
>>> import pandas as pd

>>> tokenizer = AutoTokenizer.from_pretrained("google/tapas-base")
>>> model = TapasModel.from_pretrained("google/tapas-base")

>>> data = {
...     "Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
...     "Age": ["56", "45", "59"],
...     "Number of movies": ["87", "53", "69"],
... }
>>> table = pd.DataFrame.from_dict(data)
>>> queries = ["How many movies has George Clooney played in?", "How old is Brad Pitt?"]

>>> inputs = tokenizer(table=table, queries=queries, padding="max_length", return_tensors="pt")
>>> outputs = model(**inputs)

>>> 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_embedsr\   rW   )rn   rp   ro   rq   )rP   rq   rª   )rP   rq   rª   r«   )rª   r«   r  r­   r"  r#  rá   )r   Úpooler_outputr!   r"   r]   )rP   r­   r"  r#  r†   Ú%warn_if_padding_and_no_attention_maskr_   rY   r#   Úonesrk   rI   rG   ra   rz   r   ro  rp  r   r!   r"   )rQ   rn   rª   ro   rp   rq   r«   r  r­   r"  r#  r®   rr   rY   Úembedding_outputÚencoder_outputsrN  r3  s   &&&&&&&&&&&,      r(   r{   ÚTapasModel.forward  sú  € ðd 2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆàÒ  ]Ò%>ÜÐcÓdÐdØÒ"Ø×6Ñ6°yÔQØ#Ÿ.™.Ó*‰KØÒ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUà%.Ò%:�×!Ò!À×@TÑ@TˆàÒ!Ü"ŸZšZ¨ÔCˆNØÒ!Ü"Ÿ[š[ØA�+ÐAœs 4§;¡;×#?Ñ#?Ó@ÑAÌÏÉÐ\bôˆNð  Ÿ?™?ØÈ>ð +ó 
Ðô 3Ø—;‘;Ø*Ø)ô
ˆð "Ò-Ü%>Ø—{‘{Ø.Ø5Ø&;ô	&Ð"ð Ÿ,™,ØØ)Ø"7Ø#9Ø/Ø!5Ø#ð 'ó 
ˆð *¨!Õ,ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆçØ# ]Ð3°oÀbÕ6IÕIÐIä)Ø-Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r+   )rP   rz   ro  rp  )T)
NNNNNNNNNN)r-   r.   r/   r0   r1   r>   rw  rz  r   r{   r3   r4   r}   r~   s   @@r(   rm  rm  ý  s;   ù‡ € ñ÷ò /ò0ð ÷p
ñ p
ó ÷p
ð p
r+   rm  c                   óz   a a€ ] tR tRt oRRRR/tRtV 3R ltR tR	 t]	RV3R
 lR ll4       t
V3R ltRtVtV ;t# )ÚTapasForMaskedLMi“  zcls.predictions.decoder.biaszcls.predictions.biaszcls.predictions.decoder.weightz'tapas.embeddings.word_embeddings.weightrV  c                óŠ   <€ \         SV `  V4       \        VR R7      V n        \	        V4      V n        V P                  4        R# )F)rr  N)r=   r>   rm  rV  rI  Úclsrq  rÄ   s   &&€r(   r>   ÚTapasForMaskedLM.__init__œ  s6   ø€ Ü‰Ñ˜Ô ä ¸%Ô@ˆŒ
Ü# FÓ+ˆŒð 	�‰Ör+   c                óB   € V P                   P                  P                  # r¼   )r‰  rK  rC  rv  s   &r(   Úget_output_embeddingsÚ&TapasForMaskedLM.get_output_embeddings¥  s   € Ø�x‰x×#Ñ#×+Ñ+Ð+r+   c                ó„   € WP                   P                  n        VP                  V P                   P                  n        R # r¼   )r‰  rK  rC  rA  )rQ   Únew_embeddingss   &&r(   Úset_output_embeddingsÚ&TapasForMaskedLM.set_output_embeddings¨  s*   € Ø'5�‰×ÑÔ$Ø$2×$7Ñ$7ˆ�‰×ÑÖ!r+   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[R,          RS[R,          RS[R,          RS[S[,          /# )r   rn   Nrª   ro   rp   rq   r«   r  Úlabelsr­   r"  r#  rÉ   )r#   r}  r$   rÝ   r%   r   )r&   r'   s   "€r(   r)   ÚTapasForMaskedLM.__annotate__­  sú   ø€ ÷ Z
ñ Z
á×#Ñ# dÕ*ðZ
ñ ×)Ñ)¨DÕ0ðZ
ñ ×(Ñ(¨4Õ/ð	Z
ñ
 ×&Ñ&¨Õ-ðZ
ñ ×(Ñ(¨4Õ/ðZ
ñ  %×0Ñ0°4Õ7ðZ
ñ !&× 1Ñ 1°DÕ 8ðZ
ñ × Ñ  4Õ'ðZ
ñ   $�;ðZ
ñ # T�kðZ
ñ ˜D•[ðZ
ñ 
‘Õ	ñZ
r+   c                óÔ  € Ve   TMV P                   P                  pV P                  VVVVVVVV	V
VR7
      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'       g"   V3VR,          ,           pVe   V3V,           # T# \        VVVP                  VP                  R7      # )aZ  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
    Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
    class for more info.

    [What are token type IDs?](../glossary#token-type-ids)
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. If
    `reset_position_index_per_cell` of [`TapasConfig`] is set to `True`, relative position embeddings will be
    used. Selected in the range `[0, config.max_position_embeddings - 1]`.

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

Examples:

```python
>>> from transformers import AutoTokenizer, TapasForMaskedLM
>>> import pandas as pd

>>> tokenizer = AutoTokenizer.from_pretrained("google/tapas-base")
>>> model = TapasForMaskedLM.from_pretrained("google/tapas-base")

>>> data = {
...     "Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
...     "Age": ["56", "45", "59"],
...     "Number of movies": ["87", "53", "69"],
... }
>>> table = pd.DataFrame.from_dict(data)

>>> inputs = tokenizer(
...     table=table, queries="How many [MASK] has George [MASK] played in?", return_tensors="pt"
... )
>>> labels = tokenizer(
...     table=table, queries="How many movies has George Clooney played in?", return_tensors="pt"
... )["input_ids"]

>>> outputs = model(**inputs, labels=labels)
>>> logits = outputs.logits
```N)	rª   ro   rp   rq   r«   r  r­   r"  r#  ºr   NN©r   r   r!   r"   r]   )
rP   r#  rV  r‰  r   r˜   r@   r   r!   r"   )rQ   rn   rª   ro   rp   rq   r«   r  r“  r­   r"  r#  r®   rº   rN  rR  Úmasked_lm_lossÚloss_fctrÙ   s   &&&&&&&&&&&&,      r(   r{   ÚTapasForMaskedLM.forward¬  sü   € ðv &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà—*‘*ØØ)Ø)Ø%Ø'Ø"7Ø#9Ø/Ø!5Ø#ð ó 
ˆð " !�*ˆØ ŸH™H _Ó5ÐàˆØÒÜ'Ó)ˆHÙ%Ð&7×&<Ñ&<¸RÀÇÁ×AWÑAWÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNçØ'Ð)¨G°B­KÕ7ˆFØ3AÒ3M�^Ð%¨Õ.ÐYÐSYÐYäØØ$Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r+   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rg  r   )r&   r'   s   "€r(   r)   r”  “  s   ø‡ ‚ ñ Ñò r+   )r‰  rV  )NNNNNNNNNNN)r-   r.   r/   r0   Ú_tied_weights_keysri  r>   rŒ  r�  r   r{   r2   r3   r4   r}   r~   s   @@r(   r‡  r‡  “  sU   ù‡ € ð 	'Ð(>Ø(Ð*SðÐð
  Ðõò,ò8ð ÷Z
ñ Z
ó ðZ
÷5 … r+   r‡  a  
    Tapas Model with a cell selection head and optional aggregation head on top for question-answering tasks on tables
    (linear layers on top of the hidden-states output to compute `logits` and optional `logits_aggregation`), e.g. for
    SQA, WTQ or WikiSQL-supervised tasks.
    c                   ó^   a a€ ] tR tRt oV3R lV 3R llt]RV3R lR ll4       tRtVtV ;t	# )r\  i
  c                ó    <€ V ^8„  d   QhRS[ /# rg  r   )r&   r'   s   "€r(   r)   Ú&TapasForQuestionAnswering.__annotate__  s   ø€ ÷ ñ ™{ñ r+   c                óÒ  <€ \         SV `  V4       \        V4      V n        \        P
                  ! VP                  4      V n        \        P                  ! \        P                  ! VP                  4      4      V n        \        P                  ! \        P                  ! VP                  4      4      V n        \        P                  ! \        P                  ! . 4      4      V n        \        P                  ! \        P                  ! . 4      4      V n        VP                   ^ 8”  d1   \        P"                  ! VP                  VP                   4      V n        V P'                  4        R# )r‚   N)r=   r>   rm  rV  r   rM   rN   rO   rD  r#   ÚemptyrA   r^  r_  rb  rc  Únum_aggregation_labelsrŠ   Úaggregation_classifierrq  rÄ   s   &&€r(   r>   Ú"TapasForQuestionAnswering.__init__  så   ø€ Ü‰Ñ˜Ô ô   Ó'ˆŒ
ô —z’z &×"<Ñ"<Ó=ˆŒô !Ÿlšl¬5¯;ª;°v×7IÑ7IÓ+JÓKˆÔÜ%'§\¢\´%·+²+¸f×>PÑ>PÓ2QÓ%RˆÔ"ÜŸ<š<¬¯ª°B«Ó8ˆÔÜ"$§,¢,¬u¯{ª{¸2«Ó"?ˆÔð ×(Ñ(¨1Ô,Ü*,¯)ª)°F×4FÑ4FÈ×HeÑHeÓ*fˆDÔ'ð 	�‰Ör+   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[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[R,          RS[S[,          /# )r   rn   Nrª   ro   rp   rq   Ú
table_maskr“  Úaggregation_labelsÚfloat_answerÚnumeric_valuesÚnumeric_values_scaler­   r"  r#  rÉ   )r#   r}  r$   rÝ   r%   r   )r&   r'   s   "€r(   r)   rŸ  )  s=  ø€ ÷ q
ñ q
á×#Ñ# dÕ*ðq
ñ ×)Ñ)¨DÕ0ðq
ñ ×(Ñ(¨4Õ/ð	q
ñ
 ×&Ñ&¨Õ-ðq
ñ ×(Ñ(¨4Õ/ðq
ñ ×$Ñ$ tÕ+ðq
ñ × Ñ  4Õ'ðq
ñ "×,Ñ,¨tÕ3ðq
ñ ×'Ñ'¨$Õ.ðq
ñ ×)Ñ)¨DÕ0ðq
ñ $×/Ñ/°$Õ6ðq
ñ   $�;ðq
ñ # T�kðq
ñ ˜D•[ðq
ñ" 
Ñ-Õ	-ñ#q
r+   c                ó²  € Ve   TMV P                   P                  pV P                  VVVVVVVVR7      pV^ ,          pV^,          pV P                  V4      pVe   VP	                  4       pMVP	                  4       RR pVe   VP
                  MVP
                  pVfJ   \        P                  ! . VO\        V P                   P                  4      N5\        P                  VR7      p. ROpVRRVP                  R4      3,          pVRRVP                  R4      3,          p\        \        P                  ! V\        P                  ! V P                   P                  ^,
          VP
                  R7      4      V P                   P                  ^R7      p\        \        P                  ! V\        P                  ! V P                   P                   ^,
          VP
                  R7      4      V P                   P                   ^R7      p\#        VV4      pVe   VP	                  4       MVP	                  4       RR pVe   VP
                  MVP
                  pVf   \        P$                  ! VVR7      pVfD   \        P&                  ! V^ 8„  \        P(                  ! V4      \        P*                  ! V4      4      pVP-                  V\        P.                  R	7      pVP-                  V\        P.                  R	7      p\1        VV4      w  pp\3        VV P                   P4                  V P6                  V P8                  4      pRp V P                   P:                  '       d9   \=        VV P>                  V P@                  VVV P                   PB                  4      p Rp!V P                   PD                  ^ 8”  d   V PG                  V4      p!R
p"Rp#VEe‡   Rp#V P                   PD                  ^ 8”  * ;'       g    V P                   PH                  '       * p$V$'       d   Rp%MmV	e_   VPJ                  ^ ,          V	PJ                  ^ ,          8X  g   Q R4       h\M        V	VV P                   PN                  VV PF                  4      p%M\Q        R4      hV P                   PR                  '       d   \1        VV4      w  p&p\U        V&V4      p\        PV                  PY                  VR7      p'Rp(V P                   P:                  '       gà   \        P&                  ! V^ 8H  \        P(                  ! V\        PZ                  R7      V P                   P\                  \        P(                  ! V\        PZ                  R7      ,          4      p)V'P_                  V4      ) V),          p*\        P`                  ! V*V,          ^R7      \        P`                  ! V^R7      \b        ,           ,          p(M3\e        VV VVVV4      w  p(p\        PV                  PY                  VR7      p'V P                   Pf                  '       d   MQV$'       d   V"\        Ph                  ! V(4      ,          p"M+V"\        Ph                  ! V(RV%,
          ,          4      ,          p"V P                   PD                  ^ 8”  Ed¾   V$'       d�   Ve~   VPJ                  ^ ,          VPJ                  ^ ,          8X  g   Q R4       h\k        V!V%VV P                   PH                  V P                   PD                  V P                   Pl                  4      p+M™\Q        R4      h\        P                  ! VPJ                  ^ ,          \        P                  VP
                  R7      p\k        V!V%VV P                   PH                  V P                   PD                  V P                   Pl                  4      p+V P                   PH                  '       dc   V
eT   VeP   V
PJ                  VPJ                  8X  g   Q h\o        V	V%V'V
VVV!V P                   4      w  p,p-V+V,,          p+V+V-,          p+M\Q        R4      hV"\        Ph                  ! V+4      ,          p"M)\        P*                  ! V4      p\e        VV VVVV4      w  ppV'       g'   VV!3VR,          ,           p.V#'       d   V"3V.,           # T.# \q        V#'       d   T"MRVV!VPr                  VPt                  R7      # )aÜ  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
    Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
    class for more info.

    [What are token type IDs?](../glossary#token-type-ids)
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. If
    `reset_position_index_per_cell` of [`TapasConfig`] is set to `True`, relative position embeddings will be
    used. Selected in the range `[0, config.max_position_embeddings - 1]`.

    [What are position IDs?](../glossary#position-ids)
table_mask (`torch.LongTensor` of shape `(batch_size, seq_length)`, *optional*):
    Mask for the table. Indicates which tokens belong to the table (1). Question tokens, table headers and
    padding are 0.
labels (`torch.LongTensor` of shape `(batch_size, seq_length)`, *optional*):
    Labels per token for computing the hierarchical cell selection loss. This encodes the positions of the
    answer appearing in the table. Can be obtained using [`AutoTokenizer`].

    - 1 for tokens that are **part of the answer**,
    - 0 for tokens that are **not part of the answer**.
aggregation_labels (`torch.LongTensor` of shape `(batch_size, )`, *optional*):
    Aggregation function index for every example in the batch for computing the aggregation loss. Indices
    should be in `[0, ..., config.num_aggregation_labels - 1]`. Only required in case of strong supervision for
    aggregation (WikiSQL-supervised).
float_answer (`torch.FloatTensor` of shape `(batch_size, )`, *optional*):
    Float answer for every example in the batch. Set to *float('nan')* for cell selection questions. Only
    required in case of weak supervision (WTQ) to calculate the aggregate mask and regression loss.
numeric_values (`torch.FloatTensor` of shape `(batch_size, seq_length)`, *optional*):
    Numeric values of every token, NaN for tokens which are not numeric values. Can be obtained using
    [`AutoTokenizer`]. Only required in case of weak supervision for aggregation (WTQ) to calculate the
    regression loss.
numeric_values_scale (`torch.FloatTensor` of shape `(batch_size, seq_length)`, *optional*):
    Scale of the numeric values of every token. Can be obtained using [`AutoTokenizer`]. Only required in case
    of weak supervision for aggregation (WTQ) to calculate the regression loss.

Examples:

```python
>>> from transformers import AutoTokenizer, TapasForQuestionAnswering
>>> import pandas as pd

>>> tokenizer = AutoTokenizer.from_pretrained("google/tapas-base-finetuned-wtq")
>>> model = TapasForQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq")

>>> data = {
...     "Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
...     "Age": ["56", "45", "59"],
...     "Number of movies": ["87", "53", "69"],
... }
>>> table = pd.DataFrame.from_dict(data)
>>> queries = ["How many movies has George Clooney played in?", "How old is Brad Pitt?"]

>>> inputs = tokenizer(table=table, queries=queries, padding="max_length", return_tensors="pt")
>>> outputs = model(**inputs)

>>> logits = outputs.logits
>>> logits_aggregation = outputs.logits_aggregation
```N©rª   ro   rp   rq   r­   r"  r#  rW   Ú
column_idsÚrow_idsrZ   r\   ©ÚindicesÚnum_segmentsr[   )rY   rX   g        FTz>Make sure the answers are a FloatTensor of shape (batch_size,)zJYou have to specify float answers in order to calculate the aggregate mask©r   ©rX   r”   ç      ð?zHMake sure the aggregation labels are a LongTensor of shape (batch_size,)zQYou have to specify aggregation labels in order to calculate the aggregation losszeYou have to specify numeric values and numeric values scale in order to calculate the regression lossr–  )r   r   r    r!   r"   r]   )Úsegment_idsr­  r®  Úprev_labelsÚcolumn_ranksÚinv_column_ranksÚnumeric_relations);rP   r#  rV  rO   r_   rY   r#   rk   rI   rG   ra   Úindexre   ri   rj   Úmax_num_rowsÚmax_num_columnsrf   r‚  ÚwhereÚ	ones_likeÚ
zeros_likeÚtoÚfloatÚreduce_meanÚcompute_token_logitsÚtemperaturer^  rb  Úselect_one_columnÚcompute_column_logitsr_  rc  Úallow_empty_column_selectionr¢  r£  Úuse_answer_as_supervisionr—   Ú_calculate_aggregate_maskÚcell_selection_preferencer†   Úaverage_logits_per_cellrh   ÚdistributionsÚ	BernoulliÚfloat32Úpositive_label_weightÚlog_probÚsumÚEPSILON_ZERO_DIVISIONÚ"_single_column_cell_selection_lossÚdisable_per_token_lossÚmeanÚ_calculate_aggregation_lossÚaggregation_loss_weightÚ_calculate_regression_lossr   r!   r"   )/rQ   rn   rª   ro   rp   rq   r¦  r“  r§  r¨  r©  rª  r­   r"  r#  r®   rº   rN  r3  rr   rY   Útoken_typesr®  r­  ru   rt   Ú
cell_indexÚinput_mask_floatÚtable_mask_floatÚ	cell_maskÚ_r   Úcolumn_logitsr    Ú
total_lossÚcalculate_lossÚis_supervisedÚaggregate_maskÚlogits_per_cellÚdist_per_tokenÚselection_loss_per_exampleÚweightÚselection_loss_per_tokenÚper_example_additional_lossÚanswer_lossÚlarge_answer_loss_maskrÙ   s/   &&&&&&&&&&&&&&&,                               r(   r{   Ú!TapasForQuestionAnswering.forward(  sŠ  € ð\ &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà—*‘*ØØ)Ø)Ø%Ø'Ø/Ø!5Ø#ð ó 	
ˆð " !�*ˆØ �
ˆàŸ,™, Ó7ˆàÒ Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà%.Ò%:�×!Ò!À×@TÑ@Tˆð Ò!Ü"Ÿ[š[ØA�+ÐAœs 4§;¡;×#?Ñ#?Ó@ÑAÌÏÉÐ\bôˆNò
ˆð !  A {×'8Ñ'8¸Ó'CÐ!CÕDˆØ# A q¨+×*;Ñ*;¸LÓ*IÐ$IÕJˆ
äÜ—I’I˜g¤u§¢°t·{±{×7OÑ7OÐRSÕ7SÐ\c×\jÑ\jÔ'kÓlØŸ™×1Ñ1Øô
ˆ	ô
 Ü—I’I˜j¬%¯/ª/¸$¿+¹+×:UÑ:UÐXYÕ:YÐbl×bsÑbsÔ*tÓuØŸ™×4Ñ4Øô
ˆ	ô
 % Y°	Ó:ˆ
ð +4Ò*?�i—n‘nÔ&À]×EWÑEWÓEYÐZ]Ð[]ÐE^ˆØ%.Ò%:�×!Ò!À×@TÑ@TˆØÒ!Ü"ŸZšZ¨¸FÔCˆNàÒÜŸš W¨q¡[´%·/²/À'Ó2JÌE×L\ÒL\Ð]dÓLeÓfˆJà)×,Ñ,°FÄ%Ç+Á+Ð,ÓNÐØ%Ÿ=™=°¼e¿k¹k˜=ÓJÐä"Ð#3°ZÓ@‰ˆ	�1ô & o°t·{±{×7NÑ7NÐPT×PcÑPcÐei×euÑeuÓvˆð ˆØ�;‰;×(×(Ð(Ü1ØØ×*Ñ*Ø×'Ñ'ØØØ—‘×8Ñ8óˆMð "ÐØ�;‰;×-Ñ-°Ô1Ø!%×!<Ñ!<¸]Ó!KÐð ˆ
ØˆØÓØ!ˆNØ $§¡× BÑ BÀQÒF×sÐsÈdÏkÉk×NsÑNsÔJsˆM÷ Ø!%‘àÒ+Ø!Ÿ<™<¨�?¨l×.@Ñ.@ÀÕ.CÔCð ØXóÐCô &?Ø$Ø%ØŸ™×=Ñ=ØØ×3Ñ3ó&‘Nô %Ð%qÓrÐrð �{‰{×2×2Ð2Ü%0°¸Ó%DÑ"� Ü °Ó<�Ü"×0Ñ0×:Ñ:À&Ð:ÓIˆNð *.Ð&Ø—;‘;×0×0Ð0ÜŸšØ˜a‘KÜ—O’O F´%·-±-Ô@Ø—K‘K×5Ñ5¼¿ºÈÔV[×VcÑVcÔ8dÕdó�ð
 -;×,CÑ,CÀFÓ,KÐ+KÈfÕ+TÐ(Ü-2¯YªYÐ7OÐRbÕ7bÐhiÔ-jÜ—I’IÐ.°AÔ6Ô9NÕNõ.Ñ*ô 6XØ˜M¨6°:¸yÈ)ó6Ñ2Ð*¨Fô "'×!4Ñ!4×!>Ñ!>ÀfÐ!>Ó!M�ð �{‰{×1×1Ð1ØßØœeŸjšjÐ)CÓDÕD‘
ð œeŸjšjÐ)CÀsÈ^ÕG[Õ)\Ó]Õ]�
ð �{‰{×1Ñ1°AÕ5ß à)Ò5Ø%Ÿ|™|¨A�Ð2D×2JÑ2JÈ1Õ2MÔMð ØfóÐMô 7RØ.Ø*Ø.Ø ŸK™K×AÑAØ ŸK™K×>Ñ>Ø ŸK™K×?Ñ?ó7Ñ3ô )Øoóð ô
 */¯ª°V·\±\À!µ_ÌEÏJÉJÐ_e×_lÑ_lÔ)mÐ&Ü2MØ*Ø&Ø*ØŸ™×=Ñ=ØŸ™×:Ñ:ØŸ™×;Ñ;ó3Ð/ð —;‘;×8×8Ð8Ø%Ò1Ð6JÒ6VØ-×3Ñ3Ð7K×7QÑ7QÔQÐQÐQä>XØ(Ø*Ø*Ø*Ø0Ø,Ø.Ø ŸK™Kó	?Ñ;˜Ð%;ð 4°{ÕBÐ3à3Ð7MÕMÑ3ä(ð/óð ð
 œeŸjšjÐ)DÓEÕE�
øô ×%Ò% fÓ-ˆFÜ:Ø˜ v¨z¸9Àió‰IˆAˆv÷ ØÐ0Ð1°G¸BµKÕ?ˆFß/=�Z�M FÕ*ÐIÀ6ÐIä+ß-‘°4ØØ1Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r+   )r£  rc  r_  rO   rb  r^  rV  )NNNNNNNNNNNNNN©
r-   r.   r/   r0   r>   r   r{   r3   r4   r}   r~   s   @@r(   r\  r\  
  s1   ù‡ € ÷ó ð, ÷q
ñ q
ó ÷q
ð q
r+   r\  z¸
    Tapas Model with a sequence classification head on top (a linear layer on top of the pooled output), e.g. for table
    entailment tasks, such as TabFact (Chen et al., 2020).
    c                   óR   a a€ ] tR tRt oV 3R lt]RV3R lR ll4       tRtVtV ;t	# )ÚTapasForSequenceClassificationi]  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_labelsrm  rV  r   rM   rN   rO   rŠ   rA   Ú
classifierrq  rÄ   s   &&€r(   r>   Ú'TapasForSequenceClassification.__init__d  si   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä Ó'ˆŒ
Ü—z’z &×"<Ñ"<Ó=ˆŒÜŸ)š) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Ör+   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[R,          R	S[R,          R
S[R,          RS[S[ P
                  ,          S[,          /
# )r   rn   Nrª   ro   rp   rq   r“  r­   r"  r#  rÉ   )r#   r}  r$   rÝ   r%   rË   r   )r&   r'   s   "€r(   r)   Ú+TapasForSequenceClassification.__annotate__p  sØ   ø€ ÷ l
ñ l
á×#Ñ# dÕ*ðl
ñ ×)Ñ)¨DÕ0ðl
ñ ×(Ñ(¨4Õ/ð	l
ñ
 ×&Ñ&¨Õ-ðl
ñ ×(Ñ(¨4Õ/ðl
ñ × Ñ  4Õ'ðl
ñ   $�;ðl
ñ # T�kðl
ñ ˜D•[ðl
ñ 
‰u�|‰|Õ	Ñ7Õ	7ñl
r+   c
                ó–  € V	e   T	MV P                   P                  p	V P                  VVVVVVVV	R7      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	'       g"   V3VR,          ,           pVe   V3V,           # T# \!        VVVP"                  VP$                  R7      # )	a.  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
    Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
    class for more info.

    [What are token type IDs?](../glossary#token-type-ids)
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. If
    `reset_position_index_per_cell` of [`TapasConfig`] is set to `True`, relative position embeddings will be
    used. Selected in the range `[0, config.max_position_embeddings - 1]`.

    [What are position IDs?](../glossary#position-ids)
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
    config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
    `config.num_labels > 1` a classification loss is computed (Cross-Entropy). Note: this is called
    "classification_class_index" in the original implementation.

Examples:

```python
>>> from transformers import AutoTokenizer, TapasForSequenceClassification
>>> import torch
>>> import pandas as pd

>>> tokenizer = AutoTokenizer.from_pretrained("google/tapas-base-finetuned-tabfact")
>>> model = TapasForSequenceClassification.from_pretrained("google/tapas-base-finetuned-tabfact")

>>> data = {
...     "Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
...     "Age": ["56", "45", "59"],
...     "Number of movies": ["87", "53", "69"],
... }
>>> table = pd.DataFrame.from_dict(data)
>>> queries = [
...     "There is only one actor who is 45 years old",
...     "There are 3 actors which played in more than 60 movies",
... ]

>>> inputs = tokenizer(table=table, queries=queries, padding="max_length", return_tensors="pt")
>>> labels = torch.tensor([1, 0])  # 1 means entailed, 0 means refuted

>>> outputs = model(**inputs, labels=labels)
>>> loss = outputs.loss
>>> logits = outputs.logits
```Nr¬  Ú
regressionÚsingle_label_classificationÚmulti_label_classificationr–  r—  r]   )rP   r#  rV  rO   rò  Úproblem_typerñ  rX   r#   ra   r‡   r   Úsqueezer   r˜   r   r   r!   r"   )rQ   rn   rª   ro   rp   rq   r“  r­   r"  r#  r®   rº   r3  r   r   r™  rÙ   s   &&&&&&&&&&,      r(   r{   Ú&TapasForSequenceClassification.forwardo  sà  € ðx &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà—*‘*ØØ)Ø)Ø%Ø'Ø/Ø!5Ø#ð ó 	
ˆð   �
ˆàŸ™ ]Ó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Ü,Ó.�Ù Ó/�ßØ�Y ¨¥Õ,ˆFØ)-Ò)9�T�G˜fÕ$ÐE¸vÐEä'ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r+   )rò  rO   rñ  rV  )	NNNNNNNNNrí  r~   s   @@r(   rï  rï  ]  s,   ù‡ € õ	ð ÷l
ñ l
ó ÷l
ð l
r+   rï  c                   ó"   € ] tR tRtRtRtRtRtR# )ÚAverageApproximationFunctioniâ  ÚratioÚfirst_orderÚsecond_orderr,   N)r-   r.   r/   r0   ÚRATIOÚFIRST_ORDERÚSECOND_ORDERr3   r,   r+   r(   rþ  rþ  â  s   † Ø€EØ€KØ!„Lr+   rþ  c                   ó4   a € ] tR tRt o RtRR ltR tRtV tR# )re   ië  z'Index grouping entries within a tensor.c                óª   € \         P                  ! WP                  R7      V n        \         P                  ! W!P                  R7      V n        W0n        R# )a’  
Creates an index

Args:
    indices (`torch.LongTensor`, same shape as a *values* Tensor to which the indices refer):
        Tensor containing the indices.
    num_segments (`torch.LongTensor`):
        Scalar tensor, the number of segments. All elements in a batched segmented tensor must have the same
        number of segments (although many segments can be empty).
    batch_dims (`int`, *optional*, defaults to 0):
        The number of batch dimensions. The first *batch_dims* dimensions of a SegmentedTensor are treated as
        batch dimensions. Segments in different batch elements are always distinct even if they have the same
        index.
r\   N)r#   rj   rY   r°  r±  r[   )rQ   r°  r±  r[   s   &&&&r(   r>   ÚIndexMap.__init__î  s2   € ô —’ w·~±~ÔFˆŒÜ!ŸOšO¨LÇÁÔPˆÔØ$Žr+   c                óP   € V P                   P                  4       R V P                   # r¼   )r°  r_   r[   rv  s   &r(   Úbatch_shapeÚIndexMap.batch_shape  s!   € Ø�|‰|× Ñ Ó"Ð#4 T§_¡_Ð5Ð5r+   )r[   r°  r±  N)r‚   )	r-   r.   r/   r0   r1   r>   r	  r3   r4   r5   s   @r(   re   re   ë  s   ø‡ € Ù1ô%÷&6ð 6r+   re   c                   óB   a a€ ] tR tRt oRtV 3R ltR tR tRtVt	V ;t
# )rf   i  zThe product of two indices.c                ó2  <€ VP                   VP                   8w  d   \        R4      h\        SV `  VP                  VP                  VP
                  ,          ,           VP
                  VP
                  ,          VP                   R7       Wn        W n        R# )av  
Combines indices i and j into pairs (i, j). The result is an index where each segment (i, j) is the
intersection of segments i and j. For example if the inputs represent table cells indexed by respectively rows
and columns the output will be a table indexed by (row, column) pairs, i.e. by cell. The implementation
combines indices {0, .., n - 1} and {0, .., m - 1} into {0, .., nm - 1}. The output has *num_segments* equal to
*outer_index.num_segments* * *inner_index.num_segments*

Args:
    outer_index (`IndexMap`):
        IndexMap.
    inner_index (`IndexMap`):
        IndexMap, must have the same shape as *outer_index*.
zCouter_index.batch_dims and inner_index.batch_dims must be the same.r¯  N)r[   r†   r=   r>   r°  r±  Úouter_indexÚinner_index)rQ   r  r  rT   s   &&&€r(   r>   ÚProductIndexMap.__init__  s�   ø€ ð ×!Ñ! [×%;Ñ%;Ô;ÜÐbÓcÐcä‰ÑØ ×(Ñ(¨;×+>Ñ+>À×AYÑAYÕ+YÕYØ$×1Ñ1°K×4LÑ4LÕLØ"×-Ñ-ð 	ô 	
ð
 'ÔØ&Ör+   c                ó   € \         P                  ! VP                  V P                  P                  RR7      P                  \         P                  4      p\        W P                  P                  VP                  R7      # )zDProjects an index with the same index set onto the outer components.Úfloor)Úrounding_moder¯  )
r#   Údivr°  r  r±  Útypera   re   r  r[   )rQ   rº  r°  s   && r(   Úproject_outerÚProductIndexMap.project_outer!  sW   € ä—)’)˜EŸM™M¨4×+;Ñ+;×+HÑ+HÐX_Ô`×eÑeÔfk×fpÑfpÓqˆÜ ×6FÑ6F×6SÑ6SÐ`e×`pÑ`pÔqÐqr+   c                óP  € \        \        P                  ! VP                  V P                  P
                  4      P                  \        P                  4      P                  4       P                  \        P                  4      V P                  P
                  VP                  R7      # )zDProjects an index with the same index set onto the inner components.r¯  )re   r#   Úfmodr°  r  r±  r  rÁ  r  ra   r[   )rQ   rº  s   &&r(   Úproject_innerÚProductIndexMap.project_inner&  sh   € äÜ—J’J˜uŸ}™}¨d×.>Ñ.>×.KÑ.KÓLß‰T”%—+‘+Óß‰U‹Wß‰T”%—*‘*ÓØ×)Ñ)×6Ñ6Ø×'Ñ'ô
ð 	
r+   )r  r  )r-   r.   r/   r0   r1   r>   r  r  r3   r4   r}   r~   s   @@r(   rf   rf     s   ù‡ € Ù%õ'ò2r÷
	
ò 	
r+   rf   c                óÆ  € VP                   p\        V P                  VP                  R 4      ^8  de   \        P
                  ! V VP                  VP                  V P                  4       ^ ,          R4      4      P                  VP                  4       4      # VP                  R4      P                  V P                  4      p\        P
                  ! WP                  V4      # )a‡  
Gathers from *values* using the index map. For each element in the domain of the index map this operation looks up
a value for that index in *values*. Two elements from the same segment always get assigned the same value.

Args:
    values (`torch.Tensor` of shape (B1, ..., Bn, num_segments, V1, ...)):
        Tensor with segment values.
    index (`IndexMap` of shape (B1, ..., Bn, I1, ..., Ik)):
        IndexMap.
    name (`str`, *optional*, defaults to 'segmented_gather'):
        Name for the operation. Currently not used

Returns:
    `tuple(torch.Tensor)`: Tensor of shape (B1, ..., Bn, I1, ..., Ik, V1, ...) with the gathered values.
Nr]   )
r°  rI   r—   r[   r#   rh   r˜   r_   rb   rc   )r¡   rº  rS   r°  s   &&& r(   rh   rh   2  s¯   € ð  �m‰m€Gä
ˆ6�<‰<˜×(Ñ(Ð*Ð+Ó,¨qÔ0Ü�|Š|ØØ×ÑØ�L‰LØ—‘“˜aÕ  "óó
÷ ‰$ˆw�|‰|‹~Ó
ð	ð ×#Ñ# BÓ'×.Ñ.¨v¯|©|Ó<ˆÜ�|Š|˜F×$4Ñ$4°gÓ>Ð>r+   c                óZ  € \         P                  ! \         P                  ! \        V P	                  4       4      4      4      p\         P
                  ! ^ W P                  P                  R7      V P                  ,          pVP                  V P	                  4       4      p\        V P                  \        V P                  P                  4       4      4       F  pVP                  R4      pK  	  W0P                  ,           p\        VP                  R4      V P                  V,          ^ R7      # )a:  
Flattens a batched index map (which is typically of shape batch_size, seq_length) to a 1d index map. This operation
relabels the segments to keep batch elements distinct. The k-th batch element will have indices shifted by
*num_segments* * (k - 1). The result is a tensor with *num_segments* multiplied by the number of elements in the
batch.

Args:
    index (`IndexMap`):
        IndexMap to flatten.
    name (`str`, *optional*, defaults to 'segmented_flatten'):
        Name for the operation. Currently not used

Returns:
    (`IndexMap`): The flattened IndexMap.
©ÚstartÚendrY   r¯  r]   )r#   ÚprodÚtensorÚlistr	  r`   r±  rY   r˜   rl   r[   rI   r°  r_   rb   re   )rº  rS   Ú
batch_sizeÚoffsetrÞ  r°  s   &&    r(   Úflattenr%  S  s×   € ô" —’œEŸLšL¬¨e×.?Ñ.?Ó.AÓ)BÓCÓD€Jô �\Š\  z×:LÑ:L×:SÑ:SÔTÐW\×WiÑWiÕi€FØ�[‰[˜×*Ñ*Ó,Ó-€FÜ�5×#Ñ#¤S¨¯©×);Ñ);Ó)=Ó%>Ö?ˆØ×!Ñ! "Ó%Šñ @ð —}‘}Õ$€GÜ˜GŸL™L¨Ó,¸5×;MÑ;MÐPZÕ;ZÐghÔiÐir+   c                óº  € \         P                  ! V4      '       d   VP                  MRp\         P                  ! V \         P                  VR7      p \        V P                  4       4      ^8X  g   Q h\         P                  ! WR7      p\        VP                  4       4      ^ 8X  g   Q h\         P                  ! ^ WP                  R7      p\         P                  ! \         P                  ! V \         P                  VP                  R7      VP                  ^ R7      .^ R7      pVP                  4        Uu. uF  p\        V4      NK  	  ppVP                  V4      p\         P                  ! V \         P                  ! ^.VR7      .^ R7      pVP                  VP                  4       4      p\        WA\!        V P                  4       4      ^ ,          R7      # u upi )a}  
Constructs an index map equal to range(num_segments).

Args:
    batch_shape (`torch.Size`):
        Batch shape
    num_segments (`int`):
        Number of segments
    name (`str`, *optional*, defaults to 'range_index_map'):
        Name for the operation. Currently not used

Returns:
    (`IndexMap`): IndexMap of shape batch_shape with elements equal to range(num_segments).
ÚcpurW   r\   r  r”   r¯  )r#   Ú	is_tensorrY   rj   ra   rI   r_   r`   Úcatr¾  rb   Útolistr‡   r˜   Úrepeatre   r"  )	r	  r±  rS   rY   r°  Ú
new_tensorÚxÚ	new_shapeÚ	multipless	   &&&      r(   Úrange_index_mapr0  p  sv  € ô %*§O¢O°L×$AÒ$Aˆ\× Ò Àu€FÜ—/’/Øœ5Ÿ:™:¨fô€Kô ˆ{×ÑÓ!Ó" aÔ'Ð'Ð'Ü—?’?Øô€Lô ˆ|× Ñ Ó"Ó# qÔ(Ð(Ð(ä�lŠlØ�\×*=Ñ*=ô€Gô —’Ü	�Š˜¬E¯J©J¸|×?RÑ?RÔ	SÐUa×UkÑUkÐpqÐUkÓUrÐsØô€Jð
 ",×!2Ñ!2Ô!4Ó5Ñ!4˜A”�Q–Ñ!4€IÐ5Ø�l‰l˜9Ó%€Gä—	’	˜;¬¯ª¸¸ÀFÔ(KÐLÐRSÔT€IØ�n‰n˜Y×-Ñ-Ó/Ó0€Gô ˜GÌ4ÐP[×P`ÑP`ÓPbÓKcÐdeÕKfÔgÐgùò 6s   Ä6Gc           
     óî  € \        V4      pV P                  4       \        VP                  P                  4       4      R p\        P
                  ! \        P                  ! R.\        P                  R7      \        P                  ! V\        P                  R7      .^ R7      pV P                  VP                  4       4      p\        P                  ! \        VP                  4      \        P                  VP                  R7      pVP                  ^ VP                  P                  4       VP                  4       VRR7      p	VP                  P                  p
\        P
                  ! \        P                  ! VP!                  4       \        P                  V
R7      \        P                  ! VP                  \        P                  V
R7      P#                  ^ R7      \        P                  ! V\        P                  V
R7      .^ R7      pV	P%                  4       P'                  VP                  4       4      P)                  V P*                  4      p\-        VP!                  4       VP                  4      pWÍ3# )a´  
Applies a segment reduction segment-wise.

Args:
    values (`torch.Tensor`):
        Tensor with segment values.
    index (`IndexMap`):
        IndexMap.
    segment_reduce_fn (`str`):
        Name for the reduce operation. One of "sum", "mean", "max" or "min".
    name (`str`):
        Name for the operation. Currently not used

Returns:
    (`IndexMap`): IndexMap of shape batch_shape with elements equal to range(num_segments).
Nr³  r”   rW   F)r•   rº  ÚsrcÚreduceÚinclude_selfr]   )r%  r_   rI   r°  r#   r)  rj   ra   Úreshaper*  rk   r‡   r±  rÁ  rY   Úscatter_reducer	  rb   Úcloner˜   rÀ  rX   r0  )r¡   rº  Úsegment_reduce_fnrS   Ú
flat_indexÚvector_shapeÚflattened_shapeÚflat_valuesÚoutÚsegment_meansrY   r.  Úoutput_valuesÚoutput_indexs   &&&&          r(   Ú_segment_reducerA  œ  sÄ  € ô( ˜“€JØ—;‘;“=¤ U§]¡]×%7Ñ%7Ó%9Ó!:Ð!<Ð=€LÜ—i’iÜ	�Š˜"˜¤U§Z¡ZÔ	0´%·/²/À,ÔV[×V`ÑV`Ô2aÐbÐhiô€Oð —.‘. ×!7Ñ!7Ó!9Ó:€Kä
�+Š+”c˜*×1Ñ1Ó2¼%¿+¹+Èk×N`ÑN`Ô
a€CØ×&Ñ&Ø�Z×'Ñ'×,Ñ,Ó.°K×4EÑ4EÓ4GÐPaÐpuð 'ó €Mð ×Ñ×&Ñ&€Fä—	’	ä�OŠO˜E×-Ñ-Ó/´u·z±zÈ&ÔQÜ�OŠO˜E×.Ñ.´e·j±jÈÔP×ZÑZÐ_`ÐZÓaÜ�OŠO˜L´·
±
À6ÔJð	
ð
 ô€Ið "×'Ñ'Ó)×.Ñ.¨y×/?Ñ/?Ó/AÓB×EÑEÀfÇlÁlÓS€MÜ" 5×#4Ñ#4Ó#6¸×8JÑ8JÓK€LØÐ&Ð&r+   c                ó   € \        WRV4      # )a:  
Sums a tensor over its segments.

Outputs 0 for empty segments.

This operations computes the sum over segments, with support for:

    - Batching using the first dimensions [B1, B2, ..., Bn]. Each element in a batch can have different indices.
    - Vectorization using the last dimension [V1, V2, ...]. If they are present, the output will be a sum of
      vectors rather than scalars. Only the middle dimensions [I1, ..., Ik] are reduced by the operation.

Args:
    values (`torch.Tensor` of shape [B1, B2, ..., Bn, I1, .., Ik, V1, V2, ..]):
        Tensor containing the values of which the sum must be taken segment-wise.
    index (`IndexMap`, indices are of shape [B1, B2, ..., Bn, I1, .., Ik].):
        Index defining the segments.
    name (`str`, *optional*, defaults to 'segmented_reduce_sum'):
        Name for the operation. Currently not used

Returns:
    output_values (`torch.Tensor`of shape [B1, B2, ..., Bn, num_segments, V1, V2, ..]): Tensor containing the
    output values. output_index (`IndexMap`): IndexMap with shape [B1, B2, ..., Bn, num_segments]. .
rÑ  ©rA  ©r¡   rº  rS   s   &&&r(   Ú
reduce_sumrE  Í  s   € ô0 ˜6¨%°Ó6Ð6r+   c                ó   € \        WRV4      # )a@  
Averages a tensor over its segments.

Outputs 0 for empty segments.

This operations computes the mean over segments, with support for:

    - Batching using the first dimensions [B1, B2, ..., Bn]. Each element in a batch can have different indices.
    - Vectorization using the last dimension [V1, V2, ...]. If they are present, the output will be a mean of
      vectors rather than scalars.

Only the middle dimensions [I1, ..., Ik] are reduced by the operation.

Args:
    values (`torch.Tensor` of shape [B1, B2, ..., Bn, I1, .., Ik, V1, V2, ..]):
        Tensor containing the values of which the mean must be taken segment-wise.
    index (`IndexMap`, indices are of shape [B1, B2, ..., Bn, I1, .., Ik].):
        Index defining the segments.
    name (`str`, *optional*, defaults to 'segmented_reduce_sum'):
        Name for the operation. Currently not used

Returns:
    output_values (`torch.Tensor`of shape [B1, B2, ..., Bn, num_segments, V1, V2, ..]): Tensor containing the
    output values. output_index (`IndexMap`): IndexMap with shape [B1, B2, ..., Bn, num_segments].
rÕ  rC  rD  s   &&&r(   rÂ  rÂ  è  s   € ô4 ˜6¨&°$Ó7Ð7r+   c                ó   € \        WRV4      # )a2  
Computes the maximum over segments.

This operation computes the maximum over segments, with support for:

    - Batching using the first dimensions [B1, B2, ..., Bn]. Each element in a batch can have different indices.
    - Vectorization using the last dimension [V1, V2, ...]. If they are present, the output will be an element-wise
      maximum of vectors rather than scalars.

Only the middle dimensions [I1, ..., Ik] are reduced by the operation.

Args:
    values (`torch.Tensor` of shape [B1, B2, ..., Bn, I1, .., Ik, V1, V2, ..]):
        Tensor containing the values of which the max must be taken segment-wise.
    index (`IndexMap`, indices are of shape [B1, B2, ..., Bn, I1, .., Ik].):
        Index defining the segments.
    name (`str`, *optional*, defaults to 'segmented_reduce_sum'):
        Name for the operation. Currently not used

Returns:
    output_values (`torch.Tensor`of shape [B1, B2, ..., Bn, num_segments, V1, V2, ..]): Tensor containing the
    output values. output_index (`IndexMap`): IndexMap with shape [B1, B2, ..., Bn, num_segments].
ÚamaxrC  rD  s   &&&r(   Ú
reduce_maxrI    ó   € ô0 ˜6¨&°$Ó7Ð7r+   c                ó   € \        WRV4      # )a3  
Computes the minimum over segments.

This operations computes the minimum over segments, with support for:

    - Batching using the first dimensions [B1, B2, ..., Bn]. Each element in a batch can have different indices.
    - Vectorization using the last dimension [V1, V2, ...]. If they are present, the output will be an element-wise
      minimum of vectors rather than scalars.

Only the middle dimensions [I1, ..., Ik] are reduced by the operation.

Args:
    values (`torch.Tensor` of shape [B1, B2, ..., Bn, I1, .., Ik, V1, V2, ..]):
        Tensor containing the values of which the min must be taken segment-wise.
    index (`IndexMap`, indices are of shape [B1, B2, ..., Bn, I1, .., Ik].):
        Index defining the segments.
    name (`str`, *optional*, defaults to 'segmented_reduce_sum'):
        Name for the operation. Currently not used

Returns:
    output_values (`torch.Tensor`of shape [B1, B2, ..., Bn, num_segments, V1, V2, ..]): Tensor containing the
    output values. output_index (`IndexMap`): IndexMap with shape [B1, B2, ..., Bn, num_segments].
ÚaminrC  rD  s   &&&r(   rg   rg      rJ  r+   c                óÈ  € \         P                  ! RW4      V,           p\        Wc4      w  rxVP                  V4      p	\	        Wt,          V	4      w  r«\	        WI4      w  rÍW¬\
        ,           ,          p
\         P                  ! VR8  \         P                  ! VP                  ^ 4      ( 4      pV
\        \         P                  ! V\         P                  VP                  R7      ,          ,          p
V'       gm   V
\        \         P                  ! \         P                  ! VP                  ^ 4      \         P                  VP                  P                  R7      ,          ,          p
V
# )aá  
Computes the column logits.

Args:
    sequence_output (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
        Also known as last_hidden_state. Sequence of hidden-states at the output of the last layer of the model.
    column_output_weights (`torch.FloatTensor` of shape `(hidden_size)`):
        Weights of the linear layer for column selection.
    column_output_bias (`torch.FloatTensor` of shape `()`):
        Bias of the linear layer for column selection.
    cell_index (`ProductIndexMap`):
        Index that groups tokens into cells.
    cell_mask (`torch.FloatTensor` of shape `(batch_size, max_num_rows * max_num_cols)`):
        Mask for cells that exist in the table (i.e. that are not padding).
    allow_empty_column_selection (`bool`):
        Whether to allow not to select any column

Returns:
    column_logits (`torch.FloatTensor`of shape `(batch_size, max_num_cols)`): Tensor containing the column logits
    for every example in the batch.
ú	bsj,j->bsç      à?rW   )r#   ÚeinsumrÂ  r  rE  rÒ  Úlogical_andÚeqr°  ÚCLOSE_ENOUGH_TO_LOG_ZEROrj   rÎ  rY   )rN  r_  rc  rÚ  rÝ  rÇ  Útoken_logitsÚcell_logitsÚcell_logits_indexÚcolumn_indexrß  Ú	out_indexÚ
cell_countrÞ  Ú
is_paddings   &&&&&&         r(   rÆ  rÆ  >  s  € ô4 —<’< ¨_ÓTÐWiÕi€Lô &1°Ó%JÑ"€Kð ×+Ñ+Ð,=Ó>€LÜ)¨+Õ*AÀ<ÓPÑ€Mä˜yÓ7�M€JØÔ"7Õ7Õ7€Mô ×"Ò" :°Ñ#3´e·h²h¸y×?PÑ?PÐRSÓ6TÐ5TÓU€JØÔ-´·²Øœ%Ÿ-™-°
×0AÑ0Aô1õ õ €M÷ (ØÔ1´E·O²OÜ�HŠH�Y×&Ñ&¨Ó*´%·-±-È	×HYÑHY×H`ÑH`ô5
õ 
õ 	
ˆð Ðr+   c           
     óâ  € \        \        P                  ! V\        P                  VP                  R7      V4      w  rg\        P
                  ! VRR7      p\        P                  ! \        P                  ! VRR7      ^ ,          ^ 4      p	\        P                  ! V	P                  VP                  4       4      \        P                  ! V4      V4      p\        P                  P                  VR7      p
V
P                  V4      ) p\        W4      w  rÇ\!        \        P                  ! V\        P"                  VP                  R7      V4      w  rÞVP%                  V4      P&                  p\        P                  ! \        P                  ! V\        P(                  ! VRR7      4      \        P                  VP                  R7      p\        P                  P+                  VR7      pVP                  VP-                  \        P                  4      4      p\        P.                  ! VV,          V,          ^R7      ) pV\        P.                  ! VV,          ^R7      \0        ,           ,          pTpV\        P                  ! V	P                  VP                  4       4      \        P                  ! V4      V4      ,          p\        P                  ! \        P
                  ! VRR7      \        P"                  VP                  R7      p\        P                  ! \        P                  ! V\        P(                  ! VRR7      4      \        P                  VP                  R7      p\        P                  ! \        P                  ! V^ 4      P                  VP                  4       4      \        P                  ! V4      V4      pV\2        RVV,          ,
          ,          ,           p\5        VV4      pVV3# )aR  
Computes the loss for cell selection constrained to a single column. The loss is a hierarchical log-likelihood. The
model first predicts a column and then selects cells within that column (conditioned on the column). Cells outside
the selected column are never selected.

Args:
    token_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
        Tensor containing the logits per token.
    column_logits (`torch.FloatTensor` of shape `(batch_size, max_num_cols)`):
        Tensor containing the logits per column.
    labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
        Labels per token.
    cell_index (`ProductIndexMap`):
        Index that groups tokens into cells.
    col_index (`IndexMap`):
        Index that groups tokens into columns.
    cell_mask (`torch.FloatTensor` of shape `(batch_size, max_num_rows * max_num_cols)`):
        Mask for cells that exist in the table (i.e. that are not padding).

Returns:
    selection_loss_per_example (`torch.FloatTensor` of shape `(batch_size,)`): Loss for each example. logits
    (`torch.FloatTensor` of shape `(batch_size, sequence_length)`): New logits which are only allowed to select
    cells in a single column. Logits outside of the most likely column according to *column_logits* will be set to
    a very low value (such that the probabilities are 0).
rW   r”   r²  r´  r]   )rE  r#   rj   rÎ  rY   ÚargmaxrR  Úmaxr½  r˜   r_   r¿  rÌ  ÚCategoricalrÐ  rÂ  rI  ra   r  r°  rb   rÍ  r  rÑ  rÒ  rS  rh   )rT  rß  r“  rÚ  rt   rÝ  Úlabels_per_columnrÞ  Úcolumn_labelÚno_cell_selectedÚcolumn_distÚcolumn_loss_per_examplerä  Úlabels_per_cellÚlabels_indexÚcolumn_id_for_cellsÚcolumn_maskÚ	cell_distÚcell_log_probÚ	cell_lossræ  Úselected_column_idÚselected_column_maskÚnew_logits_per_cellr   s   &&&&&&                   r(   rÓ  rÓ  r  s÷  € ô: &¤e§o¢o°fÄEÇMÁMÐZ`×ZgÑZgÔ&hÐjsÓtÑÐä—<’<Ð 1°rÔ:€Lô —x’xÜ�	Š	Ð#¨Ô,¨QÕ/°óÐô —;’;Ø×Ñ˜l×/Ñ/Ó1Ó2´E×4DÒ4DÀ\Ó4RÐT`ó€Lô ×%Ñ%×1Ñ1¸Ð1ÓG€KØ*×3Ñ3°LÓAÐAÐô % \Ó>Ñ€Oä$.Ü�Š˜¤e§j¡j¸¿¹ÔGÈó%Ñ!€Oð %×2Ñ2°<Ó@×HÑHÐä—/’/Ü�ŠÐ$¤e§o¢o°lÈÔ&KÓLÜ�m‰mØ×Ñô€Kô ×#Ñ#×-Ñ-°_Ð-ÓE€IØ×&Ñ& ×';Ñ';¼E¿M¹MÓ'JÓK€Mä—’˜=¨;Õ6¸ÕBÈÔJÐJ€Ið ”—’˜;¨Õ2¸Ô:Ô=RÕRÕR€Ià!8ÐØ¤%§+¢+Ø×ÑÐ8×=Ñ=Ó?Ó@Ü×ÒÐ3Ó4Øó#õ Ðô ŸšÜ�Š�]¨Ô+´5·:±:Àm×FZÑFZôÐô
 !Ÿ?š?Ü�ŠÐ$¤e§o¢oÐ6HÈbÔ&QÓRÜ�m‰mØ!×(Ñ(ôÐô !Ÿ;š;Ü�ŠÐ$ aÓ(×-Ñ-Ð.B×.GÑ.GÓ.IÓJÜ×ÒÐ-Ó.ØóÐð
 *Ô,DÈÈiÐZnÕNnÕHnÕ,oÕoÐÜÐ'¨Ó4€Fà% vÐ-Ð-r+   c                óP   € \         P                  ! RW4      V,           V,          pV# )a�  
Computes logits per token

Args:
    sequence_output (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
        Also known as last_hidden_state. Sequence of hidden-states at the output of the last layer of the model.
    temperature (`float`):
        Temperature for the Bernoulli distribution.
    output_weights (`torch.FloatTensor` of shape `(hidden_size,)`):
        Weights of the linear layer for cell selection.
    output_bias (`torch.FloatTensor` of shape `()`):
        Bias of the linear layer for cell selection

Returns:
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`): Logits per token.
rN  )r#   rP  )rN  rÄ  r^  rb  r   s   &&&& r(   rÃ  rÃ  Ý  s$   € ô" �lŠl˜;¨ÓHÈ;ÕVÐZeÕe€Fà€Mr+   c                ó´  € \         P                  ! \         P                  ! V 4      4      P                  \         P                  4      P                  V P                  4      pV! V4      p\         P                  P                  P                  VR7      p\         P                  ! VP                  R,          ^R7      pW‚8*  p	\         P                  ! V^R7      ^ 8„  p
\         P                  ! \         P                  ! Wš4      P                  VP                  4       4      \         P                   ! V\         P"                  R7      V4      pVP%                  4       pV# )az  
Finds examples where the model should select cells with no aggregation.

Returns a mask that determines for which examples should the model select answers directly from the table, without
any aggregation function. If the answer is a piece of text the case is unambiguous as aggregation functions only
apply to numbers. If the answer is a number but does not appear in the table then we must use some aggregation
case. The ambiguous case is when the answer is a number that also appears in the table. In this case we use the
aggregation function probabilities predicted by the model to decide whether to select or aggregate. The threshold
for this is a hyperparameter *cell_selection_preference*

Args:
    answer (`torch.FloatTensor` of shape `(batch_size, )`):
        Answer for every example in the batch. Nan if there is no scalar answer.
    pooled_output (`torch.FloatTensor` of shape `(batch_size, hidden_size)`):
        Output of the pooler (BertPooler) on top of the encoder layer.
    cell_selection_preference (`float`):
        Preference for cell selection in ambiguous cases.
    labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
        Labels per token. aggregation_classifier (`torch.nn.Linear`): Aggregation head

Returns:
    aggregate_mask (`torch.FloatTensor` of shape `(batch_size,)`): A mask set to 1 for examples that should use
    aggregation functions.
r²  r”   r³  ©rZ   rá   )r#   Úlogical_notÚisnanr  r$   rÀ  rY   rÌ  Úcategoricalr^  rÑ  Úprobsr½  rQ  r˜   r_   r¿  rÎ  Údetach)Úanswerr3  rÊ  r“  r£  Úaggregate_mask_initr    Údist_aggregationÚaggregation_ops_total_massÚis_pred_cell_selectionÚis_cell_supervision_availablerã  s   &&&&&       r(   rÉ  rÉ  ó  s  € ô4  ×+Ò+¬E¯KªK¸Ó,?Ó@×EÑEÄe×FWÑFWÓX×[Ñ[Ð\b×\iÑ\iÓjÐÙ/°Ó>ÐÜ×*Ñ*×6Ñ6×BÑBÐJ\ÐBÓ]Ðä!&§¢Ð+;×+AÑ+AÀ%Õ+HÈaÔ!PÐð 8ÑTÐô %*§I¢I¨f¸!Ô$<¸qÑ$@Ð!ä—[’[Ü×ÒÐ0ÓP×UÑUÐVi×VnÑVnÓVpÓqÜ×ÒÐ,´E·M±MÔBØó€Nð $×*Ñ*Ó,€NàÐr+   c                ó’  € V'       d(   \         P                  ! V\         P                  R7      pMTp\        P                  P                  WTR7      P                  \         P                  4      p\        P                  P                  V RR7      p\         P                  ! Wg,          RR7      ) pV'       d   V^V,
          ,          # V# )aÓ  
Calculates aggregation loss when its type is known during training.

In the weakly supervised setting, the only known information is that for cell selection examples, "no aggregation"
should be predicted. For other examples (those that require aggregation), no loss is accumulated. In the setting
where aggregation type is always known, standard cross entropy loss is accumulated for all examples

Args:
    logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    aggregate_mask (`torch.FloatTensor` of shape `(batch_size, )`):
        A mask set to 1 for examples that should use aggregation functions.
    aggregation_labels (`torch.LongTensor` of shape `(batch_size, )`):
        Aggregation function id for every example in the batch.
    use_answer_as_supervision (`bool`, *optional*):
        Whether to use the answer as the only supervision for aggregation examples.
    num_aggregation_labels (`int`, *optional*, defaults to 0):
        The number of aggregation operators to predict.

Returns:
    aggregation_loss_known (`torch.FloatTensor` of shape `(batch_size,)`): Aggregation loss (when its type is known
    during training) per example.
r³  )Únum_classesr”   r]   )
r#   r¿  ra   r   r¦   Úone_hotr  rÎ  Úlog_softmaxrÑ  )	r    rã  r§  rÈ  r¢  Útarget_aggregationÚone_hot_labelsÚ	log_probsÚ$per_example_aggregation_intermediates	   &&&&&    r(   Ú!_calculate_aggregation_loss_knownr„  $  sŸ   € ÷4 !ä"×-Ò-¨nÄEÇJÁJÔOÑð 0Ðä—]‘]×*Ñ*Ð+=Ð*Ób×gÑgÔhm×huÑhuÓv€NÜ—‘×)Ñ)Ð*<À"Ð)ÓE€Iô -2¯IªI°nÕ6PÐVXÔ,YÐ+YÐ(ß ð 4°q¸>Õ7IÕJÐJà3Ð3r+   c                óä   € \         P                  P                  P                  V R7      p\         P                  ! VP
                  R,          ^R7      p\         P                  ! V4      ) V,          # )a÷  
Calculates aggregation loss in the case of answer supervision.

Args:
    logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    aggregate_mask (`torch.FloatTensor` of shape `(batch_size, )`):
        A mask set to 1 for examples that should use aggregation functions

Returns:
    aggregation_loss_unknown (`torch.FloatTensor` of shape `(batch_size,)`): Aggregation loss (in case of answer
    supervision) per example.
r²  r”   rp  )r#   rÌ  rs  r^  rÑ  rt  Úlog)r    rã  rx  ry  s   &&  r(   Ú#_calculate_aggregation_loss_unknownr‡  R  s\   € ô ×*Ñ*×6Ñ6×BÑBÐJ\ÐBÓ]Ðä!&§¢Ð+;×+AÑ+AÀ%Õ+HÈaÔ!PÐô
 �IŠIÐ0Ó1Ð1°NÕBÐBr+   c                ó`   € \        WW#V4      pV'       d   V\        W4      ,          pWV,          # )a¸  
Calculates the aggregation loss per example.

Args:
    logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    aggregate_mask (`torch.FloatTensor` of shape `(batch_size, )`):
        A mask set to 1 for examples that should use aggregation functions.
    aggregation_labels (`torch.LongTensor` of shape `(batch_size, )`):
        Aggregation function id for every example in the batch.
    use_answer_as_supervision (`bool`, *optional*):
        Whether to use the answer as the only supervision for aggregation examples.
    num_aggregation_labels (`int`, *optional*, defaults to 0):
        The number of aggregation operators to predict.
    aggregation_loss_weight (`float`, *optional*, defaults to 1.0):
        Importance weight for the aggregation loss.

Returns:
    aggregation_loss (`torch.FloatTensor` of shape `(batch_size,)`): Aggregation loss per example.
)r„  r‡  )r    rã  r§  rÈ  r¢  r×  Úper_example_aggregation_losss   &&&&&& r(   rÖ  rÖ  j  s9   € ô8 $EØÐ,>Ð[qó$Ð ÷ !à$Ô(KÐL^Ó(oÕoÐ$Ø"ÕAÐAr+   c           	     óè  € VP                   '       dX   \        P                  P                  VP                  V P
                  VP                  ,          R7      pVP                  4       pMV P                  pWr,          V,          p\        P                  ! V^R7      p\        P                  ! \        P                  ! V4      \        P                  ! V4      V4      p	\        P                  ! Wy,          ^R7      p
VP                  pV\        P                  8X  d   W¨\        ,           ,          pEM7V\        P                   8X  dN   \        P                  ! V^RR7      V,
          ^,           p\        P                  ! W—,          V,          ^R7      pMÕV\        P"                  8X  d©   \        P                  ! V^RR7      V,
          ^,           pV^V,
          ,          p\        P                  ! V^RR7      V,
          pV\        P$                  ! V4      ,          ^,           V,          p\        P                  ! W—,          V,          ^R7      pM\'        RVP                   24      hVP(                  '       dD   \        P                  P+                  VP,                  VR,          R7      pVP                  4       pM9\.        P0                  P3                  VR,          VP,                  ,          RR7      p\        P4                  ! \        P6                  ! V
^R7      \        P6                  ! V^R7      \        P6                  ! V^R7      .^R7      p\        P                  ! VV,          ^R7      pV# )	aÛ  
Calculates the expected result given cell and aggregation probabilities.

Args:
    dist_per_cell (`torch.distributions.Bernoulli`):
        Cell selection distribution for each cell.
    numeric_values (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Numeric values of every token. Nan for tokens which are not numeric values.
    numeric_values_scale (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Scale of the numeric values of every token.
    input_mask_float (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Mask for the table, without question tokens and table headers.
    logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    config ([`TapasConfig`]):
        Model configuration class with all the hyperparameters of the model

Returns:
    expected_result (`torch.FloatTensor` of shape `(batch_size,)`): The expected result per example.
)rÄ  r   r”   T)r•   Úkeepdimz(Invalid average_approximation_function: r²  rp  r]   )Úuse_gumbel_for_cellsr#   rÌ  ÚRelaxedBernoullirÄ  r   Úsamplert  rÑ  r½  rr  r¿  Úaverage_approximation_functionrþ  r  rÒ  r  r  Úsquarer†   Úuse_gumbel_for_aggregationÚRelaxedOneHotCategoricalÚaggregation_temperaturer   r¦   r§   r)  rb   )Údist_per_cellr©  rª  rÛ  r    rP   Úgumbel_distÚscaled_probability_per_cellÚcount_resultÚnumeric_values_maskedÚ
sum_resultÚavg_approximationÚaverage_resultÚexÚpointwise_varÚvarÚ
multiplierÚaggregation_op_only_probsÚall_resultsÚexpected_results   &&&&&&              r(   Ú_calculate_expected_resultr£  �  sÂ  € ð. ×"×"Ð"Ü×)Ñ)×:Ñ:ð ×*Ñ*Ø ×'Ñ'¨&×*<Ñ*<Õ<ð	 ;ó 
ˆð '2×&8Ñ&8Ó&:Ñ#à&3×&9Ñ&9Ð#ð $?Õ#UÐYiÕ"iÐÜ—9’9Ð8¸aÔ@€LÜ!ŸKšKÜ�Š�NÓ#¤U×%5Ò%5°nÓ%EÀ~óÐô —’Ð6ÕNÐTUÔV€JØ×=Ñ=ÐØÔ8×>Ñ>Ô>Ø#Ô6KÕ'KÕLŠØ	Ô:×FÑFÔ	Fô
 �YŠYÐ2¸À4ÔHÐKfÕfÐijÕjˆÜŸšÐ#8Õ#VÐY[Õ#[ÐabÔc‰Ø	Ô:×GÑGÔ	Gä�YŠYÐ2¸À4ÔHÐKfÕfÐijÕjˆØ3°qÐ;VÕ7VÕWˆÜ�iŠi˜¨1°dÔ;¸mÕKˆàœEŸLšL¨Ó,Õ,¨qÕ0°BÕ6ˆ
ÜŸšÐ#8Õ#VÐYcÕ#cÐijÔk‰äÐCÀF×DiÑDiÐCjÐkÓlÐlà×(×(Ð(Ü×)Ñ)×BÑBØ×*Ñ*Ð3EÀeÕ3Lð Có 
ˆð %0×$6Ñ$6Ó$8Ñ!ô %'§M¡M×$9Ñ$9Ø˜uÕ%¨×(FÑ(FÕFÈBð %:ó %
Ð!ô —)’)ä�OŠO˜J¨AÔ.Ü�OŠO˜N°Ô2Ü�OŠO˜L¨aÔ0ð	
ð
 ô€Kô —i’i Ð.GÕ GÈQÔO€OØÐr+   c                ó$   € V ^8„  d   QhR\         /# )r   Údelta)rÁ  )r&   s   "r(   r)   r)   è  s   € ÷ [ñ [¤Uñ [r+   c                 óÀ   € \         P                  ! W,
          4      p\         P                  ! W28  R V^,          ,          W2,          R V^,          ,          ,
          4      # )rO  )r#   Úabsr½  )ÚinputÚtargetr¥  Úerrorss   &&& r(   Ú
huber_lossr«  è  sA   € Ü�YŠY�u•~Ó&€FÜ�;Š;�v‘~ s¨V°Q­Y¥¸½È#ÐPUÐWXÕPXÍ.Õ8YÓZÐZr+   c           	     ó„  € \        W#WEWg4      p\        P                  ! \        P                  ! V 4      \        P                  ! V 4      V 4      p	VP
                  '       d‚   \        P                  ! \        P                  ! V4      \        P                  ! V	4      4      \        ,           P                  4       p
Wš,          pWŠ,          p\        WÁ,          W±,          4      pM$\        W�,          W‘,          VP                  R7      pVP                  f(   \        P                  ! V\        P                  R7      pMl\        P                  ! W×P                  8„  \        P                  ! V\        P                  R7      \        P                  ! V\        P                  R7      4      pVP                  WÑ,          ,          pWþ3# )a¥  
Calculates the regression loss per example.

Args:
    answer (`torch.FloatTensor` of shape `(batch_size,)`):
        Answer for every example in the batch. Nan if there is no scalar answer.
    aggregate_mask (`torch.FloatTensor` of shape `(batch_size,)`):
        A mask set to 1 for examples that should use aggregation functions.
    dist_per_cell (`torch.distributions.Bernoulli`):
        Cell selection distribution for each cell.
    numeric_values (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Numeric values of every token. Nan for tokens which are not numeric values.
    numeric_values_scale (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Scale of the numeric values of every token.
    input_mask_float (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
        Mask for the table, without question tokens and table headers.
    logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    config ([`TapasConfig`]):
        Model configuration class with all the parameters of the model

Returns:
    per_example_answer_loss_scaled (`torch.FloatTensor` of shape `(batch_size,)`): Scales answer loss for each
    example in the batch. large_answer_loss_mask (`torch.FloatTensor` of shape `(batch_size,)`): A mask which is 1
    for examples for which their answer loss is larger than the answer_loss_cutoff.
)r¥  r³  )r£  r#   r½  rr  r¿  Úuse_normalized_answer_lossr]  r§  rÒ  ru  r«  Úhuber_loss_deltaÚanswer_loss_cutoffr¾  rÎ  Úanswer_loss_importance)rv  rã  r”  r©  rª  rÛ  r    rP   r¢  Úanswer_maskedÚ
normalizerÚnormalized_answer_maskedÚnormalized_expected_resultÚper_example_answer_lossrë  Úper_example_answer_loss_scaleds   &&&&&&&&        r(   rØ  rØ  í  sS  € ôJ 1ØÐ';ÐOaó€Oô
 —K’K¤§¢¨FÓ 3´U×5EÒ5EÀfÓ5MÈvÓV€Mà×(×(Ð(Ü—i’i¤§	¢	¨/Ó :¼E¿IºIÀmÓ<TÓUÔXmÕm×uÑuÓwˆ
à#0Õ#=Ð Ø%4Õ%AÐ"Ü",Ø&Õ7Ð9QÕ9bó#
Ñô #-ØÕ,¨mÕ.LÐTZ×TkÑTkô#
Ðð × Ñ Ò(Ü!&§¢Ð1HÔPU×P]ÑP]Ô!^Ñô "'§¢Ø#×&?Ñ&?Ñ?Ü×ÒÐ4¼E¿M¹MÔJÜ�OŠOÐ3¼5¿=¹=ÔIó"
Ðð
 &,×%BÑ%BÐF]ÕFnÕ%oÐ"à)ÐAÐAr+   g     ˆÃÀ)Úsegmented_gather)Úsegmented_flatten)r0  )Úsegmented_reduce_sum)Úsegmented_reduce_mean)Úsegmented_reduce_max)Úsegmented_reduce_min)r´  )r‡  r\  rï  rm  rU  )Wr1   Úenumr¤   Údataclassesr   r#   r   Útorch.nnr   r   r   Ú r   rZ  Úactivationsr   Úcache_utilsr	   r
   r   Úmasking_utilsr   Úmodeling_layersr   Úmodeling_outputsr   r   r   r   Úmodeling_utilsr   Úpytorch_utilsr   Úutilsr   r   r   Úconfiguration_tapasr   Ú
get_loggerr-   ÚloggerrÒ  rS  r   ÚModuler7   r€   rÀ   rÖ   ræ   rõ   rý   r  r*  r6  r?  rI  rU  rm  r‡  r\  rï  rê   ÚEnumrþ  re   rf   rh   r%  r0  rA  rE  rÂ  rI  rg   rÆ  rÓ  rÃ  rÉ  r„  r‡  rÖ  r£  r«  rØ  Ú__all__r,   r+   r(   Ú<module>rÏ     s«  ðñ ã Û Ý !ã Ý ß AÑ Aå &Ý !ß CÑ CÝ 6Ý 9ß uÓ uÝ -Ý 6ß 9Ñ 9Ý ,ð 
×	Ò	˜HÓ	%€ð Ð Ø#Ð ñ ðôð
 ô7 ;ó 7ó óð7ô$J�b—i‘iô JôZV˜Ÿ™ô Vôt�b—i‘iô ô�R—Y‘Yô ô:˜Ÿ	™	ô ô �"—)‘)ô ô?Ð+ô ?ôD0
�2—9‘9ô 0
ôh�"—)‘)ô ô  2§9¡9ô ô$˜BŸI™Iô ô"!�r—y‘yô !ð ô3˜?ó 3ó ð3ð, ôR
Ð%ó R
ó ðR
ðj ôs
Ð+ó s
ó ðs
ñl ðôôI
Ð 4ó I
óðI
ñX
 ðôôy
Ð%9ó y
óðy
ðx ô" 3¨¯	©	ô "÷6ñ 6ô4*
�hô *
ôZ?ôBjô:)hòX.'ôb7ô68ô:8ô68ò<1òhh.òVò,.òb+4ò\Cò0#BòLT÷p[ò
DBòN‚r+   