Ë
    T^(hI ã                  óN  — d Z ddlm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 dd	lmZmZ dd
lmZmZmZm Z m!Z!m"Z" ddl#m$Z$  e!jJ                  e&«      Z'dZ(dZ)e G d„ de«      «       Z*e G d„ de«      «       Z+ G d„ dejX                  jZ                  «      Z. G d„ dejX                  jZ                  «      Z/ G d„ dejX                  jZ                  «      Z0 G d„ dejX                  jZ                  «      Z1 G d„ dejX                  jZ                  «      Z2 G d„ dejX                  jZ                  «      Z3 G d„ d ejX                  jZ                  «      Z4 G d!„ d"ejX                  jZ                  «      Z5 G d#„ d$ejX                  jZ                  «      Z6 G d%„ d&ejX                  jZ                  «      Z7 G d'„ d(ejX                  jZ                  «      Z8e G d)„ d*ejX                  jZ                  «      «       Z9 G d+„ d,e«      Z:d-Z;d.Z< ed/e;«       G d0„ d1e:«      «       Z= G d2„ d3ejX                  jZ                  «      Z> G d4„ d5ejX                  jZ                  «      Z? G d6„ d7ejX                  jZ                  «      Z@ G d8„ d9ejX                  jZ                  «      ZA G d:„ d;ejX                  jZ                  «      ZB G d<„ d=ejX                  jZ                  «      ZC G d>„ d?ejX                  jZ                  «      ZD ed@e;«       G dA„ dBe:«      «       ZEg dC¢ZFy)DzTF 2.0 LXMERT model.é    )ÚannotationsN)Ú	dataclass)ÚDictÚOptionalÚTupleÚUnioné   )Úget_tf_activation)ÚTFModelInputTypeÚTFPreTrainedModelÚget_initializerÚkerasÚkeras_serializableÚ
shape_listÚunpack_inputs)Úcheck_embeddings_within_boundsÚstable_softmax)ÚModelOutputÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚLxmertConfigzunc-nlp/lxmert-base-uncasedr   c                  ó‚   — 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	<   dZ
ded
<   dZded<   dZded<   y)ÚTFLxmertModelOutputa  
    Lxmert's outputs that contain the last hidden states, pooled outputs, and attention probabilities for the language,
    visual, and, cross-modality encoders. (note: the visual encoder in Lxmert is referred to as the "relation-ship"
    encoder")


    Args:
        language_output (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the language encoder.
        vision_output (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the visual encoder.
        pooled_output (`tf.Tensor` of shape `(batch_size, hidden_size)`):
            Last layer hidden-state of the first token of the sequence (classification, CLS, token) further processed
            by a Linear layer and a Tanh activation function. The Linear
        language_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 input features + one for the output of each cross-modality layer) of shape
            `(batch_size, sequence_length, hidden_size)`.
        vision_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 input features + one for the output of each cross-modality layer) of shape
            `(batch_size, sequence_length, hidden_size)`.
        language_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.
        vision_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.
        cross_encoder_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.
    Nútf.Tensor | NoneÚlanguage_outputÚvision_outputÚpooled_outputúTuple[tf.Tensor] | NoneÚlanguage_hidden_statesÚvision_hidden_statesÚlanguage_attentionsÚvision_attentionsÚcross_encoder_attentions)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r    r!   r#   r$   r%   r&   r'   © ó    úk/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/lxmert/modeling_tf_lxmert.pyr   r   8   sg   … ñ ðD )-€OÐ%Ó,Ø&*€MÐ#Ó*Ø&*€MÐ#Ó*Ø6:ÐÐ3Ó:Ø48ÐÐ1Ó8Ø37ÐÐ0Ó7Ø15ÐÐ.Ó5Ø8<ÐÐ5Ô<r.   r   c                  ó�   — 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	<   dZ
ded
<   dZded<   dZded<   dZded<   y)ÚTFLxmertForPreTrainingOutputaû
  
    Output type of [`LxmertForPreTraining`].

    Args:
        loss (*optional*, returned when `labels` is provided, `tf.Tensor` of shape `(1,)`):
            Total loss as the sum of the masked language modeling loss and the next sequence prediction
            (classification) loss.
        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).
        cross_relationship_score (`tf.Tensor` of shape `(batch_size, 2)`):
            Prediction scores of the textual matching objective (classification) head (scores of True/False
            continuation before SoftMax).
        question_answering_score (`tf.Tensor` of shape `(batch_size, n_qa_answers)`):
            Prediction scores of question answering objective (classification).
        language_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 input features + one for the output of each cross-modality layer) of shape
            `(batch_size, sequence_length, hidden_size)`.
        vision_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 input features + one for the output of each cross-modality layer) of shape
            `(batch_size, sequence_length, hidden_size)`.
        language_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.
        vision_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.
        cross_encoder_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   ÚlossÚprediction_logitsÚcross_relationship_scoreÚquestion_answering_scorer"   r#   r$   r%   r&   r'   )r(   r)   r*   r+   r2   r,   r3   r4   r5   r#   r$   r%   r&   r'   r-   r.   r/   r1   r1   f   su   … ñ!ðF "€DÐ
Ó!Ø*.ÐÐ'Ó.Ø15ÐÐ.Ó5Ø15ÐÐ.Ó5Ø6:ÐÐ3Ó:Ø48ÐÐ1Ó8Ø37ÐÐ0Ó7Ø15ÐÐ.Ó5Ø8<ÐÐ5Ô<r.   r1   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertVisualFeatureEncoderc                ó¢  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |j                  «      | _        |j"                  | _        |j&                  | _        || _        y )NÚvisn_fc©Úkernel_initializerÚnameÚvisn_layer_norm©Úepsilonr<   Úbox_fcÚbox_layer_normr-   )ÚsuperÚ__init__r   ÚlayersÚDenseÚhidden_sizer   Úinitializer_ranger9   ÚLayerNormalizationÚlayer_norm_epsr=   r@   rA   ÚDropoutÚhidden_dropout_probÚdropoutÚvisual_feat_dimÚfeat_dimÚvisual_pos_dimÚpos_dimÚconfig©ÚselfrQ   ÚkwargsÚ	__class__s      €r/   rC   z%TFLxmertVisualFeatureEncoder.__init__—   s  ø€ Ü‰ÑÑ"˜6Ò"ô —|‘|×)Ñ)Ø×ÑÜ.¨v×/GÑ/GÓHØð *ó 
ˆŒô
  %Ÿ|™|×>Ñ>Àv×G\ÑG\ÐctÐ>ÓuˆÔô —l‘l×(Ñ(Ø×ÑÜ.¨v×/GÑ/GÓHØð )ó 
ˆŒô
 $Ÿl™l×=Ñ=Àf×F[ÑF[ÐbrÐ=ÓsˆÔä—|‘|×+Ñ+¨F×,FÑ,FÓGˆŒØ×.Ñ.ˆŒØ×,Ñ,ˆŒØˆ�r.   c                óÎ   — |\  }}| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }||z   dz  }| j	                  ||¬«      }|S )Né   ©Útraining)r9   r=   r@   rA   rL   )rS   Ú
