
import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
   from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder


def 			UpperCamelCase					(    __lowerCamelCase     : str				,					__lowerCamelCase     : str				,					__lowerCamelCase     : Optional[Any]				,					__lowerCamelCase     : str=None				,					__lowerCamelCase     : Dict=None				,					__lowerCamelCase     : Optional[int]=None				,					__lowerCamelCase     : Optional[Any]=None				,					__lowerCamelCase     : List[str]=None				,					):
       if attention_mask is None:
              snake_case       :   Optional[Any]							=      input_ids.ne(config.pad_token_id    )
       if decoder_attention_mask is None:
              snake_case       :   Tuple							=      decoder_input_ids.ne(config.pad_token_id    )
       if head_mask is None:
              snake_case       :   Dict							=      torch.ones(config.encoder_layers				,					config.encoder_attention_heads				,					device=__lowerCamelCase    )
       if decoder_head_mask is None:
              snake_case       :   List[Any]							=      torch.ones(config.decoder_layers				,					config.decoder_attention_heads				,					device=__lowerCamelCase    )
       if cross_attn_head_mask is None:
              snake_case       :   Optional[int]							=      torch.ones(config.decoder_layers				,					config.decoder_attention_heads				,					device=__lowerCamelCase    )
       return {
           "input_ids": input_ids,
           "decoder_input_ids": decoder_input_ids,
           "attention_mask": attention_mask,
           "decoder_attention_mask": attention_mask,
           "head_mask": head_mask,
           "decoder_head_mask": decoder_head_mask,
           "cross_attn_head_mask": cross_attn_head_mask,
       }






