
    sg                        d Z ddlmZ ddlZddlZddl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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(m)Z)m*Z*m+Z+ ddl,m-Z-  e+j\                  e/      Z0dZ1dZ2 G d de      Z3 G d de jh                  jj                        Z6 G d de jh                  jj                        Z7 G d de jh                  jj                        Z8 G d de jh                  jj                        Z9 G d de jh                  jj                        Z: G d de jh                  jj                        Z; G d de jh                  jj                        Z< G d d e jh                  jj                        Z=e! G d! d"e jh                  jj                               Z>d#Z?d$Z@ e)d%e?       G d& d'e3             ZA G d( d)e jh                  jj                        ZB e)d*e?       G d+ d,e3e             ZC G d- d.e jh                  jj                        ZD e)d/e?       G d0 d1e3e             ZE e)d2e?       G d3 d4e3e             ZF e)d5e?       G d6 d7e3e             ZG e)d8e?       G d9 d:e3e             ZHy);zTF 2.0 MPNet model.    )annotationsN)OptionalTupleUnion   )get_tf_activation)TFBaseModelOutputTFBaseModelOutputWithPoolingTFMaskedLMOutputTFMultipleChoiceModelOutputTFQuestionAnsweringModelOutputTFSequenceClassifierOutputTFTokenClassifierOutput)TFMaskedLanguageModelingLossTFModelInputTypeTFMultipleChoiceLossTFPreTrainedModelTFQuestionAnsweringLossTFSequenceClassificationLossTFTokenClassificationLossget_initializerkeraskeras_serializableunpack_inputs)check_embeddings_within_bounds
shape_liststable_softmax)add_code_sample_docstringsadd_start_docstrings%add_start_docstrings_to_model_forwardlogging   )MPNetConfigzmicrosoft/mpnet-baser#   c                      e Zd ZdZeZdZy)TFMPNetPreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    mpnetN)__name__
__module____qualname____doc__r#   config_classbase_model_prefix     ^/var/www/html/venv/lib/python3.12/site-packages/transformers/models/mpnet/modeling_tf_mpnet.pyr%   r%   B   s    
 Lr.   r%   c                  8     e Zd ZdZ fdZddZd ZddZ xZS )TFMPNetEmbeddingsz8Construct the embeddings from word, position embeddings.c                d   t        |   di | d| _        || _        |j                  | _        |j
                  | _        |j                  | _        t        j                  j                  |j                  d      | _        t        j                  j                  |j                        | _        y )Nr"   	LayerNormepsilonnamerater-   )super__init__padding_idxconfighidden_sizemax_position_embeddingsinitializer_ranger   layersLayerNormalizationlayer_norm_epsr3   Dropouthidden_dropout_probdropoutselfr<   kwargs	__class__s      r/   r:   zTFMPNetEmbeddings.__init__O   s    "6"!--'-'E'E$!'!9!988AVAV]h8i||++1K1K+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
                  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   y xY w)	Nword_embeddingsweight)r?   r6   shapeinitializerposition_embeddings
embeddingsTr3   )tf
name_scope
add_weightr<   
vocab_sizer=   r   r?   rL   r>   rP   builtgetattrr3   r6   buildrG   input_shapes     r/   rX   zTFMPNetEmbeddings.buildZ   s@   ]],- 	//{{--t/?/?@+d>T>TU * DK	 ]]01 	'+!33T5E5EF+d>T>TU (7 (D$	 ::
4d+7t~~223 L$$dD$++2I2I%JKL L 8#	 		 	L Ls%   AEAE 3E,E E),E5c                    t        j                  t         j                  j                  || j                        |j
                        }t         j                  j                  |d      |z  }|| j                  z   S )a  
        Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding
        symbols are ignored. This is modified from fairseq's `utils.make_positions`.

        Args:
            input_ids: tf.Tensor
        Returns: tf.Tensor
        dtyper"   axis)rR   castmath	not_equalr;   r]   cumsum)rG   	input_idsmaskincremental_indicess       r/   "create_position_ids_from_input_idsz4TFMPNetEmbeddings.create_position_ids_from_input_idsp   s\     wwrww((D4D4DEY__] ggnnTn:TA"T%5%555r.   c                   ||J |At        || j                  j                         t        j                  | j
                  |      }t        |      dd }|a|| j                  |      }nLt        j                  t        j                  | j                  dz   |d   | j                  z   dz         d      }t        j                  | j                  |      }||z   }| j                  |	      }| j                  ||
      }|S )z
        Applies embedding based on inputs tensor.

        Returns:
            final_embeddings (`tf.Tensor`): output embedding tensor.
        N)paramsindices)rd   r"   )startlimitr   r^   inputsro   training)r   r<   rU   rR   gatherrL   r   rg   expand_dimsranger;   rP   r3   rE   )rG   rd   position_idsinputs_embedsrq   rZ   position_embedsfinal_embeddingss           r/   callzTFMPNetEmbeddings.call~   s    %-*?@@ *9dkk6L6LMIIT[[)LM /4$#FFQZF[!~~HH4#3#3a#7{2QUQaQa?ade?efmn  ))4+C+C\Z(?:>>1A>B<</?(<Sr.   N)NNNF)	r'   r(   r)   r*   r:   rX   rg   ry   __classcell__rI   s   @r/   r1   r1   L   s    B	ML,6 r.   r1   c                  0     e Zd Zd fdZddZddZ xZS )TFMPNetPoolerc                    t        |   di | t        j                  j	                  |j
                  t        |j                        dd      | _        || _	        y )Ntanhdense)unitskernel_initializer
