Ë
    S^(hr ã                  óÂ  — d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlZddlZddlmZ ddlmZmZmZmZmZmZmZmZmZ dd	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) dd
l*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6  e3jn                  e8«      Z9dZ:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDdZEdZF G d„ d«      ZG G d„ de'j�                  j’                  «      ZJ G d„ de'j�                  j’                  «      ZK G d „ d!e'j�                  j’                  «      ZL G d"„ d#e'j�                  j’                  «      ZM G d$„ d%e'j�                  j’                  «      ZN G d&„ d'e'j�                  j’                  «      ZO G d(„ d)e'j�                  j’                  «      ZP G d*„ d+e'j�                  j’                  «      ZQ G d,„ d-e'j�                  j’                  «      ZR G d.„ d/e'j�                  j’                  «      ZS G d0„ d1e'j�                  j’                  «      ZT G d2„ d3e'j�                  j’                  «      ZU G d4„ d5e'j�                  j’                  «      ZVe( G d6„ d7e'j�                  j’                  «      «       ZW G d8„ d9e"«      ZXe G d:„ d;e/«      «       ZYd<ZZd=Z[ e1d>eZ«       G d?„ d@eX«      «       Z\ e1dAeZ«       G dB„ dCeXeG«      «       Z] e1dDeZ«       G dE„ dFeXe«      «       Z^ G dG„ dHeXe«      Z_ e1dIeZ«       G dJ„ dKeXe!«      «       Z` e1dLeZ«       G dM„ dNeXe$«      «       Za e1dOeZ«       G dP„ dQeXe «      «       Zb e1dReZ«       G dS„ dTeXe%«      «       Zc e1dUeZ«       G dV„ dWeXe#«      «       Zdg dX¢Zey)YzTF 2.0 BERT model.é    )ÚannotationsN)Ú	dataclass)ÚDictÚOptionalÚTupleÚUnioné   )Úget_tf_activation)	Ú+TFBaseModelOutputWithPastAndCrossAttentionsÚ.TFBaseModelOutputWithPoolingAndCrossAttentionsÚ#TFCausalLMOutputWithCrossAttentionsÚTFMaskedLMOutputÚTFMultipleChoiceModelOutputÚTFNextSentencePredictorOutputÚTFQuestionAnsweringModelOutputÚTFSequenceClassifierOutputÚTFTokenClassifierOutput)ÚTFCausalLanguageModelingLossÚTFMaskedLanguageModelingLossÚTFModelInputTypeÚTFMultipleChoiceLossÚTFNextSentencePredictionLossÚTFPreTrainedModelÚTFQuestionAnsweringLossÚTFSequenceClassificationLossÚTFTokenClassificationLossÚget_initializerÚkerasÚkeras_serializableÚunpack_inputs)Úcheck_embeddings_within_boundsÚ
shape_listÚstable_softmax)ÚModelOutputÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú
BertConfigzgoogle-bert/bert-base-uncasedr+   z0dbmdz/bert-large-cased-finetuned-conll03-englishzZ['O', 'I-ORG', 'I-ORG', 'I-ORG', 'O', 'O', 'O', 'O', 'O', 'I-LOC', 'O', 'I-LOC', 'I-LOC'] g{®Gáz„?zydshieh/bert-base-cased-squad2z'a nice puppet'g¤p=
×£@é   é   z'ydshieh/bert-base-uncased-yelp-polarityz	'LABEL_1'c                  ó   — e Zd ZdZdd„Zy)ÚTFBertPreTrainingLosszø
    Loss function suitable for BERT-like pretraining, that is, the task of pretraining a language model by combining
    NSP + MLM. .. note:: Any label of -100 will be ignored (along with the corresponding logits) in the loss
    computation.
    c                óÊ  — t         j                  j                  dt         j                  j                  j                  ¬«      } |t
        j                  j                  |d   «      |d   ¬«      }t        j                  |d   dk7  |j                  ¬«      }||z  }t        j                  |«      t        j                  |«      z  } |t
        j                  j                  |d   «      |d	   ¬«      }t        j                  |d   dk7  |j                  ¬«      }	||	z  }
t        j                  |
«      t        j                  |	«      z  }t        j                  ||z   d
«      S )NT)Úfrom_logitsÚ	reductionÚlabelsr   )Úy_trueÚy_prediœÿÿÿ©ÚdtypeÚnext_sentence_labelr*   )r*   )r   ÚlossesÚSparseCategoricalCrossentropyÚ	ReductionÚNONEÚtfÚnnÚreluÚcastr7   Ú
reduce_sumÚreshape)Úselfr3   ÚlogitsÚloss_fnÚunmasked_lm_lossesÚlm_loss_maskÚmasked_lm_lossesÚreduced_masked_lm_lossÚunmasked_ns_lossÚns_loss_maskÚmasked_ns_lossÚreduced_masked_ns_losss               úg/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/bert/modeling_tf_bert.pyÚhf_compute_lossz%TFBertPreTrainingLoss.hf_compute_lossc   s-  € Ü—,‘,×<Ñ<ÈÔY^×YeÑYe×YoÑYo×YtÑYtÐ<Óuˆñ %¬B¯E©E¯J©J°v¸hÑ7GÓ,HÐQWÐXYÑQZÔ[Ðô —w‘w˜v hÑ/°4Ñ7Ð?Q×?WÑ?WÔXˆØ-°Ñ<ÐÜ!#§¡Ð/?Ó!@Ä2Ç=Á=ÐQ]ÓC^Ñ!^Ðñ #¬"¯%©%¯*©*°VÐ<QÑ5RÓ*SÐ\bÐcdÑ\eÔfÐÜ—w‘w˜vÐ&;Ñ<ÀÑDÐL\×LbÑLbÔcˆØ)¨LÑ8ˆä!#§¡¨~Ó!>ÄÇÁÈ|ÓA\Ñ!\Ðä�z‰zÐ0Ð3IÑIÈ4ÓPÐPó    N)r3   ú	tf.TensorrD   rQ   ÚreturnrQ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   © rP   rN   r/   r/   \   s   „ ñôQrP   r/   c                  óX   ‡ — e Zd ZdZdˆ fd„Zdd„Z	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )	ÚTFBertEmbeddingszGConstruct the embeddings from word, position and token_type embeddings.c                óV  •— t        ‰| �  di |¤Ž || _        |j                  | _        |j                  | _        |j
                  | _        t        j                  j                  |j                  d¬«      | _
        t        j                  j                  |j                  ¬«      | _        y )NÚ	LayerNorm©ÚepsilonÚname©ÚraterW   )ÚsuperÚ__init__ÚconfigÚhidden_sizeÚmax_position_embeddingsÚinitializer_ranger   ÚlayersÚLayerNormalizationÚlayer_norm_epsr[   ÚDropoutÚhidden_dropout_probÚdropout©rC   rc   ÚkwargsÚ	__class__s      €rN   rb   zTFBertEmbeddings.__init__{   s…   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ!×-Ñ-ˆÔØ'-×'EÑ'EˆÔ$Ø!'×!9Ñ!9ˆÔÜŸ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒÜ—|‘|×+Ñ+°×1KÑ1KÐ+ÓLˆ�rP   c                óÚ  — t        j                  d«      5  | j                  d| j                  j                  | j
                  gt        | j                  «      ¬«      | _        d d d «       t        j                  d«      5  | j                  d| j                  j                  | j
                  gt        | j                  «      ¬«      | _
        d d d «       t        j                  d«      5  | j                  d| j                  | j
                  gt        | j                  «      ¬«      | _        d d d «       | j                  ry d| _        t        | dd «      �et        j                  | j                  j                   «      5  | j                  j#                  d d | j                  j
                  g«       d d d «       y y # 1 sw Y   �Œ[xY w# 1 sw Y   ŒýxY w# 1 sw Y   Œ©xY w# 1 sw Y   y xY w)	NÚword_embeddingsÚweight)r^   ÚshapeÚinitializerÚtoken_type_embeddingsÚ
embeddingsÚposition_embeddingsTr[   )r=   Ú
name_scopeÚ
add_weightrc   Ú
vocab_sizerd   r   rf   rr   Útype_vocab_sizeru   re   rw   ÚbuiltÚgetattrr[   r^   Úbuild©rC   Úinput_shapes     rN   r~   zTFBertEmbeddings.build…   s£  € Ü�]‰]Ð,Ó-ñ 	ØŸ/™/ØØ—{‘{×-Ñ-¨t×/?Ñ/?Ð@Ü+¨D×,BÑ,BÓCð *ó ˆDŒK÷	ô �]‰]Ð2Ó3ñ 	Ø)-¯©Ø!Ø—{‘{×2Ñ2°D×4DÑ4DÐEÜ+¨D×,BÑ,BÓCð *9ó *ˆDÔ&÷	ô �]‰]Ð0Ó1ñ 	Ø'+§¡Ø!Ø×3Ñ3°T×5EÑ5EÐFÜ+¨D×,BÑ,BÓCð (7ó (ˆDÔ$÷	ð �:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ LØ—‘×$Ñ$ d¨D°$·+±+×2IÑ2IÐ%JÔK÷Lð Lð 8÷1	ñ 	ú÷	ð 	ú÷	ð 	ú÷Lð Lús2   –AF<Â AG	Ã*AGÅ?3G!Æ<GÇ	GÇGÇ!G*c                ó>  — |€|€t        d«      ‚|�At        || j                  j                  «       t	        j
                  | j                  |¬«      }t        |«      dd }|€t	        j                  |d¬«      }|€2t	        j                  t	        j                  ||d   |z   ¬«      d¬	«      }t	        j
                  | j                  |¬«      }t	        j
                  | j                  |¬«      }	||z   |	z   }
| j                  |
¬
«      }
| j                  |
|¬«      }
|
S )z’
        Applies embedding based on inputs tensor.

        Returns:
            final_embeddings (`tf.Tensor`): output embedding tensor.
        Nz5Need to provide either `input_ids` or `input_embeds`.)ÚparamsÚindiceséÿÿÿÿr   ©ÚdimsÚvaluer*   )ÚstartÚlimit©Úaxis©Úinputs©r�   Útraining)Ú
ValueErrorr!   rc   rz   r=   Úgatherrr   r"   ÚfillÚexpand_dimsÚrangerw   ru   r[   rl   )rC   Ú	input_idsÚposition_idsÚtoken_type_idsÚinputs_embedsÚpast_key_values_lengthr�   r€   Úposition_embedsÚtoken_type_embedsÚfinal_embeddingss              rN   ÚcallzTFBertEmbeddings.call¢   s  € ð Ð Ð!6ÜÐTÓUÐUàÐ Ü*¨9°d·k±k×6LÑ6LÔMÜŸI™I¨T¯[©[À)ÔLˆMä  Ó/°°Ð4ˆàÐ!ÜŸW™W¨+¸QÔ?ˆNàÐÜŸ>™>Ü—‘Ð5¸[È¹^ÐNdÑ=dÔeÐlmôˆLô Ÿ)™)¨4×+CÑ+CÈ\ÔZˆÜŸI™I¨T×-GÑ-GÐQ_Ô`ÐØ(¨?Ñ:Ð=NÑNÐØŸ>™>Ð1A˜>ÓBÐØŸ<™<Ð/?È(˜<ÓSÐàÐrP   ©rc   r+   ©N)NNNNr   F)r•   úOptional[tf.Tensor]r–   r    r—   r    r˜   r    r�   ÚboolrR   rQ   )rS   rT   rU   rV   rb   r~   r�   Ú__classcell__©ro   s   @rN   rY   rY   x   se   ø„ ÙQõMóLð> *.Ø,0Ø.2Ø-1Ø Øð& à&ð& ð *ð& ð ,ð	& ð
 +ð& ð ð& ð 
