Ë
    T^(h4— ã                   ó  — d Z ddlZddlm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 ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZ ddl m!Z!  ejD                  e#«      Z$dZ%dZ&e G d„ de«      «       Z'e G d„ de«      «       Z(e G d„ de«      «       Z)e G d„ de«      «       Z*e G d„ de«      «       Z+e G d„ de«      «       Z,e G d„ de«      «       Z-e G d„ d e«      «       Z.e G d!„ d"e«      «       Z/e G d#„ d$e«      «       Z0 G d%„ d&e
jb                  «      Z2 G d'„ d(e
jb                  «      Z3 G d)„ d*e
jb                  «      Z4 G d+„ d,e
jb                  «      Z5 G d-„ d.e
jb                  «      Z6 G d/„ d0e
jb                  «      Z7 G d1„ d2e
jb                  «      Z8 G d3„ d4e
jb                  «      Z9 G d5„ d6e
jb                  «      Z: G d7„ d8e
jb                  «      Z; G d9„ d:e
jb                  «      Z< G d;„ d<e
jb                  «      Z= G d=„ d>e«      Z>d?Z?d@Z@ edAe?«       G dB„ dCe>«      «       ZAdD„ ZB G dE„ dFe
jb                  «      ZC edGe?«       G dH„ dIe>«      «       ZD edJe?«       G dK„ dLe>«      «       ZE edMe?«       G dN„ dOe>«      «       ZF edPe?«       G dQ„ dRe>«      «       ZG edSe?«       G dT„ dUe>«      «       ZH edVe?«       G dW„ dXe>«      «       ZI edYe?«       G dZ„ d[e>«      «       ZJ ed\e?«       G d]„ d^e>«      «       ZKg d_¢ZLy)`zPyTorch LUKE model.é    N)Ú	dataclass)ÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FNÚgelu)ÚBaseModelOutputÚBaseModelOutputWithPooling)ÚPreTrainedModel)Úapply_chunking_to_forward)ÚModelOutputÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú
LukeConfigr   zstudio-ousia/luke-basec                   ól   — e Zd ZU dZdZeej                     ed<   dZ	ee
ej                  df      ed<   y)ÚBaseLukeModelOutputWithPoolinga  
    Base class for outputs of the LUKE model.

    Args:
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the model.
        entity_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, entity_length, hidden_size)`):
            Sequence of entity hidden-states at the output of the last layer of the model.
        pooler_output (`torch.FloatTensor` of shape `(batch_size, hidden_size)`):
            Last layer hidden-state of the first token of the sequence (classification token) further processed by a
            Linear layer and a Tanh activation function.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
            plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length +
            entity_length, sequence_length + entity_length)`. Attentions weights after the attention softmax, used to
            compute the weighted average in the self-attention heads.
    NÚentity_last_hidden_state.Úentity_hidden_states©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚtorchÚFloatTensorÚ__annotations__r   r   © ó    úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/luke/modeling_luke.pyr   r   /   ó@   … ñð2 =AÐ˜h u×'8Ñ'8Ñ9Ó@ØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÔHr'   r   c                   ól   — e Zd ZU dZdZeej                     ed<   dZ	ee
ej                  df      ed<   y)ÚBaseLukeModelOutputa#  
    Base class for model's outputs, with potential hidden states and attentions.

    Args:
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the model.
        entity_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, entity_length, hidden_size)`):
            Sequence of entity hidden-states at the output of the last layer of the model.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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   .r   r   r&   r'   r(   r+   r+   N   r)   r'   r+   c                   ól  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeeej                        ed<   dZeeej                  d	f      ed
<   dZeeej                  d	f      ed<   y)ÚLukeMaskedLMOutputa>	  
    Base class for model's outputs, with potential hidden states and attentions.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            The sum of masked language modeling (MLM) loss and entity prediction loss.
        mlm_loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Masked language modeling (MLM) loss.
        mep_loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Masked entity prediction (MEP) loss.
        logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
        entity_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the entity prediction head (scores for each entity vocabulary token before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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ÚlossÚmlm_lossÚmep_lossÚlogitsÚentity_logitsÚhidden_states.r   Ú
attentions)r   r    r!   r"   r.   r   r#   r$   r%   r/   r0   r1   r2   r3   r   r   r4   r&   r'   r(   r-   r-   m   sË   … ñð> )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø,0€Hˆh�u×(Ñ(Ñ)Ó0Ø,0€Hˆh�u×(Ñ(Ñ)Ó0Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø15€M�8˜E×-Ñ-Ñ.Ó5Ø8<€M�8˜E %×"3Ñ"3Ñ4Ñ5Ó<ØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÓHØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r'   r-   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚEntityClassificationOutputay  
    Outputs of entity classification models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
            Classification scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
            plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   ©r   r    r!   r"   r.   r   r#   r$   r%   r1   r3   r   r   r4   r&   r'   r(   r6   r6   ˜   ó‘   … ñð, )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÓHØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r'   r6   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚEntityPairClassificationOutputa~  
    Outputs of entity pair classification models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
            Classification scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
            plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   r7   r&   r'   r(   r:   r:   ·   r8   r'   r:   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚEntitySpanClassificationOutputa�  
    Outputs of entity span classification models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, entity_length, config.num_labels)`):
            Classification scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer
            plus the initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   r7   r&   r'   r(   r<   r<   Ö   r8   r'   r<   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚLukeSequenceClassifierOutputa  
    Outputs of sentence classification models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Classification (or regression if config.num_labels==1) loss.
        logits (`torch.FloatTensor` of shape `(batch_size, config.num_labels)`):
            Classification (or regression if config.num_labels==1) scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   r7   r&   r'   r(   r>   r>   õ   ó‘   … ñð2 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÓHØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r'   r>   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚLukeTokenClassifierOutputaÖ  
    Base class for outputs of token classification models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided) :
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_labels)`):
            Classification scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   r7   r&   r'   r(   rA   rA     r?   r'   rA   c                   ó   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed	<   y)
Ú LukeQuestionAnsweringModelOutputay  
    Outputs of question answering models.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.
        start_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
            Span-start scores (before SoftMax).
        end_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
            Span-end scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   Ústart_logitsÚ
end_logits.r3   r   r4   )r   r    r!   r"   r.   r   r#   r$   r%   rD   rE   r3   r   r   r4   r&   r'   r(   rC   rC   9  s¦   … ñð6 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø04€L�(˜5×,Ñ,Ñ-Ó4Ø.2€J�˜×*Ñ*Ñ+Ó2Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÓHØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r'   rC   c                   óø   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eeej                  df      ed<   dZeeej                  df      ed<   dZeeej                  df      ed<   y)	ÚLukeMultipleChoiceModelOutputa  
    Outputs of multiple choice models.

    Args:
        loss (`torch.FloatTensor` of shape *(1,)*, *optional*, returned when `labels` is provided):
            Classification loss.
        logits (`torch.FloatTensor` of shape `(batch_size, num_choices)`):
            *num_choices* is the second dimension of the input tensors. (see *input_ids* above).

            Classification scores (before SoftMax).
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
        entity_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, entity_length, hidden_size)`. Entity hidden-states of the model at the output of each
            layer plus the initial entity embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (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.   r1   .r3   r   r4   r7   r&   r'   r(   rG   rG   ^  s‘   … ñð6 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø*.€FˆH�U×&Ñ&Ñ'Ó.Ø=A€M�8˜E %×"3Ñ"3°SÐ"8Ñ9Ñ:ÓAØDHÐ˜( 5¨×):Ñ):¸CÐ)?Ñ#@ÑAÓHØ:>€J�˜˜u×0Ñ0°#Ð5Ñ6Ñ7Ô>r'   rG   c                   ó8   ‡ — e Zd ZdZˆ fd„Z	 	 	 	 dd„Zd„ Zˆ xZS )ÚLukeEmbeddingszV
    Same as BertEmbeddings with a tiny tweak for positional embeddings indexing.
    c                 ó”  •— t         ‰| �  «        t        j                  |j                  |j
                  |j                  ¬«      | _        t        j                  |j                  |j
                  «      | _	        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        |j                  | _        t        j                  |j                  |j
                  | j"                  ¬«      | _	        y )N©Úpadding_idx©Úeps)ÚsuperÚ__init__r   Ú	EmbeddingÚ
vocab_sizeÚhidden_sizeÚpad_token_idÚword_embeddingsÚmax_position_embeddingsÚposition_embeddingsÚtype_vocab_sizeÚtoken_type_embeddingsÚ	LayerNormÚlayer_norm_epsÚDropoutÚhidden_dropout_probÚdropoutrL   ©ÚselfÚconfigÚ	__class__s     €r(   rP   zLukeEmbeddings.__init__‡  så   ø€ Ü‰ÑÔÜ!Ÿ|™|¨F×,=Ñ,=¸v×?QÑ?QÐ_e×_rÑ_rÔsˆÔÜ#%§<¡<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ Ü%'§\¡\°&×2HÑ2HÈ&×J\ÑJ\Ó%]ˆÔ"ô Ÿ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒð "×.Ñ.ˆÔÜ#%§<¡<Ø×*Ñ*¨F×,>Ñ,>ÈD×L\ÑL\ô$
ˆÕ r'   c                 ó  — |€C|�0t        || j                  «      j                  |j                  «      }n| j	                  |«      }|�|j                  «       }n|j                  «       d d }|€:t        j                  |t        j                  | j                  j                  ¬«      }|€| j                  |«      }| j                  |«      }| j                  |«      }||z   |z   }| j                  |«      }| j                  |«      }|S )Néÿÿÿÿ©ÚdtypeÚdevice)Ú"create_position_ids_from_input_idsrL   Útorg   Ú&create_position_ids_from_inputs_embedsÚsizer#   ÚzerosÚlongÚposition_idsrU   rW   rY   rZ   r^   )	r`   Ú	input_idsÚtoken_type_idsrn   Úinputs_embedsÚinput_shaperW   rY   Ú
embeddingss	            r(   ÚforwardzLukeEmbeddings.forward˜  sþ   € ð ÐØÐ$äAÀ)ÈT×M]ÑM]Ó^×aÑaÐbk×brÑbrÓs‘à#×JÑJÈ=ÓY�àÐ Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKàÐ!Ü"Ÿ[™[¨¼E¿J¹JÈt×O`ÑO`×OgÑOgÔhˆNàÐ Ø ×0Ñ0°Ó;ˆMà"×6Ñ6°|ÓDÐØ $× :Ñ :¸>Ó JÐà"Ð%8Ñ8Ð;PÑPˆ
Ø—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr'   c                 ó  — |j                  «       dd }|d   }t        j                  | j                  dz   || j                  z   dz   t        j                  |j
                  ¬«      }|j                  d«      j                  |«      S )z×
        We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.

        Args:
            inputs_embeds: torch.Tensor

        Returns: torch.Tensor
        Nrd   r   re   r   )rk   r#   ÚarangerL   rm   rg   Ú	unsqueezeÚexpand)r`   rq   rr   Úsequence_lengthrn   s        r(   rj   z5LukeEmbeddings.create_position_ids_from_inputs_embeds¹  s€   € ð $×(Ñ(Ó*¨3¨BÐ/ˆØ% a™.ˆä—|‘|Ø×Ñ˜qÑ  /°D×4DÑ4DÑ"DÀqÑ"HÔPU×PZÑPZÐcp×cwÑcwô