visn_inputrY   ÚfeatsÚboxesÚxÚyÚoutputs           r/   Úcallz!TFLxmertVisualFeatureEncoder.call¯   sk   € Ø!‰ˆˆuà�L‰L˜ÓˆØ× Ñ  Ó#ˆØ�K‰K˜ÓˆØ×Ñ Ó"ˆØ�a‘%˜1‘ˆà—‘˜f¨x�Ó8ˆØˆr.   c                óð  — | j                   ry d| _         t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | 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 «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | 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   �ŒUxY w# 1 sw Y   ŒðxY w# 1 sw Y   Œ•xY w# 1 sw Y   y xY w)NTr9   r=   r@   rA   )ÚbuiltÚgetattrÚtfÚ
name_scoper9   r<   ÚbuildrN   r=   rQ   rF   r@   rP   rA   ©rS   Úinput_shapes     r/   rf   z"TFLxmertVisualFeatureEncoder.build»   sœ  € Ø�:Š:ØØˆŒ
Ü�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ @Ø—‘×"Ñ" D¨$°·±Ð#>Ô?÷@ä�4Ð*¨DÓ1Ð=Ü—‘˜t×3Ñ3×8Ñ8Ó9ñ RØ×$Ñ$×*Ñ*¨D°$¸¿¹×8OÑ8OÐ+PÔQ÷Rä�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ >Ø—‘×!Ñ! 4¨¨t¯|©|Ð"<Ô=÷>ä�4Ð)¨4Ó0Ð<Ü—‘˜t×2Ñ2×7Ñ7Ó8ñ QØ×#Ñ#×)Ñ)¨4°°t·{±{×7NÑ7NÐ*OÔP÷Qð Qð =÷@ñ @ú÷Rð Rú÷>ð >ú÷Qð Qús0   Á)GÂ23GÄ#)G Æ
3G,ÇGÇGÇ G)Ç,G5©F©N©r(   r)   r*   rC   r`   rf   Ú__classcell__©rU   s   @r/   r7   r7   –   s   ø„ ôó0
÷Qr.   r7   c                  ó2   ‡ — e Zd ZdZˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertEmbeddingszGConstruct 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Ú	LayerNormr>   )Úrater-   )rB   rC   rQ   rF   Úmax_position_embeddingsrG   r   rD   rH   rI   rq   rJ   rK   rL   rR   s      €r/   rC   zTFLxmertEmbeddings.__init__Ð   s…   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ!×-Ñ-ˆÔØ'-×'EÑ'EˆÔ$Ø!'×!9Ñ!9ˆÔÜŸ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒÜ—|‘|×+Ñ+°×1KÑ1KÐ+ÓLˆ�r.   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)rG   )r<   ÚshapeÚinitializerÚtoken_type_embeddingsÚ
embeddingsÚposition_embeddingsTrq   )rd   re   Ú
add_weightrQ   Ú
vocab_sizerF   r   rG   rv   Útype_vocab_sizery   rs   r{   rb   rc   rq   r<   rf   rg   s     r/   rf   zTFLxmertEmbeddings.buildÚ   s£  € Ü�]‰]Ð,Ó-ñ 	ØŸ/™/ØØ—{‘{×-Ñ-¨t×/?Ñ/?Ð@Ü+¸d×>TÑ>TÔUð *ó ˆDŒK÷	ô �]‰]Ð2Ó3ñ 	Ø)-¯©Ø!Ø—{‘{×2Ñ2°D×4DÑ4DÐEÜ+¸d×>TÑ>TÔUð *9ó *ˆDÔ&÷	ô �]‰]Ð0Ó1ñ 	Ø'+§¡Ø!Ø×3Ñ3°T×5EÑ5EÐFÜ+¸d×>TÑ>TÔUð (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                ó"  — |€|€J ‚|�At        || j                  j                  «       t        j                  | j
                  |¬«      }t        |«      dd }|€t        j                  |d¬«      }t        j                  t        j                  d|d   ¬«      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.
        N)ÚparamsÚindiceséÿÿÿÿr   )ÚdimsÚvalue)ÚstartÚlimit©Úaxis©Úinputs)rŠ   rY   )r   rQ   r}   rd   Úgatherrv   r   ÚfillÚexpand_dimsÚranger{   ry   rq   rL   )
rS   Ú	input_idsÚtoken_type_idsÚinputs_embedsrY   rh   Úposition_idsÚposition_embedsÚtoken_type_embedsÚfinal_embeddingss
             r/   r`   zTFLxmertEmbeddings.call÷   sõ   € ð Ð%¨-Ð*?Ð@Ð@àÐ Ü*¨9°d·k±k×6LÑ6LÔMÜŸI™I¨T¯[©[À)ÔLˆMä  Ó/°°Ð4ˆàÐ!ÜŸW™W¨+¸QÔ?ˆNä—~‘~¤b§h¡h°Q¸kÈ"¹oÔ&NÐUVÔWˆÜŸ)™)¨4×+CÑ+CÈ\ÔZˆÜŸI™I¨T×-GÑ-GÐQ_Ô`ÐØ(¨?Ñ:Ð=NÑNÐØŸ>™>Ð1A˜>ÓBÐØŸ<™<Ð/?È(˜<ÓSÐàÐr.   rj   )NNNF)r(   r)   r*   r+   rC   rf   r`   rl   rm   s   @r/   ro   ro   Í   s   ø„ ÙQôMóL÷: r.   ro   c                  ó4   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zdd„Zˆ xZS )ÚTFLxmertAttentionc                ó²  •— t        ‰| �  di |¤Ž |j                  |j                  z  dk7  r%t	        d|j                  › d|j                  › �«      ‚|j                  | _        |j                  |j                  z  dk(  sJ ‚t        |j                  |j                  z  «      | _        | j                  | j                  z  | _        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 (Úqueryr:   Úkeyr„   r-   )rB   rC   rF   Únum_attention_headsÚ
ValueErrorÚintÚattention_head_sizeÚall_head_sizer   rD   rE   r   rG   r™   rš   r„   rJ   Úattention_probs_dropout_probrL   Úctx_dimrQ   rR   s      €r/   rC   zTFLxmertAttention.__init__  s˜  ø€ Ü‰ÑÑ"˜6Ò"Ø×Ñ × :Ñ :Ñ:¸aÒ?ÜØ# F×$6Ñ$6Ð#7ð 8Ø ×4Ñ4Ð5ð7óð ð
 $*×#=Ñ#=ˆÔ Ø×!Ñ! F×$>Ñ$>Ñ>À!ÒCÐCÐCÜ#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔä—\‘\×'Ñ'Ø×ÑÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô
 —<‘<×%Ñ%Ø×ÑÜ.¨v×/GÑ/GÓHØð &ó 
ˆŒô
 —\‘\×'Ñ'Ø×ÑÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô —|‘|×+Ñ+¨F×,OÑ,OÓPˆŒØ×)Ñ)ˆŒØˆ�r.   c                ó�   — t        j                  ||d| j                  | j                  f«      }t        j                  |g d¢¬«      S )Nr‚   ©r   rW   r   r	   ©Úperm)rd   Úreshaper›   rž   Ú	transpose)rS   r]   Ú
batch_sizes      r/   Útranspose_for_scoresz&TFLxmertAttention.transpose_for_scores5  s8   € ä�J‰J�q˜: r¨4×+CÑ+CÀT×E]ÑE]Ð^Ó_ˆÜ�|‰|˜A¢LÔ1Ð1r.   c                ó  — t        |«      d   }| j                  |«      }| j                  |«      }| j                  |«      }	| j	                  ||«      }
| j	                  ||«      }| j	                  |	|«      }t        j                  |
|d¬«      }t        j                  t        |«      d   |j                  ¬«      }|t
        j                  j                  |«      z  }|�&t        j                  ||j                  ¬«      }||z   }t        |d¬«      }| j                  ||¬«      }t        j                  ||«      }t        j                  |g d¢¬	«      }t        j                  ||d| j                  f«      }|r||f}|S |f}|S )
Nr   T)Útranspose_br‚   ©Údtyper‡   rX   r£   r¤   )r   r™   rš   r„   r©   rd   ÚmatmulÚcastr­   ÚmathÚsqrtr   rL   r§   r¦   rŸ   )rS   Úhidden_statesÚcontextÚattention_maskÚoutput_attentionsrY   r¨   Úmixed_query_layerÚmixed_key_layerÚmixed_value_layerÚquery_layerÚ	key_layerÚvalue_layerÚattention_scoresÚdkÚattention_probsÚcontext_layerÚoutputss                     r/   r`   zTFLxmertAttention.call:  sx  € Ü Ó.¨qÑ1ˆ
Ø ŸJ™J }Ó5ÐØŸ(™( 7Ó+ˆØ ŸJ™J wÓ/Ðà×/Ñ/Ð0AÀ:ÓNˆØ×-Ñ-¨o¸zÓJˆ	Ø×/Ñ/Ð0AÀ:ÓNˆô Ÿ9™9Ø˜°ô
Ðô �W‰W”Z 	Ó*¨2Ñ.Ð6F×6LÑ6LÔMˆØ+¬b¯g©g¯l©l¸2Ó.>Ñ>ÐàÐ%äŸW™W ^Ð;K×;QÑ;QÔRˆNØ/°.Ñ@Ðô )Ð)9ÀÔCˆð Ÿ,™, À˜,ÓJˆÜŸ	™	 /°;Ó?ˆäŸ™ ]ºÔFˆÜŸ
™
Ø˜J¨¨D×,>Ñ,>Ð?ó
ˆñ 7H�= /Ð2ˆØˆð O\ÐM]ˆØˆr.   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 «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �[t        j                  | j                  j
                  «      5  | j                  j                  d d | 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„   )rb   rc   rd   re   r™   r<   rf   rQ   rF   rš   r¡   r„   rg   s     r/   rf   zTFLxmertAttention.build`  s$  € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ ;Ø—‘—‘  d¨D¯L©LÐ9Ô:÷;ä�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ =Ø—
‘
× Ñ  $¨¨d¯l©lÐ!;Ô<÷=ð =ð 4÷Hð Hú÷;ð ;ú÷=ð =ús$   Á3EÂ<)E"Ä#)E.ÅEÅ"E+Å.E7ri   rj   )r(   r)   r*   rC   r©   r`   rf   rl   rm   s   @r/   r—   r—     s   ø„ ôòB2ó
$÷L=r.   r—   c                  ó,   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zˆ xZS )ÚTFLxmertIntermediatec                óT  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        |j                  t        «      r"t        |j                  «      | _        || _        y |j                  | _        || _        y )NÚdenser:   r-   )rB   rC   r   rD   rE   Úintermediate_sizer   rG   rÅ   Ú
isinstanceÚ
hidden_actÚstrr
   Úintermediate_act_fnrQ   rR   s      €r/   rC   zTFLxmertIntermediate.__init__p  s�   ø€ Ü‰ÑÑ"˜6Ò"Ü—\‘\×'Ñ'Ø×$Ñ$Ü.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô
 �f×'Ñ'¬Ô-Ü'8¸×9JÑ9JÓ'KˆDÔ$ð ˆ�ð (.×'8Ñ'8ˆDÔ$Øˆ�r.   c                óJ   — | j                  |«      }| j                  |«      }|S rj   )rÅ   rÊ   ©rS   r²   s     r/   r`   zTFLxmertIntermediate.call}  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐr.   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Å   ©	rb   rc   rd   re   rÅ   r<   rf   rQ   rF   rg   s     r/   rf   zTFLxmertIntermediate.build‚  ó}   € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hð Hð 4÷Hð Húó   Á3BÂBrj   rk   rm   s   @r/   rÃ   rÃ   o  s   ø„ ôò÷
Hr.   rÃ   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertOutputc                óv  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |j                  «      | _        || _        y ©NrÅ   r:   rq   r>   r-   ©rB   rC   r   rD   rE   rF   r   rG   rÅ   rH   rI   rq   rJ   rK   rL   rQ   rR   s      €r/   rC   zTFLxmertOutput.__init__Œ  s�   ø€ Ü‰ÑÑ"˜6Ò"Ü—\‘\×'Ñ'Ø×ÑÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô Ÿ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒÜ—|‘|×+Ñ+¨F×,FÑ,FÓGˆŒØˆ�r.   c                ót   — | j                  |«      }| j                  ||«      }| j                  ||z   «      }|S rj   ©rÅ   rL   rq   ©rS   r²   Úinput_tensorrY   s       r/   r`   zTFLxmertOutput.call˜  s9   € ØŸ
™
 =Ó1ˆØŸ™ ]°HÓ=ˆØŸ™ }°|Ñ'CÓDˆØÐr.   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Å   rq   )rb   rc   rd   re   rÅ   r<   rf   rQ   rÆ   rq   rF   rg   s     r/   rf   zTFLxmertOutput.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úó   Á3C9Â<3DÃ9DÄDri   rj   rk   rm   s   @r/   rÓ   rÓ   ‹  s   ø„ ô
ó÷	Lr.   rÓ   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertAttentionOutputc                óv  •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      d¬«      | _        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |j                  «      | _        || _        y rÕ   rÖ   rR   s      €r/   rC   z TFLxmertAttentionOutput.__init__«  s�   ø€ Ü‰ÑÑ"˜6Ò"Ü—\‘\×'Ñ'Ø×ÑÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô
 Ÿ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒÜ—|‘|×+Ñ+¨F×,FÑ,FÓGˆŒØˆ�r.   c                óv   — | j                  |«      }| j                  ||¬«      }| j                  ||z   «      }|S )NrX   rØ   rÙ   s       r/   r`   zTFLxmertAttentionOutput.call¶  s;   € ØŸ