÷& rP   rY   c                  ó^   ‡ — e Zd Zdˆ fd„Zdd„Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zd	d„Zˆ xZS )
ÚTFBertSelfAttentionc                óÂ  •— t        ‰| �  d
i |¤Ž |j                  |j                  z  dk7  r&t	        d|j                  › d|j                  › d�«      ‚|j                  | _        t        |j                  |j                  z  «      | _        | j                  | j                  z  | _        t        j                  | j                  «      | _
        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j'                  |j(                  ¬	«      | _        |j,                  | _        || _        y )Nr   zThe hidden size (z6) is not a multiple of the number of attention heads (ú)Úquery©ÚunitsÚkernel_initializerr^   Úkeyr‡   r_   rW   )ra   rb   rd   Únum_attention_headsr�   ÚintÚattention_head_sizeÚall_head_sizeÚmathÚsqrtÚsqrt_att_head_sizer   rg   ÚDenser   rf   r¨   r¬   r‡   rj   Úattention_probs_dropout_probrl   Ú
is_decoderrc   rm   s      €rN   rb   zTFBertSelfAttention.__init__Ì   s“  ø€ Ü‰ÑÑ"˜6Ò"à×Ñ × :Ñ :Ñ:¸aÒ?ÜØ# F×$6Ñ$6Ð#7ð 8'Ø'-×'AÑ'AÐ&BÀ!ðEóð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔÜ"&§)¡)¨D×,DÑ,DÓ"EˆÔä—\‘\×'Ñ'Ø×$Ñ$¼È×IaÑIaÓ9bÐipð (ó 
ˆŒ
ô —<‘<×%Ñ%Ø×$Ñ$¼È×IaÑIaÓ9bÐinð &ó 
ˆŒô —\‘\×'Ñ'Ø×$Ñ$¼È×IaÑIaÓ9bÐipð (ó 
ˆŒ
ô —|‘|×+Ñ+°×1TÑ1TÐ+ÓUˆŒà ×+Ñ+ˆŒØˆ�rP   c                ó’   — t        j                  ||d| j                  | j                  f¬«      }t        j                  |g d¢¬«      S )Nr„   ©Útensorrs   ©r   é   r*   r	   ©Úperm)r=   rB   r­   r¯   Ú	transpose)rC   r¹   Ú
batch_sizes      rN   Útranspose_for_scoresz(TFBertSelfAttention.transpose_for_scoresè   s;   € ä—‘ 6°*¸bÀ$×BZÑBZÐ\`×\tÑ\tÐ1uÔvˆô �|‰|˜FªÔ6Ð6rP   c	                óü  — t        |«      d   }	| j                  |¬«      }
|d u}|r|�|d   }|d   }|}�n|rG| j                  | j                  |¬«      |	«      }| j                  | j	                  |¬«      |	«      }|}nÃ|�}| j                  | j                  |¬«      |	«      }| j                  | j	                  |¬«      |	«      }t        j                  |d   |gd¬«      }t        j                  |d   |gd¬«      }nD| j                  | j                  |¬«      |	«      }| j                  | j	                  |¬«      |	«      }| j                  |
|	«      }| j                  r||f}t        j                  ||d¬«      }t        j                  | j                  |j                  ¬«      }t        j                  ||«      }|�t        j                  ||«      }t        |d	¬
«      }| j                  ||¬«      }|�t        j                   ||«      }t        j                  ||«      }t        j"                  |g d¢¬«      }t        j$                  ||	d	| j&                  f¬«      }|r||fn|f}| j                  r||fz   }|S )Nr   rŒ   r*   r»   rŠ   T)Útranspose_br6   r„   )rD   r‹   rŽ   rº   r¼   r¸   )r"   r¨   rÀ   r¬   r‡   r=   Úconcatr¶   Úmatmulr@   r³   r7   ÚdivideÚaddr#   rl   Úmultiplyr¾   rB   r°   )rC   Úhidden_statesÚattention_maskÚ	head_maskÚencoder_hidden_statesÚencoder_attention_maskÚpast_key_valueÚoutput_attentionsr�   r¿   Úmixed_query_layerÚis_cross_attentionÚ	key_layerÚvalue_layerÚquery_layerÚattention_scoresÚdkÚattention_probsÚattention_outputÚoutputss                       rN   r�   zTFBertSelfAttention.callï   sy  € ô   Ó.¨qÑ1ˆ
Ø ŸJ™J¨m˜JÓ<Ðð
 3¸$Ð>Ðá .Ð"<à& qÑ)ˆIØ(¨Ñ+ˆKØ3ŠNÙØ×1Ñ1°$·(±(ÐBW°(Ó2XÐZdÓeˆIØ×3Ñ3°D·J±JÐF[°JÓ4\Ð^hÓiˆKØ3‰NØÐ'Ø×1Ñ1°$·(±(À-°(Ó2PÐR\Ó]ˆIØ×3Ñ3°D·J±JÀm°JÓ4TÐV`ÓaˆKÜŸ	™	 >°!Ñ#4°iÐ"@ÀqÔIˆIÜŸ)™) ^°AÑ%6¸Ð$DÈ1ÔM‰Kà×1Ñ1°$·(±(À-°(Ó2PÐR\Ó]ˆIØ×3Ñ3°D·J±JÀm°JÓ4TÐV`ÓaˆKà×/Ñ/Ð0AÀ:ÓNˆà�?Š?ð (¨Ð5ˆNô Ÿ9™9 [°)ÈÔNÐÜ�W‰W�T×,Ñ,Ð4D×4JÑ4JÔKˆÜŸ9™9Ð%5°rÓ:ÐàÐ%ä!Ÿv™vÐ&6¸ÓGÐô )Ð0@ÀrÔJˆð Ÿ,™,¨oÈ˜,ÓQˆð Ð Ü Ÿk™k¨/¸9ÓEˆOäŸ9™9 _°kÓBÐÜŸ<™<Ð(8º|ÔLÐô Ÿ:™:Ð-=ÀjÐRTÐVZ×VhÑVhÐEiÔjÐÙ9JÐ# _Ñ5ÐQaÐPcˆà�?Š?Ø Ð 1Ñ1ˆGØˆrP   c                ó  — | j                   ry d| _         t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   ŒíxY w# 1 sw Y   ŒˆxY w# 1 sw Y   y xY w)NTr¨   r¬   r‡   )r|   r}   r=   rx   r¨   r^   r~   rc   rd   r¬   r‡   r   s     rN   r~   zTFBertSelfAttention.build@  s9  € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ FØ—‘—‘  d¨D¯K©K×,CÑ,CÐDÔE÷Fä�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hð Hð 4÷Hð Hú÷Fð Fú÷Hð Hús$   Á3E*Â<3E6Ä-3FÅ*E3Å6E?ÆFrž   )r¹   rQ   r¿   r®   rR   rQ   ©F)rÈ   rQ   rÉ   rQ   rÊ   rQ   rË   rQ   rÌ   rQ   rÍ   úTuple[tf.Tensor]rÎ   r¡   r�   r¡   rR   rÛ   rŸ   )rS   rT   rU   rb   rÀ   r�   r~   r¢   r£   s   @rN   r¥   r¥   Ë   s€   ø„ õó87ð  ðOà ðOð "ðOð ð	Oð
  )ðOð !*ðOð )ðOð  ðOð ðOð 
óO÷bHrP   r¥   c                  ó2   ‡ — e Zd Zdˆ fd„Zddd„Zdd„Zˆ xZS )ÚTFBertSelfOutputc                óx  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |j                  ¬«      | _        || _        y ©NÚdenser©   r[   r\   r_   rW   ©ra   rb   r   rg   r´   rd   r   rf   rà   rh   ri   r[   rj   rk   rl   rc   rm   s      €rN   rb   zTFBertSelfOutput.__init__P  ó‘   ø€ Ü‰ÑÑ"˜6Ò"ä—\‘\×'Ñ'Ø×$Ñ$¼È×IaÑIaÓ9bÐipð (ó 
ˆŒ
ô Ÿ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒÜ—|‘|×+Ñ+°×1KÑ1KÐ+ÓLˆŒØˆ�rP   c                óz   — | j                  |¬«      }| j                  ||¬«      }| j                  ||z   ¬«      }|S ©NrŒ   rŽ   ©rà   rl   r[   ©rC   rÈ   Úinput_tensorr�   s       rN   r�   zTFBertSelfOutput.callZ  ó?   € ØŸ
™
¨-˜
Ó8ˆØŸ™¨MÀH˜ÓMˆØŸ™¨m¸lÑ.J˜ÓKˆàÐrP   c                ó"  — | j                   ry d| _         t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY w©NTrà   r[   ©
r|   r}   r=   rx   rà   r^   r~   rc   rd   r[   r   s     rN   r~   zTFBertSelfOutput.builda  óÞ   € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hä�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ LØ—‘×$Ñ$ d¨D°$·+±+×2IÑ2IÐ%JÔK÷Lð Lð 8÷Hð Hú÷Lð Lúó   Á3C9Â<3DÃ9DÄDrž   rÚ   ©rÈ   rQ   rç   rQ   r�   r¡   rR   rQ   rŸ   ©rS   rT   rU   rb   r�   r~   r¢   r£   s   @rN   rÝ   rÝ   O  ó   ø„ õô÷	LrP   rÝ   c                  ó\   ‡ — e Zd Zdˆ fd„Zd„ Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )	ÚTFBertAttentionc                ól   •— t        ‰| �  di |¤Ž t        |d¬«      | _        t	        |d¬«      | _        y )NrC   ©r^   ÚoutputrW   )ra   rb   r¥   Úself_attentionrÝ   Údense_outputrm   s      €rN   rb   zTFBertAttention.__init__n  s1   ø€ Ü‰ÑÑ"˜6Ò"ä1°&¸vÔFˆÔÜ,¨V¸(ÔCˆÕrP   c                ó   — t         ‚rŸ   ©ÚNotImplementedError)rC   Úheadss     rN   Úprune_headszTFBertAttention.prune_headst  s   € Ü!Ð!rP   c	           
     óx   — | j                  ||||||||¬«      }	| j                  |	d   ||¬«      }
|
f|	dd  z   }|S )N©rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   r�   r   ©rÈ   rç   r�   r*   )rö   r÷   )rC   rç   rÉ   rÊ   rË   rÌ   rÍ   rÎ   r�   Úself_outputsr×   rØ   s               rN   r�   zTFBertAttention.callw  so   € ð ×*Ñ*Ø&Ø)ØØ"7Ø#9Ø)Ø/Øð +ó 	
ˆð  ×,Ñ,Ø& q™/¸Èxð -ó 
Ðð $Ð%¨°Q°RÐ(8Ñ8ˆàˆrP   c                óÆ  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   ŒexY w# 1 sw Y   y xY w)NTrö   r÷   )r|   r}   r=   rx   rö   r^   r~   r÷   r   s     rN   r~   zTFBertAttention.build”  s¾   € Ø�:Š:ØØˆŒ
Ü�4Ð)¨4Ó0Ð<Ü—‘˜t×2Ñ2×7Ñ7Ó8ñ 0Ø×#Ñ#×)Ñ)¨$Ô/÷0ä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ .Ø×!Ñ!×'Ñ'¨Ô-÷.ð .ð ;÷0ð 0ú÷.ð .úó   ÁCÂ%CÃCÃC rž   rÚ   )rç   rQ   rÉ   rQ   rÊ   rQ   rË   rQ   rÌ   rQ   rÍ   rÛ   rÎ   r¡   r�   r¡   rR   rÛ   rŸ   )rS   rT   rU   rb   rü   r�   r~   r¢   r£   s   @rN   rò   rò   m  su   ø„ õDò"ð ðàðð "ðð ð	ð
  )ðð !*ðð )ðð  ðð ðð 