activationr6   r-   )
r9   r:   r   r@   Denser=   r   r?   r   r<   rF   s      r/   r:   zTFMPNetPooler.__init__   sT    "6"\\''$$.v/G/GH	 ( 

 r.   c                <    |d d df   }| j                  |      }|S )Nr   rn   )r   )rG   hidden_statesfirst_token_tensorpooled_outputs       r/   ry   zTFMPNetPooler.call   s*     +1a4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   	rV   rW   rR   rS   r   r6   rX   r<   r=   rY   s     r/   rX   zTFMPNetPooler.build   }    ::
4$'3tzz/ H

  $dkk.E.E!FGH H 4H H   3BBr<   r#   r   	tf.Tensorreturnr   rz   r'   r(   r)   r:   ry   rX   r{   r|   s   @r/   r~   r~      s    	Hr.   r~   c                  4     e Zd Z fdZd ZddZddZ xZS )TFMPNetSelfAttentionc                   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                  t        |j                        d      | _        t        j                  j#                  |j$                        | _        || _        y )
Nr   zThe hidden size (z6) is not a multiple of the number of attention heads (qr   r6   kvor-   )r9   r:   r=   num_attention_heads
ValueErrorintattention_head_sizeall_head_sizer   r@   r   r   r?   r   r   r   r   rC   attention_probs_dropout_probrE   r<   rF   s      r/   r:   zTFMPNetSelfAttention.__init__   s   "6" : ::a?#F$6$6#7 8 4457 
 $*#=#= !!F$>$>>!CCC#&v'9'9F<V<V'V#W !558P8PP##?6C[C[3\cf $ 
 ##?6C[C[3\cf $ 
 ##?6C[C[3\cf $ 
 ##?6C[C[3\cf $ 
 ||++F,O,OPr.   c                    t        j                  ||d| j                  | j                  f      }t        j                  |g d      S )Nrk   r      r"   r   perm)rR   reshaper   r   	transpose)rG   x