™
 =Ó1ˆØŸ™ ]¸X˜ÓFˆØŸ™ }°|Ñ'CÓDˆØÐr.   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Ü   ©
rb   rc   rd   re   rÅ   r<   rf   rQ   rF   rq   rg   s     r/   rf   zTFLxmertAttentionOutput.build¼  óÞ   € Ø�:Š:ØØˆŒ
Ü�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úrÝ   ri   rj   rk   rm   s   @r/   rß   rß   ª  s   ø„ ô	ó÷	Lr.   rß   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertSelfAttentionLayerc                ól   •— t        ‰| �  di |¤Ž t        |d¬«      | _        t	        |d¬«      | _        y )NrS   ©r<   r_   r-   )rB   rC   r—   rS   rß   Úattention_outputrR   s      €r/   rC   z#TFLxmertSelfAttentionLayer.__init__É  s0   ø€ Ü‰ÑÑ"˜6Ò"Ü% f°6Ô:ˆŒ	Ü 7¸ÀXÔ NˆÕr.   c                ót   — | j                  ||||«      }|r|d   }| j                  |d   |«      }|r|fS |fS )Nr   r   )rS   ré   )rS   rÚ   r´   rµ   rY   Úself_outputr¾   ré   s           r/   r`   zTFLxmertSelfAttentionLayer.callÎ  sQ   € à—i‘i ¨l¸NÐL]Ó^ˆÙØ)¨!™nˆOØ×0Ñ0°¸Q±ÀÓNÐÙ6GÐ  /Ð2Ð`ÐN^ÐM`Ð`r.   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)NTrS   ré   )rb   rc   rd   re   rS   r<   rf   ré   rg   s     r/   rf   z TFLxmertSelfAttentionLayer.buildÖ  s¶   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó&Ð2Ü—‘˜tŸy™yŸ~™~Ó.ñ &Ø—	‘	—‘ Ô%÷&ä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ 2Ø×%Ñ%×+Ñ+¨DÔ1÷2ð 2ð ?÷&ð &ú÷2ð 2úó   ÁCÂ%CÃCÃC ri   rj   rk   rm   s   @r/   ræ   ræ   È  s   ø„ ôOó
a÷	2r.   ræ   c                  ó2   ‡ — e Zd Zˆ fd„Z	 	 dd„Zdd„Zˆ xZS )ÚTFLxmertCrossAttentionLayerc                ól   •— t        ‰| �  di |¤Ž t        |d¬«      | _        t	        |d¬«      | _        y )NÚattrè   r_   r-   )rB   rC   r—   rñ   rß   ré   rR   s      €r/   rC   z$TFLxmertCrossAttentionLayer.__init__ã  s0   ø€ Ü‰ÑÑ"˜6Ò"Ü$ V°%Ô8ˆŒÜ 7¸ÀXÔ NˆÕr.   c                ó„   — | j                  |||||¬«      }|r|d   }| j                  |d   ||¬«      }|r|f}	|	S |f}	|	S ©NrX   r   r   )rñ   ré   )
rS   rÚ   Ú
ctx_tensorÚctx_att_maskrµ   rY   r_   r¾   ré   rÀ   s
             r/   r`   z TFLxmertCrossAttentionLayer.callè  sj   € ð —‘˜,¨
°LÐBSÐ^f�ÓgˆÙØ$ Q™iˆOØ×0Ñ0°¸±¸LÐS[Ð0Ó\ÐÙ9JÐ# _Ð5ˆØˆð RbÐPcˆØˆr.   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é   )rb   rc   rd   re   rñ   r<   rf   ré   rg   s     r/   rf   z!TFLxmertCrossAttentionLayer.build÷  s¶   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ 2Ø×%Ñ%×+Ñ+¨DÔ1÷2ð 2ð ?÷%ð %ú÷2ð 2úrí   )FFrj   rk   rm   s   @r/   rï   rï   â  s   ø„ ôOð  Øó÷	2r.   rï   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertLayerc                ó�   •— t        ‰| �  di |¤Ž t        |d¬«      | _        t	        |d¬«      | _        t        |d¬«      | _        y )NÚ	attentionrè   Úintermediater_   r-   )rB   rC   ræ   rú   rÃ   rû   rÓ   Útransformer_outputrR   s      €r/   rC   zTFLxmertLayer.__init__  s?   ø€ Ü‰ÑÑ"˜6Ò"Ü3°FÀÔMˆŒÜ0°¸nÔMˆÔÜ"0°¸hÔ"GˆÕr.   c                ó–   — | j                  ||||¬«      }|d   }| j                  |«      }| j                  |||¬«      }|f|dd  z   }	|	S )NrX   r   r   )rú   rû   rü   )
rS   r²   r´   rµ   rY   Úattention_outputsré   Úintermediate_outputÚlayer_outputrÀ   s
             r/   r`   zTFLxmertLayer.call
  sk   € Ø ŸN™N¨=¸.ÐJ[Ðfn˜NÓoÐØ,¨QÑ/ÐØ"×/Ñ/Ð0@ÓAÐØ×.Ñ.Ð/BÐDTÐ_gÐ.ÓhˆØ�/Ð$5°a°bÐ$9Ñ9ˆØˆr.   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ü   )	rb   rc   rd   re   rú   r<   rf   rû   rü   rg   s     r/   rf   zTFLxmertLayer.build  s  € Ø�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ .Ø×!Ñ!×'Ñ'¨Ô-÷.ä�4Ð-¨tÓ4Ð@Ü—‘˜t×6Ñ6×;Ñ;Ó<ñ 4Ø×'Ñ'×-Ñ-¨dÔ3÷4ð 4ð A÷+ð +ú÷.ð .ú÷4ð 4úó$   ÁD%Â%D1Ã?D=Ä%D.Ä1D:Ä=Eri   rj   rk   rm   s   @r/   rø   rø     s   ø„ ôHó÷4r.   rø   c                  óL   ‡ — e Zd Zˆ fd„Z	 dd„Z	 dd„Zdd„Z	 dd„Zdd„Zˆ xZ	S )	ÚTFLxmertXLayerc                ó   •— t        ‰| �  d	i |¤Ž t        |d¬«      | _        t	        |d¬«      | _        t	        |d¬«      | _        t        |d¬«      | _        t        |d¬«      | _
        t        |d¬«      | _        t        |d¬«      | _        y )
NÚvisual_attentionrè   Úlang_self_attÚvisn_self_attÚ
lang_interÚlang_outputÚ
visn_interÚvisn_outputr-   )rB   rC   rï   r  ræ   r  r  rÃ   r	  rÓ   r
  r  r  rR   s      €r/   rC   zTFLxmertXLayer.__init__"  s   ø€ Ü‰ÑÑ"˜6Ò"Ü ;¸FÐI[Ô \ˆÔô 8¸À_ÔUˆÔÜ7¸À_ÔUˆÔô /¨v¸LÔIˆŒÜ)¨&°}ÔEˆÔÜ.¨v¸LÔIˆŒÜ)¨&°}ÔEˆÕr.   c                ó
  — t        j                  |«      }t        j                  |«      }t        j                  |«      }	t        j                  |«      }