ó÷:	.rP   rò   c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFBertIntermediatec                óT  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        |j                  t        «      r"t        |j                  «      | _        || _        y |j                  | _        || _        y )Nrà   r©   rW   )ra   rb   r   rg   r´   Úintermediate_sizer   rf   rà   Ú
isinstanceÚ
hidden_actÚstrr
   Úintermediate_act_fnrc   rm   s      €rN   rb   zTFBertIntermediate.__init__¡  sŒ   ø€ Ü‰ÑÑ"˜6Ò"ä—\‘\×'Ñ'Ø×*Ñ*¼Èv×OgÑOgÓ?hÐovð (ó 
ˆŒ
ô �f×'Ñ'¬Ô-Ü'8¸×9JÑ9JÓ'KˆDÔ$ð ˆ�ð (.×'8Ñ'8ˆDÔ$Øˆ�rP   c                óL   — | j                  |¬«      }| j                  |«      }|S ©NrŒ   )rà   r
  ©rC   rÈ   s     rN   r�   zTFBertIntermediate.call®  s(   € ØŸ
™
¨-˜
Ó8ˆØ×0Ñ0°Ó?ˆàÐrP   c                ó(  — | j                   ry d| _         t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   y xY w©NTrà   ©	r|   r}   r=   rx   rà   r^   r~   rc   rd   r   s     rN   r~   zTFBertIntermediate.build´  ó}   € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hð Hð 4÷Hð Húó   Á3BÂBrž   ©rÈ   rQ   rR   rQ   rŸ   rï   r£   s   @rN   r  r     s   ø„ õó÷HrP   r  c                  ó2   ‡ — e Zd Zdˆ fd„Zddd„Zdd„Zˆ xZS )ÚTFBertOutputc                óx  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |j                  ¬«      | _        || _        y rß   rá   rm   s      €rN   rb   zTFBertOutput.__init__¾  râ   rP   c                óz   — | j                  |¬«      }| j                  ||¬«      }| j                  ||z   ¬«      }|S rä   rå   ræ   s       rN   r�   zTFBertOutput.callÈ  rè   rP   c                ó"  — | j                   ry d| _         t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY wrê   )r|   r}   r=   rx   rà   r^   r~   rc   r  r[   rd   r   s     rN   r~   zTFBertOutput.buildÏ  sÞ   € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ NØ—
‘
× Ñ  $¨¨d¯k©k×.KÑ.KÐ!LÔM÷Nä�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ LØ—‘×$Ñ$ d¨D°$·+±+×2IÑ2IÐ%JÔK÷Lð Lð 8÷Nð Nú÷Lð Lúrí   rž   rÚ   rî   rŸ   rï   r£   s   @rN   r  r  ½  rð   rP   r  c                  óV   ‡ — e Zd Zdˆ fd„Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )ÚTFBertLayerc                óD  •— t        ‰| �  di |¤Ž t        |d¬«      | _        |j                  | _        |j
                  | _        | j
                  r,| j                  st        | › d�«      ‚t        |d¬«      | _        t        |d¬«      | _	        t        |d¬«      | _        y )NÚ	attentionrô   z> should be used as a decoder model if cross attention is addedÚcrossattentionÚintermediaterõ   rW   )ra   rb   rò   r  r¶   Úadd_cross_attentionr�   r  r  r  r  Úbert_outputrm   s      €rN   rb   zTFBertLayer.__init__Ü  s�   ø€ Ü‰ÑÑ"˜6Ò"ä(¨°kÔBˆŒØ ×+Ñ+ˆŒØ#)×#=Ñ#=ˆÔ Ø×#Ò#Ø—?’?Ü  D 6Ð)gÐ!hÓiÐiÜ"1°&Ð?OÔ"PˆDÔÜ.¨v¸NÔKˆÔÜ'¨°XÔ>ˆÕrP   c	           
     óÐ  — |�|d d nd }	| j                  |||d d |	||¬«      }
|
d   }| j                  r|
dd }|
d   }n|
dd  }d }| j                  rV|�Tt        | d«      st        d| › d�«      ‚|�|d	d  nd }| j	                  ||||||||¬«      }|d   }||dd z   }|d   }|z   }| j                  |¬
«      }| j                  |||¬«      }|f|z   }| j                  r|fz   }|S )Nr»   )rç   rÉ   rÊ   rË   rÌ   rÍ   rÎ   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¶   Úhasattrr�   r  r  r   )rC   rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   r�   Úself_attn_past_key_valueÚself_attention_outputsr×   rØ   Úpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_past_key_valueÚcross_attention_outputsÚintermediate_outputÚlayer_outputs                      rN   r�   zTFBertLayer.callé  s›  € ð :HÐ9S >°"°1Ñ#5ÐY]Ð Ø!%§¡Ø&Ø)ØØ"&Ø#'Ø3Ø/Øð "0ó 	"
Ðð 2°!Ñ4Ðð �?Š?Ø,¨Q¨rÐ2ˆGØ 6°rÑ :Ñà,¨Q¨RÐ0ˆGà'+Ð$Ø�?Š?Ð4Ð@Ü˜4Ð!1Ô2Ü Ø=¸d¸Vð DDð Dóð ð @NÐ?Y¨°r°sÑ(;Ð_cÐ%Ø&*×&9Ñ&9Ø-Ø-Ø#Ø&;Ø'=Ø8Ø"3Ø!ð ':ó 	'Ð#ð  7°qÑ9ÐØÐ 7¸¸"Ð =Ñ=ˆGð ,CÀ2Ñ+FÐ(Ø 1Ð4PÑ PÐà"×/Ñ/Ð>NÐ/ÓOÐØ×'Ñ'Ø-Ð<LÐW_ð (ó 
ˆð  �/ GÑ+ˆð �?Š?ØÐ!2Ð 4Ñ4ˆGàˆrP   c                ó`  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   �ŒxY w# 1 sw Y   ŒÌxY w# 1 sw Y   Œ~xY w# 1 sw Y   y xY w)NTr  r  r   r  )
r|   r}   r=   rx   r  r^   r~   r  r   r  r   s     rN   r~   zTFBertLayer.build0  sZ  € Ø�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ .Ø×!Ñ!×'Ñ'¨Ô-÷.ä�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ä�4Ð)¨4Ó0Ð<Ü—‘˜t×2Ñ2×7Ñ7Ó8ñ 0Ø×#Ñ#×)Ñ)¨$Ô/÷0ð 0ð =÷+ñ +ú÷.ð .ú÷-ð -ú÷0ð 0ús0   ÁE?Â%FÃ?FÅF$Å?F	ÆFÆF!Æ$F-rž   rÚ   )rÈ   rQ   rÉ   rQ   rÊ   rQ   rË   útf.Tensor | NonerÌ   r.  rÍ   zTuple[tf.Tensor] | NonerÎ   r¡   r�   r¡   rR   rÛ   rŸ   rï   r£   s   @rN   r  r  Û  sz   ø„ õ?ð, ðEà ðEð "ðEð ð	Eð
  0ðEð !1ðEð 0ðEð  ðEð ðEð 
óE÷N0rP   r  c                  ób   ‡ — e Zd Zdˆ fd„Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )ÚTFBertEncoderc                ó¨   •— t        ‰| �  di |¤Ž || _        t        |j                  «      D �cg c]  }t        |d|› �¬«      ‘Œ c}| _        y c c}w )Nzlayer_._rô   rW   )ra   rb   rc   r”   Únum_hidden_layersr  Úlayer)rC   rc   rn   Úiro   s       €rN   rb   zTFBertEncoder.__init__C  sG   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒÜHMÈf×NfÑNfÓHgÖhÀ1”k &°¸!¸¨~Ö>Òhˆ�
ùÒhs   ¯Ac                ó¾  — |	rdnd }|rdnd }|r| j                   j                  rdnd }|rdnd }t        | j                  «      D ]h  \  }}|	r||fz   }|�||   nd } |||||   |||||¬«      }|d   }|r	||d   fz  }|sŒ=||d   fz   }| j                   j                  sŒ]|€Œ`||d   fz   }Œj |	r||fz   }|
st	        d„ ||||fD «       «      S t        |||||¬«      S )	NrW   rþ   r   r„   r*   r»   c              3  ó&   K  — | ]	  }|€Œ|–— Œ y ­wrŸ   rW   )Ú.0Úvs     rN   ú	<genexpr>z%TFBertEncoder.call.<locals>.<genexpr>z  s   è ø€ ò ØÐghÑgt”ñùs   ‚Š)Úlast_hidden_stateÚpast_key_valuesrÈ   Ú
attentionsÚcross_attentions)rc   r  Ú	enumerater3  Útupler   )rC   rÈ   rÉ   rÊ   rË   rÌ   r;  Ú	use_cacherÎ   Úoutput_hidden_statesÚreturn_dictr�   Úall_hidden_statesÚall_attentionsÚall_cross_attentionsÚnext_decoder_cacher4  Úlayer_modulerÍ   Úlayer_outputss                       rN   r�   zTFBertEncoder.callH  sV  € ñ #7™B¸DÐÙ0™°dˆÙ%6¸4¿;¹;×;ZÒ;Z™rÐ`dÐá#,™R°$ÐÜ(¨¯©Ó4ò 	V‰OˆAˆ|Ù#Ø$5¸Ð8HÑ$HÐ!à3BÐ3N˜_¨QÒ/ÐTXˆNá(Ø+Ø-Ø# A™,Ø&;Ø'=Ø-Ø"3Ø!ô	ˆMð *¨!Ñ,ˆMáØ" }°RÑ'8Ð&:Ñ:Ð"â Ø!/°=ÀÑ3CÐ2EÑ!E�Ø—;‘;×2Ó2Ð7LÑ7XØ+?À=ÐQRÑCSÐBUÑ+UÑ(ð1	Vñ6  Ø 1°]Ð4DÑ DÐáÜñ Ø)Ð+<¸nÐNbÐcôó ð ô ;Ø+Ø.Ø+Ø%Ø1ô
ð 	
rP   c                óô   — | j                   ry d| _         t        | dd «      �K| j                  D ];  }t        j                  |j
                  «      5  |j                  d «       d d d «       Œ= y y # 1 sw Y   ŒIxY w)NTr3  )r|   r}   r3  r=   rx   r^   r~   )rC   r€   r3  s      rN   r~   zTFBertEncoder.build†  sp   € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ñ&ð 4÷&ð &ús   ÁA.Á.A7	rž   rÚ   )rÈ   rQ   rÉ   rQ   rÊ   rQ   rË   r.  rÌ   r.  r;  zTuple[Tuple[tf.Tensor]] | Noner@  úOptional[bool]rÎ   r¡   rA  r¡   rB  r¡   r�   r¡   rR   zDUnion[TFBaseModelOutputWithPastAndCrossAttentions, Tuple[tf.Tensor]]rŸ   rï   r£   s   @rN   r0  r0  B  s�   ø„ õið" ð<
à ð<
ð "ð<
ð ð	<
ð
  0ð<