batch_sizes      r/   transpose_for_scoresz)TFMPNetSelfAttention.transpose_for_scores   s8    JJq:r4+C+CTE]E]^_||AL11r.   c                   t        |      d   }| j                  |      }| j                  |      }	| j                  |      }
| j	                  ||      }| j	                  |	|      }	| j	                  |
|      }
t        j                  ||	d      }t        j                  t        |	      d   |j                        }|t
        j                  j                  |      z  }|||z  }|||z   }t        |d      }| j                  ||      }|||z  }t        j                  ||
      }t        j                  |g d      }t        j                  ||d| j                  f      }| j!                  |      }|r||f}|S |f}|S )	Nr   T)transpose_brk   r^   rq   r   r   )r   r   r   r   r   rR   matmulr`   r]   ra   sqrtr   rE   r   r   r   r   )rG   r   attention_mask	head_maskoutput_attentionsposition_biasrq   r   r   r   r   attention_scoresdkattention_probscr   outputss                    r/   ry   zTFMPNetSelfAttention.call   sz   .q1
FF=!FF=!FF=!%%a4%%a4%%a499Qt<WWZ]2&(8(>(>?+bggll2.>> $-%/.@()9C,,,J -	9OIIoq)LL.JJq:r4+=+=>?FF1I*;1o& 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       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   xY w# 1 sw Y   y xY w)NTr   r   r   r   )rV   rW   rR   rS   r   r6   rX   r<   r=   r   r   r   rY   s     r/   rX   zTFMPNetSelfAttention.build  s   ::
4d#/tvv{{+ DdD$++*A*ABCD4d#/tvv{{+ DdD$++*A*ABCD4d#/tvv{{+ DdD$++*A*ABCD4d#/tvv{{+ DdD$++*A*ABCD D 0D DD DD DD Ds0   3G<3G(-3G43H G%(G14G= H	NFrz   )r'   r(   r)   r:   r   ry   rX   r{   r|   s   @r/   r   r      s    :2#JDr.   r   c                  4     e Zd Z fdZd ZddZddZ xZS )TFMPNetAttentionc                   t        |   di | t        |d      | _        t        j
                  j                  |j                  d      | _        t        j
                  j                  |j                        | _        || _        y )Nattnr6   r3   r4   r-   )r9   r:   r   r   r   r@   rA   rB   r3   rC   rD   rE   r<   rF   s      r/   r:   zTFMPNetAttention.__init__  sf    "6"(f=	88AVAV]h8i||++F,F,FGr.   c                    t         rz   NotImplementedError)rG   headss     r/   prune_headszTFMPNetAttention.prune_heads   s    !!r.   c                    | j                  ||||||      }| j                  | j                  |d         |z         }|f|dd  z   }	|	S )Nr   rq   r   r"   )r   r3   rE   )
rG   input_tensorr   r   r   r   rq   self_outputsattention_outputr   s
             r/   ry   zTFMPNetAttention.call#  sa    yy.)5FVcnv ! 
  >>$,,|A*G,*VW#%QR(88r.   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   r3   )
rV   rW   rR   rS   r   r6   rX   r3   r<   r=   rY   s     r/   rX   zTFMPNetAttention.build+  s    ::
4&2tyy~~. &		%&4d+7t~~223 L$$dD$++2I2I%JKL L 8& &L L   C"%3C."C+.C7r   rz   )r'   r(   r)   r:   r   ry   rX   r{   r|   s   @r/   r   r     s    "	Lr.   r   c                  0     e Zd Zd fdZddZddZ xZS )TFMPNetIntermediatec                T   t        |   di | t        j                  j	                  |j
                  t        |j                        d      | _        t        |j                  t              r"t        |j                        | _        || _        y |j                  | _        || _        y )Nr   r   r   r6   r-   )r9   r:   r   r@   r   intermediate_sizer   r?   r   
isinstance
hidden_actstrr   intermediate_act_fnr<   rF   s      r/   r:   zTFMPNetIntermediate.__init__9  s    "6"\\''**vOgOg?hov ( 

 f''-'89J9J'KD$  (.'8'8D$r.   c                L    | j                  |      }| j                  |      }|S )Nrn   )r   r   )rG   r   s     r/   ry   zTFMPNetIntermediate.callF  s(    

-
8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r   r   rY   s     r/   rX   zTFMPNetIntermediate.buildL  r   r   r   r   rz   r   r|   s   @r/   r   r   8  s    Hr.   r   c                  2     e Zd Zd fdZdddZddZ xZS )TFMPNetOutputc                x   t        |   di | t        j                  j	                  |j
                  t        |j                        d      | _        t        j                  j                  |j                  d      | _        t        j                  j                  |j                        | _        || _        y )Nr   r   r3   r4   r7   r-   )r9   r:   r   r@   r   r=   r   r?   r   rA   rB   r3   rC   rD   rE   r<   rF   s      r/   r:   zTFMPNetOutput.__init__W  s    "6"\\''$$IaIa9bip ( 

 88AVAV]h8i||++1K1K+Lr.   c                z    | j                  |      }| j                  ||      }| j                  ||z         }|S )Nrn   rp   )r   rE   r3   )rG   r   r   rq   s       r/   ry   zTFMPNetOutput.calla  s?    

-
8MHMml.JK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   r3   )rV   rW   rR   rS   r   r6   rX   r<   r   r3   r=   rY   s     r/   rX   zTFMPNetOutput.buildh  s    ::
4$'3tzz/ N

  $dkk.K.K!LMN4d+7t~~223 L$$dD$++2I2I%JKL L 8N NL L   3C9<3D9DDr   F)r   r   r   r   rq   boolr   r   rz   r   r|   s   @r/   r   r   V  s    	Lr.   r   c                  .     e Zd Z fdZddZddZ xZS )TFMPNetLayerc                    t        |   di | t        |d      | _        t	        |d      | _        t        |d      | _        y )N	attentionr   intermediateoutputr-   )r9   r:   r   r   r   r   r   outrF   s      r/   r:   zTFMPNetLayer.__init__u  s>    "6")&{C/^L h7r.   c                    | j                  ||||||      }|d   }|dd  }	| j                  |      }
| j                  |
||      }|f|	z   }	|	S )Nr   r   r"   r   )r   r   r   )rG   r   r   r   r   r   rq   self_attention_outputsr   r   intermediate_outputlayer_outputs               r/   ry   zTFMPNetLayer.call|  sy    !%>96GWdow "0 "
 2!4(,"//0@Axx 35EPXxY/G+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   )	rV   rW   rR   rS   r   r6   rX   r   r   rY   s     r/   rX   zTFMPNetLayer.build  s   ::
4d+7t~~223 +$$T*+4.:t00556 .!!''-.4%1txx}}- %t$% % 2+ +. .% %$   D%%D1?D=%D.1D:=Er   rz   r   r|   s   @r/   r   r   t  s    8%r.   r   c                  J     e Zd Z fdZddZ	 ddZedd       ZddZ xZ	S )	TFMPNetEncoderc                t   t        |   di | || _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _        t        |j                        D cg c]  }t        |d|        c}| _        |j                  | _        y c c}w )Nzlayer_._r   r-   )r9   r:   r<   r   n_headsr   output_hidden_statesrelative_attention_num_bucketsr?   rt   num_hidden_layersr   layer)rG   r<   rH   irI   s       r/   r:   zTFMPNetEncoder.__init__  s    "6"11!'!9!9$*$?$?!.4.S.S+!'!9!9INvOgOgIhiAl6(1#?i
.4.S.S+ js   B5c                   | j                   ry d| _         t        j                  d      5  | j                  d| j                  | j
                  gt        | j                              | _        d d d        t        | dd       K| j                  D ];  }t        j                  |j                        5  |j                  d        d d d        = y y # 1 sw Y   bxY w# 1 sw Y   UxY w)NTrelative_attention_biasrQ   rM   r   )rV   rR   rS   rT   r   r   r   r?   r   rW   r   r6   rX   )rG   rZ   r   s      r/   rX   zTFMPNetEncoder.build  s    ::
]]45 	+/??!::DLLI+D,B,BC ,; ,D(	 4$'3 &]]5::. &KK%& && 4	 	& &s   AC0CCC#	c           	     $   | j                  |      }|rdnd }	|rdnd }
t        | j                        D ]/  \  }}|r|	|fz   }	 |||||   |||      }|d   }|s'|
|d   fz   }
1 |r|	|fz   }	|st        d ||	|
fD              S t	        ||	|
      S )Nr-   r   r   r"   c              3  &   K   | ]	  }||  y wrz   r-   ).0r   s     r/   	<genexpr>z&TFMPNetEncoder.call.<locals>.<genexpr>  s     hqZ[Zghs   )last_hidden_stater   
attentions)compute_position_bias	enumerater   tupler	   )rG   r   r   r   r   r   return_dictrq   r   all_hidden_statesall_attentionsr   layer_modulelayer_outputss                 r/   ry   zTFMPNetEncoder.call  s     22=A"6BD0d(4 	FOA|#$58H$H!(!!+!M *!,M !/=3C2E!E	F$   1]4D Dh]4E~$Vhhh +;LYg
 	
r.   c                l   d}|  }|dz  }|t        j                  t         j                  j                  |d      | j                        |z  z  }t         j                  j                  |      }|dz  }t         j                  j                  ||      }|t        j                  t         j                  j                  ||z        t        j                  ||z        z  ||z
  z  | j                        z   }t         j                  j                  ||dz
        }|t        j                  |||      z  }|S )Nr   r   r\   r"   )	rR   r`   ra   lessr]   abslogminimumwhere)relative_positionnum_bucketsmax_distanceretn	max_exactis_smallval_if_larges           r/   _relative_position_bucketz(TFMPNetEncoder._relative_position_bucket  s    rwwrww||Aq)1B1H1HIKWWGGKKN  1$	77<<9- 277GGKKI&,2J)KK{]fOfg#))$
 

 ww|[1_Erxx!\22
r.   c                   t        |      }|d   |d   }}||dddddf   }|dddddf   }n8t        j                  |      dddf   }t        j                  |      dddf   }||z
  }| j                  || j                        }	t        j
                  | j                  |	      }
