


import unittest

from transformers import SPIECE_UNDERLINE, XLNetTokenizer, XLNetTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


snake_case				:    List[str]       				=     get_tests_dir('''fixtures/test_sentencepiece.model''')







@require_sentencepiece
@require_tokenizers
class 		_snake_case  (      _snake_case						,    unittest.TestCase							):
 SCREAMING_SNAKE_CASE__      =       XLNetTokenizer
 SCREAMING_SNAKE_CASE__      =       XLNetTokenizerFast
 SCREAMING_SNAKE_CASE__      =       True
 SCREAMING_SNAKE_CASE__      =       True




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       super().setUp()

       # We have a SentencePiece fixture for testing
       a						:Dict 							=       XLNetTokenizer(_lowerCamelCase					,  keep_accents=_lowerCamelCase    )
       tokenizer.sanitize_special_tokens()
       tokenizer.save_pretrained(self.tmpdirname    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:int 							=       '''<s>'''
       a						:Optional[Any] 							=       1

       self.assertEqual(self.get_tokenizer()._convert_token_to_id(_lowerCamelCase    )					,  _lowerCamelCase    )
       self.assertEqual(self.get_tokenizer()._convert_id_to_token(_lowerCamelCase    )					,  _lowerCamelCase    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:int 							=       list(self.get_tokenizer().get_vocab().keys()    )

       self.assertEqual(vocab_keys[0]					,  '''<unk>'''    )
       self.assertEqual(vocab_keys[1]					,  '''<s>'''    )
       self.assertEqual(vocab_keys[-1]					,  '''<eod>'''    )
       self.assertEqual(len(_lowerCamelCase    )					,  1006    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       self.assertEqual(self.get_tokenizer().vocab_size					,  1000    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:int 							=       XLNetTokenizer(_lowerCamelCase					,  keep_accents=_lowerCamelCase    )

       a						:Dict 							=       tokenizer.tokenize('''This is a test'''    )
       self.assertListEqual(_lowerCamelCase					,  ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']    )

       self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCamelCase    )					,  [285, 46, 10, 170, 382]    )

       a						:Optional[int] 							=       tokenizer.tokenize('''I was born in 92000, and this is falsé.'''    )
       self.assertListEqual(
           _lowerCamelCase					,  [
               SPIECE_UNDERLINE + '''I''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''9''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''s''',
               '''é''',
               '''.''',
           ]					,  )
       a						:Union[str, Any] 							=       tokenizer.convert_tokens_to_ids(_lowerCamelCase    )
       self.assertListEqual(_lowerCamelCase					,  [8, 21, 84, 55, 24, 19, 7, 0, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 0, 4]    )

       a						:int 							=       tokenizer.convert_ids_to_tokens(_lowerCamelCase    )
       self.assertListEqual(
           _lowerCamelCase					,  [
               SPIECE_UNDERLINE + '''I''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''<unk>''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''s''',
               '''<unk>''',
               '''.''',
           ]					,  )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:Optional[Any] 							=       XLNetTokenizer(_lowerCamelCase					,  do_lower_case=_lowerCamelCase    )
       a						:Dict 							=       tokenizer.tokenize('''I was born in 92000, and this is falsé.'''    )
       self.assertListEqual(
           _lowerCamelCase					,  [
               SPIECE_UNDERLINE + '''''',
               '''i''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''9''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''se''',
               '''.''',
           ]					,  )
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''    )					,  ['''▁he''', '''ll''', '''o''']    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:List[Any] 							=       XLNetTokenizer(_lowerCamelCase					,  do_lower_case=_lowerCamelCase    )
       a						:Optional[int] 							=       tokenizer.tokenize('''I was born in 92000, and this is falsé.'''    )
       self.assertListEqual(
           _lowerCamelCase					,  [
               SPIECE_UNDERLINE + '''I''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''9''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''se''',
               '''.''',
           ]					,  )




 @slow
 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:int 							=       XLNetTokenizer.from_pretrained('''xlnet-base-cased'''    )

       a						:Optional[Any] 							=       tokenizer.encode('''sequence builders'''					,  add_special_tokens=_lowerCamelCase    )
       a						:Any 							=       tokenizer.encode('''multi-sequence build'''					,  add_special_tokens=_lowerCamelCase    )

       a						:Dict 							=       tokenizer.build_inputs_with_special_tokens(_lowerCamelCase    )
       a						:Any 							=       tokenizer.build_inputs_with_special_tokens(_lowerCamelCase					,  _lowerCamelCase    )

       assert encoded_sentence == text + [4, 3]
       assert encoded_pair == text + [4] + text_a + [4, 3]




 @slow
 def        SCREAMING_SNAKE_CASE__				(		self    ):
       # fmt: off
       a						:Dict 							=       {'''input_ids''': [[17, 2_1442, 270, 17, 10, 1_4645, 318, 34, 17, 4546, 3145, 787, 13, 7752, 2_2018, 23, 21, 17, 4546, 3145, 787, 13, 3352, 1_4431, 13, 5500, 11, 1176, 580, 13, 1_6819, 4797, 23, 17, 10, 1_7135, 658, 19, 457, 7932, 13, 184, 19, 3154, 1_7135, 6468, 19, 1404, 1_2269, 19, 4229, 5356, 1_6264, 46, 19, 17, 2_0545, 1_0395, 9, 9, 9, 11, 28, 6421, 9531, 2_0729, 17, 10, 353, 1_7022, 11, 21, 6421, 9531, 1_6949, 17, 10, 1_1509, 753, 11, 33, 95, 2421, 7385, 956, 1_4431, 2626, 25, 842, 7385, 4836, 21, 1429, 2272, 9855, 3120, 161, 2_4738, 19, 1_3203, 658, 218, 787, 21, 430, 1_8482, 847, 2637, 9, 4, 3], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 322, 2_2178, 27, 1064, 22, 956, 13, 1_1101, 1429, 5854, 2_4313, 1_8953, 40, 422, 2_4366, 68, 1758, 37, 1_0483, 1_4257, 31, 207, 263, 21, 203, 3773, 25, 71, 9735, 9, 4, 3], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}  # noqa: E501
       # fmt: on

       self.tokenizer_integration_test_util(
           expected_encoding=_lowerCamelCase					,  model_name='''xlnet-base-cased'''					,  revision='''c841166438c31ec7ca9a106dee7bb312b73ae511'''					,  )










"""simple docstring"""







from ...configuration_utils import PretrainedConfig


lowerCAmelCase_   						=   {
    'google/tapas-base-finetuned-sqa': (
        'https://huggingface.co/google/tapas-base-finetuned-sqa/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-wtq': (
        'https://huggingface.co/google/tapas-base-finetuned-wtq/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-wikisql-supervised': (
        'https://huggingface.co/google/tapas-base-finetuned-wikisql-supervised/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-tabfact': (
        'https://huggingface.co/google/tapas-base-finetuned-tabfact/resolve/main/config.json'
    ),
}
class        __A       (	A_    ):







		'''simple docstring'''





		lowerCAmelCase			:					str   	=				"tapas"







		def __init__(	self						:  List[Any]			,_snake_case						:  Dict=30_522			,_snake_case						:  Union[str, Any]=768			,_snake_case						:  int=12			,_snake_case						:  Union[str, Any]=12			,_snake_case						:  Union[str, Any]=3_072			,_snake_case						:  List[Any]="gelu"			,_snake_case						:  Optional[int]=0.1			,_snake_case						:  Tuple=0.1			,_snake_case						:  List[Any]=1_024			,_snake_case						:  Any=[3, 256, 256, 2, 256, 256, 10]			,_snake_case						:  List[Any]=0.02			,_snake_case						:  Union[str, Any]=1e-12			,_snake_case						:  str=0			,_snake_case						:  Any=10.0			,_snake_case						:  int=0			,_snake_case						:  Optional[Any]=1.0			,_snake_case						:  List[str]=None			,_snake_case						:  Tuple=1.0			,_snake_case						:  Tuple=False			,_snake_case						:  List[Any]=None			,_snake_case						:  int=1.0			,_snake_case						:  List[Any]=1.0			,_snake_case						:  Optional[int]=False			,_snake_case						:  Optional[int]=False			,_snake_case						:  Optional[int]="ratio"			,_snake_case						:  Any=None			,_snake_case						:  Union[str, Any]=None			,_snake_case						:  List[str]=64			,_snake_case						:  Optional[Any]=32			,_snake_case						:  Optional[Any]=False			,_snake_case						:  Optional[int]=True			,_snake_case						:  Dict=False			,_snake_case						:  Tuple=False			,_snake_case						:  int=True			,_snake_case						:  List[str]=False			,_snake_case						:  Dict=None			,_snake_case						:  Optional[int]=None			,**_snake_case						:  int			,)					->		List[Any]:






				"""simple docstring"""



				super().__init__(pad_token_id=_snake_case			,**_snake_case						)

				# BERT hyperparameters (with updated max_position_embeddings and type_vocab_sizes)
				lowercase__   :    Optional[int]				=			vocab_size
				lowercase__   :    List[str]				=			hidden_size
				lowercase__   :    Any				=			num_hidden_layers
				lowercase__   :    Optional[Any]				=			num_attention_heads
				lowercase__   :    Optional[int]				=			hidden_act
				lowercase__   :    List[Any]				=			intermediate_size
				lowercase__   :    List[Any]				=			hidden_dropout_prob
				lowercase__   :    Dict				=			attention_probs_dropout_prob
				lowercase__   :    str				=			max_position_embeddings
				lowercase__   :    Dict				=			type_vocab_sizes
				lowercase__   :    Optional[Any]				=			initializer_range
				lowercase__   :    Dict				=			layer_norm_eps

				# Fine-tuning task hyperparameters
				lowercase__   :    Any				=			positive_label_weight
				lowercase__   :    int				=			num_aggregation_labels
				lowercase__   :    List[str]				=			aggregation_loss_weight
				lowercase__   :    Optional[int]				=			use_answer_as_supervision
				lowercase__   :    Optional[Any]				=			answer_loss_importance
				lowercase__   :    Union[str, Any]				=			use_normalized_answer_loss
				lowercase__   :    str				=			huber_loss_delta
				lowercase__   :    str				=			temperature
				lowercase__   :    int				=			aggregation_temperature
				lowercase__   :    List[Any]				=			use_gumbel_for_cells
				lowercase__   :    Tuple				=			use_gumbel_for_aggregation
				lowercase__   :    Union[str, Any]				=			average_approximation_function
				lowercase__   :    Union[str, Any]				=			cell_selection_preference
				lowercase__   :    Any				=			answer_loss_cutoff
				lowercase__   :    List[Any]				=			max_num_rows
				lowercase__   :    str				=			max_num_columns
				lowercase__   :    int				=			average_logits_per_cell
				lowercase__   :    str				=			select_one_column
				lowercase__   :    str				=			allow_empty_column_selection
				lowercase__   :    Any				=			init_cell_selection_weights_to_zero
				lowercase__   :    Optional[int]				=			reset_position_index_per_cell
				lowercase__   :    Union[str, Any]				=			disable_per_token_loss

				# Aggregation hyperparameters
				lowercase__   :    Optional[Any]				=			aggregation_labels
				lowercase__   :    List[Any]				=			no_aggregation_label_index

				if isinstance(self.aggregation_labels			,_snake_case						):
						lowercase__   :    Union[str, Any]				=			{int(_snake_case						): v for k, v in aggregation_labels.items()}