| j                  ||	|||¬«      }| j                  |
||||¬«      }||fS )N)rµ   rY   )rd   Úidentityr  )rS   Ú
lang_inputÚlang_attention_maskrZ   Úvisn_attention_maskrµ   rY   Úlang_attention_lang_inputÚvisn_attention_lang_inputÚlang_attention_visn_inputÚvisn_attention_visn_inputÚlang_att_outputÚvisn_att_outputs                r/   Ú	cross_attzTFLxmertXLayer.cross_att0  s—   € ô %'§K¡K°
Ó$;Ð!Ü$&§K¡K°
Ó$;Ð!Ü$&§K¡K°
Ó$;Ð!Ü$&§K¡K°
Ó$;Ð!à×/Ñ/Ø%Ø%ØØ/Øð 0ó 
ˆð ×/Ñ/Ø%Ø%ØØ/Øð 0ó 
ˆð  Ð/Ð/r.   c                ón   — d}| j                  ||||¬«      }| j                  ||||¬«      }|d   |d   fS )NFrX   r   )r  r  )	rS   r  r  rZ   r  rY   rµ   r  r  s	            r/   Úself_attzTFLxmertXLayer.self_attQ  sW   € ð "ÐØ×,Ñ,¨ZÐ9LÐN_ÐjrÐ,ÓsˆØ×,Ñ,¨ZÐ9LÐN_ÐjrÐ,ÓsˆØ˜qÑ! ?°1Ñ#5Ð5Ð5r.   c                óš   — | j                  |«      }| j                  |«      }| j                  |||«      }| j                  |||«      }||fS rj   )r	  r  r
  r  )rS   r  rZ   rY   Úlang_inter_outputÚvisn_inter_outputr
  r  s           r/   Ú	output_fczTFLxmertXLayer.output_fc_  sW   € à ŸO™O¨JÓ7ÐØ ŸO™O¨JÓ7Ðð ×&Ñ&Ð'8¸*ÀhÓOˆØ×&Ñ&Ð'8¸*ÀhÓOˆØ˜KÐ'Ð'r.   c                óÐ   — |}|}| j                  ||||||¬«      \  }}|dd  }	| j                  |d   ||d   ||¬«      \  }}| j                  |||¬«      \  }
}|r|
||	d   fS |
|fS ró   )r  r  r  )rS   Ú
lang_featsr  Ú
visn_featsr  rµ   rY   r  r  r¾   r
  r  s               r/   r`   zTFLxmertXLayer.calli  s³   € ð %ˆØ$ˆà+/¯>©>ØØØØØØð ,:ó ,
Ñ(ˆ˜ð *¨!¨"Ð-ˆØ+/¯=©=Ø˜AÑØØ˜AÑØØð ,9ó ,
Ñ(ˆ˜ð $(§>¡>°/À?Ð]e >Ó#fÑ ˆ�[áAR�˜[¨/¸!Ñ*<Ð=ÐrÐYdÐfqÐXrÐrr.   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 «      �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   �ŒAx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  )rb   rc   rd   re   r  r<   rf   r  r  r	  r
  r  r  rg   s     r/   rf   zTFLxmertXLayer.build‰  sF  € Ø�:Š:ØØˆŒ
Ü�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ 2Ø×%Ñ%×+Ñ+¨DÔ1÷2ä�4˜¨$Ó/Ð;Ü—‘˜t×1Ñ1×6Ñ6Ó7ñ /Ø×"Ñ"×(Ñ(¨Ô.÷/ä�4˜¨$Ó/Ð;Ü—‘˜t×1Ñ1×6Ñ6Ó7ñ /Ø×"Ñ"×(Ñ(¨Ô.÷/ä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ ,Ø—‘×%Ñ% dÔ+÷,ä�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ ,Ø—‘×%Ñ% dÔ+÷,ä�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ð -ð :÷#2ñ 2ú÷/ñ /ú÷/ñ /ú÷,ñ ,ú÷-ð -ú÷,ð ,ú÷-ð -úsT   ÁJÂ%JÃ?J'ÅJ4Æ3KÈKÉ'KÊJÊJ$Ê'J1Ê4J>ËK
ËKËK"ri   rj   )
r(   r)   r*   rC   r  r  r  r`   rf   rl   rm   s   @r/   r  r  !  s4   ø„ ôFð* ó0ðN ó6ó(ð" ós÷@-r.   r  c                  ó<   ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )ÚTFLxmertEncoderc                ó  •— t        ‰| �  di |¤Ž t        |d¬«      | _        |j                  | _        |j                  | _        |j                  | _	        t        | j
                  «      D �cg c]  }t        |d|› �¬«      ‘Œ c}| _        t        | j                  «      D �cg c]  }t        |d|› �¬«      ‘Œ c}| _        t        | j                  «      D �cg c]  }t        |d|› �¬«      ‘Œ c}| _        || _        y c c}w c c}w c c}w )Nr9   rè   zlayer_._zx_layers_._zr_layers_._r-   )rB   rC   r7   r9   Úl_layersÚnum_l_layersÚx_layersÚnum_x_layersÚr_layersÚnum_r_layersrŽ   rø   Úlayerr  rQ   )rS   rQ   rT   ÚirU   s       €r/   rC   zTFLxmertEncoder.__init__¥  sá   ø€ Ü‰ÑÑ"˜6Ò"ä3°FÀÔKˆŒð #ŸO™OˆÔØ"ŸO™OˆÔØ"ŸO™OˆÔô KPÐPT×PaÑPaÓJbÖcÀQ”m F°8¸A¸3°Ö@ÒcˆŒ
ÜQVÐW[×WhÑWhÓQiÖjÈAœ¨°{À1À#Ð5FÖGÒjˆŒÜPUÐVZ×VgÑVgÓPhÖiÈ1œ v°kÀ!ÀÐ4EÖFÒiˆŒØˆ�ùò dùÚjùÚis   Á-D Â#DÃD
c           	     ó^  — d}d}	|s| j                   j                  rdnd }
|s| j                   j                  rdnd }|s| j                   j                  rdnd }| j                  ||g|¬«      }| j                  D ]%  } |||||¬«      }|d   }|	|fz   }	|€Œ||d   fz   }Œ' | j                  D ]%  } |||||¬«      }|d   }||fz   }|
€Œ|
|d   fz   }
Œ' | j
                  D ]0  } |||||||¬«      }|d d \  }}||fz   }|	|fz   }	|€Œ(||d   fz   }Œ2 ||r|
nd f}|	|r|nd f}|||r|fS d fS )Nr-   rX   r   r   rW   )rQ   rµ   r9   r,  r*  r(  )rS   r   r  Úvisual_featsÚ
visual_posÚvisual_attention_maskrµ   rY   r$   r#   r&   r%   r'   Úlayer_moduleÚ	l_outputsÚ	v_outputsÚ	x_outputsÚvisual_encoder_outputsÚlang_encoder_outputss                      r/   r`   zTFLxmertEncoder.call¶  sé  € ð  "ÐØ!#ÐÙ"3°t·{±{×7TÒ7T™BÐZ^ÐÙ$5¸¿¹×9VÒ9V™bÐ\`ÐÙ):¸d¿k¹k×>[Ò>[¡2ÐaeÐ à—|‘| \°:Ð$>È�|ÓRˆð !ŸJ™Jò 	LˆLÙ$ ZÐ1DÐFWÐbjÔkˆIØ" 1™ˆJØ%;¸z¸mÑ%KÐ"Ø"Ñ.Ø&9¸YÀq¹\¸OÑ&KÑ#ð	Lð !ŸM™Mò 
	HˆLÙ$ØØ%Ø!Ø!ô	ˆIð % Q™<ˆLØ#7¸<¸/Ñ#IÐ Ø Ñ,Ø$5¸À1¹¸Ñ$GÑ!ð
	Hð !ŸM™Mò 	VˆLÙ$ØØ#ØØ%Ø!Ø!ôˆIð (1°°! }Ñ$ˆJ˜Ø#7¸<¸/Ñ#IÐ Ø%;¸z¸mÑ%KÐ"Ø'Ñ3Ø+CÀyÐQRÁ|ÀoÑ+UÑ(ð	Vð  !Ù!2Ñ¸ð"
Ðð
 #Ù#4Ñ¸$ð 
Ðð #Ø Ù(9Ð$ð
ð 	
ð @Dð
ð 	
r.   c                óP  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �J| j                  D ];  }t        j                  |j
                  «      5  |j                  d «       d d d «       Œ= t        | dd «      �J| j                  D ];  }t        j                  |j
                  «      5  |j                  d «       d d d «       Œ= t        | dd «      �K| j                  D ];  }t        j                  |j
                  «      5  |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   ŒoxY w)NTr9   r,  r(  r*  )
rb   rc   rd   re   r9   r<   rf   r,  r(  r*  ©rS   rh   r,  s      r/   rf   zTFLxmertEncoder.buildü  sp  € Ø�:Š:ØØˆŒ
Ü�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ )Ø—‘×"Ñ" 4Ô(÷)ä�4˜ $Ó'Ð3ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ð&ô �4˜ TÓ*Ð6ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ð&ô �4˜ TÓ*Ð6ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ñ&ð 7÷)ñ )ú÷&ñ &ú÷&ð &ú÷&ð &ús0   ÁE6Â*FÄFÅFÅ6F ÆF	ÆF	ÆF%	)NNNNNNFrj   rk   rm   s   @r/   r$  r$  ¤  s+   ø„ ôð& Ø ØØØ"ØØóD
÷L&r.   r$  c                  ód   ‡ — e Zd ZeZˆ fd„Zd„ Zd„ Zd„ Ze		 	 	 	 	 	 	 	 	 	 	 dd„«       Z
dd„Zˆ xZS )	ÚTFLxmertMainLayerc                óš  •— t        ‰| �  di |¤Ž || _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _	        |j                  | _
        |j                  | _        |j                  | _        t        |d¬«      | _        t!        |d¬«      | _        t%        |d¬«      | _        || _        y )Nrz   rè   ÚencoderÚpoolerr-   )rB   rC   rQ   r&  r'  r(  r)  r*  r+  rG   rµ   Úoutput_hidden_statesÚuse_return_dictÚreturn_dictro   rz   r$  r=  ÚTFLxmertPoolerr>  rR   s      €r/   rC   zTFLxmertMainLayer.__init__  s§   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ"ŸO™OˆÔØ"ŸO™OˆÔØ"ŸO™OˆÔØ!'×!9Ñ!9ˆÔØ!'×!9Ñ!9ˆÔØ$*×$?Ñ$?ˆÔ!Ø!×1Ñ1ˆÔÜ,¨V¸,ÔGˆŒÜ& v°IÔ>ˆŒÜ$ V°(Ô;ˆŒØˆ�r.   c                ó   — | j                   S rj   )rz   ©rS   s    r/   Úget_input_embeddingsz&TFLxmertMainLayer.get_input_embeddings%  s   € Ø�‰Ðr.   c                ó`   — || j                   _        t        |«      d   | j                   _        y ©Nr   )rz   rv   r   r}   ©rS   r„   s     r/   Úset_input_embeddingsz&TFLxmertMainLayer.set_input_embeddings(  s$   € Ø!&ˆ�‰ÔÜ%/°Ó%6°qÑ%9ˆ�‰Õ"r.   c                ó   — t         ‚rj   )ÚNotImplementedError)rS   Úheads_to_prunes     r/   Ú_prune_headszTFLxmertMainLayer._prune_heads,  s   € Ü!Ð!r.   c           
     óæ  — |�|�t        d«      ‚|�t        |«      }n|�t        |«      d d }nt        d«      ‚|�|€t        d«      ‚|€t        j                  |d«      }|€t        j                  |d«      }| j	                  ||||«      }t        j
                  ||d   dd|d   f«      }t        j                  ||j                  ¬«      }t        j                  d|j                  ¬«      }t        j                  d	|j                  ¬«      }t        j                  t        j                  ||«      |«      }|�˜t        j
                  ||d   dd|d   f«      }t        j                  t        j                  |d¬