t        j                  t        j                  |
g d      d      }
|
S )z%Compute binned relative position biasr"   N)r  )r   r   r"   r   r^   )	r   rR   rt   r  r   rr   r   rs   r   )rG   r   ru   rZ   qlenklencontext_positionmemory_positionr  	rp_bucketvaluess              r/   r   z$TFMPNetEncoder.compute_position_bias  s     m ^[^d#+Aq$J7*1dA:6O!xx~ag6 hhtnT1W5O+.>>22;; 3 
	 477CVY ?aHr.   rz   r   )       )
r'   r(   r)   r:   rX   ry   staticmethodr  r   r{   r|   s   @r/   r   r     s2    T&. (
T  *r.   r   c                  d     e Zd ZeZ fdZddZddZd Ze		 	 	 	 	 	 	 	 	 d	d       Z
d
dZ xZS )TFMPNetMainLayerc                H   t        |   di | || _        |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        t        |d      | _
        t        |d      | _        t        |d      | _        y )Nencoderr   poolerrQ   r-   )r9   r:   r<   r   r?   r   r   use_return_dictr  r   r"  r~   r#  r1   rQ   rF   s      r/   r:   zTFMPNetMainLayer.__init__  s    "6"!'!9!9!'!9!9!'!9!9$*$?$?!!11%f9=#F:+FFr.   c                    | j                   S rz   )rQ   rG   s    r/   get_input_embeddingsz%TFMPNetMainLayer.get_input_embeddings  s    r.   c                `    || j                   _        t        |      d   | j                   _        y Nr   )rQ   rL   r   rU   rG   values     r/   set_input_embeddingsz%TFMPNetMainLayer.set_input_embeddings#  s$    !&%/%6q%9"r.   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   )rG   heads_to_prunes     r/   _prune_headszTFMPNetMainLayer._prune_heads(  s
    
 "!r.   c
           	        ||t        d      |t        |      }
