


'''simple docstring'''



import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


_lowercase      :      Any            =					get_tests_dir("""fixtures/spiece.model""")






@require_sentencepiece
@require_tokenizers
class 	UpperCamelCase__(       A__						,    unittest.TestCase	):
				__magic_name__    :				List[Any]  		=	AlbertTokenizer
				__magic_name__    :				Optional[int]  		=	AlbertTokenizerFast
				__magic_name__    :				Any  		=	True
				__magic_name__    :				Tuple  		=	True
				__magic_name__    :				List[Any]  		=	True




				def 					a__(		self      :			Tuple				)->					int:

										"""simple docstring"""




										super().setUp()

										# We have a SentencePiece fixture for testing
										UpperCAmelCase					    =     AlbertTokenizer(lowerCamelCase__				)
										tokenizer.save_pretrained(self.tmpdirname				)




				def 					a__(		self      :			List[str]				,   lowerCAmelCase      :			Optional[int]				)->					List[Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     '''this is a test'''
										UpperCAmelCase					    =     '''this is a test'''
										return input_text, output_text




				def 					a__(		self      :			Dict				)->					List[Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     '''<pad>'''
										UpperCAmelCase					    =     0

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




				def 					a__(		self      :			str				)->					List[str]:

										"""simple docstring"""




										UpperCAmelCase					    =     list(self.get_tokenizer().get_vocab().keys()				)

										self.assertEqual(vocab_keys[0]				,   '''<pad>'''				)
										self.assertEqual(vocab_keys[1]				,   '''<unk>'''				)
										self.assertEqual(vocab_keys[-1]				,   '''▁eloquent'''				)
										self.assertEqual(len(lowerCamelCase__				)				,   30000				)




				def 					a__(		self      :			Optional[Any]				)->					Any:

										"""simple docstring"""




										self.assertEqual(self.get_tokenizer().vocab_size				,   30000				)




				def 					a__(		self      :			List[Any]				)->					List[Any]:

										"""simple docstring"""




										if not self.test_rust_tokenizer:
																return

										UpperCAmelCase					    =     self.get_tokenizer()
										UpperCAmelCase					    =     self.get_rust_tokenizer()

										UpperCAmelCase					    =     '''I was born in 92000, and this is falsé.'''

										UpperCAmelCase					    =     tokenizer.tokenize(lowerCamelCase__				)
										UpperCAmelCase					    =     rust_tokenizer.tokenize(lowerCamelCase__				)
										self.assertListEqual(lowerCamelCase__				,   lowerCamelCase__				)

										UpperCAmelCase					    =     tokenizer.encode(lowerCamelCase__				,   add_special_tokens=lowerCamelCase__				)
										UpperCAmelCase					    =     rust_tokenizer.encode(lowerCamelCase__				,   add_special_tokens=lowerCamelCase__				)
										self.assertListEqual(lowerCamelCase__				,   lowerCamelCase__				)

										UpperCAmelCase					    =     self.get_rust_tokenizer()
										UpperCAmelCase					    =     tokenizer.encode(lowerCamelCase__				)
										UpperCAmelCase					    =     rust_tokenizer.encode(lowerCamelCase__				)
										self.assertListEqual(lowerCamelCase__				,   lowerCamelCase__				)




				def 					a__(		self      :			Union[str, Any]				)->					Optional[int]:

										"""simple docstring"""




										UpperCAmelCase					    =     AlbertTokenizer(lowerCamelCase__				,   keep_accents=lowerCamelCase__				)

										UpperCAmelCase					    =     tokenizer.tokenize('''This is a test'''				)
										self.assertListEqual(lowerCamelCase__				,   ['''▁this''', '''▁is''', '''▁a''', '''▁test''']				)

										self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__				)				,   [48, 25, 21, 1289]				)

										UpperCAmelCase					    =     tokenizer.tokenize('''I was born in 92000, and this is falsé.'''				)
										self.assertListEqual(
										    lowerCamelCase__				,   ['''▁i''', '''▁was''', '''▁born''', '''▁in''', '''▁9''', '''2000''', ''',''', '''▁and''', '''▁this''', '''▁is''', '''▁fal''', '''s''', '''é''', '''.''']				)
										UpperCAmelCase					    =     tokenizer.convert_tokens_to_ids(lowerCamelCase__				)
										self.assertListEqual(lowerCamelCase__				,   [31, 23, 386, 19, 561, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]				)

										UpperCAmelCase					    =     tokenizer.convert_ids_to_tokens(lowerCamelCase__				)
										self.assertListEqual(
										    lowerCamelCase__				,   ['''▁i''', '''▁was''', '''▁born''', '''▁in''', '''▁9''', '''2000''', ''',''', '''▁and''', '''▁this''', '''▁is''', '''▁fal''', '''s''', '''<unk>''', '''.''']				,   )




				def 					a__(		self      :			Optional[Any]				)->					Tuple:

										"""simple docstring"""




										UpperCAmelCase					    =     AlbertTokenizer(lowerCamelCase__				)

										UpperCAmelCase					    =     tokenizer.encode('''sequence builders'''				)
										UpperCAmelCase					    =     tokenizer.encode('''multi-sequence build'''				)

										UpperCAmelCase					    =     tokenizer.build_inputs_with_special_tokens(lowerCamelCase__				)
										UpperCAmelCase					    =     tokenizer.build_inputs_with_special_tokens(lowerCamelCase__				,   lowerCamelCase__				)

										assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
										assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
										    tokenizer.sep_token_id
										]





				@slow
				def 					a__(		self      :			Optional[Any]				)->					Any:

										"""simple docstring"""




										UpperCAmelCase					    =     {'''attention_mask''': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], '''input_ids''': [[2, 21970, 13, 5, 6092, 167, 28, 7103, 2153, 673, 8, 7028, 12051, 18, 17, 7103, 2153, 673, 8, 3515, 18684, 8, 4461, 6, 1927, 297, 8, 12060, 2607, 18, 13, 5, 4461, 15, 10538, 38, 8, 135, 15, 822, 58, 15, 993, 10363, 15, 1460, 8005, 4461, 15, 993, 255, 2328, 9, 9, 9, 6, 26, 1112, 816, 3260, 13, 5, 103, 2377, 6, 17, 1112, 816, 2782, 13, 5, 103, 10641, 6, 29, 84, 2512, 2430, 782, 18684, 2761, 19, 808, 2430, 2556, 17, 855, 1480, 9477, 4091, 128, 11712, 15, 7103, 2153, 673, 17, 24883, 9990, 9, 3], [2, 11502, 25, 1006, 20, 782, 8, 11809, 855, 1732, 19393, 18667, 37, 367, 21018, 69, 1854, 34, 11860, 19124, 27, 156, 225, 17, 193, 4141, 19, 65, 9124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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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, 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]]}  # noqa: E501
										# fmt: on

										self.tokenizer_integration_test_util(
										    expected_encoding=lowerCamelCase__				,   model_name='''albert-base-v2'''				,   revision='''6b6560eaf5ff2e250b00c50f380c5389a9c2d82e'''				,   )









