




'''simple docstring'''







from typing import Callable, Optional, Union

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


_lowerCamelCase							:						Optional[int]							     =  logging.get_logger(__name__)

_lowerCamelCase							:						Dict							     =  {
    'microsoft/prophetnet-large-uncased': (
        'https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'
    ),
}





class 					lowerCamelCase_							(	UpperCAmelCase_							):




					'''simple docstring'''






					lowercase__   =			"""prophetnet"""
					lowercase__   =			["""past_key_values"""]
					lowercase__   =			{
					    """num_attention_heads""": """num_encoder_attention_heads""",
					}






					def __init__(   self,  __UpperCamelCase = 0.1,  __UpperCamelCase = "gelu",  __UpperCamelCase = 30_522,  __UpperCamelCase = 1_024,  __UpperCamelCase = 4_096,  __UpperCamelCase = 12,  __UpperCamelCase = 16,  __UpperCamelCase = 4_096,  __UpperCamelCase = 12,  __UpperCamelCase = 16,  __UpperCamelCase = 0.1,  __UpperCamelCase = 0.1,  __UpperCamelCase = 512,  __UpperCamelCase = 0.02,  __UpperCamelCase = True,  __UpperCamelCase = True,  __UpperCamelCase = 0,  __UpperCamelCase = 2,  __UpperCamelCase = 32,  __UpperCamelCase = 128,  __UpperCamelCase = False,  __UpperCamelCase = 0.0,  __UpperCamelCase = True,  __UpperCamelCase = 0,  __UpperCamelCase = 1,  __UpperCamelCase = 2,  **__UpperCamelCase,  ):
							_snake_case     	=	vocab_size
							_snake_case     	=	hidden_size
							_snake_case     	=	encoder_ffn_dim
							_snake_case     	=	num_encoder_layers
							_snake_case     	=	num_encoder_attention_heads
							_snake_case     	=	decoder_ffn_dim
							_snake_case     	=	num_decoder_layers
							_snake_case     	=	num_decoder_attention_heads
							_snake_case     	=	max_position_embeddings
							_snake_case     	=	init_std  # Normal(0, this parameter)
							_snake_case     	=	activation_function

							# parameters for prophetnet
							_snake_case     	=	ngram
							_snake_case     	=	num_buckets
							_snake_case     	=	relative_max_distance
							_snake_case     	=	disable_ngram_loss
							_snake_case     	=	eps

							# 3 Types of Dropout
							_snake_case     	=	attention_dropout
							_snake_case     	=	activation_dropout
							_snake_case     	=	dropout

							_snake_case     	=	use_cache

							super().__init__(
							    pad_token_id=__UpperCamelCase,  bos_token_id=__UpperCamelCase,  eos_token_id=__UpperCamelCase,  is_encoder_decoder=__UpperCamelCase,  add_cross_attention=__UpperCamelCase,  decoder_start_token_id=__UpperCamelCase,  **__UpperCamelCase,  )






					@property
					def     __SCREAMING_SNAKE_CASE     (   self			):
							return self.num_encoder_layers + self.num_decoder_layers






					@num_hidden_layers.setter
					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase			):
							raise NotImplementedError(
							    "This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and"
							    " `num_decoder_layers`."			)











'''simple docstring'''







import os
import tempfile
import unittest
from typing import List

from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
from transformers.testing_utils import require_tokenizers
from transformers.tokenization_utils import PreTrainedTokenizer
from transformers.tokenization_utils_base import PreTrainedTokenizerBase





@require_tokenizers
class 					lowerCamelCase_							(	unittest.TestCase							):




					'''simple docstring'''






					lowercase__   =			EsmTokenizer






					def     __SCREAMING_SNAKE_CASE     (   self			):
							super().setUp()
							_snake_case     	=	tempfile.mkdtemp()
							# fmt: off
							_snake_case     	=	["<cls>", "<pad>", "<eos>", "<unk>", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "<null_1>", "<mask>"]  # noqa: E501
							# fmt: on
							_snake_case     	=	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     __SCREAMING_SNAKE_CASE     (   self,  **__UpperCamelCase			):
							return [self.get_tokenizer(**__UpperCamelCase			)]






					def     __SCREAMING_SNAKE_CASE     (   self,  **__UpperCamelCase			):
							return self.tokenizer_class.from_pretrained(self.tmpdirname,  **__UpperCamelCase			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	tokenizer.tokenize("LAGVS"			)
							self.assertListEqual(__UpperCamelCase,  ["L", "A", "G", "V", "S"]			)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCamelCase			),  [4, 5, 6, 7, 8]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	"LAGVS"
							self.assertListEqual(tokenizer.encode(__UpperCamelCase			),  [0, 4, 5, 6, 7, 8, 2]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	["LAGVS", "WCB"]
							_snake_case     	=	tokenizer(__UpperCamelCase,  padding=__UpperCamelCase			)["input_ids"]

							self.assertListEqual(__UpperCamelCase,  [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2]]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	["LAGVS", "WCB"]
							_snake_case     	=	tokenizer(__UpperCamelCase,  padding=__UpperCamelCase			)["input_ids"]

							self.assertListEqual(__UpperCamelCase,  [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2, 1, 1]]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.get_tokenizers(fast=__UpperCamelCase			)
							for tokenizer in tokenizers:
									with self.subTest(f'''{tokenizer.__class__.__name__}'''			):
											_snake_case     	=	"<unk>"
											_snake_case     	=	"<mask>"

											_snake_case     	=	tokenizer.tokenize(__UpperCamelCase			)
											_snake_case     	=	tokenizer.tokenize(__UpperCamelCase			)

											self.assertEqual(len(__UpperCamelCase			),  1			)
											self.assertEqual(len(__UpperCamelCase			),  1			)
											self.assertEqual(token_a[0],  __UpperCamelCase			)
											self.assertEqual(token_a[0],  __UpperCamelCase			)