ð !1ð<
ð 8ð<
ð "ð<
ð  ð<
ð #ð<
ð ð<
ð ð<
ð 
Nó<
÷|&rP   r0  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFBertPoolerc                ó¼   •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      dd¬«      | _        || _	        y )NÚtanhrà   )rª   r«   Ú
activationr^   rW   )
ra   rb   r   rg   r´   rd   r   rf   rà   rc   rm   s      €rN   rb   zTFBertPooler.__init__‘  sT   ø€ Ü‰ÑÑ"˜6Ò"ä—\‘\×'Ñ'Ø×$Ñ$Ü.¨v×/GÑ/GÓHØØð	 (ó 
ˆŒ
ð ˆ�rP   c                ó<   — |d d …df   }| j                  |¬«      }|S )Nr   rŒ   )rà   )rC   rÈ   Úfirst_token_tensorÚpooled_outputs       rN   r�   zTFBertPooler.callœ  s*   € ð +ª1¨a¨4Ñ0ÐØŸ
™
Ð*<˜
Ó=ˆàÐrP   c                ó(  — | j                   ry d| _         t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   y xY wr  r  r   s     rN   r~   zTFBertPooler.build¤  r  r  rž   r  rŸ   rï   r£   s   @rN   rL  rL  �  s   ø„ õ	ó÷HrP   rL  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFBertPredictionHeadTransformc                ó¦  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        |j                  t        «      rt        |j                  «      | _        n|j                  | _        t        j                  j                  |j                  d¬«      | _        || _        y )Nrà   r©   r[   r\   rW   )ra   rb   r   rg   r´   rd   r   rf   rà   r  r  r	  r
   Útransform_act_fnrh   ri   r[   rc   rm   s      €rN   rb   z&TFBertPredictionHeadTransform.__init__®  s¤   ø€ Ü‰ÑÑ"˜6Ò"ä—\‘\×'Ñ'Ø×$Ñ$Ü.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô �f×'Ñ'¬Ô-Ü$5°f×6GÑ6GÓ$HˆDÕ!à$*×$5Ñ$5ˆDÔ!äŸ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒØˆ�rP   c                óp   — | j                  |¬«      }| j                  |«      }| j                  |¬«      }|S r  )rà   rW  r[   r  s     rN   r�   z"TFBertPredictionHeadTransform.call¿  s8   € ØŸ
™
¨-˜
Ó8ˆØ×-Ñ-¨mÓ<ˆØŸ™¨m˜Ó<ˆàÐrP   c                ó"  — | j                   ry d| _         t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY wrê   rë   r   s     rN   r~   z#TFBertPredictionHeadTransform.buildÆ  rì   rí   rž   r  rŸ   rï   r£   s   @rN   rU  rU  ­  s   ø„ õó"÷	LrP   rU  c                  óP   ‡ — e Zd Zdˆ fd„Zd	d„Zd
d„Zdd„Zdd„Zdd„Zdd„Z	ˆ xZ
S )ÚTFBertLMPredictionHeadc                ó†   •— t        ‰| �  di |¤Ž || _        |j                  | _        t	        |d¬«      | _        || _        y )NÚ	transformrô   rW   )ra   rb   rc   rd   rU  r]  Úinput_embeddings©rC   rc   r^  rn   ro   s       €rN   rb   zTFBertLMPredictionHead.__init__Ó  s@   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ!×-Ñ-ˆÔä6°vÀKÔPˆŒð !1ˆÕrP   c                óX  — | j                  | j                  j                  fddd¬«      | _        | j                  ry d| _        t        | dd «      �Nt        j                  | j                  j                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   y xY w)NÚzerosTÚbias)rs   rt   Ú	trainabler^   r]  )ry   rc   rz   rb  r|   r}   r=   rx   r]  r^   r~   r   s     rN   r~   zTFBertLMPredictionHead.buildß  s‘   € Ø—O‘O¨4¯;©;×+AÑ+AÐ*CÐQXÐdhÐou�OÓvˆŒ	à�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ð +ð 8÷+ð +ús   Á:B Â B)c                ó   — | j                   S rŸ   )r^  ©rC   s    rN   Úget_output_embeddingsz,TFBertLMPredictionHead.get_output_embeddingsé  s   € Ø×$Ñ$Ð$rP   c                ó`   — || j                   _        t        |«      d   | j                   _        y ©Nr   )r^  rr   r"   rz   ©rC   r‡   s     rN   Úset_output_embeddingsz,TFBertLMPredictionHead.set_output_embeddingsì  s(   € Ø',ˆ×ÑÔ$Ü+5°eÓ+<¸QÑ+?ˆ×ÑÕ(rP   c                ó   — d| j                   iS )Nrb  )rb  re  s    rN   Úget_biaszTFBertLMPredictionHead.get_biasð  s   € Ø˜Ÿ	™	Ð"Ð"rP   c                óX   — |d   | _         t        |d   «      d   | j                  _        y )Nrb  r   )rb  r"   rc   rz   ri  s     rN   Úset_biaszTFBertLMPredictionHead.set_biasó  s'   € Ø˜&‘MˆŒ	Ü!+¨E°&©MÓ!:¸1Ñ!=ˆ�‰ÕrP   c                ó–  — | j                  |¬«      }t        |«      d   }t        j                  |d| j                  g¬«      }t        j
                  || j                  j                  d¬«      }t        j                  |d|| j                  j                  g¬«      }t        j                  j                  || j                  ¬«      }|S )Nr#  r*   r„   r¸   T)ÚaÚbrÂ   )r‡   rb  )r]  r"   r=   rB   rd   rÄ   r^  rr   rc   rz   r>   Úbias_addrb  )rC   rÈ   Ú
seq_lengths      rN   r�   zTFBertLMPredictionHead.call÷  sŸ   € ØŸ™°]˜ÓCˆÜ Ó.¨qÑ1ˆ
ÜŸ
™
¨-ÀÀD×DTÑDTÐ?UÔVˆÜŸ	™	 M°T×5JÑ5J×5QÑ5QÐ_cÔdˆÜŸ
™
¨-ÀÀJÐPT×P[ÑP[×PfÑPfÐ?gÔhˆÜŸ™Ÿ™¨]ÀÇÁ˜ÓKˆàÐrP   ©rc   r+   r^  úkeras.layers.LayerrŸ   ©rR   ru  ©r‡   ztf.Variable)rR   zDict[str, tf.Variable]r  )rS   rT   rU   rb   r~   rf  rj  rl  rn  r�   r¢   r£   s   @rN   r[  r[  Ò  s'   ø„ õ
1ó+ó%ó@ó#ó>÷rP   r[  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFBertMLMHeadc                óJ   •— t        ‰| �  di |¤Ž t        ||d¬«      | _        y )NÚpredictionsrô   rW   )ra   rb   r[  r{  r_  s       €rN   rb   zTFBertMLMHead.__init__  s&   ø€ Ü‰ÑÑ"˜6Ò"ä1°&Ð:JÐQ^Ô_ˆÕrP   c                ó*   — | j                  |¬«      }|S )Nr#  )r{  )rC   Úsequence_outputÚprediction_scoress      rN   r�   zTFBertMLMHead.call  s   € Ø ×,Ñ,¸?Ð,ÓKÐà Ð rP   c                óú   — | j                   ry d| _         t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   y xY w)NTr{  )r|   r}   r=   rx   r{  r^   r~   r   s     rN   r~   zTFBertMLMHead.build  sm   € Ø�:Š:ØØˆŒ
Ü�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ð -ð :÷-ð -úó   ÁA1Á1A:rt  )r}  rQ   rR   rQ   rŸ   rï   r£   s   @rN   ry  ry    s   ø„ õ`ó
!÷
-rP   ry  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFBertNSPHeadc                ó¦   •— t        ‰| �  di |¤Ž t        j                  j	                  dt        |j                  «      d¬«      | _        || _        y )Nr»   Úseq_relationshipr©   rW   )	ra   rb   r   rg   r´   r   rf   r„  rc   rm   s      €rN   rb   zTFBertNSPHead.__init__  sL   ø€ Ü‰ÑÑ"˜6Ò"ä %§¡× 2Ñ 2ØÜ.¨v×/GÑ/GÓHØ#ð !3ó !
ˆÔð
 ˆ�rP   c                ó*   — | j                  |¬«      }|S r  )r„  )rC   rR  Úseq_relationship_scores      rN   r�   zTFBertNSPHead.call!  s   € Ø!%×!6Ñ!6¸mÐ!6Ó!LÐà%Ð%rP   c                ó(  — | j                   ry d| _         t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   y xY w)NTr„  )	r|   r}   r=   rx   r„  r^   r~   rc   rd   r   s     rN   r~   zTFBertNSPHead.build&  s„   € Ø�:Š:ØØˆŒ