«      d¬
«      }t        j                  ||j                  ¬«      }t        j                  t        j                  ||«      |«      }nd }| j                  |||||||«      }|d d \  }}|d   }|d   }d}|r|d   }|d   }|d   }|||f}|	r||fnd}|d   }|d   }| j                  |«      }|
s|||f|z   |z   S t        ||||	r|nd |	r|nd |rnd |rnd |r¬«      S d ¬«      S )NzDYou cannot specify both input_ids and inputs_embeds at the same timer‚   z5You have to specify either input_ids or inputs_embedszGvisual_feats and visual_pos cannot be `None` in LXMERT's `call` method.r   r   r¬   ç      ð?g     ˆÃÀr‡   rW   r-   )r!   r   r    r#   r$   r%   r&   r'   )rœ   r   rd   rŒ   rz   r¦   r¯   r­   ÚconstantÚmultiplyÚsubtractr�   r=  r>  r   )rS   r�   r/  r0  r´   r1  r�   r‘   rµ   r?  rA  rY   rh   Úembedding_outputÚextended_attention_maskÚone_cstÚten_thousand_cstÚextended_visual_attention_maskÚencoder_outputsr6  r7  r$   r#   Úall_attentionsr%   r&   r'   r²   Úvisual_outputr
  r!   s                                  r/   r`   zTFLxmertMainLayer.call/  sö  € ð Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ü$ YÓ/‰KØÐ&Ü$ ]Ó3°C°RÐ8‰KäÐTÓUÐUØÐ Ð!5ÜÐfÓgÐgàÐ!ÜŸW™W [°!Ó4ˆNàÐ!ÜŸW™W [°!Ó4ˆNð  Ÿ?™?¨9°nÀmÐU]Ó^Ðô #%§*¡*¨^¸kÈ!¹nÈaÐQRÐT_Ð`aÑTbÐ=cÓ"dÐô #%§'¡'Ð*AÐIY×I_ÑI_Ô"`ÐÜ—+‘+˜cÐ)9×)?Ñ)?Ô@ˆÜŸ;™; xÐ7G×7MÑ7MÔNÐÜ"$§+¡+¬b¯k©k¸'ÐCZÓ.[Ð]mÓ"nÐà Ð,Ü-/¯Z©ZÐ8MÐP[Ð\]ÑP^Ð`aÐcdÐfqÐrsÑftÐOuÓ-vÐ*Ü-/¯^©^¼B¿N¹NÐK`ÐghÔ<iÐpqÔ-rÐ*ä-/¯W©WÐ5SÐ[k×[qÑ[qÔ-rÐ*Ü-/¯[©[Ü—‘˜GÐ%CÓDÐFVó.Ñ*ð .2Ð*ð Ÿ,™,ØØ#ØØØ*ØØó
ˆð 8GÀrÈÐ7JÑ4ÐÐ 4Ø5°aÑ8ÐØ!5°aÑ!8ÐàˆÙØ"6°qÑ"9ÐØ 6°qÑ 9ÐØ'6°qÑ'9Ð$à#Ø!Ø(ðˆNñ K_Ð/Ð1EÑFÐdfˆà,¨RÑ0ˆØ,¨RÑ0ˆØŸ™ KÓ0ˆáØ °Ð>ÀÑNÐQ_Ñ_Ð_ä"Ø'Ø'Ø'Ù=QÑ#9ÐW[Ù9MÑ!5ÐSWÙ7HÑ 3ÈdÙ3DÑ/È$ÙARÐ%=ô	
ð 		
ð Y]ô	
ð 		
r.   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)NTrz   r=  r>  )	rb   rc   rd   re   rz   r<   rf   r=  r>  rg   s     r/   rf   zTFLxmertMainLayer.buildœ  s  € Ø�:Š:ØØˆŒ
Ü�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ ,Ø—‘×%Ñ% dÔ+÷,ä�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ )Ø—‘×"Ñ" 4Ô(÷)ä�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ (Ø—‘×!Ñ! $Ô'÷(ð (ð 5÷,ð ,ú÷)ð )ú÷(ð (úr  ©NNNNNNNNNNFrj   )r(   r)   r*   r   Úconfig_classrC   rE  rI  rM  r   r`   rf   rl   rm   s   @r/   r;  r;    s[   ø„ à€Lôò ò:ò"ð ð ØØØØ"ØØØØ!ØØòj
ó ðj
÷X(r.   r;  c                  ó8   — e Zd ZdZeZdZed„ «       Zed„ «       Z	y)ÚTFLxmertPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    Úlxmertc                ó  — d}d}t        j                  g d¢g d¢gt         j                  ¬«      }t         j                  j	                  ||| j
                  j                  f«      }t         j                  j	                  ||df«      }|||dœS )ún
        Dummy inputs to build the network.

        Returns:
            tf.Tensor with dummy inputs
        rW   é
   ©r	   é   é   ©rW   r	   é   r¬   rh  ©r�   r/  r0  )rd   rP  Úint32ÚrandomÚuniformrQ   rM   )rS   r¨   Únum_visual_featuresr�   r/  r0  s         r/   Údummy_inputsz$TFLxmertPreTrainedModel.dummy_inputs´  s   € ð ˆ
Ø ÐÜ—K‘K¢ªIÐ 6¼b¿h¹hÔGˆ	Ü—y‘y×(Ñ(¨*Ð6IÈ4Ï;É;×KfÑKfÐ)gÓhˆÜ—Y‘Y×&Ñ&¨
Ð4GÈÐ'KÓLˆ
ð #Ø(Ø$ñ
ð 	
r.   c           
     óò  — t        j                  dt         j                  d¬«      t        j                  dt         j                  d¬«      t        j                  d d | j                  j                  ft         j
                  d¬«      t        j                  dt         j
                  d¬«      t        j                  dt         j                  d¬«      t        j                  dt         j                  d	¬«      d
œS )N)NNr�   rè   r´   r/  )NNrh  r0  r1  r�   )r�   r´   r/  r0  r1  r�   )rd   Ú
TensorSpecrj  rQ   rM   Úfloat32rD  s    r/   Úinput_signaturez'TFLxmertPreTrainedModel.input_signatureÈ  sž   € ô Ÿ™ |´R·X±XÀKÔPÜ Ÿm™m¨L¼"¿(¹(ÐIYÔZÜŸM™M¨4°°t·{±{×7RÑ7RÐ*SÔUW×U_ÑU_ÐftÔuÜŸ-™-¨¼¿¹È,ÔWÜ%'§]¡]°<ÄÇÁÐPgÔ%hÜ Ÿm™m¨L¼"¿(¹(ÐIYÔZñ
ð 	
r.   N)
r(   r)   r*   r+   r   r]  Úbase_model_prefixÚpropertyrn  rr  r-   r.   r/   r_  r_  «  s:   „ ñð
  €LØ Ðàñ
ó ð
ð& ñ
ó ñ
r.   r_  aœ
  

    The LXMERT model was proposed in [LXMERT: Learning Cross-Modality Encoder Representations from
    Transformers](https://arxiv.org/abs/1908.07490) by Hao Tan and Mohit Bansal. It's a vision and language transformer
    model, pre-trained on a variety of multi-modal datasets comprising of GQA, VQAv2.0, MCSCOCO captions, and Visual
    genome, using a combination of masked language modeling, region of interest feature regression, cross entropy loss
    for question answering attribute prediction, and object tag prediction.

    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>

    Parameters:
        config ([`LxmertConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a§  
    Args:
        input_ids (`np.ndarray` or `tf.Tensor` of shape `(batch_size, sequence_length)`):
            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)
        visual_feats (`tf.Tensor` of shape `(batch_size, num_visual_features, visual_feat_dim)`):
            This input represents visual features. They ROI pooled object features from bounding boxes using a
            faster-RCNN model)

            These are currently not provided by the transformers library.
        visual_pos (`tf.Tensor` of shape `(batch_size, num_visual_features, visual_feat_dim)`):
            This input represents spacial features corresponding to their relative (via index) visual features. The
            pre-trained LXMERT model expects these spacial features to be normalized bounding boxes on a scale of 0 to
            1.

            These are currently not provided by the transformers library.
        attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *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)
        visual_attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            MMask 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 (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
            1]`:

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

            [What are token type IDs?](../glossary#token-type-ids)
        inputs_embeds (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        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 Lxmert Model transformer outputting raw hidden-states without any specific head on top.c                  ó°   ‡ — e Zd Zˆ fd„Ze ee«       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       «       «       Zdd„Zˆ xZS )ÚTFLxmertModelc                óP   •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        y )Nr`  rè   )rB   rC   r;  r`  )rS   rQ   rŠ   rT   rU   s       €r/   rC   zTFLxmertModel.__init__D  s(   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3Ü'¨°XÔ>ˆ�r.   )Ú
checkpointÚoutput_typer]  c                ó<   — | j                  |||||||||	|
|«      }|S rj   )r`  )rS   r�   r/  r0  r´   r1  r�   r‘   rµ   r?  rA  rY   rÀ   s                r/   r`   zTFLxmertModel.callH  s:   € ð* —+‘+ØØØØØ!ØØØØ ØØó
ˆð ˆr.   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`  )rb   rc   rd   re   r`  r<   rf   rg   s     r/   rf   zTFLxmertModel.buildm  si   € Ø�:Š:ØØˆŒ
Ü�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ (Ø—‘×!Ñ! $Ô'÷(ð (ð 5÷(ð (úó   ÁA1Á1A:r\  )r�   úTFModelInputType | Noner/  r   r0  r   r´   únp.ndarray | tf.Tensor | Noner1  r~  r�   r~  r‘   r~  rµ   úOptional[bool]r?  r  rA  r  rY   ÚboolÚreturnz!Union[Tuple, TFLxmertModelOutput]rj   )r(   r)   r*   rC   r   r   ÚLXMERT_INPUTS_DOCSTRINGr   Ú_CHECKPOINT_FOR_DOCr   Ú_CONFIG_FOR_DOCr`   rf   rl   rm   s   @r/   rv  rv  ?  sß   ø„ ô
?ð Ù*Ð+BÓCÙØ&Ø'Ø$ôð .2Ø)-Ø'+Ø8<Ø?CØ8<Ø7;Ø,0Ø/3Ø&*Øðà*ðð 'ðð %ð	ð
 6ðð  =ðð 6ðð 5ðð *ðð -ðð $ðð ðð 
+òóó Dó ð÷<(r.   rv  c                  ó,   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zˆ xZS )rB  c                ó¼   •— t        ‰| �  di |¤Ž t        j                  j	                  |j
                  t        |j                  «      dd¬«      | _        || _	        y )NÚtanhrÅ   )r;   Ú