ˆð ×%Ñ% aÓ(×/Ñ/°Ó<Ð<r'   )NNNN)r   r    r!   r"   rP   rt   rj   Ú__classcell__©rb   s   @r(   rI   rI   ‚  s&   ø„ ñô
ð& ØØØóöB=r'   rI   c                   ó~   ‡ — e Zd Zdefˆ fd„Z	 ddej                  dej                  deej                     fd„Zˆ xZ	S )ÚLukeEntityEmbeddingsra   c                 óŠ  •— t         ‰| �  «        || _        t        j                  |j
                  |j                  d¬«      | _        |j                  |j                  k7  r1t        j                  |j                  |j                  d¬«      | _
        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                   ¬«      | _        t        j"                  |j$                  «      | _        y )Nr   rK   F©ÚbiasrM   )rO   rP   ra   r   rQ   Úentity_vocab_sizeÚentity_emb_sizeÚentity_embeddingsrS   ÚLinearÚentity_embedding_denserV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   s     €r(   rP   zLukeEntityEmbeddings.__init__Ì  sà   ø€ Ü‰ÑÔØˆŒä!#§¡¨f×.FÑ.FÈ×H^ÑH^ÐlmÔ!nˆÔØ×!Ñ! V×%7Ñ%7Ò7Ü*,¯)©)°F×4JÑ4JÈF×L^ÑL^ÐejÔ*kˆDÔ'ä#%§<¡<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ Ü%'§\¡\°&×2HÑ2HÈ&×J\ÑJ\Ó%]ˆÔ"äŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r'   Ú
entity_idsrn   rp   c                 óR  — |€t        j                  |«      }| j                  |«      }| j                  j                  | j                  j
                  k7  r| j                  |«      }| j                  |j                  d¬«      «      }|dk7  j                  |«      j                  d«      }||z  }t        j                  |d¬«      }||j                  d¬«      j                  d¬«      z  }| j                  |«      }||z   |z   }| j                  |«      }| j                  |«      }|S )Nr   )Úminrd   éþÿÿÿ©ÚdimgH¯¼šò×z>)r#   Ú
zeros_likerƒ   ra   r‚   rS   r…   rW   ÚclampÚtype_asrw   ÚsumrY   rZ   r^   )	r`   r†   rn   rp   rƒ   rW   Úposition_embedding_maskrY   rs   s	            r(   rt   zLukeEntityEmbeddings.forwardÚ  s'  € ð Ð!Ü"×-Ñ-¨jÓ9ˆNà ×2Ñ2°:Ó>ÐØ�;‰;×&Ñ&¨$¯+©+×*AÑ*AÒAØ $× ;Ñ ;Ð<MÓ NÐà"×6Ñ6°|×7IÑ7IÈaÐ7IÓ7PÓQÐØ#/°2Ñ#5×">Ñ">Ð?RÓ"S×"]Ñ"]Ð^`Ó"aÐØ1Ð4KÑKÐÜ#Ÿi™iÐ(;ÀÔDÐØ1Ð4K×4OÑ4OÐTVÐ4OÓ4W×4]Ñ4]ÐbfÐ4]Ó4gÑgÐà $× :Ñ :¸>Ó JÐà&Ð)<Ñ<Ð?TÑTˆ
Ø—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
àÐr'   ©N)
r   r    r!   r   rP   r#   Ú
LongTensorr   rt   rz   r{   s   @r(   r}   r}   Ë  sL   ø„ ð>˜zõ >ð$ 6:ñ	à×$Ñ$ðð ×&Ñ&ðð ! ×!1Ñ!1Ñ2÷	r'   r}   c                   ó2   ‡ — e Zd Zˆ fd„Zd„ Z	 	 	 dd„Zˆ xZS )ÚLukeSelfAttentionc                 ó   •— t         ‰| �  «        |j                  |j                  z  dk7  r2t	        |d«      s&t        d|j                  › d|j                  › d�«      ‚|j                  | _        t        |j                  |j                  z  «      | _        | j                  | j                  z  | _        |j                  | _	        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        | j                  r�t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j$                  |j&                  «      | _        y )Nr   Úembedding_sizezThe hidden size z4 is not a multiple of the number of attention heads ú.)rO   rP   rS   Únum_attention_headsÚhasattrÚ
ValueErrorÚintÚattention_head_sizeÚall_head_sizeÚuse_entity_aware_attentionr   r„   ÚqueryÚkeyÚvalueÚ	w2e_queryÚ	e2w_queryÚ	e2e_queryr\   Úattention_probs_dropout_probr^   r_   s     €r(   rP   zLukeSelfAttention.__init__÷  s�  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Ñ:¸aÒ?ÌÐPVÐXhÔHiÜØ" 6×#5Ñ#5Ð"6ð 7Ø×3Ñ3Ð4°Að7óð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔØ*0×*KÑ*KˆÔ'ä—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
Ü—9‘9˜V×/Ñ/°×1CÑ1CÓDˆŒÜ—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
à×*Ò*ÜŸY™Y v×'9Ñ'9¸4×;MÑ;MÓNˆDŒNÜŸY™Y v×'9Ñ'9¸4×;MÑ;MÓNˆDŒNÜŸY™Y v×'9Ñ'9¸4×;MÑ;MÓNˆDŒNä—z‘z &×"EÑ"EÓFˆ�r'   c                 ó    — |j                  «       d d | j                  | j                  fz   } |j                  |Ž }|j	                  dddd«      S )Nrd   r   é   r   r   )rk   r˜   rœ   ÚviewÚpermute)r`   ÚxÚnew_x_shapes      r(   Útranspose_for_scoresz&LukeSelfAttention.transpose_for_scores  sN   € Ø—f‘f“h˜s �m t×'?Ñ'?À×AYÑAYÐ&ZÑZˆØˆA�F‰F�KÐ ˆØ�y‰y˜˜A˜q !Ó$Ð$r'   c                 óÐ  — |j                  d«      }|€|}nt        j                  ||gd¬«      }| j                  | j	                  |«      «      }| j                  | j                  |«      «      }	| j                  �r«|��¨| j                  | j                  |«      «      }
| j                  | j                  |«      «      }| j                  | j                  |«      «      }| j                  | j                  |«      «      }|d d …d d …d |…d d …f   }|d d …d d …d |…d d …f   }|d d …d d …|d …d d …f   }|d d …d d …|d …d d …f   }t        j                  |
|j                  dd«      «      }t        j                  ||j                  dd«      «      }t        j                  ||j                  dd«      «      }t        j                  ||j                  dd«      «      }t        j                  ||gd¬«      }t        j                  ||gd¬«      }t        j                  ||gd¬«      }nF| j                  | j                  |«      «      }t        j                  ||j                  dd«      «      }|t        j                  | j                  «      z  }|�||z   }t         j"                  j%                  |d¬«      }| j'                  |«      }|�||z  }t        j                  ||	«      }|j)                  dddd«      j+                  «       }|j                  «       d d | j,                  fz   } |j.                  |Ž }|d d …d |…d d …f   }|€d }n|d d …|d …d d …f   }|r|||f}|S ||f}|S )Nr   rŠ   rd   r‰   r   r§   r   )rk   r#   Úcatr¬   r    r¡   rž   rŸ   r¢   r£   r¤   ÚmatmulÚ	transposeÚmathÚsqrtrœ   r   Ú
functionalÚsoftmaxr^   r©   Ú
contiguousr�   r¨   ) r`   Úword_hidden_statesr   Úattention_maskÚ	head_maskÚoutput_attentionsÚ	word_sizeÚconcat_hidden_statesÚ	key_layerÚvalue_layerÚw2w_query_layerÚw2e_query_layerÚe2w_query_layerÚe2e_query_layerÚw2w_key_layerÚe2w_key_layerÚw2e_key_layerÚe2e_key_layerÚw2w_attention_scoresÚw2e_attention_scoresÚe2w_attention_scoresÚe2e_attention_scoresÚword_attention_scoresÚentity_attention_scoresÚattention_scoresÚquery_layerÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutput_word_hidden_statesÚoutput_entity_hidden_statesÚoutputss                                    r(   rt   zLukeSelfAttention.forward  sx  € ð '×+Ñ+¨AÓ.ˆ	àÐ'Ø#5Ñ ä#(§9¡9Ð.@ÐBVÐ-WÐ]^Ô#_Ð à×-Ñ-¨d¯h©hÐ7KÓ.LÓMˆ	Ø×/Ñ/°·
±
Ð;OÓ0PÓQˆà×*Ó*Ð/CÑ/Oð #×7Ñ7¸¿
¹
ÐCUÓ8VÓWˆOØ"×7Ñ7¸¿¹ÐGYÓ8ZÓ[ˆOØ"×7Ñ7¸¿¹ÐG[Ó8\Ó]ˆOØ"×7Ñ7¸¿¹ÐG[Ó8\Ó]ˆOð &¢aª¨J¨Y¨JºÐ&9Ñ:ˆMØ%¢aª¨J¨Y¨JºÐ&9Ñ:ˆMØ%¢aª¨I©JºÐ&9Ñ:ˆMØ%¢aª¨I©JºÐ&9Ñ:ˆMô $)§<¡<°À×AXÑAXÐY[Ð]_ÓA`Ó#aÐ Ü#(§<¡<°À×AXÑAXÐY[Ð]_ÓA`Ó#aÐ Ü#(§<¡<°À×AXÑAXÐY[Ð]_ÓA`Ó#aÐ Ü#(§<¡<°À×AXÑAXÐY[Ð]_ÓA`Ó#aÐ ô %*§I¡IÐ/CÐEYÐ.ZÐ`aÔ$bÐ!Ü&+§i¡iÐ1EÐG[Ð0\ÐbcÔ&dÐ#Ü$Ÿy™yÐ*?ÐAXÐ)YÐ_`ÔaÑð ×3Ñ3°D·J±JÐ?SÓ4TÓUˆKÜ$Ÿ|™|¨K¸×9LÑ9LÈRÐQSÓ9TÓUÐà+¬d¯i©i¸×8PÑ8PÓ.QÑQÐØÐ%à/°.Ñ@Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆð Ð Ø-°	Ñ9ˆOäŸ™ _°kÓBˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÑ"SÐØ*˜×*Ñ*Ð,CÐDˆà$1²!°Z°i°ZÂÐ2BÑ$CÐ!ØÐ'Ø*.Ñ'à*7º¸9¹:ÂqÐ8HÑ*IÐ'áØ0Ð2MÈÐ_ˆGð ˆð 1Ð2MÐNˆGàˆr'   ©NNF)r   r    r!   rP   r¬   rt   rz   r{   s   @r(   r”   r”   ö  s   ø„ ôGò0%ð ØØ÷Pr'   r”   c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )ÚLukeSelfOutputc                 ó(  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  «      | _
        y ©NrM   )rO   rP   r   r„   rS   ÚdenserZ   r[   r\   r]   r^   r_   s     €r(   rP   zLukeSelfOutput.__init__i  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r'   r3   Úinput_tensorÚreturnc                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r‘   ©rÙ   r^   rZ   ©r`   r3   rÚ   s      r(   rt   zLukeSelfOutput.forwardo  ó7   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ }°|Ñ'CÓDˆØÐr'   ©r   r    r!   rP   r#   ÚTensorrt   rz   r{   s   @r(   rÖ   rÖ   h  ó1   ø„ ô>ð U§\¡\ð ÀÇÁð ÐRW×R^ÑR^÷ r'   rÖ   c                   ó2   ‡ — e Zd Zˆ fd„Zd„ Z	 	 	 dd„Zˆ xZS )ÚLukeAttentionc                 ó€   •— t         ‰| �  «        t        |«      | _        t	        |«      | _        t        «       | _        y r‘   )rO   rP   r”   r`   rÖ   ÚoutputÚsetÚpruned_headsr_   s     €r(   rP   zLukeAttention.__init__w  s0   ø€ Ü‰ÑÔÜ% fÓ-ˆŒ	Ü$ VÓ,ˆŒÜ›EˆÕr'   c                 ó   — t        d«      ‚©Nz4LUKE does not support the pruning of attention heads©ÚNotImplementedError)r`   Úheadss     r(   Úprune_headszLukeAttention.prune_heads}  ó   € Ü!Ð"XÓYÐYr'   c                 óF  — |j                  d«      }| j                  |||||«      }|€|d   }|}	n3t        j                  |d d d¬«      }t        j                  ||gd¬«      }	| j	                  ||	«      }