Ü�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ SØ×%Ñ%×+Ñ+¨T°4¸¿¹×9PÑ9PÐ,QÔR÷Sð Sð ?÷Sð Súr  rž   )rR  rQ   rR   rQ   rŸ   rï   r£   s   @rN   r‚  r‚    s   ø„ õó&÷
SrP   r‚  c                  ó®   ‡ — e Zd ZeZddˆ fd„Zd	d„Zd
d„Zd„ Ze		 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Z
dd„Zˆ xZS )ÚTFBertMainLayerc                óÔ   •— t        ‰| �  di |¤Ž || _        |j                  | _        t	        |d¬«      | _        t        |d¬«      | _        |rt        |d¬«      | _	        y d | _	        y )Nrv   rô   ÚencoderÚpoolerrW   )
ra   rb   rc   r¶   rY   rv   r0  r‹  rL  rŒ  )rC   rc   Úadd_pooling_layerrn   ro   s       €rN   rb   zTFBertMainLayer.__init__3  sZ   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ ×+Ñ+ˆŒä*¨6¸ÔEˆŒÜ$ V°)Ô<ˆŒÙ=N”l 6°Ô9ˆ�ÐTXˆ�rP   c                ó   — | j                   S rŸ   )rv   re  s    rN   Úget_input_embeddingsz$TFBertMainLayer.get_input_embeddings=  s   € Ø�‰ÐrP   c                ó`   — || j                   _        t        |«      d   | j                   _        y rh  )rv   rr   r"   rz   ri  s     rN   Úset_input_embeddingsz$TFBertMainLayer.set_input_embeddings@  s$   € Ø!&ˆ�‰ÔÜ%/°Ó%6°qÑ%9ˆ�‰Õ"rP   c                ó   — t         ‚)z�
        Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
        class PreTrainedModel
        rù   )rC   Úheads_to_prunes     rN   Ú_prune_headszTFBertMainLayer._prune_headsD  s
   € ô
 "Ð!rP   c                ó  — | j                   j                  sd}
|�|�t        d«      ‚|�t        |«      }n|�t        |«      d d }nt        d«      ‚|\  }}|	€&d}d gt	        | j
                  j                  «      z  }	nt        |	d   d   «      d   }|€t        j                  |||z   fd¬«      }|€t        j                  |d¬«      }| j                  ||||||¬	«      }t        |«      }||z   }| j                  rÈt        j                  |«      }t        j                  t        j                  |d d d d …f   ||df«      |d d d …d f   «      }t        j                  ||j                  ¬
«      }||d d …d d d …f   z  }t        |«      }t        j                  ||d   d|d   |d   f«      }|	d   �3|d d …d d …| d …d d …f   }n t        j                  ||d   dd|d   f«      }t        j                  ||j                  ¬
«      }t        j                   d|j                  ¬
«      }t        j                   d|j                  ¬
«      }t        j"                  t        j$                  ||«      |«      }| j                  rf|�dt        j                  ||j                  ¬
«      }t	        t        |«      «      }|dk(  r|d d …d d d …d d …f   }|dk(  r|d d …d d d d …f   }dz
  dz  }nd }|�t&        ‚d g| j                   j(                  z  }| j                  ||||||	|
||||¬«      }|d   }| j*                  �| j+                  |¬«      nd }|s
||f|dd  z   S t-        |||j.                  |j0                  |j2                  |j4                  ¬«      S )NFzDYou cannot specify both input_ids and inputs_embeds at the same timer„   z5You have to specify either input_ids or inputs_embedsr   r"  r*   r…   )r•   r–   r—   r˜   r™   r�   r6   r»   g      ð?g     ˆÃÀr	   )rÈ   rÉ   rÊ   rË   rÌ   r;  r@  rÎ   rA  rB  r�   r#  )r:  Úpooler_outputr;  rÈ   r<  r=  )rc   r¶   r�   r"   Úlenr‹  r3  r=   r’   rv   r”   Ú
less_equalÚtiler@   r7   rB   ÚconstantrÇ   Úsubtractrú   r2  rŒ  r   r;  rÈ   r<  r=  ) rC   r•   rÉ   r—   r–   rÊ   r˜   rË   rÌ   r;  r@  rÎ   rA  rB  r�   r€   r¿   rs  r™   Úembedding_outputÚattention_mask_shapeÚmask_seq_lengthÚseq_idsÚcausal_maskÚextended_attention_maskÚone_cstÚten_thousand_cstÚnum_dims_encoder_attention_maskÚencoder_extended_attention_maskÚencoder_outputsr}  rR  s                                    rN   r�   zTFBertMainLayer.callK  s  € ð$ �{‰{×%Ò%ØˆIàÐ  ]Ð%>ÜÐcÓdÐdØÐ"Ü$ YÓ/‰KØÐ&Ü$ ]Ó3°C°RÐ8‰KäÐTÓUÐUà!,Ñˆ
�JàÐ"Ø%&Ð"Ø#˜f¤s¨4¯<©<×+=Ñ+=Ó'>Ñ>‰Oä%/°ÀÑ0BÀ1Ñ0EÓ%FÀrÑ%JÐ"àÐ!ÜŸW™W¨:°zÐDZÑ7ZÐ*[ÐcdÔeˆNàÐ!ÜŸW™W¨+¸QÔ?ˆNàŸ?™?ØØ%Ø)Ø'Ø#9Øð +ó 
Ðô  *¨.Ó9Ðà$Ð'=Ñ=ˆð
 �?Š?Ü—h‘h˜Ó/ˆGÜŸ-™-Ü—‘˜  dªA Ñ.°¸_ÈaÐ0PÓQØ˜ša ˜Ñ&óˆKô Ÿ'™' +°^×5IÑ5IÔJˆKØ&1°NÂ1ÀdÊAÀ:Ñ4NÑ&NÐ#Ü#-Ð.EÓ#FÐ Ü&(§j¡jØ'Ð*>¸qÑ*AÀ1ÐFZÐ[\ÑF]Ð_sÐtuÑ_vÐ)wó'Ð#ð ˜qÑ!Ð-à*AÂ!ÂQÈÈÉÒVWÐBWÑ*XÑ'ä&(§j¡jØÐ!5°aÑ!8¸!¸QÐ@TÐUVÑ@WÐ Xó'Ð#ô #%§'¡'Ð*AÐIY×I_ÑI_Ô"`ÐÜ—+‘+˜cÐ)9×)?Ñ)?Ô@ˆÜŸ;™; xÐ7G×7MÑ7MÔNÐÜ"$§+¡+¬b¯k©k¸'ÐCZÓ.[Ð]mÓ"nÐð �?Š?Ð5ÐAô &(§W¡WÐ-CÐKb×KhÑKhÔ%iÐ"Ü.1´*Ð=SÓ2TÓ.UÐ+Ø.°!Ò3Ø2HÊÈDÒRSÒUVÈÑ2WÐ/Ø.°!Ò3Ø2HÊÈDÐRVÒXYÐIYÑ2ZÐ/ð 03Ð5TÑ/TÐX`Ñ.`Ñ+à.2Ð+ð Ð Ü%Ð%à˜ §¡×!>Ñ!>Ñ>ˆIàŸ,™,Ø*Ø2ØØ"7Ø#BØ+ØØ/Ø!5Ø#Øð 'ó 
ˆð *¨!Ñ,ˆØFJÇkÁkÐF]˜Ÿ™°/˜ÔBÐcgˆáàØðð    Ð#ñ$ð $ô
 >Ø-Ø'Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1Ø,×=Ñ=ô
