




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


lowerCAmelCase_		      = logging.get_logger(__name__)

lowerCAmelCase_		      = {
    'google/pegasus-large': 'https://huggingface.co/google/pegasus-large/resolve/main/config.json',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}
class 						_A					(  _UpperCAmelCase      ):
  _UpperCamelCase   :			List[Any] =			'pegasus'
  _UpperCamelCase   :			Union[str, Any] =			['past_key_values']
  _UpperCamelCase   :			Optional[Any] =			{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}






  def __init__(  self		:	Any      ,						_A		:	Optional[int]=50_265      ,						_A		:	int=1_024      ,						_A		:	List[str]=12      ,						_A		:	List[Any]=4_096      ,						_A		:	List[str]=16      ,						_A		:	Any=12      ,						_A		:	Union[str, Any]=4_096      ,						_A		:	Tuple=16      ,						_A		:	Optional[Any]=0.0      ,						_A		:	Any=0.0      ,						_A		:	List[str]=True      ,						_A		:	Optional[int]=True      ,						_A		:	Union[str, Any]="gelu"      ,						_A		:	List[str]=1_024      ,						_A		:	int=0.1      ,						_A		:	List[str]=0.0      ,						_A		:	int=0.0      ,						_A		:	Optional[Any]=0.02      ,						_A		:	Optional[int]=0      ,						_A		:	Tuple=False      ,						_A		:	List[Any]=0      ,						_A		:	Any=1      ,						_A		:	List[Any]=1      ,						**_A		:	List[Any]      ,						)		->    Tuple:






       """simple docstring"""







       lowercase					:   str								= vocab_size
       lowercase					:   Optional[Any]								= max_position_embeddings
       lowercase					:   Optional[Any]								= d_model
       lowercase					:   Optional[Any]								= encoder_ffn_dim
       lowercase					:   Optional[int]								= encoder_layers
       lowercase					:   str								= encoder_attention_heads
       lowercase					:   Any								= decoder_ffn_dim
       lowercase					:   str								= decoder_layers
       lowercase					:   Optional[int]								= decoder_attention_heads
       lowercase					:   Dict								= dropout
       lowercase					:   Tuple								= attention_dropout
       lowercase					:   Union[str, Any]								= activation_dropout
       lowercase					:   Dict								= activation_function
       lowercase					:   Any								= init_std
       lowercase					:   Optional[Any]								= encoder_layerdrop
       lowercase					:   Any								= decoder_layerdrop
       lowercase					:   Any								= use_cache
       lowercase					:   Optional[Any]								= encoder_layers
       lowercase					:   Optional[int]								= scale_embedding  # scale factor will be sqrt(d_model) if True
       super().__init__(
           pad_token_id=a__      ,						eos_token_id=a__      ,						is_encoder_decoder=a__      ,						decoder_start_token_id=a__      ,						forced_eos_token_id=a__      ,						**a__      ,						)






  @property
  def 					__a			(  self		:	Any      )		->    Tuple:






       """simple docstring"""







       return self.encoder_attention_heads






  @property
  def 					__a			(  self		:	Tuple      )		->    Optional[Any]:






       """simple docstring"""







       return self.d_model






import os
import unittest

from transformers.models.bartpho.tokenization_bartpho import VOCAB_FILES_NAMES, BartphoTokenizer
from transformers.testing_utils import get_tests_dir

from ...test_tokenization_common import TokenizerTesterMixin


snake_case_				=			get_tests_dir('fixtures/test_sentencepiece_bpe.model')

class 		SCREAMING_SNAKE_CASE__				(       _UpperCAmelCase						,      unittest.TestCase  ):
      A_						:				List[Any]							=    BartphoTokenizer
      A_						:				List[str]							=    False
      A_						:				Optional[Any]							=    True


      def    a (self       :      Tuple      ):





         """simple docstring"""



         super().setUp()

         __snake_case							       =   ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']
         __snake_case							       =   dict(zip(a__				,			range(len(a__      )      )      )      )
         __snake_case							       =   {'''unk_token''': '''<unk>'''}

         __snake_case							       =   os.path.join(self.tmpdirname				,			VOCAB_FILES_NAMES['''monolingual_vocab_file''']      )
         with open(self.monolingual_vocab_file				,			'''w'''				,			encoding='''utf-8'''      ) as fp:
            for token in vocab_tokens:
               fp.write(f"""{token} {vocab_tokens[token]}\n"""      )

         __snake_case							       =   BartphoTokenizer(a__				,			self.monolingual_vocab_file				,			**self.special_tokens_map      )
         tokenizer.save_pretrained(self.tmpdirname      )


      def    a (self       :      str				,			**a__       :      str      ):





         """simple docstring"""



         kwargs.update(self.special_tokens_map      )
         return BartphoTokenizer.from_pretrained(self.tmpdirname				,			**a__      )


      def    a (self       :      str				,			a__       :      Any      ):





         """simple docstring"""



         __snake_case							       =   '''This is a là test'''
         __snake_case							       =   '''This is a<unk><unk> test'''
         return input_text, output_text


      def    a (self       :      Dict      ):





         """simple docstring"""



         __snake_case							       =   BartphoTokenizer(a__				,			self.monolingual_vocab_file				,			**self.special_tokens_map      )
         __snake_case							       =   '''This is a là test'''
         __snake_case							       =   '''▁This ▁is ▁a ▁l à ▁t est'''.split()
         __snake_case							       =   tokenizer.tokenize(a__      )
         self.assertListEqual(a__				,			a__      )

         __snake_case							       =   tokens + [tokenizer.unk_token]
         __snake_case							       =   [4, 5, 6, 3, 3, 7, 8, 3]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(a__      )				,			a__      )