|
d d …d |…d d …f   }|€d }n|
d d …|d …d d …f   }||f|dd  z   }|S )Nr   r   r§   rŠ   )rk   r`   r#   r®   ræ   )r`   r¶   r   r·   r¸   r¹   rº   Úself_outputsÚconcat_self_outputsr»   Úattention_outputÚword_attention_outputÚentity_attention_outputrÓ   s                 r(   rt   zLukeAttention.forward€  sã   € ð '×+Ñ+¨AÓ.ˆ	Ø—y‘yØØ ØØØó
ˆð  Ð'Ø".¨q¡/ÐØ#5Ñ ä"'§)¡)¨L¸¸!Ð,<À!Ô"DÐÜ#(§9¡9Ð.@ÐBVÐ-WÐ]^Ô#_Ð àŸ;™;Ð':Ð<PÓQÐà 0²°J°Y°JÂÐ1AÑ BÐØÐ'Ø&*Ñ#à&6²q¸)¹*ÂaÐ7GÑ&HÐ#ð )Ð*AÐBÀ\ÐRSÐRTÐEUÑUˆàˆr'   rÔ   )r   r    r!   rP   rî   rt   rz   r{   s   @r(   rä   rä   v  s   ø„ ô"òZð ØØ÷"r'   rä   c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚLukeIntermediatec                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        |j                  t        «      rt        |j                     | _        y |j                  | _        y r‘   )rO   rP   r   r„   rS   Úintermediate_sizerÙ   Ú
isinstanceÚ
hidden_actÚstrr   Úintermediate_act_fnr_   s     €r(   rP   zLukeIntermediate.__init__§  s]   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬Ô-Ü'-¨f×.?Ñ.?Ñ'@ˆDÕ$à'-×'8Ñ'8ˆDÕ$r'   r3   rÛ   c                 óJ   — | j                  |«      }| j                  |«      }|S r‘   )rÙ   rý   ©r`   r3   s     r(   rt   zLukeIntermediate.forward¯  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐr'   rà   r{   s   @r(   r÷   r÷   ¦  s#   ø„ ô9ð U§\¡\ð °e·l±l÷ r'   r÷   c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )Ú
LukeOutputc                 ó(  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y rØ   )rO   rP   r   r„   rù   rS   rÙ   rZ   r[   r\   r]   r^   r_   s     €r(   rP   zLukeOutput.__init__·  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r'   r3   rÚ   rÛ   c                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r‘   rÝ   rÞ   s      r(   rt   zLukeOutput.forward½  rß   r'   rà   r{   s   @r(   r  r  ¶  râ   r'   r  c                   ó2   ‡ — e Zd Zˆ fd„Z	 	 	 dd„Zd„ Zˆ xZS )Ú	LukeLayerc                 ó²   •— t         ‰| �  «        |j                  | _        d| _        t	        |«      | _        t        |«      | _        t        |«      | _	        y ©Nr   )
rO   rP   Úchunk_size_feed_forwardÚseq_len_dimrä   Ú	attentionr÷   Úintermediater  ræ   r_   s     €r(   rP   zLukeLayer.__init__Å  sI   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ& vÓ.ˆŒÜ,¨VÓ4ˆÔÜ  Ó(ˆ�r'   c                 óJ  — |j                  d«      }| j                  |||||¬«      }|€|d   }nt        j                  |d d d¬«      }|dd  }	t	        | j
                  | j                  | j                  |«      }
|
d d …d |…d d …f   }|€d }n|
d d …|d …d d …f   }||f|	z   }	|	S )Nr   )r¹   r   r§   rŠ   )rk   r
  r#   r®   r   Úfeed_forward_chunkr  r	  )r`   r¶   r   r·   r¸   r¹   rº   Úself_attention_outputsÚconcat_attention_outputrÓ   Úlayer_outputÚword_layer_outputÚentity_layer_outputs                r(   rt   zLukeLayer.forwardÍ  sã   € ð '×+Ñ+¨AÓ.ˆ	à!%§¡ØØ ØØØ/ð "0ó "
Ðð  Ð'Ø&<¸QÑ&?Ñ#ä&+§i¡iÐ0FÀrÈÐ0JÐPQÔ&RÐ#à(¨¨Ð,ˆä0Ø×#Ñ# T×%AÑ%AÀ4×CSÑCSÐUló
ˆð )ª¨J¨Y¨JºÐ)9Ñ:ÐØÐ'Ø"&Ñà".ªq°)±*ºaÐ/?Ñ"@Ðà$Ð&9Ð:¸WÑDˆàˆr'   c                 óL   — | j                  |«      }| j                  ||«      }|S r‘   )r  ræ   )r`   ró   Úintermediate_outputr  s       r(   r  zLukeLayer.feed_forward_chunkò  s,   € Ø"×/Ñ/Ð0@ÓAÐØ—{‘{Ð#6Ð8HÓIˆØÐr'   rÔ   )r   r    r!   rP   rt   r  rz   r{   s   @r(   r  r  Ä  s   ø„ ô)ð ØØó#öJr'   r  c                   ó0   ‡ — e Zd Zˆ fd„Z	 	 	 	 	 dd„Zˆ xZS )ÚLukeEncoderc                 óÐ   •— t         ‰| �  «        || _        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        d| _	        y c c}w )NF)
rO   rP   ra   r   Ú
ModuleListÚrangeÚnum_hidden_layersr  ÚlayerÚgradient_checkpointing)r`   ra   Ú_rb   s      €r(   rP   zLukeEncoder.__init__ù  sN   ø€ Ü‰ÑÔØˆŒÜ—]‘]¼uÀV×E]ÑE]Ó?^Ö#_¸!¤I¨fÕ$5Ò#_Ó`ˆŒ
Ø&+ˆÕ#ùò $`s   ½A#c           	      ó¶  — |rdnd }|rdnd }	|rdnd }
t        | j                  «      D ]y  \  }}|r||fz   }|	|fz   }	|�||   nd }| j                  r-| j                  r!| j	                  |j
                  |||||«      }n ||||||«      }|d   }|�|d   }|sŒq|
