






import torch

from transformers import AutoModel

class     _SCREAMING_SNAKE_CASE       (			torch.nn.Module      ):





	def __init__(		self				:					int ,  __lowerCamelCase				:					Any="sayef/fsner-bert-base-uncased"	):
		super(snake_case_ ,  self	).__init__()

		UpperCamelCase     :Any          =	AutoModel.from_pretrained(snake_case_ ,  return_dict=snake_case_	)
		UpperCamelCase     :Dict          =	torch.nn.CosineSimilarity(3 ,  1E-08	)
		UpperCamelCase     :List[Any]          =	torch.nn.Softmax(dim=1	)





	def 						_A (		self				:					int ,  **__lowerCamelCase				:					int	):
		return self.bert(**snake_case_	).last_hidden_state





	def 						_A (		self				:					Optional[Any] ,  __lowerCamelCase				:					Optional[Any]	):
		return token_embeddings.sum(2 ,  keepdim=snake_case_	)





	def 						_A (		self				:					List[Any] ,  __lowerCamelCase				:					List[str] ,  __lowerCamelCase				:					str ,  __lowerCamelCase				:					Dict=1	):
		return self.softmax(T * self.cos(snake_case_ ,  snake_case_	)	)





	def 						_A (		self				:					Dict ,  __lowerCamelCase				:					List[str] ,  __lowerCamelCase				:					Optional[int]	):
		UpperCamelCase     :Tuple          =	W_supports['''sizes'''].tolist()
		UpperCamelCase     :Any          =	W_supports['''start_token_id'''].item()
		UpperCamelCase     :Dict          =	W_supports['''end_token_id'''].item()

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

		UpperCamelCase     :Any          =	self.BERT(**snake_case_	)
		UpperCamelCase     :List[Any]          =	self.BERT(**snake_case_	)

		UpperCamelCase     :List[Any]          =	None
		UpperCamelCase     :Tuple          =	None

		UpperCamelCase     :Optional[Any]          =	W_supports['''input_ids'''] == start_token_id
		UpperCamelCase     :int          =	W_supports['''input_ids'''] == end_token_id

		for i, size in enumerate(snake_case_	):
			if i == 0:
				UpperCamelCase     :str          =	0
			else:
				UpperCamelCase     :List[str]          =	support_sizes[i - 1]

			UpperCamelCase     :int          =	S[s : s + size][start_token_masks[s : s + size]]
			UpperCamelCase     :List[str]          =	S[s : s + size][end_token_masks[s : s + size]]

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

			if p_starts is not None:
				UpperCamelCase     :Any          =	torch.vstack((p_starts, p_start)	)
				UpperCamelCase     :str          =	torch.vstack((p_ends, p_end)	)
			else:
				UpperCamelCase     :int          =	p_start
				UpperCamelCase     :Optional[int]          =	p_end

		return p_starts, p_ends


import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowercase__       ={
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

lowercase__       =logging.WARNING




def    __UpperCamelCase     (				):
 __a :  Optional[Any]						=  os.getenv('''DATASETS_VERBOSITY'''  ,   lowerCAmelCase__  )
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
       f"has to be one of: { ', '.join(log_levels.keys()  ) }"  )
 return _default_log_level




def    __UpperCamelCase     (				):
 return __name__.split('''.'''  )[0]




def    __UpperCamelCase     (				):
 return logging.getLogger(_get_library_name()  )




def    __UpperCamelCase     (				):
 # Apply our default configuration to the library root logger.
 __a :  str						=  _get_library_root_logger()
 library_root_logger.setLevel(_get_default_logging_level()  )




def    __UpperCamelCase     (				):
 __a :  Any						=  _get_library_root_logger()
 library_root_logger.setLevel(logging.NOTSET  )




def    __UpperCamelCase     (				lowerCAmelCase__							:				Optional[str] = None  ):
 if name is None:
  __a :  Union[str, Any]						=  _get_library_name()
 return logging.getLogger(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return _get_library_root_logger().getEffectiveLevel()




def    __UpperCamelCase     (				lowerCAmelCase__							:				int  ):
 _get_library_root_logger().setLevel(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 __a :  Union[str, Any]						=  False




def    __UpperCamelCase     (				):
 __a :  Tuple						=  True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()



class 		UpperCamelCase__  :
   def __init__(self :					str					,				*snake_case_ :					str					,				**snake_case_ :					Union[str, Any]   ):  # pylint: disable=unused-argument
    __a :  Optional[Any]						=  args[0] if args else None
   def __iter__(self :					List[str]   ):
    return iter(self._iterator   )
   def __getattr__(self :					str					,				snake_case_ :					Optional[Any]   ):

    def empty_fn(*snake_case_ :					int					,				**snake_case_ :					int   ):  # pylint: disable=unused-argument
     return

    return empty_fn
   def __enter__(self :					Union[str, Any]   ):
    return self







   def __exit__(self :					str					,				snake_case_ :					List[str]					,				snake_case_ :					int					,				snake_case_ :					Optional[Any]   ):
    return





lowercase__       =True



class 		UpperCamelCase__  :
   def __call__(self :					Tuple					,				*snake_case_ :					str					,				snake_case_ :					str=False					,				**snake_case_ :					Dict   ):
    if _tqdm_active and not disable:
     return tqdm_lib.tqdm(*snake_case_					,				**snake_case_   )
    else:
     return EmptyTqdm(*snake_case_					,				**snake_case_   )
   def       lowerCAmelCase			(self :					Optional[Any]					,				*snake_case_ :					Union[str, Any]					,				**snake_case_ :					Optional[Any]   ):
    __a :  List[Any]						=  None
    if _tqdm_active:
     return tqdm_lib.tqdm.set_lock(*snake_case_					,				**snake_case_   )







   def       lowerCAmelCase			(self :					str   ):
    if _tqdm_active:
     return tqdm_lib.tqdm.get_lock()





lowercase__       =_tqdm_cls()




def    __UpperCamelCase     (				):
 global _tqdm_active
 return bool(_tqdm_active  )




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Dict						=  True




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Union[str, Any]						=  False