ð 	
rP   c                ó’  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   Œ¿xY w# 1 sw Y   ŒqxY w# 1 sw Y   y xY w)NTrv   r‹  rŒ  )	r|   r}   r=   rx   rv   r^   r~   r‹  rŒ  r   s     rN   r~   zTFBertMainLayer.buildé  s  € Ø�:Š:ØØˆŒ
Ü�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ ,Ø—‘×%Ñ% dÔ+÷,ä�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ )Ø—‘×"Ñ" 4Ô(÷)ä�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ (Ø—‘×!Ñ! $Ô'÷(ð (ð 5÷,ð ,ú÷)ð )ú÷(ð (úó$   ÁD%Â%D1Ã?D=Ä%D.Ä1D:Ä=E©T©rc   r+   r�  r¡   rv  rw  ©NNNNNNNNNNNNNF)r•   úTFModelInputType | NonerÉ   únp.ndarray | tf.Tensor | Noner—   r­  r–   r­  rÊ   r­  r˜   r­  rË   r­  rÌ   r­  r;  ú4Optional[Tuple[Tuple[Union[np.ndarray, tf.Tensor]]]]r@  rJ  rÎ   rJ  rA  rJ  rB  rJ  r�   r¡   rR   úGUnion[TFBaseModelOutputWithPoolingAndCrossAttentions, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   r+   Úconfig_classrb   r�  r‘  r”  r    r�   r~   r¢   r£   s   @rN   r‰  r‰  /  s
  ø„ à€LöYóó:ò"ð ð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø?CØ@DØPTØ$(Ø,0Ø/3Ø&*Øð[
à*ð[
ð 6ð[
ð 6ð	[
ð
 4ð[
ð 1ð[
ð 5ð[
ð  =ð[
ð !>ð[
ð Nð[
ð "ð[
ð *ð[
ð -ð[
ð $ð[
ð ð[
ð  
Qò![
ó ð[
÷z(rP   r‰  c                  ó   — e Zd ZdZeZdZy)ÚTFBertPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚbertN)rS   rT   rU   rV   r+   r°  Úbase_model_prefixrW   rP   rN   r²  r²  ø  s   „ ñð
 €LØÑrP   r²  c                  óX   — e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   dZ	ded
<   y)ÚTFBertForPreTrainingOutputa?  
    Output type of [`TFBertForPreTraining`].

    Args:
        prediction_logits (`tf.Tensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
        seq_relationship_logits (`tf.Tensor` of shape `(batch_size, 2)`):
            Prediction scores of the next sequence prediction (classification) head (scores of True/False continuation
            before SoftMax).
        hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

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

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
    Nr.  Úlossr    Úprediction_logitsÚseq_relationship_logitsz,Optional[Union[Tuple[tf.Tensor], tf.Tensor]]rÈ   r<  )
rS   rT   rU   rV   r·  Ú__annotations__r¸  r¹  rÈ   r<  rW   rP   rN   r¶  r¶    sB   … ñð, "€DÐ
Ó!Ø-1ÐÐ*Ó1Ø37ÐÐ0Ó7ØBF€MÐ?ÓFØ?C€JÐ<ÔCrP   r¶  av	  

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

    This model is also a [keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model) subclass. Use it
    as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to general usage and
    behavior.

    <Tip>

    TensorFlow models and layers in `transformers` accept two formats as input:

    - having all inputs as keyword arguments (like PyTorch models), or
    - having all inputs as a list, tuple or dict in the first positional argument.

    The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
    and layers. Because of this support, when using methods like `model.fit()` things should "just work" for you - just
    pass your inputs and labels in any format that `model.fit()` supports! If, however, you want to use the second
    format outside of Keras methods like `fit()` and `predict()`, such as when creating your own layers or models with
    the Keras `Functional` API, there are three possibilities you can use to gather all the input Tensors in the first
    positional argument:

    - a single Tensor with `input_ids` only and nothing else: `model(input_ids)`
    - a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
    `model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
    - a dictionary with one or several input Tensors associated to the input names given in the docstring:
    `model({"input_ids": input_ids, "token_type_ids": token_type_ids})`

    Note that when creating models and layers with
    [subclassing](https://keras.io/guides/making_new_layers_and_models_via_subclassing/) then you don't need to worry
    about any of this, as you can just pass inputs like you would to any other Python function!

    </Tip>

    Args:
        config ([`BertConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
a  
    Args:
        input_ids (`np.ndarray`, `tf.Tensor`, `List[tf.Tensor]` ``Dict[str, tf.Tensor]` or `Dict[str, np.ndarray]` and each example must have the shape `({0})`):
            Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`np.ndarray` or `tf.Tensor` of shape `({0})`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)
        token_type_ids (`np.ndarray` or `tf.Tensor` of shape `({0})`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
            1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.

            [What are token type IDs?](../glossary#token-type-ids)
        position_ids (`np.ndarray` or `tf.Tensor` of shape `({0})`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

            [What are position IDs?](../glossary#position-ids)
        head_mask (`np.ndarray` or `tf.Tensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

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

        inputs_embeds (`np.ndarray` or `tf.Tensor` of shape `({0}, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail. This argument can be used only in eager mode, in graph mode the value in the
            config will be used instead.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail. This argument can be used only in eager mode, in graph mode the value in the config will be
            used instead.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple. This argument can be used in
            eager mode, in graph mode the value will always be set to True.
        training (`bool`, *optional*, defaults to `False``):
            Whether or not to use the model in training mode (some modules like dropout modules have different
            behaviors between training and evaluation).
z^The bare Bert Model transformer outputting raw hidden-states without any specific head on top.c                  óä   ‡ — e Zd Zddˆ fd„Ze eej                  d«      «       ee	e
e¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	d„«       «       «       Zd
d„Zˆ xZS )ÚTFBertModelc                óR   •— t        ‰| �  |g|¢­i |¤Ž t        ||d¬«      | _        y )Nr³  rô   )ra   rb   r‰  r³  )rC   rc   r�  r�   rn   ro   s        €rN   rb   zTFBertModel.__init__ˆ  s+   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3ä# FÐ,=ÀFÔKˆ�	rP   úbatch_size, sequence_length©Ú
checkpointÚoutput_typer°  c                óD   — | j                  |||||||||	|
||||¬«      }|S )aÓ  
        encoder_hidden_states  (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
            the model is configured as a decoder.
        encoder_attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
            the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:

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

        past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers`)
            contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        use_cache (`bool`, *optional*, defaults to `True`):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`). Set to `False` during training, `True` during generation
        ©r•   rÉ   r—   r–   rÊ   r˜   rË   rÌ   r;  r@  rÎ   rA  rB  r�   )r³  )rC   r•   rÉ   r—   r–   rÊ   r˜   rË   rÌ   r;  r@  rÎ   rA  rB  r�   rØ   s                   rN   r�   zTFBertModel.call�  sI   € ðX —)‘)ØØ)Ø)Ø%ØØ'Ø"7Ø#9Ø+ØØ/Ø!5Ø#Øð ó 
ˆð  ˆrP   c                óú   — | j                   ry d| _         t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   y xY w)NTr³  )r|   r}   r=   rx   r³  r^   r~   r   s     rN   r~   zTFBertModel.buildË  se   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó&Ð2Ü—‘˜tŸy™yŸ~™~Ó.ñ &Ø—	‘	—‘ Ô%÷&ð &ð 3÷&ð &úr€  r©  rª  r«  )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rË   r­  rÌ   r­  r;  r®  r@  rJ  rÎ   rJ  rA  rJ  rB  rJ  r�   rJ  rR   r¯  rŸ   )rS   rT   rU   rb   r    r'   ÚBERT_INPUTS_DOCSTRINGÚformatr%   Ú_CHECKPOINT_FOR_DOCr   Ú_CONFIG_FOR_DOCr�   r~   r¢   r£   s   @rN   r¼  r¼  ƒ  s  ø„ ö
Lð
 Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙØ&ØBØ$ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø?CØ@DØPTØ$(Ø,0Ø/3Ø&*Ø#(ð5à*ð5ð 6ð5ð 6ð	5ð
 4ð5ð 1ð5ð 5ð5ð  =ð5ð !>ð5ð Nð5ð "ð5ð *ð5ð -ð5ð $ð5ð !ð5ð  
Qò!5óó hó ð5÷n&rP   r¼  z¤
Bert Model with two heads on top as done during the pretraining:
    a `masked language modeling` head and a `next sentence prediction (classification)` head.
    c                  óì   ‡ — e Zd Zg d¢Zd	ˆ fd„Zd
d„Zdd„Ze ee	j                  d«      «       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       «       «       Zdd„Zˆ xZS )ÚTFBertForPreTraining)r–   úcls.predictions.decoder.weightzcls.predictions.decoder.biasc                óÂ   •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        t	        |d¬«      | _        t        || j                  j                  d¬«      | _        y )Nr³  rô   Ú	nsp___clsÚ	mlm___cls©r^  r^   )	ra   rb   r‰  r³  r‚  Únspry  rv   Úmlm©rC   rc   r�   rn   ro   s       €rN   rb   zTFBertForPreTraining.__init__ã  sQ   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3ä# F°Ô8ˆŒ	Ü  ¨kÔ:ˆŒÜ  ¸$¿)¹)×:NÑ:NÐU`Ôaˆ�rP   c                ó.   — | j                   j                  S rŸ   ©rÑ  r{  re  s    rN   Úget_lm_headz TFBertForPreTraining.get_lm_headê  ó   € Ø�x‰x×#Ñ#Ð#rP   c                óÊ   — t        j                  dt        «       | j                  dz   | j                  j                  z   dz   | j                  j
                  j                  z   S ©NzMThe method get_prefix_bias_name is deprecated. Please use `get_bias` instead.ú/©ÚwarningsÚwarnÚFutureWarningr^   rÑ  r{  re  s    rN   Úget_prefix_bias_namez)TFBertForPreTraining.get_prefix_bias_nameí  óG   € Ü�‰ÐeÔgtÔuØ�y‰y˜3‰ §¡§¡Ñ.°Ñ4°t·x±x×7KÑ7K×7PÑ7PÑPÐPrP   r¾  ©rÁ  r°  c                óN  — | j                  |||||||||	|¬«
      }|dd \  }}| j                  ||¬«      }| j                  |¬«      }d}|
� |�d|
i}||d<   | j                  |||f¬«      }|	s||f|dd z   }|�|f|z   S |S t	        ||||j
                  |j                  ¬	«      S )
aù  
        labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
            config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
            loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`
        next_sentence_label (`tf.Tensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the next sequence prediction (classification) loss. Input should be a sequence pair
            (see `input_ids` docstring) Indices should be in `[0, 1]`:

            - 0 indicates sequence B is a continuation of sequence A,
            - 1 indicates sequence B is a random sequence.
        kwargs (`Dict[str, any]`, *optional*, defaults to `{}`):
            Used to hide legacy arguments that have been deprecated.

        Return:

        Examples:

        ```python
        >>> import tensorflow as tf
        >>> from transformers import AutoTokenizer, TFBertForPreTraining

        >>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
        >>> model = TFBertForPreTraining.from_pretrained("google-bert/bert-base-uncased")
        >>> input_ids = tokenizer("Hello, my dog is cute", add_special_tokens=True, return_tensors="tf")
        >>> # Batch size 1

        >>> outputs = model(input_ids)
        >>> prediction_logits, seq_relationship_logits = outputs[:2]
        ```©
r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r�   Nr»   ©r}  r�   ©rR  r3   r8   ©r3   rD   )r·  r¸  r¹  rÈ   r<  )r³  rÑ  rÐ  rO   r¶  rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r3   r8   r�   rØ   r}  rR  r~  r†  Ú
total_lossÚd_labelsrõ   s                        rN   r�   zTFBertForPreTraining.callñ  s  € ð` —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð *1°°!¨Ñ&ˆ˜Ø ŸH™H°_Èx˜HÓXÐØ!%§¡¸ Ó!FÐØˆ
àÐÐ"5Ð"AØ  &Ð)ˆHØ.AˆHÐ*Ñ+Ø×-Ñ-°XÐGXÐZpÐFqÐ-ÓrˆJáØ'Ð)?Ð@À7È1È2À;ÑNˆFØ/9Ð/E�Z�M FÑ*ÐQÈ6ÐQä)ØØ/Ø$:Ø!×/Ñ/Ø×)Ñ)ô
ð 	
rP   c                ó’  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   Œ¿xY w# 1 sw Y   ŒqxY w# 1 sw Y   y xY w)NTr³  rÐ  rÑ  )	r|   r}   r=   rx   r³  r^   r~   rÐ  rÑ  r   s     rN   r~   zTFBertForPreTraining.buildC  sõ   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó&Ð2Ü—‘˜tŸy™yŸ~™~Ó.ñ &Ø—	‘	—‘ Ô%÷&ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ð %ð 2÷&ð &ú÷%ð %ú÷%ð %úr¨  rž   rv  ©rR   r	  ©NNNNNNNNNNNF)r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r8   r­  r�   rJ  rR   z3Union[TFBertForPreTrainingOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   Ú"_keys_to_ignore_on_load_unexpectedrb   rÕ  rÞ  r    r'   rÅ  rÆ  r)   r¶  rÈ  r�   r~   r¢   r£   s   @rN   rÊ  rÊ  Ô  s  ø„ ò*Ð&õbó$óQð Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+EÐTcÔdð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø04Ø=AØ#(ðM
à*ðM
ð 6ðM
ð 6ð	M
ð
 4ðM
ð 1ðM
ð 5ðM
ð *ðM
ð -ðM
ð $ðM
ð .ðM
ð ;ðM
ð !ðM
ð 
=òM
ó eó hó ðM
÷^%rP   rÊ  z2Bert Model with a `language modeling` head on top.c            	      óì   ‡ — e Zd Zg d¢Zdˆ fd„Zdd„Zdd„Ze ee	j                  d«      «       eeeedd¬«      	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	„«       «       «       Zdd
„Zˆ xZS )ÚTFBertForMaskedLM©rŒ  úcls.seq_relationshiprË  rÍ  c                óâ   •— t        ‰| �  |g|¢­i |¤Ž |j                  rt        j	                  d«       t        |dd¬«      | _        t        || j                  j                  d¬«      | _	        y )NzmIf you want to use `TFBertForMaskedLM` make sure `config.is_decoder=False` for bi-directional self-attention.Fr³  ©r�  r^   rÎ  rÏ  ©
ra   rb   r¶   ÚloggerÚwarningr‰  r³  ry  rv   rÑ  rÒ  s       €rN   rb   zTFBertForMaskedLM.__init__\  sa   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3à×ÒÜ�N‰Nð1ôô
 $ F¸eÈ&ÔQˆŒ	Ü  ¸$¿)¹)×:NÑ:NÐU`Ôaˆ�rP   c                ó.   — | j                   j                  S rŸ   rÔ  re  s    rN   rÕ  zTFBertForMaskedLM.get_lm_headh  rÖ  rP   c                óÊ   — t        j                  dt        «       | j                  dz   | j                  j                  z   dz   | j                  j
                  j                  z   S rØ  rÚ  re  s    rN   rÞ  z&TFBertForMaskedLM.get_prefix_bias_namek  rß  rP   r¾  z'paris'g)\�Âõ(ì?©rÀ  rÁ  r°  Úexpected_outputÚexpected_lossc                ó  — | j                  |||||||||	|¬«
      }|d   }| j                  ||¬«      }|
€dn| j                  |
|¬«      }|	s|f|dd z   }|�|f|z   S |S t        |||j                  |j
                  ¬«      S )a«  
        labels (`tf.Tensor` or `np.ndarray` 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]`
        râ  r   rã  Nrå  r»   ©r·  rD   rÈ   r<  )r³  rÑ  rO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r3   r�   rØ   r}  r~  r·  rõ   s                    rN   r�   zTFBertForMaskedLM.callo  sÁ   € ð: —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð " !™*ˆØ ŸH™H°_Èx˜HÓXÐØ�~‰t¨4×+?Ñ+?ÀvÐVgÐ+?Ó+hˆáØ'Ð)¨G°A°B¨KÑ7ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEäØØ$Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
rP   c                óÆ  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   ŒexY w# 1 sw Y   y xY w©NTr³  rÑ  ©r|   r}   r=   rx   r³  r^   r~   rÑ  r   s     rN   r~   zTFBertForMaskedLM.build§  ó­   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó&Ð2Ü—‘˜tŸy™yŸ~™~Ó.ñ &Ø—	‘	—‘ Ô%÷&ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ð %ð 2÷&ð &ú÷%ð %úr  rž   rv  ré  ©NNNNNNNNNNF)r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r�   rJ  rR   z)Union[TFMaskedLMOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  rb   rÕ  rÞ  r    r'   rÅ  rÆ  r%   rÇ  r   rÈ  r�   r~   r¢   r£   s   @rN   rí  rí  R  s  ø„ ò*Ð&õ
bó$óQð Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙØ&Ø$Ø$Ø!Øôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø04Ø#(ð-
à*ð-
ð 6ð-
ð 6ð	-
ð
 4ð-
ð 1ð-
ð 5ð-
ð *ð-
ð -ð-
ð $ð-
ð .ð-
ð !ð-
ð 
3ò-
óó hó ð-
÷^	%rP   rí  c                  óÔ   ‡ — e Zd Zg d¢Zd	ˆ fd„Zd
d„Zdd„Zdd„Ze e	e
ee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       «       Zdd„Zˆ xZS )ÚTFBertLMHeadModelrî  c                óâ   •— t        ‰| �  |g|¢­i |¤Ž |j                  st        j	                  d«       t        |dd¬«      | _        t        || j                  j                  d¬«      | _	        y )NzNIf you want to use `TFBertLMHeadModel` as a standalone, add `is_decoder=True.`Fr³  rñ  rÎ  rÏ  rò  rÒ  s       €rN   rb   zTFBertLMHeadModel.__init__¼  s[   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3à× Ò Ü�N‰NÐkÔlä# F¸eÈ&ÔQˆŒ	Ü  ¸$¿)¹)×:NÑ:NÐU`Ôaˆ�rP   c                ó.   — | j                   j                  S rŸ   rÔ  re  s    rN   rÕ  zTFBertLMHeadModel.get_lm_headÅ  rÖ  rP   c                óÊ   — t        j                  dt        «       | j                  dz   | j                  j                  z   dz   | j                  j
                  j                  z   S rØ  rÚ  re  s    rN   rÞ  z&TFBertLMHeadModel.get_prefix_bias_nameÈ  rß  rP   c                ón   — |j                   }|€t        j                  |«      }|�|d d …dd …f   }|||dœS )Nr„   )r•   rÉ   r;  )rs   r=   Úones)rC   r•   r;  rÉ   Úmodel_kwargsr€   s         rN   Úprepare_inputs_for_generationz/TFBertLMHeadModel.prepare_inputs_for_generationÌ  sE   € Ø—o‘oˆàÐ!ÜŸW™W [Ó1ˆNð Ð&Ø!¢! R¡S &Ñ)ˆIà&¸.Ð]lÑmÐmrP   r¿  c                óf  — | j                  |||||||||	|
||||¬«      }|d   }| j                  ||¬«      }d}|�)|dd…dd…f   }|dd…dd…f   }| j                  ||¬«      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j
                  |j                  |j                  ¬	«      S )