|d   fz   }
Œ{ |r||fz   }|	|fz   }	|st        d„ |||
||	fD «       «      S t        |||
||	¬«      S )Nr&   r   r   r§   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   ©Ú.0Úvs     r(   ú	<genexpr>z&LukeEncoder.forward.<locals>.<genexpr>2  ó   è ø€ ò 
àð �=ô ñ
ùó   ‚)Úlast_hidden_stater3   r4   r   r   )Ú	enumerater  r  ÚtrainingÚ_gradient_checkpointing_funcÚ__call__Útupler+   )r`   r¶   r   r·   r¸   r¹   Úoutput_hidden_statesÚreturn_dictÚall_word_hidden_statesÚall_entity_hidden_statesÚall_self_attentionsÚiÚlayer_moduleÚlayer_head_maskÚlayer_outputss                  r(   rt   zLukeEncoder.forwardÿ  si  € ñ (<¡ÀÐÙ)=¡2À4Ð Ù$5™b¸4Ðä(¨¯©Ó4ò 	P‰OˆAˆ|Ù#Ø)?ÐCUÐBWÑ)WÐ&Ø+CÐG[ÐF]Ñ+]Ð(à.7Ð.C˜i¨šlÈˆOØ×*Ò*¨t¯}ª}Ø $× AÑ AØ ×)Ñ)Ø&Ø(Ø"Ø#Ø%ó!‘ñ !-Ø&Ø(Ø"Ø#Ø%ó!�ð "/¨qÑ!1Ðà#Ð/Ø'4°QÑ'7Ð$â Ø&9¸]È1Ñ=MÐ<OÑ&OÑ#ð=	Pñ@  Ø%;Ð?QÐ>SÑ%SÐ"Ø'?ÐCWÐBYÑ'YÐ$áÜñ 
ð 'Ø*Ø'Ø(Ø,ðô
ó 
ð 
ô #Ø0Ø0Ø*Ø%9Ø!9ô
ð 	
r'   )NNFFT©r   r    r!   rP   rt   rz   r{   s   @r(   r  r  ø  s   ø„ ô,ð ØØØ"Ø÷D
r'   r  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )Ú
LukePoolerc                 ó²   •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  «       | _        y r‘   )rO   rP   r   r„   rS   rÙ   ÚTanhÚ
activationr_   s     €r(   rP   zLukePooler.__init__H  s9   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ'™'›)ˆ�r'   r3   rÛ   c                 ó\   — |d d …df   }| j                  |«      }| j                  |«      }|S )Nr   )rÙ   r:  )r`   r3   Úfirst_token_tensorÚpooled_outputs       r(   rt   zLukePooler.forwardM  s6   € ð +ª1¨a¨4Ñ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐr'   rà   r{   s   @r(   r7  r7  G  s#   ø„ ô$ð
 U§\¡\ð °e·l±l÷ r'   r7  c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚEntityPredictionHeadTransformc                 óh  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        |j                  t        «      rt        |j                     | _        n|j                  | _        t        j                  |j
                  |j                  ¬«      | _        y rØ   )rO   rP   r   r„   rS   r‚   rÙ   rú   rû   rü   r   Útransform_act_fnrZ   r[   r_   s     €r(   rP   z&EntityPredictionHeadTransform.__init__W  s{   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3IÑ3IÓJˆŒ
Ü�f×'Ñ'¬Ô-Ü$*¨6×+<Ñ+<Ñ$=ˆDÕ!à$*×$5Ñ$5ˆDÔ!ÜŸ™ f×&<Ñ&<À&×BWÑBWÔXˆ�r'   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r‘   )rÙ   rA  rZ   rÿ   s     r(   rt   z%EntityPredictionHeadTransform.forward`  s4   € ØŸ
™
 =Ó1ˆØ×-Ñ-¨mÓ<ˆØŸ™ }Ó5ˆØÐr'   r5  r{   s   @r(   r?  r?  V  s   ø„ ôYör'   r?  c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚEntityPredictionHeadc                 ó   •— t         ‰| �  «        || _        t        |«      | _        t        j                  |j                  |j                  d¬«      | _	        t        j                  t        j                  |j                  «      «      | _        y )NFr   )rO   rP   ra   r?  Ú	transformr   r„   r‚   r�   ÚdecoderÚ	Parameterr#   rl   r€   r_   s     €r(   rP   zEntityPredictionHead.__init__h  sa   ø€ Ü‰ÑÔØˆŒÜ6°vÓ>ˆŒÜ—y‘y ×!7Ñ!7¸×9QÑ9QÐX]Ô^ˆŒÜ—L‘L¤§¡¨V×-EÑ-EÓ!FÓGˆ�	r'   c                 ód   — | j                  |«      }| j                  |«      | j                  z   }|S r‘   )rF  rG  r€   rÿ   s     r(   rt   zEntityPredictionHead.forwardo  s-   € ØŸ™ }Ó5ˆØŸ™ ]Ó3°d·i±iÑ?ˆàÐr'   r5  r{   s   @r(   rD  rD  g  s   ø„ ôHör'   rD  c                   óD   — e Zd ZdZeZdZdZddgZde	j                  fd„Zy)	ÚLukePreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚlukeTrä   r}   Úmodulec                 ój  — t        |t        j                  «      rm|j                  j                  j                  d| j                  j                  ¬«       |j                  �%|j                  j                  j                  «        yyt        |t        j                  «      r®|j                  dk(  r%|j                  j                  j                  «        n;|j                  j                  j                  d| j                  j                  ¬«       |j                  �2|j                  j                  |j                     j                  «        yyt        |t        j                  «      rJ|j                  j                  j                  «        |j                  j                  j                  d«       yy)zInitialize the weightsg        )ÚmeanÚstdNr   ç      ð?)rú   r   r„   ÚweightÚdataÚnormal_ra   Úinitializer_ranger€   Úzero_rQ   Úembedding_dimrL   rZ   Úfill_)r`   rM  s     r(   Ú_init_weightsz!LukePreTrainedModel._init_weights�  s(  € ä�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø×#Ñ# qÒ(Ø—‘×"Ñ"×(Ñ(Õ*à—‘×"Ñ"×*Ñ*°¸¿¹×9VÑ9VÐ*ÔWØ×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)ð .r'   N)r   r    r!   r"   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesr   ÚModulerY  r&   r'   r(   rK  rK  v  s6   „ ñð
 €LØÐØ&*Ð#Ø(Ð*@ÐAÐð* B§I¡Iô *r'   rK  a>  

    This model inherits from [`PreTrainedModel`]. 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 PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`LukeConfig`]): 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 (`torch.LongTensor` of shape `({0})`):
            Indices of input sequence tokens in the vocabulary.

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

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

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

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

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

            [What are token type IDs?](../glossary#token-type-ids)
        position_ids (`torch.LongTensor` 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)

        entity_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`):
            Indices of entity tokens in the entity vocabulary.

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

        entity_attention_mask (`torch.FloatTensor` of shape `(batch_size, entity_length)`, *optional*):
            Mask to avoid performing attention on padding entity token indices. Mask values selected in `[0, 1]`:

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

        entity_token_type_ids (`torch.LongTensor` of shape `(batch_size, entity_length)`, *optional*):
            Segment token indices to indicate first and second portions of the entity token inputs. Indices are
            selected in `[0, 1]`:

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

        entity_position_ids (`torch.LongTensor` of shape `(batch_size, entity_length, max_mention_length)`, *optional*):
            Indices of positions of each input entity in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

        inputs_embeds (`torch.FloatTensor` 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.

        head_mask (`torch.FloatTensor` 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**.

        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        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.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
z€The bare LUKE model transformer outputting raw hidden-states for both word tokens and entities without any specific head on top.c            !       óP  ‡ — e Zd Zddedefˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 eej                  d	«      «       eee¬
«      	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej&                     deej(                     deej&                     deej&                     deej&                     deej(                     deej&                     deej&                     deej(                     deej(                     dee   dee   dee   deeef   fd„«       «       Zdej&                  deej&                     fd„Zˆ xZS )Ú	LukeModelra   Úadd_pooling_layerc                 óÚ   •— t         ‰| �  |«       || _        t        |«      | _        t        |«      | _        t        |«      | _        |rt        |«      nd | _
        | j                  «        y r‘   )rO   rP   ra   rI   rs   r}   rƒ   r  Úencoderr7  ÚpoolerÚ	post_init)r`   ra   ra  rb   s      €r(   rP   zLukeModel.__init__ô  sX   ø€ Ü‰Ñ˜Ô ØˆŒä(¨Ó0ˆŒÜ!5°fÓ!=ˆÔÜ" 6Ó*ˆŒá,=”j Ô(À4ˆŒð 	�‰Õr'   c                 ó.   — | j                   j                  S r‘   ©rs   rU   ©r`   s    r(   Úget_input_embeddingszLukeModel.get_input_embeddings  s   € Ø�‰×.Ñ.Ð.r'   c                 ó&   — || j                   _        y r‘   rg  ©r`   r¡   s     r(   Úset_input_embeddingszLukeModel.set_input_embeddings  s   € Ø*/ˆ�‰Õ'r'   c                 ó.   — | j                   j                   S r‘   ©rƒ   rh  s    r(   Úget_entity_embeddingszLukeModel.get_entity_embeddings  s   € Ø×%Ñ%×7Ñ7Ð7r'   c                 ó&   — || j                   _         y r‘   rn  rk  s     r(   Úset_entity_embeddingszLukeModel.set_entity_embeddings
  s   € Ø38ˆ×ÑÕ0r'   c                 ó   — t        d«      ‚rê   rë   )r`   Úheads_to_prunes     r(   Ú_prune_headszLukeModel._prune_heads  rï   r'   úbatch_size, sequence_length©Úoutput_typerZ  ro   r·   rp   rn   r†   Úentity_attention_maskÚentity_token_type_idsÚentity_position_idsr¸   rq   r¹   r,  r-  rÛ   c           	      óˆ  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|
�t	        d«      ‚|�#| j                  ||«       |j                  «       }n!|
�|
j                  «       dd }nt	        d«      ‚|\  }}|�|j                  n|
j                  }|€t        j                  ||f|¬«      }|€&t        j                  |t        j                  |¬«      }|�V|j                  d«      }|€t        j                  ||f|¬«      }|€(t        j                  ||ft        j                  |¬«      }| j                  |	| j                   j                  «      }	| j                  ||||
¬«      }| j                  ||«      }|€d}n| j!                  |||«      }| j#                  ||||	|||¬	«      }|d
   }| j$                  �| j%                  |«      nd}|s
||f|dd z   S t'        |||j(                  |j*                  |j,                  |j.                  ¬«      S )u‰  

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, LukeModel

        >>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-base")
        >>> model = LukeModel.from_pretrained("studio-ousia/luke-base")
        # Compute the contextualized entity representation corresponding to the entity mention "BeyoncÃ©"

        >>> text = "BeyoncÃ© lives in Los Angeles."
        >>> entity_spans = [(0, 7)]  # character-based entity span corresponding to "BeyoncÃ©"

        >>> encoding = tokenizer(text, entity_spans=entity_spans, add_prefix_space=True, return_tensors="pt")
        >>> outputs = model(**encoding)
        >>> word_last_hidden_state = outputs.last_hidden_state
        >>> entity_last_hidden_state = outputs.entity_last_hidden_state
        # Input Wikipedia entities to obtain enriched contextualized representations of word tokens

        >>> text = "BeyoncÃ© lives in Los Angeles."
        >>> entities = [
        ...     "BeyoncÃ©",
        ...     "Los Angeles",
        ... ]  # Wikipedia entity titles corresponding to the entity mentions "BeyoncÃ©" and "Los Angeles"
        >>> entity_spans = [
        ...     (0, 7),
        ...     (17, 28),
        ... ]  # character-based entity spans corresponding to "BeyoncÃ©" and "Los Angeles"

        >>> encoding = tokenizer(
        ...     text, entities=entities, entity_spans=entity_spans, add_prefix_space=True, return_tensors="pt"
        ... )
        >>> outputs = model(**encoding)
        >>> word_last_hidden_state = outputs.last_hidden_state
        >>> entity_last_hidden_state = outputs.entity_last_hidden_state
        ```NzDYou cannot specify both input_ids and inputs_embeds at the same timerd   z5You have to specify either input_ids or inputs_embeds)rg   re   r   )ro   rn   rp   rq   )r·   r¸   r¹   r,  r-  r   )r&  Úpooler_outputr3   r4   r   r   )ra   r¹   r,  Úuse_return_dictrš   Ú%warn_if_padding_and_no_attention_maskrk   rg   r#   Úonesrl   rm   Úget_head_maskr  rs   Úget_extended_attention_maskrƒ   rc  rd  r   r3   r4   r   r   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r¹   r,  r-  rr   Ú
batch_sizeÚ
seq_lengthrg   Úentity_seq_lengthÚword_embedding_outputÚextended_attention_maskÚentity_embedding_outputÚencoder_outputsÚsequence_outputr=  s                            r(   rt   zLukeModel.forward  s„  € ðr 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*‰KØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUà!,Ñˆ
�JØ%.Ð%:�×!Ò!À×@TÑ@TˆàÐ!Ü"ŸZ™Z¨°ZÐ(@ÈÔPˆNØÐ!Ü"Ÿ[™[¨¼E¿J¹JÈvÔVˆNØÐ!Ø *§¡°Ó 2ÐØ$Ð,Ü(-¯
©
°JÐ@QÐ3RÐ[aÔ(bÐ%Ø$Ð,Ü(-¯©°ZÐARÐ4SÔ[`×[eÑ[eÐntÔ(uÐ%ð ×&Ñ& y°$·+±+×2OÑ2OÓPˆ	ð !%§¡ØØ%Ø)Ø'ð	 !0ó !
Ðð #'×"BÑ"BÀ>ÐShÓ"iÐð ÐØ&*Ñ#à&*×&<Ñ&<¸ZÐI\Ð^sÓ&tÐ#ð Ÿ,™,Ø!Ø#Ø2ØØ/Ø!5Ø#ð 'ó 
ˆð *¨!Ñ,ˆð 9=¿¹Ð8O˜Ÿ™ OÔ4ÐUYˆáØ# ]Ð3°oÀaÀbÐ6IÑIÐIä-Ø-Ø'Ø)×7Ñ7Ø&×1Ñ1Ø%4×%MÑ%MØ!0×!EÑ!Eô
ð 	
r'   Úword_attention_maskc                 ó�  — |}|�t        j                  ||gd¬«      }|j                  «       dk(  r|dd…ddd…dd…f   }n:|j                  «       dk(  r|dd…dddd…f   }nt        d|j                  › d�«      ‚|j                  | j                  ¬«      }d	|z
  t        j                  | j                  «      j                  z  }|S )
