



'''simple docstring'''





import torch

from transformers import AutoModel



class  snake_case__						(    torch.nn.Module				):
 def __init__(   self						:							List[Any]      ,     __a						:							int="sayef/fsner-bert-base-uncased"  )      ->   Optional[Any]:







       '''simple docstring'''
       super(__a      ,     self  ).__init__()

       __snake_case :   List[Any]													=    AutoModel.from_pretrained(__a      ,     return_dict=__a  )
       __snake_case :   Any													=    torch.nn.CosineSimilarity(3      ,     1e-08  )
       __snake_case :   Dict													=    torch.nn.Softmax(dim=1  )
 def A_   (   self						:							Optional[Any]      ,     **__a						:							Optional[int]  )      ->   int:







       '''simple docstring'''
       return self.bert(**__a  ).last_hidden_state
 def A_   (   self						:							List[Any]      ,     __a						:							Dict  )      ->   Tuple:







       '''simple docstring'''
       return token_embeddings.sum(2      ,     keepdim=__a  )
 def A_   (   self						:							Any      ,     __a						:							Any      ,     __a						:							List[str]      ,     __a						:							Tuple=1  )      ->   List[Any]:







       '''simple docstring'''
       return self.softmax(T * self.cos(__a      ,     __a  )  )





 def A_   (   self						:							Any      ,     __a						:							List[str]      ,     __a						:							List[Any]  )      ->   int:







       '''simple docstring'''
       __snake_case :   Dict													=    W_supports['sizes'].tolist()
       __snake_case :   int													=    W_supports['start_token_id'].item()
       __snake_case :   str													=    W_supports['end_token_id'].item()

       del W_supports["sizes"]
       del W_supports["start_token_id"]
       del W_supports["end_token_id"]

       __snake_case :   List[Any]													=    self.BERT(**__a  )
       __snake_case :   Any													=    self.BERT(**__a  )

       __snake_case :   str													=    None
       __snake_case :   Any													=    None

       __snake_case :   Dict													=    W_supports['input_ids'] == start_token_id
       __snake_case :   Tuple													=    W_supports['input_ids'] == end_token_id

       for i, size in enumerate(__a  ):
             if i == 0:
                   __snake_case :   Any													=    0
             else:
                   __snake_case :   int													=    support_sizes[i - 1]

             __snake_case :   str													=    S[s : s + size][start_token_masks[s : s + size]]
             __snake_case :   Dict													=    S[s : s + size][end_token_masks[s : s + size]]

             __snake_case :   str													=    torch.matmul(q[i]      ,     s_start.T  ).sum(1  ).softmax(0  )
             __snake_case :   Tuple													=    torch.matmul(q[i]      ,     s_end.T  ).sum(1  ).softmax(0  )

             if p_starts is not None:
                   __snake_case :   Tuple													=    torch.vstack((p_starts, p_start)  )
                   __snake_case :   str													=    torch.vstack((p_ends, p_end)  )
             else:
                   __snake_case :   Any													=    p_start
                   __snake_case :   int													=    p_end

       return p_starts, p_ends








'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__    :   List[Any]           =					{
    '''configuration_luke''': ['''LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''LukeConfig'''],
    '''tokenization_luke''': ['''LukeTokenizer'''],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A__    :   Union[str, Any]           =					[
        '''LUKE_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''LukeForEntityClassification''',
        '''LukeForEntityPairClassification''',
        '''LukeForEntitySpanClassification''',
        '''LukeForMultipleChoice''',
        '''LukeForQuestionAnswering''',
        '''LukeForSequenceClassification''',
        '''LukeForTokenClassification''',
        '''LukeForMaskedLM''',
        '''LukeModel''',
        '''LukePreTrainedModel''',
    ]


if TYPE_CHECKING:
    from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
    from .tokenization_luke import LukeTokenizer

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_luke import (
            LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
            LukeForEntityClassification,
            LukeForEntityPairClassification,
            LukeForEntitySpanClassification,
            LukeForMaskedLM,
            LukeForMultipleChoice,
            LukeForQuestionAnswering,
            LukeForSequenceClassification,
            LukeForTokenClassification,
            LukeModel,
            LukePreTrainedModel,
        )

else:
    import sys

    A__    :   List[str]           =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