'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase      :      int            =					logging.get_logger(__name__)

_lowercase      :      Optional[Any]            =					{"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/config.json"""}






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Union[str, Any]  		=	"openai-gpt"
				__magic_name__    :				Optional[int]  		=	{
				    "max_position_embeddings": "n_positions",
				    "hidden_size": "n_embd",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}




				def __init__(		self      :			Optional[int]				,   lowerCAmelCase      :			Optional[Any]=40478				,   lowerCAmelCase      :			str=512				,   lowerCAmelCase      :			List[Any]=768				,   lowerCAmelCase      :			Tuple=12				,   lowerCAmelCase      :			int=12				,   lowerCAmelCase      :			List[str]="gelu"				,   lowerCAmelCase      :			List[str]=0.1				,   lowerCAmelCase      :			List[Any]=0.1				,   lowerCAmelCase      :			Dict=0.1				,   lowerCAmelCase      :			Tuple=1E-5				,   lowerCAmelCase      :			Tuple=0.02				,   lowerCAmelCase      :			Optional[int]="cls_index"				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			int=0.1				,   **lowerCAmelCase      :			Optional[int]				,   )->					str:

										"""simple docstring"""




										UpperCAmelCase					    =     vocab_size
										UpperCAmelCase					    =     n_positions
										UpperCAmelCase					    =     n_embd
										UpperCAmelCase					    =     n_layer
										UpperCAmelCase					    =     n_head
										UpperCAmelCase					    =     afn
										UpperCAmelCase					    =     resid_pdrop
										UpperCAmelCase					    =     embd_pdrop
										UpperCAmelCase					    =     attn_pdrop
										UpperCAmelCase					    =     layer_norm_epsilon
										UpperCAmelCase					    =     initializer_range
										UpperCAmelCase					    =     summary_type
										UpperCAmelCase					    =     summary_use_proj
										UpperCAmelCase					    =     summary_activation
										UpperCAmelCase					    =     summary_first_dropout
										UpperCAmelCase					    =     summary_proj_to_labels
										super().__init__(**lowerCAmelCase				)