n|t        |      d d }
nt        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        d g| j                  z  }| j                  |||||||	      }|d   }| j                  |      }|s
||f|dd  z   S t        |||j                   |j"                  
      S )NzDYou cannot specify both input_ids and inputs_embeds at the same timerk   z5You have to specify either input_ids or inputs_embedsr"   r   r   g      ?r\   g     )r   pooler_outputr   r   )r   r   rR   fillrQ   r   r`   r]   constantmultiplysubtractr   r   r"  r#  r
   r   r   )rG   rd   r   ru   r   rv   r   r   r  rq   rZ   embedding_outputextended_attention_maskone_cstten_thousand_cstencoder_outputssequence_outputr   s                     r/   ry   zTFMPNetMainLayer.call/  s     ]%>cdd"$Y/K&$]3CR8KTUU!WW[!4N??	 + 
 #%**^k!naQRT_`aTb=c"d #%''*ACSCYCY"Z++c)9)?)?@;;x7G7M7MN"$++bkk'CZ.[]m"n  %%!7!77I,,#  ' 
 *!,O4  #$ $
 ,-')77&11	
 	
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#  rQ   )	rV   rW   rR   rS   r"  r6   rX   r#  rQ   rY   s     r/   rX   zTFMPNetMainLayer.build  s   ::
4D)5t||001 )""4()44(4t{{//0 (!!$'(4t,8t334 ,%%d+, , 9) )( (, ,r   )r   zkeras.layers.Layer)r+  ztf.Variable	NNNNNNNNFrz   )r'   r(   r)   r#   r+   r:   r'  r,  r/  r   ry   rX   r{   r|   s   @r/   r   r     sV    LG:
"  !R
 R
h,r.   r   au	  

    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 ([`MPNetConfig`]): 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 (`Numpy array` or `tf.Tensor` of 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 (`Numpy array` 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)
        position_ids (`Numpy array` 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 (`Numpy array` 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 (`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 MPNet Model transformer outputting raw hidden-states without any specific head on top.c                       e Zd Z fdZe eej                  d             ee	e
e      	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd                     ZddZ xZS )	TFMPNetModelc                P    t        |   |g|i | t        |d      | _        y )Nr&   r   )r9   r:   r   r&   rG   r<   ro   rH   rI   s       r/   r:   zTFMPNetModel.__init__  s(    3&3F3%f7;
r.   batch_size, sequence_length
checkpointoutput_typer+   c
                :    | j                  |||||||||		      }
|
S )N	rd   r   ru   r   rv   r   r   r  rq   )r&   )rG   rd   r   ru   r   rv   r   r   r  rq   r   s              r/   ry   zTFMPNetModel.call  s9    & **)%'/!5#  

 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&   )rV   rW   rR   rS   r&   r6   rX   rY   s     r/   rX   zTFMPNetModel.build  sg    ::
4$'3tzz/ '

  &' ' 4' 's   A11A:r=  )rd   TFModelInputType | Noner   $Optional[Union[np.array, tf.Tensor]]ru   rJ  r   rJ  rv   tf.Tensor | Noner   Optional[bool]r   rL  r  rL  rq   r   r   z*Union[TFBaseModelOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   r:   r   r    MPNET_INPUTS_DOCSTRINGformatr   _CHECKPOINT_FOR_DOCr	   _CONFIG_FOR_DOCry   rX   r{   r|   s   @r/   r?  r?    s    
< *+A+H+HIf+gh&%$ .2?C=A:>*.,0/3&** = ;	
 8 ( * - $  
4 i 2'r.   r?  c                  H     e Zd ZdZ fdZd	dZd Zd Zd Zd Z	d Z
 xZS )
TFMPNetLMHeadz4MPNet head for masked and permuted language modelingc                j   t        |   di | || _        |j                  | _        t        j
                  j                  |j                  t        |j                        d      | _	        t        j
                  j                  |j                  d      | _        t        d      | _        || _        y )Nr   r   
layer_normr4   gelur-   )r9   r:   r<   r=   r   r@   r   r   r?   r   rA   rB   rT  r   actdecoder)rG   r<   input_embeddingsrH   rI   s       r/   r:   zTFMPNetLMHead.__init__"  s    "6"!--\\''?6C[C[3\cj ( 

  ,,99&BWBW^j9k$V, (r.   c                   | j                  | j                  j                  fddd      | _        | 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)NzerosTbias)rN   rO   	trainabler6   r   rT  )rT   r<   rU   r[  rV   rW   rR   rS   r   r6   rX   r=   rT  rY   s     r/   rX   zTFMPNetLMHead.build1  s   OO4;;+A+A*CQXdhouOv	::
4$'3tzz/ H

  $dkk.E.E!FGH4t,8t334 M%%tT4;;3J3J&KLM M 9H HM Ms   :3D(+3D4(D14D=c                    | j                   S rz   )rW  r&  s    r/   get_output_embeddingsz#TFMPNetLMHead.get_output_embeddings>      ||r.   c                `    || j                   _        t        |      d   | j                   _        y r)  )rW  rL   r   rU   r*  s     r/   set_output_embeddingsz#TFMPNetLMHead.set_output_embeddingsA  s$    #",U"3A"6r.   c                    d| j                   iS )Nr[  )r[  r&  s    r/   get_biaszTFMPNetLMHead.get_biasE  s    		""r.   c                X    |d   | _         t        |d         d   | j                  _        y )Nr[  r   )r[  r   r<   rU   r*  s     r/   set_biaszTFMPNetLMHead.set_biasH  s'    &M	!+E&M!:1!=r.   c                   | j                  |      }| j                  |      }| 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)tensorr"   rk   )rg  rN   T)abr   )r+  r[  )r   rV  rT  r   rR   r   r=   r   rW  rL   r<   rU   nnbias_addr[  )rG   r   
seq_lengths      r/   ry   zTFMPNetLMHead.callL  s    

=1/6  }5a8


-DDTDT?UV		MT\\5H5HVZ[

-JPTP[P[PfPf?gh]Kr.   rz   )r'   r(   r)   r*   r:   rX   r^  ra  rc  re  ry   r{   r|   s   @r/   rR  rR    s*    >(M7#>r.   rR  z3MPNet Model with a `language modeling` head on top.c                       e Zd ZdgZ fdZd Zd Ze ee	j                  d             eeee      	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d                     ZddZ xZS )TFMPNetForMaskedLMr#  c                    t        |   |g|i | t        |d      | _        t	        || j                  j
                  d      | _        y )Nr&   r   lm_head)r9   r:   r   r&   rR  rQ   rp  rA  s       r/   r:   zTFMPNetForMaskedLM.__init___  sB    3&3F3%f7;
$VTZZ-B-BSr.   c                    | j                   S rz   )rp  r&  s    r/   get_lm_headzTFMPNetForMaskedLM.get_lm_heade  r_  r.   c                    t        j                  dt               | j                  dz   | j                  j                  z   S )NzMThe method get_prefix_bias_name is deprecated. Please use `get_bias` instead./)warningswarnFutureWarningr6   rp  r&  s    r/   get_prefix_bias_namez'TFMPNetForMaskedLM.get_prefix_bias_nameh  s/    egtuyy3!2!222r.   rB  rC  c                    | j                  |||||||||
	      }|d   }| j                  |      }|	dn| j                  |	|      }|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]`
        r   ru   r   rv   r   r   r  rq   r   Nr   losslogitsr   r   )r&   rp  hf_compute_lossr   r   r   )rG   rd   r   ru   r   rv   r   r   r  labelsrq   r   r;  prediction_scoresr|  r   s                   r/   ry   zTFMPNetForMaskedLM.calll  s    4 **)%'/!5#  

 "!* LL9~t4+?+?HY+Z')GABK7F)-)9TGf$EvE$!//))	
 	
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&   rp  )rV   rW   rR   rS   r&   r6   rX   rp  rY   s     r/   rX   zTFMPNetForMaskedLM.build  s    ::
4$'3tzz/ '

  &'4D)5t||001 )""4() ) 6' ') )   C%CCC 
NNNNNNNNNF)rd   rI  r   np.ndarray | tf.Tensor | Noneru   r  r   r  rv   rK  r   rL  r   rL  r  rL  r  rK  rq   r   r   z)Union[TFMaskedLMOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   _keys_to_ignore_on_load_missingr:   rr  rx  r   r    rM  rN  r   rO  r   rP  ry   rX   r{   r|   s   @r/   rn  rn  [  s    '0k#T3 *+A+H+HIf+gh&$$ .28<6:37*.,0/3&*#',
*,
 6,
 4	,

 1,
 (,
 *,
 -,
 $,
 !,
 ,
 
3,
 i ,
\	)r.   rn  c                  2     e Zd ZdZ fdZddZddZ xZS )TFMPNetClassificationHeadz-Head for sentence-level classification tasks.c                   t        |   di | t        j                  j	                  |j
                  t        |j                        dd      | _        t        j                  j                  |j                        | _        t        j                  j	                  |j                  t        |j                        d      | _        || _        y )Nr   r   )r   r   r6   out_projr   r-   )r9   r:   r   r@   r   r=   r   r?   r   rC   rD   rE   
num_labelsr  r<   rF   s      r/   r:   z"TFMPNetClassificationHead.__init__  s    "6"\\''.v/G/GH	 ( 

 ||++F,F,FG**/&BZBZ2[bl + 
 r.   c                    |d d dd d f   }| j                  ||      }| j                  |      }| j                  ||      }| j                  |      }|S )Nr   r   )rE   r   r  )rG   featuresrq   r   s       r/   ry   zTFMPNetClassificationHead.call  sV    Q1WLLXL.JJqMLLXL.MM!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   r  )
rV   rW   rR   rS   r   r6   rX   r<   r=   r  rY   s     r/   rX   zTFMPNetClassificationHead.build  s    ::
4$'3tzz/ H

  $dkk.E.E!FGH4T*6t}}112 K##T41H1H$IJK K 7H HK Kr   r   rz   )r'   r(   r)   r*   r:   ry   rX   r{   r|   s   @r/   r  r    s    7	Kr.   r  z
    MPNet 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dgZ fdZe eej                  d             e	e
ee      	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd                     Zd	dZ xZS )
 TFMPNetForSequenceClassificationr#  c                    t        |   |g|i | |j                  | _        t        |d      | _        t        |d      | _        y )Nr&   r   
classifier)r9   r:   r  r   r&   r  r  rA  s       r/   r:   z)TFMPNetForSequenceClassification.__init__  sC    3&3F3 ++%f7;
3FNr.   rB  rC  c                   | j                  |||||||||
	      }|d   }| j                  ||
      }|	dn| j                  |	|      }|s|f|dd z   }||f|z   S |S t        |||j                  |j
                        S )a  
        labels (`tf.Tensor` 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).
        rz  r   r   Nr   r{  )r&   r  r~  r   r   r   rG   rd   r   ru   r   rv   r   r   r  r  rq   r   r;  r}  r|  r   s                   r/   ry   z%TFMPNetForSequenceClassification.call  s    4 **)%'/!5#  

 "!*8D~t4+?+?+OY,F)-)9TGf$EvE)!//))	
 	
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  )rV   rW   rR   rS   r&   r6   rX   r  rY   s     r/   rX   z&TFMPNetForSequenceClassification.build  s    ::
4$'3tzz/ '

  &'4t,8t334 ,%%d+, , 9' ', ,r  r  )rd   rI  r   rJ  ru   rJ  r   rJ  rv   rK  r   rL  r   rL  r  rL  r  rK  rq   r   r   z3Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   r  r:   r   r    rM  rN  r   rO  r   rP  ry   rX   r{   r|   s   @r/   r  r    s     (1k#O *+A+H+HIf+gh&.$ .2?C=A:>*.,0/3&*#'-
*-
 =-
 ;	-

 8-
 (-
 *-
 --
 $-
 !-
 -
 
=-
 i -
^	,r.   r  z
    MPNet 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 fdZe eej                  d             ee	e
e      	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd                     ZddZ xZS )	TFMPNetForMultipleChoicec                .   t        |   |g|i | t        |d      | _        t        j
                  j                  |j                        | _        t        j
                  j                  dt        |j                        d      | _        || _        y )Nr&   r   r"   r  r   )r9   r:   r   r&   r   r@   rC   rD   rE   r   r   r?   r  r<   rA  s       r/   r:   z!TFMPNetForMultipleChoice.__init__-  s{    3&3F3%f7;
||++F,F,FG,,,,/&2J2J"KR^ - 
 r.   z(batch_size, num_choices, sequence_lengthrC  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|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 )	a5  
        labels (`tf.Tensor` 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   rk   r   )r  rq   r   r{  )
r   rR   r   r&   rE   r  r~  r   r   r   )rG   rd   r   ru   r   rv   r   r   r  r  rq   num_choicesrl  flat_input_idsflat_attention_maskflat_position_idsflat_inputs_embedsr   r   r}  reshaped_logitsr|  r   s                          r/   ry   zTFMPNetForMultipleChoice.call7  s   2  $Y/2K#I.q1J$]3A6K#M215JDMDYIJ/?@_cN\Nhbjj"j9IJnrJVJbBJJ|b*5EFhl ( JJ}r:z-7PQR7S&TU 	
 ** #  

  
]XF/**Vb+->?~t4+?+?+X%''!"+5F)-)9TGf$EvE*"!//))	
 	
r.   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  
rV   rW   rR   rS   r&   r6   rX   r  r<   r=   rY   s     r/   rX   zTFMPNetForMultipleChoice.build{      ::
4$'3tzz/ '

  &'4t,8t334 M%%tT4;;3J3J&KLM M 9' 'M Mr   r  )rd   rI  r   r  ru   r  r   r  rv   rK  r   rL  r   rL  r  rL  r  rK  rq   r   r   z4Union[TFMultipleChoiceModelOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   r:   r   r    rM  rN  r   rO  r   rP  ry   rX   r{   r|   s   @r/   r  r  %  s     *+A+H+HIs+tu&/$ .28<6:37*.,0/3&*#';
*;
 6;
 4	;

 1;
 (;
 *;
 -;
 $;
 !;
 ;
 
>;
 v ;
z	Mr.   r  z
       MPNet 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dgZ fdZe eej                  d             e	e
ee      	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd                     Zd	dZ xZS )
TFMPNetForTokenClassificationr#  c                d   t        |   |g|i | |j                  | _        t        |d      | _        t
        j                  j                  |j                        | _	        t
        j                  j                  |j                  t        |j                        d      | _        || _        y )Nr&   r   r  r   )r9   r:   r  r   r&   r   r@   rC   rD   rE   r   r   r?   r  r<   rA  s       r/   r:   z&TFMPNetForTokenClassification.__init__  s    3&3F3 ++%f7;
||++F,F,FG,,,,/&BZBZ2[bn - 
 r.   rB  rC  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` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        rG  r   r   Nr"   r{  )r&   rE   r  r~  r   r   r   r  s                   r/   ry   z"TFMPNetForTokenClassification.call  s    0 **)%'/!5#  

 "!*,,,J1~t4+?+?+OY,F)-)9TGf$EvE&!//))	
 	
