



'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCamelCase											=			logging.get_logger(__name__)

_UpperCamelCase											=			{
    '''tau/splinter-base''': '''https://huggingface.co/tau/splinter-base/resolve/main/config.json''',
    '''tau/splinter-base-qass''': '''https://huggingface.co/tau/splinter-base-qass/resolve/main/config.json''',
    '''tau/splinter-large''': '''https://huggingface.co/tau/splinter-large/resolve/main/config.json''',
    '''tau/splinter-large-qass''': '''https://huggingface.co/tau/splinter-large-qass/resolve/main/config.json''',
    # See all Splinter models at https://huggingface.co/models?filter=splinter
}



class _A  (    __SCREAMING_SNAKE_CASE    ):
		_SCREAMING_SNAKE_CASE					:    Any						      =			"splinter"





		def __init__(     self ,       __UpperCAmelCase=30_522 ,       __UpperCAmelCase=768 ,       __UpperCAmelCase=12 ,       __UpperCAmelCase=12 ,       __UpperCAmelCase=3_072 ,       __UpperCAmelCase="gelu" ,       __UpperCAmelCase=0.1 ,       __UpperCAmelCase=0.1 ,       __UpperCAmelCase=512 ,       __UpperCAmelCase=2 ,       __UpperCAmelCase=0.02 ,       __UpperCAmelCase=1E-12 ,       __UpperCAmelCase=True ,       __UpperCAmelCase=0 ,       __UpperCAmelCase=104 ,       **__UpperCAmelCase ,       )       ->     Dict:

					'''simple docstring'''
					super().__init__(pad_token_id=__UpperCAmelCase ,       **__UpperCAmelCase				)

					__UpperCAmelCase   :      int										=     vocab_size
					__UpperCAmelCase   :      Union[str, Any]										=     max_position_embeddings
					__UpperCAmelCase   :      Tuple										=     hidden_size
					__UpperCAmelCase   :      Optional[int]										=     num_hidden_layers
					__UpperCAmelCase   :      List[str]										=     num_attention_heads
					__UpperCAmelCase   :      Optional[int]										=     intermediate_size
					__UpperCAmelCase   :      List[str]										=     hidden_act
					__UpperCAmelCase   :      List[str]										=     hidden_dropout_prob
					__UpperCAmelCase   :      str										=     attention_probs_dropout_prob
					__UpperCAmelCase   :      Dict										=     initializer_range
					__UpperCAmelCase   :      str										=     type_vocab_size
					__UpperCAmelCase   :      Any										=     layer_norm_eps
					__UpperCAmelCase   :      Dict										=     use_cache
					__UpperCAmelCase   :      List[Any]										=     question_token_id









'''simple docstring'''
import torch

from transformers import AutoTokenizer



class _A  (    __SCREAMING_SNAKE_CASE    ):





		def __init__(     self ,       __UpperCAmelCase				)       ->     Union[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase   :      Any										=     AutoTokenizer.from_pretrained(__UpperCAmelCase				)





		def 							__A       (     self ,       __UpperCAmelCase				)       ->     Any:

					'''simple docstring'''

					if isinstance(__UpperCAmelCase ,       __UpperCAmelCase				) and all(isinstance(_x ,       __UpperCAmelCase				) for _x in x				):
								__UpperCAmelCase   :      Dict										=     None
								for l in x:
											__UpperCAmelCase   :      Dict										=     self.tokenizer(
											    __UpperCAmelCase ,       padding="""max_length""" ,       max_length=384 ,       truncation=__UpperCAmelCase ,       return_tensors="""pt""" ,       )
											__UpperCAmelCase   :      Union[str, Any]										=     torch.tensor([len(__UpperCAmelCase				)]				)
											if d is not None:
														for k in d.keys():
																	__UpperCAmelCase   :      Dict										=     torch.cat((d[k], t[k]) ,       0				)
											else:
														__UpperCAmelCase   :      List[str]										=     t

								__UpperCAmelCase   :      Union[str, Any]										=     torch.tensor(self.tokenizer.convert_tokens_to_ids("""[E]"""				)				)
								__UpperCAmelCase   :      Any										=     torch.tensor(self.tokenizer.convert_tokens_to_ids("""[/E]"""				)				)

					elif isinstance(__UpperCAmelCase ,       __UpperCAmelCase				) and all(isinstance(_x ,       __UpperCAmelCase				) for _x in x				):
								__UpperCAmelCase   :      int										=     self.tokenizer(
								    __UpperCAmelCase ,       padding="""max_length""" ,       max_length=384 ,       truncation=__UpperCAmelCase ,       return_tensors="""pt""" ,       )

					else:
								raise Exception(
								    """Type of parameter x was not recognized! Only `list of strings` for query or `list of lists of"""
								    """ strings` for supports are supported."""				)

					return d





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase=0.70				)       ->     Dict:

					'''simple docstring'''
					__UpperCAmelCase   :      Tuple										=     []
					for idx in range(len(W_query["""input_ids"""]				)				):
								__UpperCAmelCase   :      Optional[int]										=     range(p_start.shape[1]				)

								__UpperCAmelCase   :      Union[str, Any]										=     []
								for start_id in start_indexes:
											for end_id in end_indexes:
														if start_id < end_id:
																	output.append(
																	    (
																	        start_id,
																	        end_id,
																	        p_start[idx][start_id].item(),
																	        p_end[idx][end_id].item(),
																	    )				)

								output.sort(key=lambda __UpperCAmelCase				: (tup[2] * tup[3]) ,       reverse=__UpperCAmelCase				)
								__UpperCAmelCase   :      Optional[Any]										=     []
								for k in range(len(__UpperCAmelCase				)				):
											if output[k][2] * output[k][3] >= thresh:
														__UpperCAmelCase				,  __UpperCAmelCase   :      Tuple										=     output[k][0], output[k][1]
														__UpperCAmelCase   :      int										=     self.tokenizer.decode(W_query["""input_ids"""][idx][c_start_pos:c_end_pos]				)
														temp.append((decoded, output[k][2] * output[k][3])				)

								final_outputs.append(__UpperCAmelCase				)

					return final_outputs