class   UpperCAmelCase		:



   def __init__(self		:					Any    ,						snake_case__		:					Dict    ,						snake_case__		:					Union[str, Any]=13    ,						snake_case__		:					str=7    ,						snake_case__		:					List[str]=True    ,						snake_case__		:					Any=False    ,						snake_case__		:					Tuple=99    ,						snake_case__		:					str=16    ,						snake_case__		:					Optional[int]=2    ,						snake_case__		:					int=4    ,						snake_case__		:					int=4    ,						snake_case__		:					Optional[Any]="relu"    ,						snake_case__		:					Union[str, Any]=0.1    ,						snake_case__		:					Any=0.1    ,						snake_case__		:					Optional[Any]=0.0    ,						snake_case__		:					int=0.0    ,						snake_case__		:					Optional[Any]=20    ,						snake_case__		:					int=2    ,						snake_case__		:					Any=1    ,						snake_case__		:					str=0    ,						)		->	Optional[Any]:


          '''simple docstring'''


          snake_case       :   str							=      parent
          snake_case       :   int							=      batch_size
          snake_case       :   int							=      seq_length
          snake_case       :   str							=      is_training
          snake_case       :   Tuple							=      use_labels
          snake_case       :   List[Any]							=      vocab_size
          snake_case       :   List[str]							=      hidden_size
          snake_case       :   str							=      num_hidden_layers
          snake_case       :   Dict							=      num_attention_heads
          snake_case       :   int							=      intermediate_size
          snake_case       :   int							=      hidden_act
          snake_case       :   List[Any]							=      hidden_dropout_prob
          snake_case       :   Tuple							=      attention_probs_dropout_prob
          snake_case       :   int							=      encoder_layerdrop
          snake_case       :   Tuple							=      decoder_layerdrop
          snake_case       :   Tuple							=      max_position_embeddings
          snake_case       :   Optional[int]							=      eos_token_id
          snake_case       :   int							=      pad_token_id
          snake_case       :   Optional[Any]							=      bos_token_id



   def 				_SCREAMING_SNAKE_CASE   (self		:					Any )		->	List[str]:


          '''simple docstring'''


          snake_case       :   str							=      ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size )
          snake_case       :   Any							=      self.eos_token_id  # Eos Token
          snake_case       :   int							=      ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size )

          # we need to clamp the input ids here to avoid having pad token in between
          # this is because for M2M100 the position_ids are prepared such that
          # all pad tokens have pos id = 2 and rest are between 2..seq_length
          # and the seq_length here is seq_length - num_pad_tokens
          # but when using past, there is no way of knowing if the past input ids had
          # pad tokens in them, which results in incorrect seq_lenth and which in turn results in
          # position_ids being off by num_pad_tokens in past input
          snake_case       :   Dict							=      input_ids.clamp(self.pad_token_id + 1 )
          snake_case       :   List[str]							=      decoder_input_ids.clamp(self.pad_token_id + 1 )

          snake_case       :   Dict							=      self.get_config()
          snake_case       :   Tuple							=      prepare_mam_aaa_inputs_dict(snake_case__    ,						snake_case__    ,						snake_case__ )
          return config, inputs_dict



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


          '''simple docstring'''


          return MaMaaaConfig(
              vocab_size=self.vocab_size    ,						d_model=self.hidden_size    ,						encoder_layers=self.num_hidden_layers    ,						decoder_layers=self.num_hidden_layers    ,						encoder_attention_heads=self.num_attention_heads    ,						decoder_attention_heads=self.num_attention_heads    ,						encoder_ffn_dim=self.intermediate_size    ,						decoder_ffn_dim=self.intermediate_size    ,						dropout=self.hidden_dropout_prob    ,						attention_dropout=self.attention_probs_dropout_prob    ,						encoder_layerdrop=self.encoder_layerdrop    ,						decoder_layerdrop=self.decoder_layerdrop    ,						max_position_embeddings=self.max_position_embeddings    ,						eos_token_id=self.eos_token_id    ,						bos_token_id=self.bos_token_id    ,						pad_token_id=self.pad_token_id    ,						)



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


          '''simple docstring'''


          snake_case				,					snake_case       :   List[str]							=      self.prepare_config_and_inputs()
          return config, inputs_dict



   def 				_SCREAMING_SNAKE_CASE   (self		:					Dict    ,						snake_case__		:					Dict    ,						snake_case__		:					Optional[int] )		->	Optional[int]:


          '''simple docstring'''


          snake_case       :   Optional[int]							=      MaMaaaModel(config=snake_case__ ).get_decoder().to(snake_case__ ).eval()
          snake_case       :   List[str]							=      inputs_dict["input_ids"]
          snake_case       :   Optional[Any]							=      inputs_dict["attention_mask"]
          snake_case       :   Dict							=      inputs_dict["head_mask"]

          # first forward pass
          snake_case       :   Any							=      model(snake_case__    ,						attention_mask=snake_case__    ,						head_mask=snake_case__    ,						use_cache=snake_case__ )

          snake_case				,					snake_case       :   List[str]							=      outputs.to_tuple()

          # create hypothetical multiple next token and extent to next_input_ids
          snake_case       :   str							=      ids_tensor((self.batch_size, 3)    ,						config.vocab_size )
          snake_case       :   int							=      ids_tensor((self.batch_size, 3)    ,						2 )

          # append to next input_ids and
          snake_case       :   Union[str, Any]							=      torch.cat([input_ids, next_tokens]    ,						dim=-1 )
          snake_case       :   List[Any]							=      torch.cat([attention_mask, next_attn_mask]    ,						dim=-1 )

          snake_case       :   Union[str, Any]							=      model(snake_case__    ,						attention_mask=snake_case__ )["last_hidden_state"]
          snake_case       :   Optional[int]							=      model(snake_case__    ,						attention_mask=snake_case__    ,						past_key_values=snake_case__ )[
              "last_hidden_state"
          ]

          # select random slice
          snake_case       :   Dict							=      ids_tensor((1,)    ,						output_from_past.shape[-1] ).item()
          snake_case       :   Optional[int]							=      output_from_no_past[:, -3:, random_slice_idx].detach()
          snake_case       :   str							=      output_from_past[:, :, random_slice_idx].detach()

          self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1] )

          # test that outputs are equal for slice
          self.parent.assertTrue(torch.allclose(snake_case__    ,						snake_case__    ,						atol=1e-2 ) )



   def 				_SCREAMING_SNAKE_CASE   (self		:					Dict    ,						snake_case__		:					Optional[Any]    ,						snake_case__		:					List[str] )		->	Union[str, Any]:


          '''simple docstring'''


          snake_case       :   Optional[Any]							=      MaMaaaModel(config=snake_case__ ).to(snake_case__ ).eval()
          snake_case       :   int							=      model(**snake_case__ )

          snake_case       :   List[str]							=      outputs.encoder_last_hidden_state
          snake_case       :   Optional[int]							=      outputs.last_hidden_state

          with tempfile.TemporaryDirectory() as tmpdirname:
                 snake_case       :   int							=      model.get_encoder()
                 encoder.save_pretrained(snake_case__ )
                 snake_case       :   Optional[int]							=      MaMaaaEncoder.from_pretrained(snake_case__ ).to(snake_case__ )

          snake_case       :   Any							=      encoder(inputs_dict["input_ids"]    ,						attention_mask=inputs_dict["attention_mask"] )[
              0
          ]

          self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1e-3 )

          with tempfile.TemporaryDirectory() as tmpdirname:
                 snake_case       :   int							=      model.get_decoder()
                 decoder.save_pretrained(snake_case__ )
                 snake_case       :   List[str]							=      MaMaaaDecoder.from_pretrained(snake_case__ ).to(snake_case__ )

          snake_case       :   Tuple							=      decoder(
              input_ids=inputs_dict["decoder_input_ids"]    ,						attention_mask=inputs_dict["decoder_attention_mask"]    ,						encoder_hidden_states=snake_case__    ,						encoder_attention_mask=inputs_dict["attention_mask"]    ,						)[0]

          self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1e-3 )






