
'''simple docstring'''
import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin


class 			SCREAMING_SNAKE_CASE__      (     snake_case_							,       unittest.TestCase):
				lowerCAmelCase_     			=							ProphetNetTokenizer
				lowerCAmelCase_     			=							False







				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											super().setUp()

											UpperCamelCase   			=     [
											    '[UNK]',
											    '[CLS]',
											    '[SEP]',
											    '[PAD]',
											    '[MASK]',
											    'want',
											    '##want',
											    '##ed',
											    'wa',
											    'un',
											    'runn',
											    '##ing',
											    ',',
											    'low',
											    'lowest',
											]
											UpperCamelCase   			=     os.path.join(self.tmpdirname						,				VOCAB_FILES_NAMES['vocab_file']     )
											with open(self.vocab_file						,				'w'						,				encoding='utf-8'     ) as vocab_writer:
																		vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]     )     )







				def 						UpperCAmelCase_    (       self						,				A_     )->		Tuple:







											'''simple docstring'''






											UpperCamelCase   			=     'UNwant\u00E9d,running'
											UpperCamelCase   			=     'unwanted, running'
											return input_text, output_text







				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     self.tokenizer_class(self.vocab_file     )

											UpperCamelCase   			=     tokenizer.tokenize('UNwant\u00E9d,running'     )
											self.assertListEqual(A_						,				['un', '##want', '##ed', ',', 'runn', '##ing']     )
											self.assertListEqual(tokenizer.convert_tokens_to_ids(A_     )						,				[9, 6, 7, 12, 10, 11]     )







				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer()

											self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'     )						,				['ah', '\u535A', '\u63A8', 'zz']     )







				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     )						,				['hello', '!', 'how', 'are', 'you', '?']     )
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,				['hello']     )







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







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_						,				strip_accents=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,				['hällo', '!', 'how', 'are', 'you', '?']     )
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,				['h\u00E9llo']     )







				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_						,				strip_accents=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,				['hallo', '!', 'how', 'are', 'you', '?']     )
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,				['hello']     )







				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,				['hallo', '!', 'how', 'are', 'you', '?']     )
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,				['hello']     )







				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     )						,				['HeLLo', '!', 'how', 'Are', 'yoU', '?']     )







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







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_						,				strip_accents=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,				['HäLLo', '!', 'how', 'Are', 'yoU', '?']     )







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







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_						,				strip_accents=A_     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,				['HaLLo', '!', 'how', 'Are', 'yoU', '?']     )







				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											UpperCamelCase   			=     BasicTokenizer(do_lower_case=A_						,				never_split=['[UNK]']     )

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'     )						,				['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']     )







				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     ['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

											UpperCamelCase   			=     {}
											for i, token in enumerate(A_     ):
																		UpperCamelCase   			=     i
											UpperCamelCase   			=     WordpieceTokenizer(vocab=A_						,				unk_token='[UNK]'     )

											self.assertListEqual(tokenizer.tokenize(''     )						,				[]     )

											self.assertListEqual(tokenizer.tokenize('unwanted running'     )						,				['un', '##want', '##ed', 'runn', '##ing']     )

											self.assertListEqual(tokenizer.tokenize('unwantedX running'     )						,				['[UNK]', 'runn', '##ing']     )







				@require_torch
				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'     )

											UpperCamelCase   			=     ['A long paragraph for summarization.', 'Another paragraph for summarization.']
											UpperCamelCase   			=     [1037, 2146, 20423, 2005, 7680, 7849, 3989, 1012, 102]
											UpperCamelCase   			=     tokenizer(A_						,				padding=A_						,				return_tensors='pt'     )
											self.assertIsInstance(A_						,				A_     )
											UpperCamelCase   			=     list(batch.input_ids.numpy()[0]     )
											self.assertListEqual(A_						,				A_     )

											self.assertEqual((2, 9)						,				batch.input_ids.shape     )
											self.assertEqual((2, 9)						,				batch.attention_mask.shape     )







				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											self.assertTrue(_is_whitespace(' '     )     )
											self.assertTrue(_is_whitespace('\t'     )     )
											self.assertTrue(_is_whitespace('\r'     )     )
											self.assertTrue(_is_whitespace('\n'     )     )
											self.assertTrue(_is_whitespace('\u00A0'     )     )

											self.assertFalse(_is_whitespace('A'     )     )
											self.assertFalse(_is_whitespace('-'     )     )







				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											self.assertTrue(_is_control('\u0005'     )     )

											self.assertFalse(_is_control('A'     )     )
											self.assertFalse(_is_control(' '     )     )
											self.assertFalse(_is_control('\t'     )     )
											self.assertFalse(_is_control('\r'     )     )







				def 						UpperCAmelCase_    (       self     )->		Tuple:







											'''simple docstring'''






											self.assertTrue(_is_punctuation('-'     )     )
											self.assertTrue(_is_punctuation('$'     )     )
											self.assertTrue(_is_punctuation('`'     )     )
											self.assertTrue(_is_punctuation('.'     )     )

											self.assertFalse(_is_punctuation('A'     )     )
											self.assertFalse(_is_punctuation(' '     )     )







				@slow
				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'     )

											UpperCamelCase   			=     tokenizer.encode('sequence builders'						,				add_special_tokens=A_     )
											UpperCamelCase   			=     tokenizer.encode('multi-sequence build'						,				add_special_tokens=A_     )

											UpperCamelCase   			=     tokenizer.build_inputs_with_special_tokens(A_     )
											UpperCamelCase   			=     tokenizer.build_inputs_with_special_tokens(A_						,				A_     )

											assert encoded_sentence == text + [102]
											assert encoded_pair == text + [102] + text_a + [102]












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


__a   :							Dict						= logging.get_logger(__name__)

__a   :							Dict						= {
    "bigcode/gpt_bigcode-santacoder": "https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json",
}


class    __lowercase   (						lowercase_	):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE     =					"gpt_bigcode"
     SCREAMING_SNAKE_CASE     =					["past_key_values"]
     SCREAMING_SNAKE_CASE     =					{
         "hidden_size": "n_embd",
         "max_position_embeddings": "n_positions",
         "num_attention_heads": "n_head",
         "num_hidden_layers": "n_layer",
     }




     def __init__(					self							:      List[str]			,						UpperCamelCase_							:      Dict=50_257			,						UpperCamelCase_							:      int=1_024			,						UpperCamelCase_							:      List[Any]=768			,						UpperCamelCase_							:      str=12			,						UpperCamelCase_							:      Union[str, Any]=12			,						UpperCamelCase_							:      Optional[Any]=None			,						UpperCamelCase_							:      Tuple="gelu_pytorch_tanh"			,						UpperCamelCase_							:      Optional[Any]=0.1			,						UpperCamelCase_							:      List[str]=0.1			,						UpperCamelCase_							:      Optional[int]=0.1			,						UpperCamelCase_							:      int=1e-5			,						UpperCamelCase_							:      Tuple=0.02			,						UpperCamelCase_							:      Any=True			,						UpperCamelCase_							:      List[Any]=True			,						UpperCamelCase_							:      Dict=50_256			,						UpperCamelCase_							:      Optional[Any]=50_256			,						UpperCamelCase_							:      int=True			,						UpperCamelCase_							:      List[Any]=True			,						UpperCamelCase_							:      List[Any]=True			,						**UpperCamelCase_							:      int			,						):


         """simple docstring"""



         __A       =						vocab_size
         __A       =						n_positions
         __A       =						n_embd
         __A       =						n_layer
         __A       =						n_head
         __A       =						n_inner
         __A       =						activation_function
         __A       =						resid_pdrop
         __A       =						embd_pdrop
         __A       =						attn_pdrop
         __A       =						layer_norm_epsilon
         __A       =						initializer_range
         __A       =						scale_attn_weights
         __A       =						use_cache
         __A       =						attention_softmax_in_fpaa
         __A       =						scale_attention_softmax_in_fpaa
         __A       =						multi_query

         __A       =						bos_token_id
         __A       =						eos_token_id

         super().__init__(bos_token_id=UpperCamelCase_			,						eos_token_id=UpperCamelCase_			,						**UpperCamelCase_					)




