





'''simple docstring'''






import enum
import warnings

from .. import MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_CAUSAL_LM_MAPPING
from ..utils import add_end_docstrings, is_tf_available
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
	import tensorflow as tf




class  _A (					enum.Enum		):
		lowercase__:   Any				     =   0
		lowercase__:   Optional[Any]				     =   1
		lowercase__:   List[Any]				     =   2





@add_end_docstrings(__lowercase		)
class  _A (					__lowercase		):
		lowercase__:   List[Any]				     =   '''
    In 1991, the remains of Russian Tsar Nicholas II and his family (except for Alexei and Maria) are discovered. The
    voice of Nicholas\'s young son, Tsarevich Alexei Nikolaevich, narrates the remainder of the story. 1883 Western
    Siberia, a young Grigori Rasputin is asked by his father and a group of men to perform magic. Rasputin has a vision
    and denounces one of the men as a horse thief. Although his father initially slaps him for making such an
    accusation, Rasputin watches as the man is chased outside and beaten. Twenty years later, Rasputin sees a vision of
    the Virgin Mary, prompting him to become a priest. Rasputin quickly becomes famous, with people, even a bishop,
    begging for his blessing. <eod> </s> <eos>
    '''

		def __init__(   self					:   int  ,      *__magic_name__					:   Tuple  ,      **__magic_name__					:   Optional[Any]			)					->    Optional[int]:


					"""simple docstring"""

					super().__init__(*__magic_name__  ,      **__magic_name__			)
					self.check_model_type(
					    TF_MODEL_FOR_CAUSAL_LM_MAPPING if self.framework == """tf""" else MODEL_FOR_CAUSAL_LM_MAPPING			)
					if "prefix" not in self._preprocess_params:
								# This is very specific. The logic is quite complex and needs to be done
								# as a "default".
								# It also defines both some preprocess_kwargs and generate_kwargs
								# which is why we cannot put them in their respective methods.
								__snake_case					:      Union[str, Any]							      =     None
								if self.model.config.prefix is not None:
											__snake_case					:      Optional[Any]							      =     self.model.config.prefix
								if prefix is None and self.model.__class__.__name__ in [
								    "XLNetLMHeadModel",
								    "TransfoXLLMHeadModel",
								    "TFXLNetLMHeadModel",
								    "TFTransfoXLLMHeadModel",
								]:
											# For XLNet and TransformerXL we add an article to the prompt to give more state to the model.
											__snake_case					:      Union[str, Any]							      =     self.XL_PREFIX
								if prefix is not None:
											# Recalculate some generate_kwargs linked to prefix.
											__snake_case      ,     __snake_case      ,     __snake_case					:      int							      =     self._sanitize_parameters(prefix=__magic_name__  ,      **self._forward_params			)
											__snake_case					:      Optional[Any]							      =     {**self._preprocess_params, **preprocess_params}
											__snake_case					:      Dict							      =     {**self._forward_params, **forward_params}

		def 	lowercase__     (   self					:   Optional[Any]  ,      __magic_name__					:   Optional[Any]=None  ,      __magic_name__					:   Union[str, Any]=None  ,      __magic_name__					:   Any=None  ,      __magic_name__					:   str=None  ,      __magic_name__					:   Dict=None  ,      __magic_name__					:   Dict=None  ,      __magic_name__					:   Tuple=None  ,      __magic_name__					:   Any=None  ,      **__magic_name__					:   List[str]  ,      )					->    Any:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     {}
					if prefix is not None:
								__snake_case					:      Tuple							      =     prefix
					if prefix:
								__snake_case					:      List[str]							      =     self.tokenizer(
								    __magic_name__  ,      padding=__magic_name__  ,      add_special_tokens=__magic_name__  ,      return_tensors=self.framework			)
								__snake_case					:      Optional[int]							      =     prefix_inputs["""input_ids"""].shape[-1]

					if handle_long_generation is not None:
								if handle_long_generation not in {"hole"}:
											raise ValueError(
											    f'''{handle_long_generation} is not a valid value for `handle_long_generation` parameter expected'''
											    """ [None, 'hole']"""			)
								__snake_case					:      Optional[Any]							      =     handle_long_generation

					preprocess_params.update(__magic_name__			)
					__snake_case					:      Dict							      =     generate_kwargs

					__snake_case					:      List[Any]							      =     {}
					if return_full_text is not None and return_type is None:
								if return_text is not None:
											raise ValueError("""`return_text` is mutually exclusive with `return_full_text`"""			)
								if return_tensors is not None:
											raise ValueError("""`return_full_text` is mutually exclusive with `return_tensors`"""			)
								__snake_case					:      Union[str, Any]							      =     ReturnType.FULL_TEXT if return_full_text else ReturnType.NEW_TEXT
					if return_tensors is not None and return_type is None:
								if return_text is not None:
											raise ValueError("""`return_text` is mutually exclusive with `return_tensors`"""			)
								__snake_case					:      Union[str, Any]							      =     ReturnType.TENSORS
					if return_type is not None:
								__snake_case					:      Dict							      =     return_type
					if clean_up_tokenization_spaces is not None:
								__snake_case					:      Any							      =     clean_up_tokenization_spaces

					if stop_sequence is not None:
								__snake_case					:      List[str]							      =     self.tokenizer.encode(__magic_name__  ,      add_special_tokens=__magic_name__			)
								if len(__magic_name__			) > 1:
											warnings.warn(
											    """Stopping on a multiple token sequence is not yet supported on transformers. The first token of"""
											    """ the stop sequence will be used as the stop sequence string in the interim."""			)
								__snake_case					:      Union[str, Any]							      =     stop_sequence_ids[0]

					return preprocess_params, forward_params, postprocess_params

		def 	lowercase__     (   self					:   str  ,      *__magic_name__					:   Optional[int]  ,      **__magic_name__					:   int			)					->    int:


					"""simple docstring"""

					if self.model.__class__.__name__ in ["TransfoXLLMHeadModel"]:
								kwargs.update({"""add_space_before_punct_symbol""": True}			)

					return super()._parse_and_tokenize(*__magic_name__  ,      **__magic_name__			)

		def __call__(   self					:   int  ,      __magic_name__					:   List[str]  ,      **__magic_name__					:   Optional[int]			)					->    Dict:


					"""simple docstring"""

					return super().__call__(__magic_name__  ,      **__magic_name__			)

		def 	lowercase__     (   self					:   Tuple  ,      __magic_name__					:   int  ,      __magic_name__					:   List[str]=""  ,      __magic_name__					:   List[str]=None  ,      **__magic_name__					:   str			)					->    str:


					"""simple docstring"""

					__snake_case					:      Optional[int]							      =     self.tokenizer(
					    prefix + prompt_text  ,      padding=__magic_name__  ,      add_special_tokens=__magic_name__  ,      return_tensors=self.framework			)
					__snake_case					:      Optional[int]							      =     prompt_text

					if handle_long_generation == "hole":
								__snake_case					:      List[str]							      =     inputs["""input_ids"""].shape[-1]
								if "max_new_tokens" in generate_kwargs:
											__snake_case					:      List[Any]							      =     generate_kwargs["""max_new_tokens"""]
								else:
											__snake_case					:      Tuple							      =     generate_kwargs.get("""max_length"""  ,      self.model.config.max_length			) - cur_len
											if new_tokens < 0:
														raise ValueError("""We cannot infer how many new tokens are expected"""			)
								if cur_len + new_tokens > self.tokenizer.model_max_length:
											__snake_case					:      str							      =     self.tokenizer.model_max_length - new_tokens
											if keep_length <= 0:
														raise ValueError(
														    """We cannot use `hole` to handle this generation the number of desired tokens exceeds the"""
														    """ models max length"""			)

											__snake_case					:      Dict							      =     inputs["""input_ids"""][:, -keep_length:]
											if "attention_mask" in inputs:
														__snake_case					:      int							      =     inputs["""attention_mask"""][:, -keep_length:]

					return inputs

		def 	lowercase__     (   self					:   List[Any]  ,      __magic_name__					:   List[Any]  ,      **__magic_name__					:   Optional[int]			)					->    Any:


					"""simple docstring"""

					__snake_case					:      Any							      =     model_inputs["""input_ids"""]
					__snake_case					:      List[Any]							      =     model_inputs.get("""attention_mask"""  ,      __magic_name__			)
					# Allow empty prompts
					if input_ids.shape[1] == 0:
								__snake_case					:      List[str]							      =     None
								__snake_case					:      Optional[int]							      =     None
								__snake_case					:      List[str]							      =     1
					else:
								__snake_case					:      Optional[int]							      =     input_ids.shape[0]
					__snake_case					:      Union[str, Any]							      =     model_inputs.pop("""prompt_text"""			)

					# If there is a prefix, we may need to adjust the generation length. Do so without permanently modifying
					# generate_kwargs, as some of the parameterization may come from the initialization of the pipeline.
					__snake_case					:      Tuple							      =     generate_kwargs.pop("""prefix_length"""  ,      0			)
					if prefix_length > 0:
								__snake_case					:      str							      =     """max_new_tokens""" in generate_kwargs or (
								    """generation_config""" in generate_kwargs
								    and generate_kwargs["""generation_config"""].max_new_tokens is not None
								)
								if not has_max_new_tokens:
											__snake_case					:      List[str]							      =     generate_kwargs.get("""max_length"""			) or self.model.config.max_length
											generate_kwargs["max_length"] += prefix_length
								__snake_case					:      Dict							      =     """min_new_tokens""" in generate_kwargs or (
								    """generation_config""" in generate_kwargs
								    and generate_kwargs["""generation_config"""].min_new_tokens is not None
								)
								if not has_min_new_tokens and "min_length" in generate_kwargs:
											generate_kwargs["min_length"] += prefix_length

        # BS x SL
					__snake_case					:      Any							      =     self.model.generate(input_ids=__magic_name__  ,      attention_mask=__magic_name__  ,      **__magic_name__			)
					__snake_case					:      Any							      =     generated_sequence.shape[0]
					if self.framework == "pt":
								__snake_case					:      List[str]							      =     generated_sequence.reshape(__magic_name__  ,      out_b // in_b  ,      *generated_sequence.shape[1:]			)
					elif self.framework == "tf":
								__snake_case					:      List[Any]							      =     tf.reshape(__magic_name__  ,      (in_b, out_b // in_b, *generated_sequence.shape[1:])			)
					return {"generated_sequence": generated_sequence, "input_ids": input_ids, "prompt_text": prompt_text}

		def 	lowercase__     (   self					:   Dict  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   Any=ReturnType.FULL_TEXT  ,      __magic_name__					:   str=True			)					->    Tuple:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     model_outputs["""generated_sequence"""][0]
					__snake_case					:      Union[str, Any]							      =     model_outputs["""input_ids"""]
					__snake_case					:      str							      =     model_outputs["""prompt_text"""]
					__snake_case					:      List[Any]							      =     generated_sequence.numpy().tolist()
					__snake_case					:      str							      =     []
					for sequence in generated_sequence:
								if return_type == ReturnType.TENSORS:
											__snake_case					:      Tuple							      =     {"""generated_token_ids""": sequence}
								elif return_type in {ReturnType.NEW_TEXT, ReturnType.FULL_TEXT}:
											# Decode text
											__snake_case					:      Tuple							      =     self.tokenizer.decode(
											    __magic_name__  ,      skip_special_tokens=__magic_name__  ,      clean_up_tokenization_spaces=__magic_name__  ,      )

											# Remove PADDING prompt of the sequence if XLNet or Transfo-XL model is used
											if input_ids is None:
														__snake_case					:      List[str]							      =     0
											else:
														__snake_case					:      Tuple							      =     len(
														    self.tokenizer.decode(
														        input_ids[0]  ,      skip_special_tokens=__magic_name__  ,      clean_up_tokenization_spaces=__magic_name__  ,      )			)

											if return_type == ReturnType.FULL_TEXT:
														__snake_case					:      List[str]							      =     prompt_text + text[prompt_length:]
											else:
														__snake_case					:      Dict							      =     text[prompt_length:]

											__snake_case					:      Union[str, Any]							      =     {"""generated_text""": all_text}
								records.append(__magic_name__			)

					return records







'''simple docstring'''

import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

from ...tokenization_utils import BatchEncoding, PreTrainedTokenizer
from ...utils import logging


a							   =				logging.get_logger(__name__)

a							   =				'▁'

a							   =				{
    'vocab_file': 'vocab.json',
    'spm_file': 'sentencepiece.bpe.model',
    'tokenizer_config_file': 'tokenizer_config.json',
}

a							   =				{
    'vocab_file': {
        'facebook/m2m100_418M': 'https://huggingface.co/facebook/m2m100_418M/resolve/main/vocab.json',
        'facebook/m2m100_1.2B': 'https://huggingface.co/facebook/m2m100_1.2B/resolve/main/vocab.json',
    },
    'spm_file': {
        'facebook/m2m100_418M': 'https://huggingface.co/facebook/m2m100_418M/resolve/main/sentencepiece.bpe.model',
        'facebook/m2m100_1.2B': 'https://huggingface.co/facebook/m2m100_1.2B/resolve/main/sentencepiece.bpe.model',
    },
    'tokenizer_config_file': {
        'facebook/m2m100_418M': 'https://huggingface.co/facebook/m2m100_418M/resolve/main/tokenizer_config.json',
        'facebook/m2m100_1.2B': 'https://huggingface.co/facebook/m2m100_1.2B/resolve/main/tokenizer_config.json',
    },
}

a							   =				{
    'facebook/m2m100_418M': 1_024,
}

# fmt: off
a							   =				{
    'm2m100': ['af', 'am', 'ar', 'ast', 'az', 'ba', 'be', 'bg', 'bn', 'br', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'ff', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'ilo', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'lb', 'lg', 'ln', 'lo', 'lt', 'lv', 'mg', 'mk', 'ml', 'mn', 'mr', 'ms', 'my', 'ne', 'nl', 'no', 'ns', 'oc', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'si', 'sk', 'sl', 'so', 'sq', 'sr', 'ss', 'su', 'sv', 'sw', 'ta', 'th', 'tl', 'tn', 'tr', 'uk', 'ur', 'uz', 'vi', 'wo', 'xh', 'yi', 'yo', 'zh', 'zu'],
    'wmt21': ['en', 'ha', 'is', 'ja', 'cs', 'ru', 'zh', 'de']
}






class 						a_		(     snake_case    ):
							UpperCAmelCase			:		int        =				VOCAB_FILES_NAMES
							UpperCAmelCase			:		Tuple        =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							UpperCAmelCase			:		Any        =				PRETRAINED_VOCAB_FILES_MAP
							UpperCAmelCase			:		Tuple        =				["""input_ids""", """attention_mask"""]

							UpperCAmelCase			:		List[int]        =				[]
							UpperCAmelCase			:		List[int]        =				[]


							def __init__(				self   :						int      ,						a_   :						Union[str, Any]      ,						a_   :						Union[str, Any]      ,						a_   :						Optional[Any]=None      ,						a_   :						str=None      ,						a_   :						Tuple="<s>"      ,						a_   :						int="</s>"      ,						a_   :						int="</s>"      ,						a_   :						Any="<pad>"      ,						a_   :						Union[str, Any]="<unk>"      ,						a_   :						Optional[Any]="m2m100"      ,						a_   :						Optional[Dict[str, Any]] = None      ,						a_   :						Dict=8      ,						**a_   :						Union[str, Any]      ,						)			->					None:
										snake_case:    Optional[Any]      							={} if sp_model_kwargs is None else sp_model_kwargs

										snake_case:    Union[str, Any]      							=language_codes
										snake_case:    Optional[int]      							=FAIRSEQ_LANGUAGE_CODES[language_codes]
										snake_case:    Dict      							={lang_code: F'''__{lang_code}__''' for lang_code in fairseq_language_code}

										snake_case:    Optional[int]      							=kwargs.get('additional_special_tokens'      ,						[]			)
										kwargs["additional_special_tokens"] += [
										    self.get_lang_token(a_			)
										    for lang_code in fairseq_language_code
										    if self.get_lang_token(a_			) not in kwargs["additional_special_tokens"]
										]

										super().__init__(
										    src_lang=a_      ,						tgt_lang=a_      ,						bos_token=a_      ,						eos_token=a_      ,						sep_token=a_      ,						unk_token=a_      ,						pad_token=a_      ,						language_codes=a_      ,						sp_model_kwargs=self.sp_model_kwargs      ,						num_madeup_words=a_      ,						**a_      ,						)

										snake_case:    int      							=vocab_file
										snake_case:    int      							=load_json(a_			)
										snake_case:    Tuple      							={v: k for k, v in self.encoder.items()}
										snake_case:    Any      							=spm_file
										snake_case:    int      							=load_spm(a_      ,						self.sp_model_kwargs			)

										snake_case:    List[Any]      							=len(self.encoder			)

										snake_case:    Optional[Any]      							={
										    self.get_lang_token(a_			): self.encoder_size + i for i, lang_code in enumerate(a_			)
										}
										snake_case:    List[str]      							={lang_code: self.encoder_size + i for i, lang_code in enumerate(a_			)}
										snake_case:    int      							={v: k for k, v in self.lang_token_to_id.items()}

										snake_case:    Any      							=src_lang if src_lang is not None else 'en'
										snake_case:    Optional[int]      							=tgt_lang
										snake_case:    Optional[int]      							=self.get_lang_id(self._src_lang			)
										self.set_src_lang_special_tokens(self._src_lang			)

										snake_case:    str      							=num_madeup_words


							@property
							def    UpperCamelCase     (				self   :						int			)			->					int:
										return len(self.encoder			) + len(self.lang_token_to_id			)


							@property
							def    UpperCamelCase     (				self   :						Optional[int]			)			->					str:
										return self._src_lang


							@src_lang.setter
							def    UpperCamelCase     (				self   :						List[Any]      ,						a_   :						str			)			->					None:
										snake_case:    Optional[Any]      							=new_src_lang
										self.set_src_lang_special_tokens(self._src_lang			)


							def    UpperCamelCase     (				self   :						Optional[int]      ,						a_   :						str			)			->					List[str]:
										return self.sp_model.encode(a_      ,						out_type=a_			)


							def    UpperCamelCase     (				self   :						List[Any]      ,						a_   :						Optional[int]			)			->					Union[str, Any]:
										if token in self.lang_token_to_id:
													return self.lang_token_to_id[token]
										return self.encoder.get(a_      ,						self.encoder[self.unk_token]			)


							def    UpperCamelCase     (				self   :						str      ,						a_   :						int			)			->					str:
										if index in self.id_to_lang_token:
													return self.id_to_lang_token[index]
										return self.decoder.get(a_      ,						self.unk_token			)


							def    UpperCamelCase     (				self   :						int      ,						a_   :						Optional[Any]			)			->					Tuple:
										snake_case:    List[Any]      							=[]
										snake_case:    List[str]      							=''
										for token in tokens:
													# make sure that special tokens are not decoded using sentencepiece model
													if token in self.all_special_tokens:
																out_string += self.sp_model.decode(a_			) + token
																snake_case:    Optional[Any]      							=[]
													else:
																current_sub_tokens.append(a_			)
										out_string += self.sp_model.decode(a_			)
										return out_string.strip()


							def    UpperCamelCase     (				self   :						Dict      ,						a_   :						List[int]      ,						a_   :						Optional[List[int]] = None      ,						a_   :						bool = False			)			->					List[int]:

										if already_has_special_tokens:
													return super().get_special_tokens_mask(
													    token_ids_a=a_      ,						token_ids_a=a_      ,						already_has_special_tokens=a_			)

										snake_case:    List[Any]      							=[1] * len(self.prefix_tokens			)
										snake_case:    Optional[int]      							=[1] * len(self.suffix_tokens			)
										if token_ids_a is None:
													return prefix_ones + ([0] * len(a_			)) + suffix_ones
										return prefix_ones + ([0] * len(a_			)) + ([0] * len(a_			)) + suffix_ones


							def    UpperCamelCase     (				self   :						str      ,						a_   :						List[int]      ,						a_   :						Optional[List[int]] = None			)			->					List[int]:
										if token_ids_a is None:
													return self.prefix_tokens + token_ids_a + self.suffix_tokens
										# We don't expect to process pairs, but leave the pair logic for API consistency
										return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens


							def    UpperCamelCase     (				self   :						Any			)			->					Dict:
										snake_case:    List[str]      							={self.convert_ids_to_tokens(a_			): i for i in range(self.vocab_size			)}
										vocab.update(self.added_tokens_encoder			)
										return vocab


							def __getstate__(				self   :						Union[str, Any]			)			->					Dict:
										snake_case:    Optional[int]      							=self.__dict__.copy()
										snake_case:    List[Any]      							=None
										return state


							def __setstate__(				self   :						int      ,						a_   :						Dict			)			->					None:
										snake_case:    Any      							=d

										# for backward compatibility
										if not hasattr(self      ,						'sp_model_kwargs'			):
													snake_case:    Optional[int]      							={}

										snake_case:    List[str]      							=load_spm(self.spm_file      ,						self.sp_model_kwargs			)


							def    UpperCamelCase     (				self   :						str      ,						a_   :						str      ,						a_   :						Optional[str] = None			)			->					Tuple[str]:
										snake_case:    Tuple      							=Path(a_			)
										if not save_dir.is_dir():
													raise OSError(F'''{save_directory} should be a directory'''			)
										snake_case:    Union[str, Any]      							=save_dir / (
										    (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['vocab_file']
										)
										snake_case:    List[Any]      							=save_dir / (
										    (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['spm_file']
										)

										save_json(self.encoder      ,						a_			)

										if os.path.abspath(self.spm_file			) != os.path.abspath(a_			) and os.path.isfile(self.spm_file			):
													copyfile(self.spm_file      ,						a_			)
										elif not os.path.isfile(self.spm_file			):
													with open(a_      ,						'wb'			) as fi:
																snake_case:    Any      							=self.sp_model.serialized_model_proto()
																fi.write(a_			)

										return (str(a_			), str(a_			))


							def    UpperCamelCase     (				self   :						Optional[Any]      ,						a_   :						List[str]      ,						a_   :						str = "en"      ,						a_   :						Optional[List[str]] = None      ,						a_   :						str = "ro"      ,						**a_   :						List[str]      ,						)			->					BatchEncoding:
										snake_case:    List[str]      							=src_lang
										snake_case:    Optional[int]      							=tgt_lang
										self.set_src_lang_special_tokens(self.src_lang			)
										return super().prepare_seqaseq_batch(a_      ,						a_      ,						**a_			)


							def    UpperCamelCase     (				self   :						Union[str, Any]      ,						a_   :						int      ,						a_   :						Optional[str]      ,						a_   :						Optional[str]      ,						**a_   :						Union[str, Any]			)			->					Any:
										if src_lang is None or tgt_lang is None:
													raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'			)
										snake_case:    List[str]      							=src_lang
										snake_case:    List[str]      							=self(a_      ,						add_special_tokens=a_      ,						**a_			)
										snake_case:    List[Any]      							=self.get_lang_id(a_			)
										snake_case:    List[str]      							=tgt_lang_id
										return inputs


							def    UpperCamelCase     (				self   :						str			)			->					List[str]:
										self.set_src_lang_special_tokens(self.src_lang			)


							def    UpperCamelCase     (				self   :						Dict			)			->					Tuple:
										self.set_tgt_lang_special_tokens(self.tgt_lang			)


							def    UpperCamelCase     (				self   :						List[str]      ,						a_   :						str			)			->					None:
										snake_case:    Optional[Any]      							=self.get_lang_token(a_			)
										snake_case:    Optional[Any]      							=self.lang_token_to_id[lang_token]
										snake_case:    Optional[Any]      							=[self.cur_lang_id]
										snake_case:    Optional[int]      							=[self.eos_token_id]


							def    UpperCamelCase     (				self   :						Optional[int]      ,						a_   :						str			)			->					None:
										snake_case:    Dict      							=self.get_lang_token(a_			)
										snake_case:    Tuple      							=self.lang_token_to_id[lang_token]
										snake_case:    Optional[int]      							=[self.cur_lang_id]
										snake_case:    List[str]      							=[self.eos_token_id]


							def    UpperCamelCase     (				self   :						Union[str, Any]      ,						a_   :						str			)			->					str:
										return self.lang_code_to_token[lang]




							def    UpperCamelCase     (				self   :						int      ,						a_   :						str			)			->					int:
										snake_case:    Union[str, Any]      							=self.get_lang_token(a_			)
										return self.lang_token_to_id[lang_token]







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase					)				->					sentencepiece.SentencePieceProcessor:





			"""simple docstring"""







			snake_case:    Dict      							=sentencepiece.SentencePieceProcessor(**__UpperCAmelCase					)
			spm.Load(str(__UpperCAmelCase					)					)
			return spm







def a_     (    __UpperCAmelCase					)				->					Union[Dict, List]:





			"""simple docstring"""







			with open(__UpperCAmelCase				,							'r'					) as f:
						return json.load(__UpperCAmelCase					)







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase					)				->					None:





			"""simple docstring"""







			with open(__UpperCAmelCase				,							'w'					) as f:
						json.dump(__UpperCAmelCase				,							__UpperCAmelCase				,							indent=2					)