ac  
        Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

        Arguments:
            word_attention_mask (`torch.LongTensor`):
                Attention mask for word tokens with ones indicating tokens to attend to, zeros for tokens to ignore.
            entity_attention_mask (`torch.LongTensor`, *optional*):
                Attention mask for entity tokens with ones indicating tokens to attend to, zeros for tokens to ignore.

        Returns:
            `torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.
        Nrd   rŠ   r   r§   z&Wrong shape for attention_mask (shape ú))rf   rQ  )	r#   r®   r‹   rš   Úshaperi   rf   Úfinforˆ   )r`   rŠ  rx  r·   r†  s        r(   r�  z%LukeModel.get_extended_attention_maskœ  sÑ   € ð -ˆØ Ð,Ü"ŸY™Y¨Ð8MÐ'NÐTVÔWˆNà×ÑÓ 1Ò$Ø&4²Q¸ºaÂ°]Ñ&CÑ#Ø×ÑÓ! QÒ&Ø&4²Q¸¸dÂAÐ5EÑ&FÑ#äÐEÀn×FZÑFZÐE[Ð[\Ð]Ó^Ð^à"9×"<Ñ"<À4Ç:Á:Ð"<Ó"NÐØ#&Ð)@Ñ#@ÄEÇKÁKÐPT×PZÑPZÓD[×D_ÑD_Ñ"_ÐØ&Ð&r'   )T)NNNNNNNNNNNNN)r   r    r!   r   ÚboolrP   ri  rl  ro  rq  rt  r   ÚLUKE_INPUTS_DOCSTRINGÚformatr   r   Ú_CONFIG_FOR_DOCr   r#   r’   r$   r   r   rt   r�  rz   r{   s   @r(   r`  r`  î  sÙ  ø„ ñ˜zð ¸dõ ò/ò0ò8ò9òZñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+IÐXgÔhð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø,0Ø/3Ø&*ñH
à˜E×,Ñ,Ñ-ðH
ð ! ×!2Ñ!2Ñ3ðH
ð ! ×!1Ñ!1Ñ2ð	H
ð
 ˜u×/Ñ/Ñ0ðH
ð ˜U×-Ñ-Ñ.ðH
ð  (¨×(9Ñ(9Ñ:ðH
ð  (¨×(8Ñ(8Ñ9ðH
ð & e×&6Ñ&6Ñ7ðH
ð ˜E×-Ñ-Ñ.ðH
ð   × 1Ñ 1Ñ2ðH
ð $ D™>ðH
ð ' t™nðH
ð ˜d‘^ðH
ð 
ˆuÐ4Ð4Ñ	5òH
ó ió hðH
ðT'Ø#(×#3Ñ#3ð'ØLTÐUZ×UeÑUeÑLf÷'r'   r`  c                 ó¸   — | j                  |«      j                  «       }t        j                  |d¬«      j	                  |«      |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:
        x: torch.Tensor x:

    Returns: torch.Tensor
    r   rŠ   )Úner›   r#   ÚcumsumrŽ   rm   )ro   rL   ÚmaskÚincremental_indicess       r(   rh   rh   »  sP   € ð �<‰<˜Ó$×(Ñ(Ó*€DÜ Ÿ<™<¨°!Ô4×<Ñ<¸TÓBÀdÑJÐØ×#Ñ#Ó%¨Ñ3Ð3r'   c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )Ú
LukeLMHeadz*Roberta Head for masked language modeling.c                 óâ  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  |j                  «      | _
        t        j                  t        j                  |j                  «      «      | _        | j                  | j                  _        y rØ   )rO   rP   r   r„   rS   rÙ   rZ   r[   Ú
layer_normrR   rG  rH  r#   rl   r€   r_   s     €r(   rP   zLukeLMHead.__init__Ï  s—   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ,™, v×'9Ñ'9¸v×?TÑ?TÔUˆŒä—y‘y ×!3Ñ!3°V×5FÑ5FÓGˆŒÜ—L‘L¤§¡¨V×->Ñ->Ó!?Ó@ˆŒ	Ø ŸI™Iˆ�‰Õr'   c                 ó‚   — | j                  |«      }t        |«      }| j                  |«      }| j                  |«      }|S r‘   )rÙ   r   r›  rG  )r`   ÚfeaturesÚkwargsrª   s       r(   rt   zLukeLMHead.forwardØ  s;   € Ø�J‰J�xÓ ˆÜ�‹GˆØ�O‰O˜AÓˆð �L‰L˜‹Oˆàˆr'   c                 óÌ   — | j                   j                  j                  j                  dk(  r| j                  | j                   _        y | j                   j                  | _        y )NÚmeta)rG  r€   rg   Útyperh  s    r(   Ú_tie_weightszLukeLMHead._tie_weightsâ  sC   € ð �<‰<×Ñ×#Ñ#×(Ñ(¨FÒ2Ø $§	¡	ˆD�L‰LÕàŸ™×)Ñ)ˆD�Ir'   )r   r    r!   r"   rP   rt   r¢  rz   r{   s   @r(   r™  r™  Ì  s   ø„ Ù4ô&òö*r'   r™  z—
    The LUKE model with a language modeling head and entity prediction head on top for masked language modeling and
    masked entity prediction.
    c            %       óF  ‡ — e Zd Zg d¢Zˆ fd„Zˆ fd„Zd„ Zd„ Z ee	j                  d«      «       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                      d	eej"                     d
eej                      deej                      deej                      deej                      deej                      deej                      deej                      deej                      deej"                     deej"                     dee   dee   dee   deeef   f d„«       «       Zˆ xZS )ÚLukeForMaskedLM)zlm_head.decoder.weightzlm_head.decoder.biasz!entity_predictions.decoder.weightc                 óÖ   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        t        |«      | _        t        j                  «       | _
        | j                  «        y r‘   )rO   rP   r`  rL  r™  Úlm_headrD  Úentity_predictionsr   r	   Úloss_fnre  r_   s     €r(   rP   zLukeForMaskedLM.__init__õ  sQ   ø€ Ü‰Ñ˜Ô ä˜fÓ%ˆŒ	ä! &Ó)ˆŒÜ"6°vÓ">ˆÔä×*Ñ*Ó,ˆŒð 	�‰Õr'   c                 óª   •— t         ‰| �  «        | j                  | j                  j                  | j
                  j                  j                  «       y r‘   )rO   Útie_weightsÚ_tie_or_clone_weightsr§  rG  rL  rƒ   )r`   rb   s    €r(   rª  zLukeForMaskedLM.tie_weights  s:   ø€ Ü‰ÑÔØ×"Ñ" 4×#:Ñ#:×#BÑ#BÀDÇIÁI×D_ÑD_×DqÑDqÕrr'   c                 ó.   — | j                   j                  S r‘   ©r¦  rG  rh  s    r(   Úget_output_embeddingsz%LukeForMaskedLM.get_output_embeddings  s   € Ø�|‰|×#Ñ#Ð#r'   c                 ó&   — || j                   _        y r‘   r­  )r`   Únew_embeddingss     r(   Úset_output_embeddingsz%LukeForMaskedLM.set_output_embeddings	  s   € Ø-ˆ�‰Õr'   ru  rv  ro   r·   rp   rn   r†   rx  ry  rz  ÚlabelsÚentity_labelsr¸   rq   r¹   r,  r-  rÛ   c                 óJ  — |�|n| j                   j                  }| j                  ||||||||||||d¬«      }d}d}| j                  |j                  «      }|	�d|	j                  |j                  «      }	| j                  |j                  d| j                   j                  «      |	j                  d«      «      }|€|}d}d}|j                  �l| j                  |j                  «      }|
�O| j                  |j                  d| j                   j                  «      |
j                  d«      «      }|€|}n||z   }|s8t        d„ ||||||j                  |j                  |j                   fD «       «      S t#        ||||||j                  |j                  |j                   ¬«      S )aS  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
            config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
            loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`
        entity_labels (`torch.LongTensor` of shape `(batch_size, entity_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]`

        Returns:

        NT©ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r¹   r,  r-  rd   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z*LukeForMaskedLM.forward.<locals>.<genexpr>W  s   è ø€ ò àð �=ô ñùr%  )r.   r/   r0   r1   r2   r3   r   r4   )ra   r}  rL  r¦  r&  ri   rg   r¨  r¨   rR   r   r§  r�   r+  r3   r   r4   r-   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r²  r³  r¸   rq   r¹   r,  r-  rÓ   r.   r/   r1   r0   r2   s                         r(   rt   zLukeForMaskedLM.forward  sÂ  € ðD &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð  ˆàˆØ—‘˜g×7Ñ7Ó8ˆØÐà—Y‘Y˜vŸ}™}Ó-ˆFØ—|‘| F§K¡K°°D·K±K×4JÑ4JÓ$KÈVÏ[É[ÐY[Ë_Ó]ˆHØˆ|Ø�àˆØˆØ×+Ñ+Ð7Ø ×3Ñ3°G×4TÑ4TÓUˆMØÐ(ØŸ<™<¨×(:Ñ(:¸2¸t¿{¹{×?\Ñ?\Ó(]Ð_l×_qÑ_qÐrtÓ_uÓv�Ø�<Ø#‘Dà (™?�DáÜñ ð ØØØØ!Ø×)Ñ)Ø×0Ñ0Ø×&Ñ&ð	ôó ð ô "ØØØØØ'Ø!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô	
ð 		
r'   ©NNNNNNNNNNNNNNN)r   r    r!   Ú_tied_weights_keysrP   rª  r®  r±  r   r�  r‘  r   r-   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   r¤  r¤  ë  sÓ  ø„ ò qÐôôsò$ò.ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+=ÈOÔ\ð 15Ø6:Ø59Ø37Ø15Ø<@Ø<@Ø:>Ø-1Ø48Ø15Ø59Ø,0Ø/3Ø&*ñ!a
à˜E×,Ñ,Ñ-ða
ð ! ×!2Ñ!2Ñ3ða
ð ! ×!1Ñ!1Ñ2ð	a
ð
 ˜u×/Ñ/Ñ0ða
ð ˜U×-Ñ-Ñ.ða
ð  (¨×(8Ñ(8Ñ9ða
ð  (¨×(8Ñ(8Ñ9ða
ð & e×&6Ñ&6Ñ7ða
ð ˜×)Ñ)Ñ*ða
ð   × 0Ñ 0Ñ1ða
ð ˜E×-Ñ-Ñ.ða
ð   × 1Ñ 1Ñ2ða
ð $ D™>ða
ð ' t™nða
ð  ˜d‘^ð!a
ð" 
ˆuÐ(Ð(Ñ	)ò#a
ó ]ó hôa
r'   r¤  zº
    The LUKE model with a classification head on top (a linear layer on top of the hidden state of the first entity
    token) for entity classification tasks, such as Open Entity.
    c            #       ó  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )ÚLukeForEntityClassificationc                 ó,  •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r‘   ©rO   rP   r`  rL  Ú
num_labelsr   r\   r]   r^   r„   rS   Ú
classifierre  r_   s     €r(   rP   z$LukeForEntityClassification.__init__z  si   ø€ Ü‰Ñ˜Ô ä˜fÓ%ˆŒ	à ×+Ñ+ˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr'   ru  rv  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÛ   c                 óä  — |�|n| j                   j                  }| j                  |||||||||	|
||d¬«      }|j                  dd…ddd…f   }| j	                  |«      }| j                  |«      }d}|�˜|j                  |j                  «      }|j                  dk(  r!t        j                  j                  ||«      }nMt        j                  j                  |j                  d«      |j                  d«      j                  |«      «      }|s5t        d„ |||j                   |j"                  |j$                  fD «       «      S t'        |||j                   |j"                  |j$                  ¬«      S )	uÇ  
        labels (`torch.LongTensor` of shape `(batch_size,)` or `(batch_size, num_labels)`, *optional*):
            Labels for computing the classification loss. If the shape is `(batch_size,)`, the cross entropy loss is
            used for the single-label classification. In this case, labels should contain the indices that should be in
            `[0, ..., config.num_labels - 1]`. If the shape is `(batch_size, num_labels)`, the binary cross entropy
            loss is used for the multi-label classification. In this case, labels should only contain `[0, 1]`, where 0
            and 1 indicate false and true, respectively.

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, LukeForEntityClassification

        >>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-open-entity")
        >>> model = LukeForEntityClassification.from_pretrained("studio-ousia/luke-large-finetuned-open-entity")

        >>> text = "BeyoncÃ© lives in Los Angeles."
        >>> entity_spans = [(0, 7)]  # character-based entity span corresponding to "BeyoncÃ©"
        >>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="pt")
        >>> outputs = model(**inputs)
        >>> logits = outputs.logits
        >>> predicted_class_idx = logits.argmax(-1).item()
        >>> print("Predicted class:", model.config.id2label[predicted_class_idx])
        Predicted class: person
        ```NTrµ  r   r   rd   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z6LukeForEntityClassification.forward.<locals>.<genexpr>Ö  ó   è ø€ ò àØ�=ô ñùr%  ©r.   r1   r3   r   r4   )ra   r}  rL  r   r^   r¾  ri   rg   Úndimr   r³   Úcross_entropyÚ binary_cross_entropy_with_logitsr¨   rŽ   r+  r3   r   r4   r6   ©r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÓ   Úfeature_vectorr1   r.   s                      r(   rt   z#LukeForEntityClassification.forward†  sm  € ð\ &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð  !×9Ñ9º!¸QÂ¸'ÑBˆØŸ™ nÓ5ˆØ—‘ Ó0ˆàˆØÐð —Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{˜aÒÜ—}‘}×2Ñ2°6¸6ÓB‘ä—}‘}×EÑEÀfÇkÁkÐRTÃoÐW]×WbÑWbÐceÓWf×WnÑWnÐouÓWvÓw�áÜñ à ¨×(=Ñ(=¸w×?[Ñ?[Ð]d×]oÑ]oÐpôó ð ô *ØØØ!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   ©NNNNNNNNNNNNNN)r   r    r!   rP   r   r�  r‘  r   r6   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   rº  rº  r  s¢  ø„ ô
ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+EÐTcÔdð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø.2Ø,0Ø/3Ø&*ñZ
à˜E×,Ñ,Ñ-ðZ
ð ! ×!2Ñ!2Ñ3ðZ
ð ! ×!1Ñ!1Ñ2ð	Z
ð
 ˜u×/Ñ/Ñ0ðZ
ð ˜U×-Ñ-Ñ.ðZ
ð  (¨×(9Ñ(9Ñ:ðZ
ð  (¨×(8Ñ(8Ñ9ðZ
ð & e×&6Ñ&6Ñ7ðZ
ð ˜E×-Ñ-Ñ.ðZ
ð   × 1Ñ 1Ñ2ðZ
ð ˜×*Ñ*Ñ+ðZ
ð $ D™>ðZ
ð ' t™nðZ
ð ˜d‘^ðZ
ð  
ˆuÐ0Ð0Ñ	1ò!Z
ó eó hôZ
r'   rº  zº
    The LUKE model with a classification head on top (a linear layer on top of the hidden states of the two entity
    tokens) for entity pair classification tasks, such as TACRED.
    c            #       ó  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )ÚLukeForEntityPairClassificationc                 ó4  •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  «      | _        t        j                  |j                  dz  |j                  d«      | _        | j                  «        y )Nr§   Fr¼  r_   s     €r(   rP   z(LukeForEntityPairClassification.__init__í  sp   ø€ Ü‰Ñ˜Ô ä˜fÓ%ˆŒ	à ×+Ñ+ˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒÜŸ)™) F×$6Ñ$6¸Ñ$:¸F×<MÑ<MÈuÓUˆŒð 	�‰Õr'   ru  rv  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÛ   c                 ó:  — |�|n| j                   j                  }| j                  |||||||||	|
||d¬«      }t        j                  |j
                  dd…ddd…f   |j
                  dd…ddd…f   gd¬«      }| j                  |«      }| j                  |«      }d}|�˜|j                  |j                  «      }|j                  dk(  r!t        j                  j                  ||«      }nMt        j                  j                  |j                  d«      |j                  d«      j!                  |«      «      }|s5t#        d„ |||j$                  |j&                  |j(                  fD «       «      S t+        |||j$                  |j&                  |j(                  ¬	«      S )
u"  
        labels (`torch.LongTensor` of shape `(batch_size,)` or `(batch_size, num_labels)`, *optional*):
            Labels for computing the classification loss. If the shape is `(batch_size,)`, the cross entropy loss is
            used for the single-label classification. In this case, labels should contain the indices that should be in
            `[0, ..., config.num_labels - 1]`. If the shape is `(batch_size, num_labels)`, the binary cross entropy
            loss is used for the multi-label classification. In this case, labels should only contain `[0, 1]`, where 0
            and 1 indicate false and true, respectively.

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, LukeForEntityPairClassification

        >>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-tacred")
        >>> model = LukeForEntityPairClassification.from_pretrained("studio-ousia/luke-large-finetuned-tacred")

        >>> text = "BeyoncÃ© lives in Los Angeles."
        >>> entity_spans = [
        ...     (0, 7),
        ...     (17, 28),
        ... ]  # character-based entity spans corresponding to "BeyoncÃ©" and "Los Angeles"
        >>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="pt")
        >>> outputs = model(**inputs)
        >>> logits = outputs.logits
        >>> predicted_class_idx = logits.argmax(-1).item()
        >>> print("Predicted class:", model.config.id2label[predicted_class_idx])
        Predicted class: per:cities_of_residence
        ```NTrµ  r   r   rŠ   rd   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z:LukeForEntityPairClassification.forward.<locals>.<genexpr>N  rÁ  r%  rÂ  )ra   r}  rL  r#   r®   r   r^   r¾  ri   rg   rÃ  r   r³   rÄ  rÅ  r¨   rŽ   r+  r3   r   r4   r:   rÆ  s                      r(   rt   z'LukeForEntityPairClassification.forwardù  s˜  € ðb &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆô  Ÿ™Ø×-Ñ-ªa°²A¨gÑ6¸×8XÑ8XÒYZÐ\]Ò_`ÐY`Ñ8aÐbÐhiô
