






"""simple docstring"""






from ..utils import DummyObject, requires_backends





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							int   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Any   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Any   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[str]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Tuple   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							int   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[str]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[Any]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Tuple   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Any   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							str   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							int   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Dict   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)





class       snake_case_       (    metaclass=_lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							int   			=					["""sentencepiece"""]


	def __init__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					requires_backends(self  ,					['sentencepiece']						)










"""simple docstring"""






import torch

from transformers import AutoModel





class       snake_case_       (    torch.nn.Module       ):



	"""simple docstring"""

	def __init__(      self  ,					__a="sayef/fsner-bert-base-uncased"						):


					"""simple docstring"""

					super(__a  ,					self						).__init__()

					A__							 =       AutoModel.from_pretrained(__a  ,					return_dict=__a						)
					A__							 =       torch.nn.CosineSimilarity(3  ,					1E-08						)
					A__							 =       torch.nn.Softmax(dim=1						)


	def       _UpperCAmelCase						(      self  ,					**__a						):


					"""simple docstring"""

					return self.bert(**__a						).last_hidden_state


	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

					return token_embeddings.sum(2  ,					keepdim=__a						)


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a=1						):


					"""simple docstring"""

					return self.softmax(T * self.cos(__a  ,					__a						)						)






	def       _UpperCAmelCase						(      self  ,					__a  ,					__a						):


					"""simple docstring"""

					A__							 =       W_supports['sizes'].tolist()
					A__							 =       W_supports['start_token_id'].item()
					A__							 =       W_supports['end_token_id'].item()

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

					A__							 =       self.BERT(**__a						)
					A__							 =       self.BERT(**__a						)

					A__							 =       None
					A__							 =       None

					A__							 =       W_supports['input_ids'] == start_token_id
					A__							 =       W_supports['input_ids'] == end_token_id

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

									A__							 =       S[s : s + size][start_token_masks[s : s + size]]
									A__							 =       S[s : s + size][end_token_masks[s : s + size]]

									A__							 =       torch.matmul(q[i]  ,					s_start.T						).sum(1						).softmax(0						)
									A__							 =       torch.matmul(q[i]  ,					s_end.T						).sum(1						).softmax(0						)

									if p_starts is not None:
													A__							 =       torch.vstack((p_starts, p_start)						)
													A__							 =       torch.vstack((p_ends, p_end)						)
									else:
													A__							 =       p_start
													A__							 =       p_end

					return p_starts, p_ends