r.   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  rY   s     r/   rX   z#TFMPNetForTokenClassification.build  r  r   r  )rd   rI  r   r  ru   r  r   r  rv   rK  r   rL  r   rL  r  rL  r  rK  rq   r   r   z0Union[TFTokenClassifierOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   r  r:   r   r    rM  rN  r   rO  r   rP  ry   rX   r{   r|   s   @r/   r  r    s     (1k#	 *+A+H+HIf+gh&+$ .28<6:37*.,0/3&*#',
*,
 6,
 4	,

 1,
 (,
 *,
 -,
 $,
 !,
 ,
 
:,
 i ,
\	Mr.   r  z
    MPNet Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                       e Zd ZdgZ fdZe eej                  d             e	e
ee      	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd                     Zd	dZ xZS )
TFMPNetForQuestionAnsweringr#  c                   t        |   |g|i | |j                  | _        t        |d      | _        t
        j                  j                  |j                  t        |j                        d      | _
        || _        y )Nr&   r   
qa_outputsr   )r9   r:   r  r   r&   r   r@   r   r   r?   r  r<   rA  s       r/   r:   z$TFMPNetForQuestionAnswering.__init__  sr    3&3F3 ++%f7;
,,,,/&BZBZ2[bn - 
 r.   rB  rC  c                   | j                  |||||||||	      }|d   }| j                  |      }t        j                  |dd      \  }}t        j                  |d      }t        j                  |d      }d}|	|