ˆð Ÿ™ nÓ5ˆØ—‘ Ó0ˆàˆØÐð —Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{˜aÒÜ—}‘}×2Ñ2°6¸6ÓB‘ä—}‘}×EÑEÀfÇkÁkÐRTÃoÐW]×WbÑWbÐceÓWf×WnÑWnÐouÓWvÓw�áÜñ à ¨×(=Ñ(=¸w×?[Ñ?[Ð]d×]oÑ]oÐpôó ð ô .ØØØ!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   rÈ  )r   r    r!   rP   r   r�  r‘  r   r:   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   rÊ  rÊ  å  s¢  ø„ ô
ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+IÐXgÔhð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø-1Ø,0Ø/3Ø&*ñ_
à˜E×,Ñ,Ñ-ð_
ð ! ×!2Ñ!2Ñ3ð_
ð ! ×!1Ñ!1Ñ2ð	_
ð
 ˜u×/Ñ/Ñ0ð_
ð ˜U×-Ñ-Ñ.ð_
ð  (¨×(9Ñ(9Ñ:ð_
ð  (¨×(8Ñ(8Ñ9ð_
ð & e×&6Ñ&6Ñ7ð_
ð ˜E×-Ñ-Ñ.ð_
ð   × 1Ñ 1Ñ2ð_
ð ˜×)Ñ)Ñ*ð_
ð $ D™>ð_
ð ' t™nð_
ð ˜d‘^ð_
ð  
ˆuÐ4Ð4Ñ	5ò!_
ó ió hô_
r'   rÊ  z£
    The LUKE model with a span classification head on top (a linear layer on top of the hidden states output) for tasks
    such as named entity recognition.
    c            '       óH  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
ej                     de
e   de
e   de
e   deeef   f"d„«       «       Zˆ xZS )ÚLukeForEntitySpanClassificationc                 ó2  •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  «      | _        t        j                  |j                  dz  |j                  «      | _        | j                  «        y )Nr   r¼  r_   s     €r(   rP   z(LukeForEntitySpanClassification.__init__e  sn   ø€ Ü‰Ñ˜Ô ä˜fÓ%ˆŒ	à ×+Ñ+ˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒÜŸ)™) F×$6Ñ$6¸Ñ$:¸F×<MÑ<MÓNˆŒð 	�‰Õr'   ru  rv  ro   r·   rp   rn   r†   rx  ry  rz  Úentity_start_positionsÚentity_end_positionsr¸   rq   r²  r¹   r,  r-  rÛ   c                 ó´  — |�|n| j                   j                  }| j                  ||||||||||||d¬«      }|j                  j	                  d«      }|	j                  d«      j                  dd|«      }	|	j                  |j                  j                  k7  r%|	j                  |j                  j                  «      }	t        j                  |j                  d|	«      }|
j                  d«      j                  dd|«      }
|
j                  |j                  j                  k7  r%|
j                  |j                  j                  «      }
t        j                  |j                  d|
«      }t        j                  |||j                  gd¬«      }| j                  |«      }| j                  |«      }d}|�Á|j                  |j                  «      }|j                  dk(  rJt         j"                  j%                  |j'                  d| j(                  «      |j'                  d«      «      }nMt         j"                  j+                  |j'                  d«      |j'                  d«      j-                  |«      «      }|s5t/        d„ |||j0                  |j2                  |j4                  fD «       «      S t7        |||j0                  |j2                  |j4                  ¬	«      S )
u'	  
        entity_start_positions (`torch.LongTensor`):
            The start positions of entities in the word token sequence.

        entity_end_positions (`torch.LongTensor`):
            The end positions of entities in the word token sequence.

        labels (`torch.LongTensor` of shape `(batch_size, entity_length)` or `(batch_size, entity_length, num_labels)`, *optional*):
            Labels for computing the classification loss. If the shape is `(batch_size, entity_length)`, the cross
            entropy loss is used for the single-label classification. In this case, labels should contain the indices
            that should be in `[0, ..., config.num_labels - 1]`. If the shape is `(batch_size, entity_length,
            num_labels)`, the binary cross entropy loss is used for the multi-label classification. In this case,
            labels should only contain `[0, 1]`, where 0 and 1 indicate false and true, respectively.

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, LukeForEntitySpanClassification

        >>> tokenizer = AutoTokenizer.from_pretrained("studio-ousia/luke-large-finetuned-conll-2003")
        >>> model = LukeForEntitySpanClassification.from_pretrained("studio-ousia/luke-large-finetuned-conll-2003")

        >>> text = "BeyoncÃ© lives in Los Angeles"
        # List all possible entity spans in the text

        >>> word_start_positions = [0, 8, 14, 17, 21]  # character-based start positions of word tokens
        >>> word_end_positions = [7, 13, 16, 20, 28]  # character-based end positions of word tokens
        >>> entity_spans = []
        >>> for i, start_pos in enumerate(word_start_positions):
        ...     for end_pos in word_end_positions[i:]:
        ...         entity_spans.append((start_pos, end_pos))

        >>> inputs = tokenizer(text, entity_spans=entity_spans, return_tensors="pt")
        >>> outputs = model(**inputs)
        >>> logits = outputs.logits
        >>> predicted_class_indices = logits.argmax(-1).squeeze().tolist()
        >>> for span, predicted_class_idx in zip(entity_spans, predicted_class_indices):
        ...     if predicted_class_idx != 0:
        ...         print(text[span[0] : span[1]], model.config.id2label[predicted_class_idx])
        BeyoncÃ© PER
        Los Angeles LOC
        ```NTrµ  rd   r‰   r§   rŠ   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z:LukeForEntitySpanClassification.forward.<locals>.<genexpr>à  rÁ  r%  rÂ  )ra   r}  rL  r&  rk   rw   rx   rg   ri   r#   Úgatherr®   r   r^   r¾  rÃ  r   r³   rÄ  r¨   r½  rÅ  rŽ   r+  r3   r   r4   r<   )r`   ro   r·   rp   rn   r†   rx  ry  rz  rÑ  rÒ  r¸   rq   r²  r¹   r,  r-  rÓ   rS   Ústart_statesÚ