activationr<   r-   )
rB   rC   r   rD   rE   rF   r   rG   rÅ   rQ   rR   s      €r/   rC   zTFLxmertPooler.__init__w  sT   ø€ Ü‰ÑÑ"˜6Ò"Ü—\‘\×'Ñ'Ø×ÑÜ.¨v×/GÑ/GÓHØØð	 (ó 
ˆŒ
ð ˆ�r.   c                ó:   — |d d …df   }| j                  |«      }|S rG  )rÅ   )rS   r²   Úfirst_token_tensorr!   s       r/   r`   zTFLxmertPooler.call�  s(   € ð +ª1¨a¨4Ñ0ÐØŸ
™
Ð#5Ó6ˆØÐr.   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Ï   rg   s     r/   rf   zTFLxmertPooler.buildˆ  rÐ   rÑ   rj   rk   rm   s   @r/   rB  rB  v  s   ø„ ôò÷Hr.   rB  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertPredictionHeadTransformc                ó¦  •— 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Å   )Úunitsr;   r<   rq   r>   r-   )rB   rC   r   rD   rE   rF   r   rG   rÅ   rÇ   rÈ   rÉ   r
   Útransform_act_fnrH   rI   rq   rQ   rR   s      €r/   rC   z(TFLxmertPredictionHeadTransform.__init__“  s¤   ø€ Ü‰ÑÑ"˜6Ò"ä—\‘\×'Ñ'Ø×$Ñ$Ü.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô �f×'Ñ'¬Ô-Ü$5°f×6GÑ6GÓ$HˆDÕ!à$*×$5Ñ$5ˆDÔ!äŸ™×8Ñ8À×AVÑAVÐ]hÐ8ÓiˆŒØˆ�r.   c                óp   — | j                  |¬«      }| j                  |«      }| j                  |¬«      }|S )Nr‰   )rÅ   r�  rq   rÌ   s     r/   r`   z$TFLxmertPredictionHeadTransform.call¤  s8   € ØŸ
™
¨-˜
Ó8ˆØ×-Ñ-¨mÓ<ˆØŸ™¨m˜Ó<ˆàÐr.   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ã   rg   s     r/   rf   z%TFLxmertPredictionHeadTransform.build«  rä   rÝ   )rQ   r   ©r²   ú	tf.Tensorr�  r”  rj   rk   rm   s   @r/   r�  r�  ’  s   ø„ õó"÷	Lr.   r�  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 )ÚTFLxmertLMPredictionHeadc                ó†   •— t        ‰| �  di |¤Ž || _        |j                  | _        t	        |d¬«      | _        || _        y )NÚ	transformrè   r-   )rB   rC   rQ   rF   r�  r˜  Úinput_embeddings©rS   rQ   r™  rT   rU   s       €r/   rC   z!TFLxmertLMPredictionHead.__init__¹  s@   ø€ Ü‰ÑÑ"˜6Ò"àˆŒØ!×-Ñ-ˆÔä8¸ÀkÔRˆŒð !1ˆÕr.   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)rw   rx   Ú	trainabler<   r˜  )r|   rQ   r}   r�  rb   rc   rd   re   r˜  r<   rf   rg   s     r/   rf   zTFLxmertLMPredictionHead.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 rj   )r™  rD  s    r/   Úget_output_embeddingsz.TFLxmertLMPredictionHead.get_output_embeddingsÏ  s   € Ø×$Ñ$Ð$r.   c                ó`   — || j                   _        t        |«      d   | j                   _        y rG  )r™  rv   r   r}   rH  s     r/   Úset_output_embeddingsz.TFLxmertLMPredictionHead.set_output_embeddingsÒ  s(   € Ø',ˆ×ÑÔ$Ü+5°eÓ+<¸QÑ+?ˆ×ÑÕ(r.   c                ó   — d| j                   iS )Nr�  )r�  rD  s    r/   Úget_biasz!TFLxmertLMPredictionHead.get_biasÖ  s   € Ø˜Ÿ	™	Ð"Ð"r.   c                óX   — |d   | _         t        |d   «      d   | j                  _        y )Nr�  r   )r�  r   rQ   r}   rH  s     r/   Úset_biasz!TFLxmertLMPredictionHead.set_biasÙ  s'   € Ø˜&‘MˆŒ	Ü!+¨E°&©MÓ!:¸1Ñ!=ˆ�‰Õr.   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 )N©r²   r   r‚   )Útensorrw   T)ÚaÚbr«   )r„   r�  )r˜  r   rd   r¦   rF   r®   r™  rv   rQ   r}   ÚnnÚbias_addr�  )rS   r²   Ú
seq_lengths      r/   r`   zTFLxmertLMPredictionHead.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ˆàÐr.   ©rQ   r   r™  úkeras.layers.Layerrj   )r�  r°  )r„   ztf.Variable)r�  zDict[str, tf.Variable]r“  )r(   r)   r*   rC   rf   r   r¢  r¤  r¦  r`   rl   rm   s   @r/   r–  r–  ¸  s'   ø„ õ
1ó+ó%ó@ó#ó>÷r.   r–  c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLxmertMLMHeadc                óJ   •— t        ‰| �  di |¤Ž t        ||d¬«      | _        y )NÚpredictionsrè   r-   )rB   rC   r–  r´  rš  s       €r/   rC   zTFLxmertMLMHead.__init__ê  s&   ø€ Ü‰ÑÑ"˜6Ò"ä3°FÐ<LÐS`ÔaˆÕr.   c                ó*   — | j                  |¬«      }|S )Nr¨  )r´  )rS   Úsequence_outputÚprediction_scoress      r/   r`   zTFLxmertMLMHead.callï  s   € Ø ×,Ñ,¸?Ð,ÓKÐà Ð r.   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´  )rb   rc   rd   re   r´  r<   rf   rg   s     r/   rf   zTFLxmertMLMHead.buildô  sm   € Ø�:Š:ØØˆŒ
Ü�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ð -ð :÷-ð -úr|  r¯  )r¶  r”  r�  r”  rj   rk   rm   s   @r/   r²  r²  é  s   ø„ õbó
!÷
-r.   r²  c                  ó,   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zˆ xZS )ÚTFLxmertPreTrainingHeadsc                óÌ   •— t        ‰| �  di |¤Ž t        ||d¬«      | _        t        j
                  j                  dt        |j                  «      d¬«      | _	        || _
        y )Nr´  rè   rW   Úseq_relationshipr:   r-   )rB   rC   r–  r´  r   rD   rE   r   rG   r¼  rQ   rš  s       €r/   rC   z!TFLxmertPreTrainingHeads.__init__þ  s_   ø€ Ü‰ÑÑ"˜6Ò"Ü3°FÐ<LÐS`ÔaˆÔä %§¡× 2Ñ 2ØÜ.¨v×/GÑ/GÓHØ#ð !3ó !
ˆÔð
 ˆ�r.   c                óN   — | j                  |«      }| j                  |«      }||fS rj   )r´  r¼  )rS   r¶  r!   r·  Úseq_relationship_scores        r/   r`   zTFLxmertPreTrainingHeads.call	  s0   € Ø ×,Ñ,¨_Ó=ÐØ!%×!6Ñ!6°}Ó!EÐØ Ð"8Ð8Ð8r.   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¼  )
rb   rc   rd   re   r´  r<   rf   r¼  rQ   rF   rg   s     r/   rf   zTFLxmertPreTrainingHeads.build  sÔ   € Ø�:Š:ØØˆŒ
Ü�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ SØ×%Ñ%×+Ñ+¨T°4¸¿¹×9PÑ9PÐ,QÔR÷Sð Sð ?÷-ð -ú÷Sð Sús   ÁC"Â%3C.Ã"C+Ã.C7rj   rk   rm   s   @r/   rº  rº  ý  s   ø„ ô	ò9÷
	Sr.   rº  c                  ó,   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zˆ xZS )ÚTFLxmertVisualAnswerHeadc                ó¸  •— t        ‰| �  di |¤Ž |j                  }t        j                  j                  |dz  t        |j                  «      d¬«      | _        t        d«      | _
        t        j                  j                  |j                  d¬«      | _        t        j                  j                  |t        |j                  «      d¬«      | _        || _        y )	NrW   zlogit_fc_._0r:   Úgeluzlogit_fc_._2r>   zlogit_fc_._3r-   )rB   rC   rF   r   rD   rE   r   rG   rÅ   r
   rˆ  rH   rI   Ú
layer_normÚdense_1Úhid_dim)rS   rQ   Ú
num_labelsrT   rÆ  rU   s        €r/   rC   z!TFLxmertVisualAnswerHead.__init__  s¹   ø€ Ü‰ÑÑ"˜6Ò"Ø×$Ñ$ˆÜ—\‘\×'Ñ'Ø�a‰KÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô
 ,¨FÓ3ˆŒÜŸ,™,×9Ñ9À&×BWÑBWÐ^lÐ9ÓmˆŒÜ—|‘|×)Ñ)ØÜ.¨v×/GÑ/GÓHØð *ó 