@require_torch
class   UpperCAmelCase		(						A_       ,A_       ,A_       ,unittest.TestCase ):
   A__					:		str						     =     (
       (
           MaMaaaModel,
           MaMaaaForConditionalGeneration,
       )
       if is_torch_available()
       else ()
   )
   A__					:		List[Any]						     =     (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
   A__					:		str						     =     (
       {
           "conversational": MaMaaaForConditionalGeneration,
           "feature-extraction": MaMaaaModel,
           "summarization": MaMaaaForConditionalGeneration,
           "text2text-generation": MaMaaaForConditionalGeneration,
           "translation": MaMaaaForConditionalGeneration,
       }
       if is_torch_available()
       else {}
   )
   A__					:		Tuple						     =     True
   A__					:		List[str]						     =     True
   A__					:		Any						     =     False
   A__					:		Optional[Any]						     =     False



   def 				_SCREAMING_SNAKE_CASE   (self		:					List[str]    ,						snake_case__		:					Union[str, Any]    ,						snake_case__		:					List[str]    ,						snake_case__		:					Optional[int]    ,						snake_case__		:					Union[str, Any]    ,						snake_case__		:					Optional[int] )		->	List[Any]:


          '''simple docstring'''


          if pipeline_test_casse_name == "TranslationPipelineTests":
                 # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
                 # `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
                 return True

          return False



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


          '''simple docstring'''


          snake_case       :   str							=      MaMaaaModelTester(self )
          snake_case       :   List[Any]							=      ConfigTester(self    ,						config_class=snake_case__ )



   def 				_SCREAMING_SNAKE_CASE   (self		:					int )		->	int:


          '''simple docstring'''


          self.config_tester.run_common_tests()



   def 				_SCREAMING_SNAKE_CASE   (self		:					List[Any] )		->	Optional[Any]:


          '''simple docstring'''


          snake_case				,					snake_case       :   Dict							=      self.model_tester.prepare_config_and_inputs()
          for model_class in self.all_model_classes:
                 snake_case       :   Dict							=      model_class(snake_case__ )

                 with tempfile.TemporaryDirectory() as tmpdirname:
                        model.save_pretrained(snake_case__ )
                        snake_case				,					snake_case       :   Optional[int]							=      model_class.from_pretrained(snake_case__    ,						output_loading_info=snake_case__ )
                 self.assertEqual(info["missing_keys"]    ,						[] )



   def 				_SCREAMING_SNAKE_CASE   (self		:					Optional[Any] )		->	Optional[int]:


          '''simple docstring'''


          snake_case       :   List[str]							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_decoder_model_past_large_inputs(*snake_case__ )



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


          '''simple docstring'''


          snake_case       :   Optional[Any]							=      self.model_tester.prepare_config_and_inputs_for_common()
          self.model_tester.check_encoder_decoder_model_standalone(*snake_case__ )



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


          '''simple docstring'''


          snake_case				,					snake_case       :   int							=      self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
                 snake_case       :   Any							=      model_class(snake_case__ )
                 model.to(snake_case__ )
                 model.eval()

                 snake_case       :   Any							=      copy.deepcopy(self._prepare_for_class(snake_case__    ,						snake_case__ ) )

                 if not self.is_encoder_decoder:
                        snake_case       :   Optional[Any]							=      inputs["input_ids"]
                        del inputs["input_ids"]
                 else:
                        snake_case       :   Union[str, Any]							=      inputs["input_ids"]
                        snake_case       :   Dict							=      inputs.get("decoder_input_ids"    ,						snake_case__ )
                        del inputs["input_ids"]
                        inputs.pop("decoder_input_ids"    ,						snake_case__ )

                 snake_case       :   List[str]							=      model.get_input_embeddings()
                 if not self.is_encoder_decoder:
                        snake_case       :   Union[str, Any]							=      wte(snake_case__ )
                 else:
                        snake_case       :   List[str]							=      wte(snake_case__ )
                        snake_case       :   str							=      wte(snake_case__ )

                 with torch.no_grad():
                        model(**snake_case__ )[0]



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


          '''simple docstring'''


          snake_case				,					snake_case       :   Optional[int]							=      self.model_tester.prepare_config_and_inputs()
          snake_case       :   Union[str, Any]							=      input_dict["input_ids"]
          snake_case       :   Optional[int]							=      input_ids.ne(1 ).to(snake_case__ )
          snake_case       :   Optional[int]							=      MaMaaaForConditionalGeneration(snake_case__ ).eval().to(snake_case__ )
          if torch_device == "cuda":
                 model.half()
          model.generate(snake_case__    ,						attention_mask=snake_case__ )
          model.generate(num_beams=4    ,						do_sample=snake_case__    ,						early_stopping=snake_case__    ,						num_return_sequences=3 )



def 			UpperCamelCase					(    __lowerCamelCase     : Optional[Any]    ):
       return torch.tensor(__lowerCamelCase				,					dtype=torch.long				,					device=__lowerCamelCase    )


__lowerCamelCase							=       1e-4






@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class   UpperCAmelCase		(						unittest.TestCase ):



   @cached_property
   def 				_SCREAMING_SNAKE_CASE   (self		:					Union[str, Any] )		->	str:


          '''simple docstring'''


          return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M" )



   def 				_SCREAMING_SNAKE_CASE   (self		:					List[str] )		->	Tuple:


          '''simple docstring'''


          snake_case       :   int							=      MaMaaaModel.from_pretrained("facebook/m2m100_418M" ).to(snake_case__ )
          snake_case       :   List[str]							=      _long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]] )
          snake_case       :   List[str]							=      _long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]] )
          snake_case       :   Union[str, Any]							=      prepare_mam_aaa_inputs_dict(model.config    ,						snake_case__    ,						snake_case__ )
          with torch.no_grad():
                 snake_case       :   Dict							=      model(**snake_case__ )[0]
          snake_case       :   Any							=      torch.Size((1, 11, 10_24) )
          self.assertEqual(output.shape    ,						snake_case__ )
          # change to expected output here
          snake_case       :   Optional[Any]							=      torch.tensor(
              [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]    ,						device=snake_case__ )
          self.assertTrue(torch.allclose(output[:, :3, :3]    ,						snake_case__    ,						atol=snake_case__ ) )



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


          '''simple docstring'''


          snake_case       :   Union[str, Any]							=      MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M" ).to(snake_case__ )

          # change to intended input
          snake_case       :   List[str]							=      _long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]] )
          snake_case       :   str							=      _long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]] )
          snake_case       :   Optional[int]							=      prepare_mam_aaa_inputs_dict(model.config    ,						snake_case__    ,						snake_case__ )
          with torch.no_grad():
                 snake_case       :   Any							=      model(**snake_case__ )[0]
          snake_case       :   Union[str, Any]							=      torch.Size((1, 11, model.config.vocab_size) )
          self.assertEqual(output.shape    ,						snake_case__ )
          # change to expected output here
          snake_case       :   int							=      torch.tensor(
              [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]    ,						device=snake_case__ )
          self.assertTrue(torch.allclose(output[:, :3, :3]    ,						snake_case__    ,						atol=snake_case__ ) )



   def 				_SCREAMING_SNAKE_CASE   (self		:					Tuple )		->	List[str]:


          '''simple docstring'''


          snake_case       :   List[str]							=      MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M" ).to(snake_case__ )
          snake_case       :   int							=      MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"    ,						src_lang="fr"    ,						tgt_lang="en" )

          snake_case       :   List[str]							=      [
              "L'affaire NSA souligne l'absence totale de débat sur le renseignement",
              "Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.",
              "Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"
              " Fabius convoque l'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"
              " l'ampleur de la surveillance américaine sur l'ensemble des communications en France.",
          ]

          # The below article tests that we don't add any hypotheses outside of the top n_beams
          snake_case       :   List[str]							=      tokenizer(snake_case__    ,						padding=snake_case__    ,						return_tensors="pt" )

          snake_case       :   Any							=      model.generate(
              input_ids=dct["input_ids"].to(snake_case__ )    ,						attention_mask=dct["attention_mask"].to(snake_case__ )    ,						num_beams=5    ,						forced_bos_token_id=tokenizer.get_lang_id("en" )    ,						)

          snake_case       :   List[Any]							=      [
              "The NSA case highlights the total absence of intelligence debate",
              "I think there are two levels of response from the French government.",
              "When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."
              " Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"
              " communications in France.",
          ]

          snake_case       :   List[str]							=      tokenizer.batch_decode(
              hypotheses_batch.tolist()    ,						clean_up_tokenization_spaces=snake_case__    ,						skip_special_tokens=snake_case__ )
          assert generated == expected_en