end_statesrÇ  r1   r.   s                           r(   rt   z'LukeForEntitySpanClassification.forwardq  sŠ  € ðB &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð ×/Ñ/×4Ñ4°RÓ8ˆà!7×!AÑ!AÀ"Ó!E×!LÑ!LÈRÐQSÐU`Ó!aÐØ!×(Ñ(¨G×,EÑ,E×,LÑ,LÒLØ%;×%>Ñ%>¸w×?XÑ?X×?_Ñ?_Ó%`Ð"Ü—|‘| G×$=Ñ$=¸rÐCYÓZˆà3×=Ñ=¸bÓA×HÑHÈÈRÐQ\Ó]ÐØ×&Ñ&¨'×*CÑ*C×*JÑ*JÒJØ#7×#:Ñ#:¸7×;TÑ;T×;[Ñ;[Ó#\Ð Ü—\‘\ '×";Ñ";¸RÐAUÓVˆ
äŸ™ L°*¸g×>^Ñ>^Ð#_ÐefÔgˆàŸ™ nÓ5ˆØ—‘ Ó0ˆàˆØÐà—Y‘Y˜vŸ}™}Ó-ˆFð �{‰{˜aÒÜ—}‘}×2Ñ2°6·;±;¸rÀ4Ç?Á?Ó3SÐU[×U`ÑU`ÐacÓUdÓe‘ä—}‘}×EÑEÀfÇkÁkÐRTÃoÐW]×WbÑWbÐceÓWf×WnÑWnÐouÓWvÓw�áÜñ à ¨×(=Ñ(=¸w×?[Ñ?[Ð]d×]oÑ]oÐpôó ð ô .ØØØ!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   )NNNNNNNNNNNNNNNN)r   r    r!   rP   r   r�  r‘  r   r<   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   rÏ  rÏ  ]  sÔ  ø„ ô
ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙÐ+IÐXgÔhð 15Ø6:Ø59Ø37Ø15Ø<@Ø<@Ø:>Ø=AØ;?Ø15Ø59Ø-1Ø,0Ø/3Ø&*ñ#y
à˜E×,Ñ,Ñ-ðy
ð ! ×!2Ñ!2Ñ3ðy
ð ! ×!1Ñ!1Ñ2ð	y
ð
 ˜u×/Ñ/Ñ0ðy
ð ˜U×-Ñ-Ñ.ðy
ð  (¨×(8Ñ(8Ñ9ðy
ð  (¨×(8Ñ(8Ñ9ðy
ð & e×&6Ñ&6Ñ7ðy
ð !)¨×)9Ñ)9Ñ :ðy
ð ' u×'7Ñ'7Ñ8ðy
ð ˜E×-Ñ-Ñ.ðy
ð   × 1Ñ 1Ñ2ðy
ð ˜×)Ñ)Ñ*ðy
ð $ D™>ðy
ð  ' t™nð!y
ð" ˜d‘^ð#y
ð$ 
ˆuÐ4Ð4Ñ	5ò%y
ó ió hôy
r'   rÏ  z 
    The LUKE 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ˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deej                     dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚLukeForSequenceClassificationc                 ó\  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  �|j                  n|j                  «      | _	        t        j                  |j                  |j                  «      | _        | j                  «        y r‘   ©rO   rP   r½  r`  rL  r   r\   Úclassifier_dropoutr]   r^   r„   rS   r¾  re  r_   s     €r(   rP   z&LukeForSequenceClassification.__init__÷  s‚   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ˜fÓ%ˆŒ	Ü—z‘zØ)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnó
ˆŒô Ÿ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr'   ru  ©Ú
checkpointrw  rZ  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÛ   c                 óæ  — |�|n| j                   j                  }| j                  |||||||||	|
||d¬«      }|j                  }| j	                  |«      }| j                  |«      }d}|��¢|j                  |j                  «      }| j                   j                  €�| j                  dk(  rd| j                   _        nl| j                  dkD  rL|j                  t        j                  k(  s|j                  t        j                  k(  rd| j                   _        nd| j                   _        | j                   j                  dk(  rIt        «       }| j                  dk(  r& ||j                  «       |j                  «       «      }nŒ |||«      }n‚| j                   j                  dk(  r=t!        «       } ||j#                  d| j                  «      |j#                  d«      «      }n,| j                   j                  dk(  rt%        «       } |||«      }|s5t'        d	„ |||j(                  |j*                  |j,                  fD «       «      S t/        |||j(                  |j*                  |j,                  ¬
«      S )a�  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        NTrµ  r   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrd   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z8LukeForSequenceClassification.forward.<locals>.<genexpr>Q  rÁ  r%  rÂ  )ra   r}  rL  r|  r^   r¾  ri   rg   Úproblem_typer½  rf   r#   rm   r›   r
   Úsqueezer	   r¨   r   r+  r3   r   r4   r>   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÓ   r=  r1   r.   Úloss_fcts                       r(   rt   z%LukeForSequenceClassification.forward  s"  € ð: &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð   ×-Ñ-ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÑà—Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�áÜñ à ¨×(=Ñ(=¸w×?[Ñ?[Ð]d×]oÑ]oÐpôó ð ô ,ØØØ!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   rÈ  )r   r    r!   rP   r   r�  r‘  r   Ú_CHECKPOINT_FOR_DOCr>   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   rÙ  rÙ  ï  s¦  ø„ ô
ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙØ&Ø0Ø$ôð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø.2Ø,0Ø/3Ø&*ñT
à˜E×,Ñ,Ñ-ðT
ð ! ×!2Ñ!2Ñ3ðT
ð ! ×!1Ñ!1Ñ2ð	T
ð
 ˜u×/Ñ/Ñ0ðT
ð ˜U×-Ñ-Ñ.ðT
ð  (¨×(9Ñ(9Ñ:ðT
ð  (¨×(8Ñ(8Ñ9ðT
ð & e×&6Ñ&6Ñ7ðT
ð ˜E×-Ñ-Ñ.ðT
ð   × 1Ñ 1Ñ2ðT
ð ˜×*Ñ*Ñ+ðT
ð $ D™>ðT
ð ' t™nðT
ð ˜d‘^ðT
ð  
ˆuÐ2Ð2Ñ	3ò!T
óó hôT
r'   rÙ  zú
    The LUKE Model with a token classification head on top (a linear layer on top of the hidden-states output). To
    solve Named-Entity Recognition (NER) task using LUKE, `LukeForEntitySpanClassification` is more suitable than this
    class.
    c            #       ó
  ‡ — e Zd Zˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deej                     dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚLukeForTokenClassificationc                 ó`  •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        t        j                  |j                  �|j                  n|j                  «      | _	        t        j                  |j                  |j                  «      | _        | j                  «        y ©NF)ra  rÛ  r_   s     €r(   rP   z#LukeForTokenClassification.__init__i  s„   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä˜f¸Ô>ˆŒ	Ü—z‘zØ)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnó
ˆŒô Ÿ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr'   ru  rÝ  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÛ   c                 óN  — |�|n| j                   j                  }| j                  |||||||||	|
||d¬«      }|j                  }| j	                  |«      }| j                  |«      }d}|�W|j                  |j                  «      }t        «       } ||j                  d| j                  «      |j                  d«      «      }|s5t        d„ |||j                  |j                  |j                  fD «       «      S t        |||j                  |j                  |j                  ¬«      S )áJ  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
            num_choices-1]` where `num_choices` is the size of the second dimension of the input tensors. (See
            `input_ids` above)
        NTrµ  rd   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z5LukeForTokenClassification.forward.<locals>.<genexpr>²  rÁ  r%  rÂ  )ra   r}  rL  r&  r^   r¾  ri   rg   r	   r¨   r½  r+  r3   r   r4   rA   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÓ   r‰  r1   r.   ræ  s                       r(   rt   z"LukeForTokenClassification.forwardv  s0  € ð: &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð  "×3Ñ3ˆàŸ,™, Ó7ˆØ—‘ Ó1ˆàˆØÐà—Y‘Y˜vŸ}™}Ó-ˆFÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDáÜñ à ¨×(=Ñ(=¸w×?[Ñ?[Ð]d×]oÑ]oÐpôó ð ô )ØØØ!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   rÈ  )r   r    r!   rP   r   r�  r‘  r   rç  rA   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   ré  ré  `  s¦  ø„ ôñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙØ&Ø-Ø$ôð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø.2Ø,0Ø/3Ø&*ñB
à˜E×,Ñ,Ñ-ðB
ð ! ×!2Ñ!2Ñ3ðB
ð ! ×!1Ñ!1Ñ2ð	B
ð
 ˜u×/Ñ/Ñ0ðB