ˆŒð
 ˆ�r.   c                óŽ   — | j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }|S rj   )rÅ   rˆ  rÄ  rÅ  rÌ   s     r/   r`   zTFLxmertVisualAnswerHead.call,  s@   € ØŸ
™
 =Ó1ˆØŸ™¨Ó6ˆØŸ™¨Ó6ˆØŸ™ ]Ó3ˆàÐr.   c                óê  — | j                   ry d| _         t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �\t        j                  | j                  j
                  «      5  | j                  j                  d | j                  dz  g«       d d d «       t        | dd «      �^t        j                  | j                  j
                  «      5  | j                  j                  d d | j                  dz  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Ä  rW   rÅ  )
rb   rc   rd   re   rÅ   r<   rf   rÆ  rÄ  rÅ  rg   s     r/   rf   zTFLxmertVisualAnswerHead.build4  s1  € Ø�:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ =Ø—
‘
× Ñ  $¨¨d¯l©lÐ!;Ô<÷=ä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ @Ø—‘×%Ñ% t¨T¯\©\¸AÑ-=Ð&>Ô?÷@ä�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ CØ—‘×"Ñ" D¨$°·±¸qÑ0@Ð#AÔB÷Cð Cð 6÷=ð =ú÷@ð @ú÷Cð Cús$   Á)EÂ2+EÄ,E)ÅEÅE&Å)E2rj   rk   rm   s   @r/   rÁ  rÁ    s   ø„ ôò"÷Cr.   rÁ  c                  ó,   ‡ — e Zd Zˆ fd„Zd„ Zdd„Zˆ xZS )ÚTFLxmertVisualObjHeadc           
     óò  •— t        ‰| �  di |¤Ž t        |d¬«      | _        i }|j                  rd|j
                  dœ|d<   |j                  rd|j                  dœ|d<   |j                  rd|j                  dœ|d<   || _
        | j                  D �ci c]K  }|t        j                  j                  | j                  |   d	   t        |j                  «      d
|› �¬«      “ŒM c}| _        || _        y c c}w )Nr˜  rè   ©r‚   )rw   ÚnumÚobjÚattr)r‚   i   ÚfeatrÎ  zdecoder_dict.r:   r-   )rB   rC   r�  r˜  Úvisual_obj_lossÚnum_object_labelsÚvisual_attr_lossÚnum_attr_labelsÚvisual_feat_lossrM   Úvisual_lossesr   rD   rE   r   rG   Údecoder_dictrQ   )rS   rQ   rT   r×  rš   rU   s        €r/   rC   zTFLxmertVisualObjHead.__init__D  s  ø€ Ü‰ÑÑ"˜6Ò"Ü8¸ÀkÔRˆŒð ˆØ×!Ò!Ø-2¸6×;SÑ;SÑ#TˆM˜%Ñ Ø×"Ò"Ø.3¸F×<RÑ<RÑ$SˆM˜&Ñ!Ø×"Ò"Ø.8À×AWÑAWÑ$XˆM˜&Ñ!Ø*ˆÔð ×)Ñ)ö
ð ð ”—‘×#Ñ#Ø×"Ñ" 3Ñ'¨Ñ.Ü#2°6×3KÑ3KÓ#LØ$ S EÐ*ð $ó ñ ò
ˆÔð ˆ�ùò
s   ÂAC4c                ó~   — | j                  |«      }i }| j                  D ]  } | j                  |   |«      ||<   Œ |S rj   )r˜  r×  rØ  )rS   r²   r_   rš   s       r/   r`   zTFLxmertVisualObjHead.call^  sL   € ØŸ™ }Ó5ˆØˆØ×%Ñ%ò 	@ˆCØ0˜$×+Ñ+¨CÑ0°Ó?ˆF�3ŠKð	@àˆr.   c                ó
  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �p| j                  j                  «       D ]R  }t        j                  |j
                  «      5  |j                  d d | j                  j                  g«       d d d «       ŒT y y # 1 sw Y   Œ‡xY w# 1 sw Y   ŒlxY w)NTr˜  rØ  )rb   rc   rd   re   r˜  r<   rf   rØ  ÚvaluesrQ   rF   r9  s      r/   rf   zTFLxmertVisualObjHead.builde  sß   € Ø�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ä�4˜¨Ó.Ð:Ø×*Ñ*×1Ñ1Ó3ò G�Ü—]‘] 5§:¡:Ó.ñ GØ—K‘K  t¨T¯[©[×-DÑ-DÐ EÔF÷Gð GñGð ;÷+ð +ú÷Gð Gús   ÁC-Â8)C9Ã-C6Ã9D	rj   rk   rm   s   @r/   rË  rË  C  s   ø„ ôò4÷
Gr.   rË  z4Lxmert Model with a `language modeling` head on top.c                  óâ   ‡ — e Zd Zˆ fd„Zed„ «       Zd„ Zd„ Ze e	e
«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	d„«       «       «       Zd
d„Zˆ xZS )ÚTFLxmertForPreTrainingc                ó¶  •— t        ‰| �  |g|¢­i |¤Ž || _        |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _        t        |d¬«      | _
        t        || j                  j                  d¬«      | _        | j                  rt        |d¬«      | _        | j                  rt!        || j                  d¬«      | _        t$        j&                  j)                  dd¬«      t$        j&                  j+                  d	¬
«      t$        j&                  j+                  d	¬
«      dœ| _        i }|j.                  rd|j0                  ddœ|d<   |j2                  rd|j4                  ddœ|d<   |j6                  rd|j8                  f|j8                  ddœ|d<   || _        y )Nr`  rè   ÚclsÚobj_predict_headÚanswer_headrO  Ú
huber_loss)Údeltar<   T)Úfrom_logits)Úl2Úvisn_ceÚcerÍ  ræ  )rw   rÎ  r2   rÏ  rÐ  r‚   rå  rÑ  )rB   rC   rQ   Únum_qa_labelsÚvisual_loss_normalizerÚtask_mask_lmÚtask_obj_predictÚtask_matchedÚtask_qar;  r`  rº  rz   rß  rË  rà  rÁ  rá  r   ÚlossesÚHuberÚSparseCategoricalCrossentropyÚ	loss_fctsrÒ  rÓ  rÔ  rÕ  rÖ  rM   r×  )rS   rQ   rŠ   rT   r×  rU   s        €r/   rC   zTFLxmertForPreTraining.__init__t  s±  ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3àˆŒØ#×1Ñ1ˆÔØ&,×&CÑ&CˆÔ#ð #×/Ñ/ˆÔØ &× 7Ñ 7ˆÔØ"×/Ñ/ˆÔØ—~‘~ˆŒô (¨°XÔ>ˆŒô ,¨F°D·K±K×4JÑ4JÐQVÔWˆŒØ× Ò Ü$9¸&ÐGYÔ$ZˆDÔ!Ø�<Š<Ü7¸À×@RÑ@RÐYfÔgˆDÔô —,‘,×$Ñ$¨3°\Ð$ÓBÜ—|‘|×AÑAÈdÐAÓSÜ—,‘,×<Ñ<ÈÐ<ÓNñ
ˆŒð ˆØ×!Ò!àØ×/Ñ/Ø!ñ$ˆM˜%Ñ ð
 ×"Ò"àØ×-Ñ-Ø!ñ%ˆM˜&Ñ!ð
 ×"Ò"à˜f×4Ñ4Ð5Ø×-Ñ-Øñ%ˆM˜&Ñ!ð
 +ˆÕr.   c                óâ  — d}d}t        j                  g d¢g d¢gt         j                  ¬«      }t         j                  j	                  ||| j
                  j                  f«      }t         j                  j	                  ||df«      }| j
                  j                  ri }| j
                  j                  rG| j
                  j                  r1t        j                  ||g«      t        j                  ||g«      fd<   | j
                  j                  r\| j
                  j                  rFt        j                  ||| j
                  j                  g«      t        j                  ||g«      fd<   | j
                  j                  rG| j
                  j                  r1t        j                  ||g«      t        j                  ||g«      fd	<   i |||d
œ¥| j
                  j                  rdi¥S i ¥S )rb  rW   rc  rd  rg  r¬   rh  rÐ  rÑ  rÏ  ri  Ú