'''simple docstring'''




import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing


class  SCREAMING_SNAKE_CASE    (a__							):


     def __init__(						self						,	_UpperCAmelCase = "▁"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = "<unk>"						,	_UpperCAmelCase = "</s>"						,	_UpperCAmelCase = "<pad>"						,	):

          '''simple docstring'''






          __A						: Dict      =       {
              'pad': {'id': 0, 'token': pad_token},
              'eos': {'id': 1, 'token': eos_token},
              'unk': {'id': 2, 'token': unk_token},
          }

          __A						: List[Any]      =       [None] * len(self.special_tokens)
          for token_dict in self.special_tokens.values():
               __A						: List[str]      =       token_dict['token']

          __A						: str      =       Tokenizer(Unigram())

          __A						: Dict      =       normalizers.Sequence(
              [
                  normalizers.Nmt(),
                  normalizers.NFKC(),
                  normalizers.Replace(Regex(' {2,}')						,	' '),
                  normalizers.Lowercase(),
              ])
          __A						: Union[str, Any]      =       pre_tokenizers.Sequence(
              [
                  pre_tokenizers.Metaspace(replacement=_UpperCAmelCase						,	add_prefix_space=_UpperCAmelCase),
                  pre_tokenizers.Digits(individual_digits=_UpperCAmelCase),
                  pre_tokenizers.Punctuation(),
              ])
          __A						: Any      =       decoders.Metaspace(replacement=_UpperCAmelCase						,	add_prefix_space=_UpperCAmelCase)

          __A						: Dict      =       TemplateProcessing(
              single=F'$A {self.special_tokens["eos"]["token"]}'						,	special_tokens=[(self.special_tokens['eos']['token'], self.special_tokens['eos']['id'])]						,	)

          __A						: Any      =       {
              'model': 'SentencePieceUnigram',
              'replacement': replacement,
              'add_prefix_space': add_prefix_space,
          }

          super().__init__(_UpperCAmelCase						,	_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 8000						,	_UpperCAmelCase = True						,	):

          '''simple docstring'''






          __A						: str      =       trainers.UnigramTrainer(
              vocab_size=_UpperCAmelCase						,	special_tokens=self.special_tokens_list						,	show_progress=_UpperCAmelCase						,	)

          if isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
               __A						: Union[str, Any]      =       [files]
          self._tokenizer.train(_UpperCAmelCase						,	trainer=_UpperCAmelCase)

          self.add_unk_id()


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 8000						,	_UpperCAmelCase = True						,	):

          '''simple docstring'''






          __A						: Dict      =       trainers.UnigramTrainer(
              vocab_size=_UpperCAmelCase						,	special_tokens=self.special_tokens_list						,	show_progress=_UpperCAmelCase						,	)

          self._tokenizer.train_from_iterator(_UpperCAmelCase						,	trainer=_UpperCAmelCase)

          self.add_unk_id()


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Any      =       json.loads(self._tokenizer.to_str())

          __A						: Union[str, Any]      =       self.special_tokens['unk']['id']

          __A						: str      =       Tokenizer.from_str(json.dumps(_UpperCAmelCase))