aÂ  
        encoder_hidden_states  (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
            the model is configured as a decoder.
        encoder_attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
            the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:

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

        past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers`)
            contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        use_cache (`bool`, *optional*, defaults to `True`):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`). Set to `False` during training, `True` during generation
        labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the cross entropy classification loss. Indices should be in `[0, ...,
            config.vocab_size - 1]`.
        rÃ  r   rã  Nr„   r*   rå  r»   )r·  rD   r;  rÈ   r<  r=  )r³  rÑ  rO   r   r;  rÈ   r<  r=  )rC   r•   rÉ   r—   r–   rÊ   r˜   rË   rÌ   r;  r@  rÎ   rA  rB  r3   r�   rn   rØ   r}  rD   r·  Úshifted_logitsrõ   s                          rN   r�   zTFBertLMHeadModel.callØ  s  € ð` —)‘)ØØ)Ø)Ø%ØØ'Ø"7Ø#9Ø+ØØ/Ø!5Ø#Øð ó 
ˆð  " !™*ˆØ—‘¨/ÀH�ÓMˆØˆàÐà#¢A s¨ s F™^ˆNØšA˜q™r˜E‘]ˆFØ×'Ñ'¨v¸nÐ'ÓMˆDáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä2ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
rP   c                óÆ  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   ŒexY w# 1 sw Y   y xY wrý  rþ  r   s     rN   r~   zTFBertLMHeadModel.build/  rÿ  r  rž   rv  ré  )NN)NNNNNNNNNNNNNNF) r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rË   r­  rÌ   r­  r;  r®  r@  rJ  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r�   rJ  rR   z<Union[TFCausalLMOutputWithCrossAttentions, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  rb   rÕ  rÞ  r	  r    r%   rÇ  r   rÈ  r�   r~   r¢   r£   s   @rN   r  r  ³  s3  ø„ ò*Ð&õbó$óQó
nð ÙØ&Ø7Ø$ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø?CØ@DØPTØ$(Ø,0Ø/3Ø&*Ø04Ø#(ð!O
à*ðO
ð 6ðO
ð 6ð	O
ð
 4ðO
ð 1ðO
ð 5ðO
ð  =ðO
ð !>ðO
ð NðO
ð "ðO
ð *ðO
ð -ðO
ð $ðO
ð .ðO
ð  !ð!O
ð$ 
Fò%O
óó ðO
÷b	%rP   r  zJBert Model with a `next sentence prediction (classification)` head on top.c                  óÖ   ‡ — e Zd ZddgZdˆ fd„Ze eej                  d«      «       e	e
e¬«      	 	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„«       «       «       Zdd„Zˆ xZS )ÚTFBertForNextSentencePredictionrÎ  úcls.predictionsc                ót   •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        t	        |d¬«      | _        y )Nr³  rô   rÍ  )ra   rb   r‰  r³  r‚  rÐ  rÒ  s       €rN   rb   z(TFBertForNextSentencePrediction.__init__C  s6   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3ä# F°Ô8ˆŒ	Ü  ¨kÔ:ˆ�rP   r¾  rà  c                ó  — | j                  |||||||||	|¬«
      }|d   }| j                  |¬«      }|
€dn| j                  |
|¬«      }|	s|f|dd z   }|�|f|z   S |S t        |||j                  |j
                  ¬«      S )aB  
        Return:

        Examples:

        ```python
        >>> import tensorflow as tf
        >>> from transformers import AutoTokenizer, TFBertForNextSentencePrediction

        >>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
        >>> model = TFBertForNextSentencePrediction.from_pretrained("google-bert/bert-base-uncased")

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

        >>> logits = model(encoding["input_ids"], token_type_ids=encoding["token_type_ids"])[0]
        >>> assert logits[0][0] < logits[0][1]  # the next sentence was random
        ```râ  r*   rä  Nrå  r»   rû  )r³  rÐ  rO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r8   r�   rØ   rR  Úseq_relationship_scoresÚnext_sentence_lossrõ   s                    rN   r�   z$TFBertForNextSentencePrediction.callI  sÐ   € ðH —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð   ™
ˆØ"&§(¡(¸ (Ó"GÐð #Ð*ñ à×%Ñ%Ð-@ÐI`Ð%Óað 	ñ Ø-Ð/°'¸!¸"°+Ñ=ˆFØ7IÐ7UÐ'Ð)¨FÑ2ÐaÐ[aÐaä,Ø#Ø*Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
rP   c                óÆ  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   ŒexY w# 1 sw Y   y xY w)NTr³  rÐ  )r|   r}   r=   rx   r³  r^   r~   rÐ  r   s     rN   r~   z%TFBertForNextSentencePrediction.buildŒ  rÿ  r  rž   r   )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r8   r­  r�   rJ  rR   z6Union[TFNextSentencePredictorOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  rb   r    r'   rÅ  rÆ  r)   r   rÈ  r�   r~   r¢   r£   s   @rN   r  r  ;  s÷   ø„ ð +7Ð8JÐ)KÐ&õ;ð Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+HÐWfÔgð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø=AØ#(ð>
à*ð>
ð 6ð>
ð 6ð	>
ð
 4ð>
ð 1ð>
ð 5ð>
ð *ð>
ð -ð>
ð $ð>
ð ;ð>
ð !ð>
ð 
@ò>
ó hó hó ð>
÷@	%rP   r  zœ
    Bert Model transformer with a sequence classification/regression head on top (a linear layer on top of the pooled
    output) e.g. for GLUE tasks.
    c            	      óâ   ‡ — e Zd Zg d¢ZdgZdˆ fd„Ze eej                  d«      «       e
eeeee¬«      	 	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„«       «       «       Zdd„Zˆ xZS )ÚTFBertForSequenceClassification©rÎ  rÍ  r  rï  rl   c                óš  •— t        ‰| �  |g|¢­i |¤Ž |j                  | _        t        |d¬«      | _        |j
                  �|j
                  n|j                  }t        j                  j                  |¬«      | _
        t        j                  j                  |j                  t        |j                  «      d¬«      | _        || _        y )Nr³  rô   r_   Ú
classifierr©   ©ra   rb   Ú
num_labelsr‰  r³  Úclassifier_dropoutrk   r   rg   rj   rl   r´   r   rf   r  rc   ©rC   rc   r�   rn   r  ro   s        €rN   rb   z(TFBertForSequenceClassification.__init__¤  s±   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3à ×+Ñ+ˆŒä# F°Ô8ˆŒ	à)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnð 	ô —|‘|×+Ñ+Ð1CÐ+ÓDˆŒÜŸ,™,×,Ñ,Ø×#Ñ#Ü.¨v×/GÑ/GÓHØð -ó 
ˆŒð
 ˆ�rP   r¾  r÷  c                ó*  — | j                  |||||||||	|¬«
      }|d   }| j                  ||¬«      }| j                  |¬«      }|
€dn| j                  |
|¬«      }|	s|f|dd z   }|�|f|z   S |S t	        |||j
                  |j                  ¬«      S )	a–  
        labels (`tf.Tensor` or `np.ndarray` 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).
        râ  r*   rŽ   rŒ   Nrå  r»   rû  )r³  rl   r  rO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r3   r�   rØ   rR  rD   r·  rõ   s                    rN   r�   z$TFBertForSequenceClassification.callµ  sÏ   € ð: —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð   ™
ˆØŸ™¨MÀH˜ÓMˆØ—‘¨�Ó6ˆØ�~‰t¨4×+?Ñ+?ÀvÐV\Ð+?Ó+]ˆáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä)ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
rP   c                óô  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY w©NTr³  r  ©
r|   r}   r=   rx   r³  r^   r~   r  rc   rd   r   s     rN   r~   z%TFBertForSequenceClassification.buildî  óÇ   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó&Ð2Ü—‘˜tŸy™yŸ~™~Ó.ñ &Ø—	‘	—‘ Ô%÷&ä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ MØ—‘×%Ñ% t¨T°4·;±;×3JÑ3JÐ&KÔL÷Mð Mð 9÷&ð &ú÷Mð Múó   ÁC"Â%3C.Ã"C+Ã.C7rž   r   )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r�   rJ  rR   z3Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  Ú_keys_to_ignore_on_load_missingrb   r    r'   rÅ  rÆ  r%   Ú'_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATIONr   rÈ  Ú_SEQ_CLASS_EXPECTED_OUTPUTÚ_SEQ_CLASS_EXPECTED_LOSSr�   r~   r¢   r£   s   @rN   r  r  ˜  s  ø„ ò *sÐ&Ø'1 lÐ#õð" Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙØ:Ø.Ø$Ø2Ø.ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø04Ø#(ð.
à*ð.
ð 6ð.
ð 6ð	.
ð
 4ð.
ð 1ð.
ð 5ð.
ð *ð.
ð -ð.
ð $ð.
ð .ð.
ð !ð.
ð 
=ò.
óó hó ð.
÷`	MrP   r  z¥
    Bert Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
    softmax) e.g. for RocStories/SWAG tasks.
    c                  óÞ   ‡ — e Zd Zg d¢ZdgZdˆ fd„Ze eej                  d«      «       e
eee¬«      	 	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„«       «       «       Zdd„Zˆ xZS )ÚTFBertForMultipleChoicer  rl   c                ó0  •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        t        j
                  j                  |j                  ¬«      | _        t        j
                  j                  dt        |j                  «      d¬«      | _        || _        y )Nr³  rô   r_   r*   r  r©   )ra   rb   r‰  r³  r   rg   rj   rk   rl   r´   r   rf   r  rc   rÒ  s       €rN   rb   z TFBertForMultipleChoice.__init__  s~   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3ä# F°Ô8ˆŒ	Ü—|‘|×+Ñ+°×1KÑ1KÐ+ÓLˆŒÜŸ,™,×,Ñ,Ø¬¸×8PÑ8PÓ(QÐXdð -ó 
ˆŒð ˆ�rP   z(batch_size, num_choices, sequence_lengthr¿  c                ó  — |�t        |«      d   }t        |«      d   }nt        |«      d   }t        |«      d   }|�t        j                  |d|f¬«      nd}|�t        j                  |d|f¬«      nd}|�t        j                  |d|f¬«      nd}|�t        j                  |d|f¬«      nd}|�&t        j                  |d|t        |«      d   f¬«      nd}| j                  |||||||||	|¬«
      }|d   }| j	                  ||¬«      }| j                  |¬	«      }t        j                  |d|f¬«      }|
€dn| j                  |
|¬
«      }|	s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  ¬«      S )aE  
        labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size,)`, *optional*):
            Labels for computing the multiple choice classification loss. Indices should be in `[0, ..., num_choices]`
            where `num_choices` is the size of the second dimension of the input tensors. (See `input_ids` above)
        Nr*   r»   r„   r¸   r	   râ  rŽ   rŒ   rå  rû  )