obj_labels)rd   rP  rj  rk  rl  rQ   rM   rë  rÔ  ÚonesrÖ  rÒ  )rS   r¨   rm  r�   r/  r0  ró  s          r/   rn  z#TFLxmertForPreTraining.dummy_inputs§  s°  € ð ˆ
Ø ÐÜ—K‘K¢ªIÐ 6¼b¿h¹hÔGˆ	Ü—y‘y×(Ñ(¨*Ð6IÈ4Ï;É;×KfÑKfÐ)gÓhˆÜ—Y‘Y×&Ñ&¨
Ð4GÈÐ'KÓLˆ
à�;‰;×'Ò'ØˆJØ�;‰;×'Ò'¨D¯K©K×,HÒ,Hä—‘˜Ð%8Ð9Ó:Ü—‘˜Ð%8Ð9Ó:ð"ˆJ�vÑð �;‰;×'Ò'¨D¯K©K×,HÒ,Hä—‘˜Ð%8¸$¿+¹+×:UÑ:UÐVÓWÜ—‘˜Ð%8Ð9Ó:ð"ˆJ�vÑð �;‰;×&Ò&¨4¯;©;×+GÒ+Gä—‘˜Ð%8Ð9Ó:Ü—‘˜Ð%8Ð9Ó:ð!ˆJ�uÑð

à&Ø ,Ø(ñð
ð .2¯[©[×-IÒ-I�˜jÐ)ð
ð 	
ð PRð
ð 	
r.   c                ó.   — | j                   j                  S rj   )rß  r´  rD  s    r/   Úget_lm_headz"TFLxmertForPreTraining.get_lm_headÐ  s   € Ø�x‰x×#Ñ#Ð#r.   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´  rD  s    r/   Úget_prefix_bias_namez+TFLxmertForPreTraining.get_prefix_bias_nameÓ  sG   € Ü�‰ÐeÔgtÔuØ�y‰y˜3‰ §¡§¡Ñ.°Ñ4°t·x±x×7KÑ7K×7PÑ7PÑPÐPr.   )ry  r]  c                ó‚  — | j                  |||||||||||«      }|d   |d   |d   }}}| j                  ||«      \  }}| j                  r| j                  |«      }n|d   d   }|€|
€|	€|€dnt	        j
                  d«      }d}|�l| j                  r` | j                  d   t	        j                  |dg«      t	        j                  |d| j                  j                  g«      «      }||z  }||fz  }|
�X| j                  rL | j                  d   t	        j                  |
dg«      t	        j                  |ddg«      «      }||z  }||fz  }|	��.| j                  �r!d}| j                  |«      }| j                  j                  «       D ]ì  \  }}|	|   \  }} |d	   }!|d
   }"|d   }#| j                   }$| j                  |"   }%||   }& |%t	        j                  ||#«      t	        j                  |&d|!g«      «      }'|'j"                  dkD  rt	        j$                  |'«      }'t	        j$                  |'t	        j&                  t	        j                  | dg«      |'j(                  «      z  «      |$z  }'||'z  }||'fz  }Œî ||z  }|�b| j                  rV | j                  d   t	        j                  |dg«      t	        j                  |d| j*                  g«      «      }(||(z  }||(fz  }|s|||f|dd z   })|�|f|)z   S |)S t-        |||||j.                  |j0                  |j2                  |j4                  |j6                  ¬«	      S )ag  
        masked_lm_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]`
        obj_labels (`Dict[Str: Tuple[tf.Tensor, tf.Tensor]]`, *optional*, defaults to `None`):
            each key is named after each one of the visual losses and each element of the tuple is of the shape
            `(batch_size, num_features)` and `(batch_size, num_features, visual_feature_dim)` for each the label id and
            the label score respectively
        matched_label (`tf.Tensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the whether or not the text input matches the image (classification) loss. Input
            should be a sequence pair (see `input_ids` docstring) Indices should be in `[0, 1]`:

            - 0 indicates that the sentence does not match the image,
            - 1 indicates that the sentence does match the image.
        ans (`tf.Tensor` of shape `(batch_size)`, *optional*, defaults to `None`):
            a one hot representation hof the correct answer *optional*

        Returns:
        r   r   rW   Ng        r-   rç  r‚   rÎ  r2   rw   r	   )	r2   r3   r4   r5   r#   r$   r%   r&   r'   )r`  rß  rí  rá  rd   rP  rê  rñ  r¦   rQ   r}   rì  rë  rà  r×  Úitemsré  ÚndimÚreduce_meanr¯   r­   rè  r1   r#   r$   r%   r&   r'   )*rS   r�   r/  r0  r´   r1  r�   r‘   Úmasked_lm_labelsró  Úmatched_labelÚansrµ   r?  rA  rY   Úlxmert_outputr
  rZ  r!   Úlang_prediction_scoresr4   Úanswer_scoreÚ
total_lossrî  Úmasked_lm_lossÚmatched_lossÚtotal_visn_lossÚvisn_prediction_scores_dictrš   Úkey_infoÚlabelÚ	mask_confÚ
output_dimÚloss_fct_nameÚlabel_shaperv   Úvisn_loss_fctÚvisn_prediction_scoresÚ	visn_lossÚanswer_lossr_   s*                                             r/   r`   zTFLxmertForPreTraining.call×  s´  € ðT Ÿ™ØØØØØ!ØØØØ ØØó
ˆð ˜!ÑØ˜!ÑØ˜!Ñð %2�]ˆð
 <@¿8¹8ÀKÐQ^Ó;_Ñ8ÐÐ 8Ø�<Š<Ø×+Ñ+¨MÓ:‰Là(¨Ñ+¨AÑ.ˆLð !Ð(¨]Ð-BÀzÐGYÐ^aÐ^iñ ä—‘˜SÓ!ð 	ð
 ˆØÐ'¨D×,=Ò,=Ø1˜TŸ^™^¨DÑ1Ü—
‘
Ð+¨b¨TÓ2Ü—
‘
Ð1°B¸¿¹×8NÑ8NÐ3OÓPóˆNð ˜.Ñ(ˆJØ�~Ð'Ñ'ˆFØÐ$¨×):Ò):Ø/˜4Ÿ>™>¨$Ñ/Ü—
‘
˜=¨2¨$Ó/Ü—
‘
Ð3°b¸!°WÓ=óˆLð ˜,Ñ&ˆJØ�|�oÑ%ˆFØÑ! d×&;Ó&;Ø!ˆOØ*.×*?Ñ*?ÀÓ*NÐ'Ø!%×!3Ñ!3×!9Ñ!9Ó!;ò '‘��XØ#-¨c¡?Ñ ��yØ% e™_�
Ø (¨Ñ 0�Ø& wÑ/�Ø×4Ñ4�Ø $§¡¨}Ñ =�Ø)DÀSÑ)IÐ&Ù)Ü—J‘J˜u kÓ2Ü—J‘JÐ5¸¸JÐ7GÓHó�	ð
 —>‘> AÒ%Ü "§¡¨yÓ 9�IÜŸN™N¨9´r·w±w¼r¿z¹zÈ)ÐVXÐUYÓ?ZÐ\e×\kÑ\kÓ7lÑ+lÓmÐpvÑv�	Ø 9Ñ,�Ø˜9˜,Ñ&‘ð#'ð$ ˜/Ñ)ˆJØˆ?˜tŸ|š|Ø.˜$Ÿ.™.¨Ñ.Ü—
‘
˜3  Ó%¤r§z¡z°,ÀÀT×EWÑEWÐ@XÓ'YóˆKð ˜+Ñ%ˆJØ�{�nÑ$ˆFñ à&Ø(Øðð ˜a˜bÐ!ñ	"ˆFð
 0:Ð/E�Z�M FÑ*ÐQÈ6ÐQä+ØØ4Ø%=Ø%1Ø#0×#GÑ#GØ!.×!CÑ!CØ -× AÑ AØ+×=Ñ=Ø%2×%KÑ%Kô

ð 
	
r.   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á  )
rb   rc   rd   re   r`  r<   rf   rß  rà  rá  rg   s     r/   rf   zTFLxmertForPreTraining.builde  sR  € Ø�:Š:ØØˆŒ
Ü�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ (Ø—‘×!Ñ! $Ô'÷(ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ 2Ø×%Ñ%×+Ñ+¨DÔ1÷2ä�4˜¨Ó-Ð9Ü—‘˜t×/Ñ/×4Ñ4Ó5ñ -Ø× Ñ ×&Ñ& tÔ,÷-ð -ð :÷(ñ (ú÷%ð %ú÷2ð 2ú÷-ð -ús0   ÁE?Â%FÃ?FÅF$Å?F	ÆFÆF!Æ$F-)NNNNNNNNNNNNNNF) r�   r}  r/  r   r0  r   r´   r   r1  r   r�   r   r‘   r   r  r   ró  z-Dict[str, Tuple[tf.Tensor, tf.Tensor]] | Noner  r   r  r   rµ   úbool | Noner?  r  rA  r  rY   r€  r�  z/Tuple[tf.Tensor] | TFLxmertForPreTrainingOutputrj   )r(   r)   r*   rC   rt  rn  rö  rü  r   r   r‚  r   r1   r„  r`   rf   rl   rm   s   @r/   rÝ  rÝ  r  sD  ø„ ô1+ðf ñ&
ó ð&
òP$òQð Ù*Ð+BÓCÙÐ+GÐVeÔfð .2Ø)-Ø'+Ø+/Ø26Ø+/Ø*.Ø-1ØDHØ*.Ø $Ø)-Ø,0Ø#'Øð!I
à*ðI
ð 'ðI
ð %ð	I
ð
 )ðI
ð  0ðI
ð )ðI
ð (ðI
ð +ðI
ð BðI
ð (ðI
ð ðI
ð 'ðI
ð *ðI
ð !ðI
ð  ð!I
ð" 
9ò#I
ó gó Dó ðI
÷V-r.   rÝ  )rÝ  r;  rv  r_  r7   )Gr+   Ú
__future__r   rù  Údataclassesr   Útypingr   r   r   r   ÚnumpyÚnpÚ
tensorflowrd   Úactivations_tfr
   Úmodeling_tf_utilsr   r   r   r   r   r   r   Útf_utilsr   r   Úutilsr   r   r   r   r   r   Úconfiguration_lxmertr   Ú
get_loggerr(   Úloggerrƒ  r„  r   r1   rD   ÚLayerr7   ro   r—   rÃ   rÓ   rß   ræ   rï   rø   r  r$  r;  r_  ÚLXMERT_START_DOCSTRINGr‚  rv  rB  r�  r–  r²  rº  rÁ  rË  rÝ  Ú__all__r-   r.   r/   ú<module>r(     sï  ðñ" å "ã Ý !ß /Ó /ã Û å /÷÷ ñ ÷ G÷÷ õ /ð 
ˆ×	Ñ	˜HÓ	%€à3Ð Ø €ð ô*=˜+ó *=ó ð*=ðZ ô,= ;ó ,=ó ð,=ô^4Q 5§<¡<×#5Ñ#5ô 4QônC ˜Ÿ™×+Ñ+ô C ôLY=˜Ÿ™×*Ñ*ô Y=ôxH˜5Ÿ<™<×-Ñ-ô Hô8L�U—\‘\×'Ñ'ô Lô>L˜eŸl™l×0Ñ0ô Lô<2 §¡×!3Ñ!3ô 2ô42 %§,¡,×"4Ñ"4ô 2ôB4�E—L‘L×&Ñ&ô 4ô<@-�U—\‘\×'Ñ'ô @-ôFj&�e—l‘l×(Ñ(ô j&ðZ ôV(˜Ÿ™×*Ñ*ó V(ó ðV(ôr&
Ð/ô &
ðR*Ð ðX<Ð ñ~ ØfØóô0(Ð+ó 0(ó	ð0(ôfH�U—\‘\×'Ñ'ô Hô8"L e§l¡l×&8Ñ&8ô "LôL-˜uŸ|™|×1Ñ1ô -ôb-�e—l‘l×(Ñ(ô -ô(S˜uŸ|™|×1Ñ1ô Sô:&C˜uŸ|™|×1Ñ1ô &CôR,G˜EŸL™L×.Ñ.ô ,Gñ^ ÐPÐRhÓiôA-Ð4ó A-ó jðA-òH�r.   