|	|
d}| j                  |||f      }|s||f|dd z   }||f|z   S |S t        ||||j                  |j                        S )	a  
        start_positions (`tf.Tensor` 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` 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.
        rz  r   r   rk   r^   N)start_positionend_position)r|  start_logits
end_logitsr   r   )	r&   r  rR   splitsqueezer~  r   r   r   )rG   rd   r   ru   r   rv   r   r   r  start_positionsend_positionsrq   rH   r   r;  r}  r  r  r|  r  r   s                        r/   ry   z TFMPNetForQuestionAnswering.call  s   @ **)%'/!5#  

 "!*1#%88FAB#? jzz,R8ZZ
4
&=+D(7WF''z0JKD"J/'!"+=F)-)9TGf$EvE-%!!//))
 	
r.   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  )
rV   rW   rR   rS   r&   r6   rX   r  r<   r=   rY   s     r/   rX   z!TFMPNetForQuestionAnswering.build4  r  r   )NNNNNNNNNNF)rd   rI  r   rJ  ru   rJ  r   rJ  rv   rK  r   rL  r   rL  r  rL  r  rK  r  rK  rq   r   r   z7Union[TFQuestionAnsweringModelOutput, Tuple[tf.Tensor]]rz   )r'   r(   r)   r  r:   r   r    rM  rN  r   rO  r   rP  ry   rX   r{   r|   s   @r/   r  r    s     (1k# *+A+H+HIf+gh&2$ .2?C=A:>*.,0/3&*,0*.:
*:
 =:
 ;	:

 8:
 (:
 *:
 -:
 $:
 *:
 (:
 :
 
A:
 i :
x	Mr.   r  )Ir*   
__future__r   ra   ru  typingr   r   r   numpynp
tensorflowrR   activations_tfr   modeling_tf_outputsr	   r
   r   r   r   r   r   modeling_tf_utilsr   r   r   r   r   r   r   r   r   r   r   tf_utilsr   r   r   utilsr   r   r    r!   configuration_mpnetr#   
get_loggerr'   loggerrO  rP  r%   r@   Layerr1   r~   r   r   r   r   r   r   r   MPNET_START_DOCSTRINGrM  r?  rR  rn  r  r  r  r  r  r-   r.   r/   <module>r     s     "   ) )   /      S R  - 
		H	%,  .  O ** O fHELL&& H:XD5<<-- XDvLu||)) LBH%,,,, H<LELL&& L<!%5<<%% !%HqU\\'' qh C,u||)) C, C,L( T- ` e+') +'	+'\9ELL&& 9x OQfgN)/1M N) hN)b"K 2 2 "KJ  I,'=?[ I,I,X  XM57K XMXMv  LM$:<U LMLM^  YM"8:Q YMYMr.   