r"   r=   rB   r³  rl   r  rO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r3   r�   Únum_choicesrs  Úflat_input_idsÚflat_attention_maskÚflat_token_type_idsÚflat_position_idsÚflat_inputs_embedsrØ   rR  rD   Úreshaped_logitsr·  rõ   s                            rN   r�   zTFBertForMultipleChoice.call  sà  € ð4 Ð Ü$ YÓ/°Ñ2ˆKÜ# IÓ.¨qÑ1‰Jä$ ]Ó3°AÑ6ˆKÜ# MÓ2°1Ñ5ˆJàQZÐQfœŸ™¨9¸RÀÐ<LÕMÐlpˆàIWÐIcŒB�J‰J˜n°R¸Ð4DÕEÐimð 	ð JXÐIcŒB�J‰J˜n°R¸Ð4DÕEÐimð 	ð HTÐG_ŒB�J‰J˜l°2°zÐ2BÕCÐeið 	ð
 Ð(ô �J‰J˜m°B¸
ÄJÈ}ÓD]Ð^_ÑD`Ð3aÕbàð 	ð
 —)‘)Ø$Ø.Ø.Ø*ØØ,Ø/Ø!5Ø#Øð ó 
ˆð   ™
ˆØŸ™¨MÀH˜ÓMˆØ—‘¨�Ó6ˆÜŸ*™*¨F¸2¸{Ð:KÔLˆØ�~‰t¨4×+?Ñ+?ÀvÐVeÐ+?Ó+fˆáØ%Ð'¨'°!°"¨+Ñ5ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä*ØØ"Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
rP   c                óô  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY wr   r!  r   s     rN   r~   zTFBertForMultipleChoice.build]  r"  r#  rž   r   )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r�   rJ  rR   z4Union[TFMultipleChoiceModelOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  r$  rb   r    r'   rÅ  rÆ  r%   rÇ  r   rÈ  r�   r~   r¢   r£   s   @rN   r)  r)  ú  s  ø„ ò *sÐ&Ø'1 lÐ#õð Ù*Ð+@×+GÑ+GÐHrÓ+sÓtÙØ&Ø/Ø$ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø04Ø#(ðD
à*ðD
ð 6ðD
ð 6ð	D
ð
 4ðD
ð 1ðD
ð 5ðD
ð *ðD
ð -ðD
ð $ðD
ð .ðD
ð !ðD
ð 
>òD
óó uó ðD
÷L	MrP   r)  z£
    Bert Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
    Named-Entity-Recognition (NER) tasks.
    c            	      óâ   ‡ — e Zd Zg d¢ZdgZdˆ fd„Ze eej                  d«      «       e
eeeee¬«      	 	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„«       «       «       Zdd„Zˆ xZS )ÚTFBertForTokenClassification©rŒ  rÎ  rÍ  r  rï  rl   c                óœ  •— t        ‰| �  |g|¢­i |¤Ž |j                  | _        t        |dd¬«      | _        |j
                  �|j
                  n|j                  }t        j                  j                  |¬«      | _
        t        j                  j                  |j                  t        |j                  «      d¬«      | _        || _        y )NFr³  rñ  r_   r  r©   r  r  s        €rN   rb   z%TFBertForTokenClassification.__init__{  s³   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3à ×+Ñ+ˆŒä# F¸eÈ&ÔQˆŒ	à)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnð 	ô —|‘|×+Ñ+Ð1CÐ+ÓDˆŒÜŸ,™,×,Ñ,Ø×#Ñ#Ü.¨v×/GÑ/GÓHØð -ó 
ˆŒð
 ˆ�rP   r¾  r÷  c                ó*  — | j                  |||||||||	|¬«
      }|d   }| j                  ||¬«      }| j                  |¬«      }|
€dn| j                  |
|¬«      }|	s|f|dd z   }|�|f|z   S |S t	        |||j
                  |j                  ¬«      S )	zä
        labels (`tf.Tensor` or `np.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        râ  r   rŽ   rŒ   Nrå  r»   rû  )r³  rl   r  rO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  r3   r�   rØ   r}  rD   r·  rõ   s                    rN   r�   z!TFBertForTokenClassification.callŒ  sÏ   € ð6 —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð " !™*ˆØŸ,™,¨oÈ˜,ÓQˆØ—‘¨�Ó8ˆØ�~‰t¨4×+?Ñ+?ÀvÐV\Ð+?Ó+]ˆáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä&ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
rP   c                óô  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY wr   r!  r   s     rN   r~   z"TFBertForTokenClassification.buildÃ  r"  r#  rž   r   )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  r3   r­  r�   rJ  rR   z0Union[TFTokenClassifierOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  r$  rb   r    r'   rÅ  rÆ  r%   Ú$_CHECKPOINT_FOR_TOKEN_CLASSIFICATIONr   rÈ  Ú_TOKEN_CLASS_EXPECTED_OUTPUTÚ_TOKEN_CLASS_EXPECTED_LOSSr�   r~   r¢   r£   s   @rN   r5  r5  i  s  ø„ ò*Ð&ð (2 lÐ#õð" Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙØ7Ø+Ø$Ø4Ø0ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø04Ø#(ð,
à*ð,
ð 6ð,
ð 6ð	,
ð
 4ð,
ð 1ð,
ð 5ð,
ð *ð,
ð -ð,
ð $ð,
ð .ð,
ð !ð,
ð 
:ò,
óó hó ð,
÷\	MrP   r5  zÜ
    Bert Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                  óæ   ‡ — e Zd Zg d¢Zdˆ fd„Ze eej                  d«      «       e	e
eeeeee¬«      	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	d„«       «       «       Zd
d„Zˆ xZS )ÚTFBertForQuestionAnsweringr6  c                ó
  •— t        ‰| �  |g|¢­i |¤Ž |j                  | _        t        |dd¬«      | _        t
        j                  j                  |j                  t        |j                  «      d¬«      | _
        || _        y )NFr³  rñ  Ú
qa_outputsr©   )ra   rb   r  r‰  r³  r   rg   r´   r   rf   r@  rc   rÒ  s       €rN   rb   z#TFBertForQuestionAnswering.__init__à  su   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3à ×+Ñ+ˆŒä# F¸eÈ&ÔQˆŒ	ÜŸ,™,×,Ñ,Ø×#Ñ#Ü.¨v×/GÑ/GÓHØð -ó 
ˆŒð
 ˆ�rP   r¾  )rÀ  rÁ  r°  Úqa_target_start_indexÚqa_target_end_indexrø  rù  c                ó´  — | j                  |||||||||	|¬«
      }|d   }| j                  |¬«      }t        j                  |dd¬«      \  }}t        j                  |d¬«      }t        j                  |d¬«      }d}|
� |�d	|
i}||d
<   | j                  |||f¬«      }|	s||f|dd z   }|�|f|z   S |S t        ||||j                  |j                  ¬«      S )a  
        start_positions (`tf.Tensor` or `np.ndarray` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`tf.Tensor` or `np.ndarray` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        râ  r   rŒ   r»   r„   )r‡   Únum_or_size_splitsr‹   )Úinputr‹   NÚstart_positionÚend_positionrå  )r·  Ústart_logitsÚ
end_logitsrÈ   r<  )	r³  r@  r=   ÚsplitÚsqueezerO   r   rÈ   r<  )rC   r•   rÉ   r—   r–   rÊ   r˜   rÎ   rA  rB  Ústart_positionsÚend_positionsr�   rØ   r}  rD   rH  rI  r·  r3   rõ   s                        rN   r�   zTFBertForQuestionAnswering.callí  s  € ðH —)‘)ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#Øð ó 
ˆð " !™*ˆØ—‘¨�Ó8ˆÜ#%§8¡8°&ÈQÐUWÔ#XÑ ˆ�jÜ—z‘z¨¸2Ô>ˆÜ—Z‘Z j°rÔ:ˆ
ØˆàÐ&¨=Ð+DØ&¨Ð8ˆFØ%2ˆF�>Ñ"Ø×'Ñ'¨v¸|ÈZÐ>XÐ'ÓYˆDáØ" JÐ/°'¸!¸"°+Ñ=ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä-ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ô
ð 	
rP   c                óô  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY w)NTr³  r@  )
r|   r}   r=   rx   r³  r^   r~   r@  rc   rd   r   s     rN   r~   z TFBertForQuestionAnswering.build5  r"  r#  rž   rê  )r•   r¬  rÉ   r­  r—   r­  r–   r­  rÊ   r­  r˜   r­  rÎ   rJ  rA  rJ  rB  rJ  rL  r­  rM  r­  r�   rJ  rR   z7Union[TFQuestionAnsweringModelOutput, Tuple[tf.Tensor]]rŸ   )rS   rT   rU   rë  rb   r    r'   rÅ  rÆ  r%   Ú_CHECKPOINT_FOR_QAr   rÈ  Ú_QA_TARGET_START_INDEXÚ_QA_TARGET_END_INDEXÚ_QA_EXPECTED_OUTPUTÚ_QA_EXPECTED_LOSSr�   r~   r¢   r£   s   @rN   r>  r>  Ï  s  ø„ ò*Ð&õð Ù*Ð+@×+GÑ+GÐHeÓ+fÓgÙØ%Ø2Ø$Ø4Ø0Ø+Ø'ôð .2Ø8<Ø8<Ø6:Ø37Ø7;Ø,0Ø/3Ø&*Ø9=Ø7;Ø#(ð;
à*ð;
ð 6ð;
ð 6ð	;
ð
 4ð;
ð 1ð;
ð 5ð;
ð *ð;
ð -ð;
ð $ð;
ð 7ð;
ð 5ð;
ð !ð;
ð 
Aò;
óó hó ð;
÷z	MrP   r>  )rY   rí  r)  r  rÊ  r>  r  r5  r  r‰  r¼  r²  )frV   Ú
__future__r   r±   rÛ  Údataclassesr   Útypingr   r   r   r   ÚnumpyÚnpÚ
tensorflowr=   Úactivations_tfr
   Úmodeling_tf_outputsr   r   r   r   r   r   r   r   r   Úmodeling_tf_utilsr   r   r   r   r   r   r   r   r   r   r   r   r    Útf_utilsr!   r"   r#   Úutilsr$   r%   r&   r'   r(   r)   Úconfiguration_bertr+   Ú
get_loggerrS   ró  rÇ  rÈ  r:  r;  r<  rO  rR  rS  rP  rQ  r%  r&  r'  r/   rg   ÚLayerrY   r¥   rÝ   rò   r  r  r  r0  rL  rU  r[  ry  r‚  r‰  r²  r¶  ÚBERT_START_DOCSTRINGrÅ  r¼  rÊ  rí  r  r  r  r)  r5  r>  Ú__all__rW   rP   rN   ú<module>rd     s   ðñ  å "ã Û Ý !ß /Ó /ã Û å /÷
÷ 
õ 
÷÷ ÷ õ ÷ SÑ R÷÷ õ +ð 
ˆ×	Ñ	˜HÓ	%€à5Ð Ø€ð (ZÐ $à`ð ð "Ð ð 6Ð Ø'Ð ØÐ ØÐ ØÐ ð +TÐ 'Ø(Ð ØÐ ÷Qñ Qô8P �u—|‘|×)Ñ)ô P ôfAH˜%Ÿ,™,×,Ñ,ô AHôHL�u—|‘|×)Ñ)ô Lô<0.�e—l‘l×(Ñ(ô 0.ôfH˜Ÿ™×+Ñ+ô Hô:L�5—<‘<×%Ñ%ô Lô<d0�%—,‘,×$Ñ$ô d0ôNK&�E—L‘L×&Ñ&ô K&ô\H�5—<‘<×%Ñ%ô Hô:"L E§L¡L×$6Ñ$6ô "LôJ-˜UŸ\™\×/Ñ/ô -ô`-�E—L‘L×&Ñ&ô -ô(S�E—L‘L×&Ñ&ô Sð2 ôE(�e—l‘l×(Ñ(ó E(ó ðE(ôPÐ-ô ð ôD ó Dó ðDð<(Ð ðT5Ð ñp ØdØóôJ&Ð'ó J&ó	ðJ&ñZ ðð óôt%Ð0Ð2Gó t%óðt%ñn ÐNÐPdÓeô]%Ð-Ð/Kó ]%ó fð]%ô@E%Ð-Ð/Kô E%ñP ØTØóôV%Ð&;Ð=Yó V%ó	ðV%ñr ðð óôXMÐ&;Ð=Yó XMóðXMñv ðð óôeMÐ3Ð5Ió eMóðeMñP ðð óô\MÐ#8Ð:Só \Móð\Mñ~ ðð óôhMÐ!6Ð8Oó hMóðhMòV�rP   