ð ˜U×-Ñ-Ñ.ðB
ð  (¨×(9Ñ(9Ñ:ðB
ð  (¨×(8Ñ(8Ñ9ðB
ð & e×&6Ñ&6Ñ7ðB
ð ˜E×-Ñ-Ñ.ðB
ð   × 1Ñ 1Ñ2ðB
ð ˜×*Ñ*Ñ+ðB
ð $ D™>ðB
ð ' t™nðB
ð ˜d‘^ðB
ð  
ˆuÐ/Ð/Ñ	0ò!B
óó hôB
r'   ré  zá
    The LUKE 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ˆ fd„Z eej                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deej                     deej                     dee   dee   dee   deee	f   f d„«       «       Zˆ xZS )ÚLukeForQuestionAnsweringc                 óè   •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y rë  )
rO   rP   r½  r`  rL  r   r„   rS   Ú
qa_outputsre  r_   s     €r(   rP   z!LukeForQuestionAnswering.__init__É  sU   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒä˜f¸Ô>ˆŒ	ÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr'   ru  rÝ  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   Ústart_positionsÚend_positionsr¹   r,  r-  rÛ   c                 ó`  — |�|n| j                   j                  }| j                  |||||||||	|
||d¬«      }|j                  }| j	                  |«      }|j                  dd¬«      \  }}|j                  d«      }|j                  d«      }d}|�·|�µt        |j                  «       «      dkD  r|j                  d«      }t        |j                  «       «      dkD  r|j                  d«      }|j                  d«      }|j                  d|«       |j                  d|«       t        |¬«      } |||«      } |||«      }||z   d	z  }|s6t        d
„ ||||j                  |j                  |j                  fD «       «      S t        ||||j                  |j                  |j                  ¬«      S )a  
        start_positions (`torch.LongTensor` 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 (`torch.LongTensor` 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.
        NTrµ  r   rd   rŠ   r   )Úignore_indexr§   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z3LukeForQuestionAnswering.forward.<locals>.<genexpr>!  s   è ø€ ò àð �=ô ñùr%  )r.   rD   rE   r3   r   r4   )ra   r}  rL  r&  rò  Úsplitrå  Úlenrk   Úclamp_r	   r+  r3   r   r4   rC   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   ró  rô  r¹   r,  r-  rÓ   r‰  r1   rD   rE   Ú
total_lossÚignored_indexræ  Ú
start_lossÚend_losss                             r(   rt   z LukeForQuestionAnswering.forwardÔ  sÜ  € ðD &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð  "×3Ñ3ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/ˆØ×'Ñ'¨Ó+ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ×"Ñ" 1 mÔ4Ø× Ñ   MÔ2ä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJáÜñ ð Ø ØØ×)Ñ)Ø×0Ñ0Ø×&Ñ&ðôó ð ô 0ØØ%Ø!Ø!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   r·  )r   r    r!   rP   r   r�  r‘  r   rç  rC   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   rð  rð  Á  s¿  ø„ ô	ñ +Ð+@×+GÑ+GÐHeÓ+fÓgÙØ&Ø4Ø$ôð 15Ø6:Ø59Ø48Ø15Ø=AØ<@Ø:>Ø15Ø59Ø6:Ø48Ø,0Ø/3Ø&*ñ![
à˜E×,Ñ,Ñ-ð[
ð ! ×!2Ñ!2Ñ3ð[
ð ! ×!1Ñ!1Ñ2ð	[
ð
 ˜u×0Ñ0Ñ1ð[
ð ˜U×-Ñ-Ñ.ð[
ð  (¨×(9Ñ(9Ñ:ð[
ð  (¨×(8Ñ(8Ñ9ð[
ð & e×&6Ñ&6Ñ7ð[
ð ˜E×-Ñ-Ñ.ð[
ð   × 1Ñ 1Ñ2ð[
ð " %×"2Ñ"2Ñ3ð[
ð   × 0Ñ 0Ñ1ð[
ð $ D™>ð[
ð ' t™nð[
ð  ˜d‘^ð![
ð" 
ˆuÐ6Ð6Ñ	7ò#[
óó hô[
r'   rð  z©
    The LUKE 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j                  d«      «       eee	e
¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deej                     dee   dee   dee   deee	f   fd„«       «       Zˆ xZS )ÚLukeForMultipleChoicec                 ó&  •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  �|j                  n|j                  «      | _        t	        j                  |j                  d«      | _        | j                  «        y r  )rO   rP   r`  rL  r   r\   rÜ  r]   r^   r„   rS   r¾  re  r_   s     €r(   rP   zLukeForMultipleChoice.__init__@  so   ø€ Ü‰Ñ˜Ô ä˜fÓ%ˆŒ	Ü—z‘zØ)/×)BÑ)BÐ)NˆF×%Ò%ÐTZ×TnÑTnó
ˆŒô Ÿ)™) F×$6Ñ$6¸Ó:ˆŒð 	�‰Õr'   z(batch_size, num_choices, sequence_lengthrÝ  ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  rÛ   c                 ó:  — |�|n| j                   j                  }|�|j                  d   n|
j                  d   }|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|
�1|
j                  d|
j	                  d«      |
j	                  d«      «      nd}
|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�1|j                  d|j	                  d«      |j	                  d«      «      nd}| j                  |||||||||	|
||d¬«      }|j                  }| j                  |«      }| j                  |«      }|j                  d|«      }d}|�.|j                  |j                  «      }t        «       } |||«      }|s5t        d„ |||j                  |j                  |j                  fD «       «      S t!        |||j                  |j                  |j                  ¬«      S )	rí  Nr   rd   r‰   Trµ  c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr‘   r&   r   s     r(   r#  z0LukeForMultipleChoice.forward.<locals>.<genexpr>¥  r$  r%  rÂ  )ra   r}  r�  r¨   rk   rL  r|  r^   r¾  ri   rg   r	   r+  r3   r   r4   rG   )r`   ro   r·   rp   rn   r†   rx  ry  rz  r¸   rq   r²  r¹   r,  r-  Únum_choicesrÓ   r=  r1   Úreshaped_logitsr.   ræ  s                         r(   rt   zLukeForMultipleChoice.forwardL  sÝ  € ð: &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØ,5Ð,A�i—o‘o aÒ(À}×GZÑGZÐ[\ÑG]ˆà>GÐ>S�I—N‘N 2 y§~¡~°bÓ'9Ô:ÐY]ˆ	ØM[ÐMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØM[ÐMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØGSÐG_�|×(Ñ(¨¨\×->Ñ->¸rÓ-BÔCÐeiˆð Ð(ð ×Ñ˜r =×#5Ñ#5°bÓ#9¸=×;MÑ;MÈbÓ;QÔRàð 	ð BLÐAW�Z—_‘_ R¨¯©¸Ó)<Ô=Ð]aˆ
ð %Ð0ð "×&Ñ& rÐ+@×+EÑ+EÀbÓ+IÔJàð 	ð %Ð0ð "×&Ñ& rÐ+@×+EÑ+EÀbÓ+IÔJàð 	ð #Ð.ð  ×$Ñ$ RÐ)<×)AÑ)AÀ"Ó)EÐGZ×G_ÑG_Ð`bÓGcÔdàð 	ð —)‘)ØØ)Ø)Ø%Ø!Ø"7Ø"7Ø 3ØØ'Ø/Ø!5Øð ó 
ˆð   ×-Ñ-ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆØ Ÿ+™+ b¨+Ó6ˆàˆØÐà—Y‘Y˜×5Ñ5Ó6ˆFÜ'Ó)ˆHÙ˜O¨VÓ4ˆDáÜñ 
ð Ø#Ø×)Ñ)Ø×0Ñ0Ø×&Ñ&ðô
ó 
ð 
ô -ØØ"Ø!×/Ñ/Ø!(×!=Ñ!=Ø×)Ñ)ô
ð 	
r'   rÈ  )r   r    r!   rP   r   r�  r‘  r   rç  rG   r’  r   r#   r’   r$   r�  r   r   rt   rz   r{   s   @r(   r   r   8  s¦  ø„ ô
ñ +Ð+@×+GÑ+GÐHrÓ+sÓtÙØ&Ø1Ø$ôð 15Ø6:Ø59Ø37Ø15Ø=AØ<@Ø:>Ø15Ø59Ø.2Ø,0Ø/3Ø&*ñe
à˜E×,Ñ,Ñ-ðe
ð ! ×!2Ñ!2Ñ3ðe
ð ! ×!1Ñ!1Ñ2ð	e
ð
 ˜u×/Ñ/Ñ0ðe
ð ˜U×-Ñ-Ñ.ðe
ð  (¨×(9Ñ(9Ñ:ðe
ð  (¨×(8Ñ(8Ñ9ðe
ð & e×&6Ñ&6Ñ7ðe
ð ˜E×-Ñ-Ñ.ðe
ð   × 1Ñ 1Ñ2ðe
ð ˜×*Ñ*Ñ+ðe
ð $ D™>ðe
ð ' t™nðe
ð ˜d‘^ðe
ð  
ˆuÐ3Ð3Ñ	4ò!e
óó uôe
r'   r   )
rº  rÊ  rÏ  r   rð  rÙ  ré  r¤  r`  rK  )Mr"   r±   Údataclassesr   Útypingr   r   r   r#   Útorch.utils.checkpointr   Útorch.nnr   r	   r
   Úactivationsr   r   Úmodeling_outputsr   r   Úmodeling_utilsr   Úpytorch_utilsr   Úutilsr   r   r   r   r   r   Úconfiguration_luker   Ú
get_loggerr   Úloggerr’  rç  r   r+   r-   r6   r:   r<   r>   rA   rC   rG   r^  rI   r}   r”   rÖ   rä   r÷   r  r  r  r7  r?  rD  rK  ÚLUKE_START_DOCSTRINGr�  r`  rh   r™  r¤  rº  rÊ  rÏ  rÙ  ré  rð  r   Ú__all__r&   r'   r(   ú<module>r     s$  ðñ ã Ý !ß )Ñ )ã Û Ý ß AÑ Aç 'ß KÝ -Ý 6÷÷ õ +ð 
ˆ×	Ñ	˜HÓ	%€à€Ø.Ð ð ôIÐ%?ó Ió ðIð< ôI˜/ó Ió ðIð< ô'?˜ó '?ó ð'?ðT ô? ó ?ó ð?ð< ô? [ó ?ó ð?ð< ô? [ó ?ó ð?ð< ô? ;ó ?ó ð?ðB ô? ó ?ó ð?ðB ô!? {ó !?ó ð!?ðH ô ? Kó  ?ó ð ?ôFF=�R—Y‘Yô F=ôR(˜2Ÿ9™9ô (ôVn˜Ÿ	™	ô nôd�R—Y‘Yô ô,�B—I‘Iô ,ô`�r—y‘yô ô �—‘ô ô1�—	‘	ô 1ôhK
�"—)‘)ô K
ô^�—‘ô ô B§I¡Iô ô"˜2Ÿ9™9ô ô*˜/ô *ð:Ð ð HÐ ñV ðàóô
E'Ð#ó E'óð
E'òP4ô"*�—‘ô *ñ> ðð óô}
Ð)ó }
óð}
ñ@ ðð óôi
Ð"5ó i
óði
ñX ðð óôn
Ð&9ó n
óðn
ñb ðð óôH
Ð&9ó H
óðH
ñV ðð óôg
Ð$7ó g
óðg
ñT ðð
 óôV
Ð!4ó V
óðV
ñr ðð óôm
Ð2ó m
óðm
ñ` ðð óôx
Ð/ó x
óðx
òv�r'   