




'''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 PreTrainedTokenizer
from ...utils import logging


lowerCAmelCase_     						=				logging.get_logger(__name__)

lowerCAmelCase_     						=				'''▁'''

lowerCAmelCase_     						=				{
    '''vocab_file''': '''vocab.json''',
    '''spm_file''': '''sentencepiece.bpe.model''',
}

lowerCAmelCase_     						=				{
    '''vocab_file''': {
        '''facebook/s2t-small-librispeech-asr''': (
            '''https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/vocab.json'''
        ),
    },
    '''spm_file''': {
        '''facebook/s2t-small-librispeech-asr''': (
            '''https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/sentencepiece.bpe.model'''
        )
    },
}

lowerCAmelCase_     						=				{
    '''facebook/s2t-small-librispeech-asr''': 1_0_2_4,
}

lowerCAmelCase_     						=				['''pt''', '''fr''', '''ru''', '''nl''', '''ro''', '''it''', '''es''', '''de''']

lowerCAmelCase_     						=				{'''mustc''': MUSTC_LANGS}

class 	_snake_case(			UpperCAmelCase      ):
 __snake_case:							Optional[Any]						=					VOCAB_FILES_NAMES
 __snake_case:							int						=					PRETRAINED_VOCAB_FILES_MAP
 __snake_case:							List[str]						=					MAX_MODEL_INPUT_SIZES
 __snake_case:							Optional[int]						=					['''input_ids''', '''attention_mask''']

 __snake_case:							List[int]						=					[]






 def __init__(self       :  Optional[int]    ,		a       :  str    ,		a       :  Optional[Any]    ,		a       :  Tuple="<s>"    ,		a       :  Optional[int]="</s>"    ,		a       :  Union[str, Any]="<pad>"    ,		a       :  str="<unk>"    ,		a       :  List[Any]=False    ,		a       :  Dict=False    ,		a       :  Tuple=None    ,		a       :  Optional[int]=None    ,		a       :  Optional[Dict[str, Any]] = None    ,		**a       :  List[str]    ,		)       ->   None:






    """simple docstring"""


    A__       =     {} if sp_model_kwargs is None else sp_model_kwargs

    super().__init__(
        bos_token=a    ,		eos_token=a    ,		unk_token=a    ,		pad_token=a    ,		do_upper_case=a    ,		do_lower_case=a    ,		tgt_lang=a    ,		lang_codes=a    ,		sp_model_kwargs=self.sp_model_kwargs    ,		**a    ,		)
    A__       =     do_upper_case
    A__       =     do_lower_case

    A__       =     load_json(a    )
    A__       =     {v: k for k, v in self.encoder.items()}
    A__       =     spm_file
    A__       =     load_spm(a    ,		self.sp_model_kwargs    )

    if lang_codes is not None:
       A__       =     lang_codes
       A__       =     LANGUAGES[lang_codes]
       A__       =     [f"""<lang:{lang}>""" for lang in self.langs]
       A__       =     {lang: self.sp_model.PieceToId(f"""<lang:{lang}>"""    ) for lang in self.langs}

       A__       =     self.lang_tokens
       A__       =     tgt_lang if tgt_lang is not None else self.langs[0]

       self.set_tgt_lang_special_tokens(self._tgt_lang    )
    else:
       A__       =     {}






 @property
 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   int:






    """simple docstring"""


    return len(self.encoder    )






 @property
 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   str:






    """simple docstring"""


    return self._tgt_lang






 @tgt_lang.setter
 def 						_UpperCamelCase (self       :  List[str]    ,		a       :  Optional[Any]    )       ->   None:






    """simple docstring"""


    A__       =     new_tgt_lang
    self.set_tgt_lang_special_tokens(a    )






 def 						_UpperCamelCase (self       :  Optional[Any]    ,		a       :  str    )       ->   None:






    """simple docstring"""


    A__       =     self.lang_code_to_id[tgt_lang]
    A__       =     [lang_code_id]






 def 						_UpperCamelCase (self       :  Union[str, Any]    ,		a       :  str    )       ->   List[str]:






    """simple docstring"""


    return self.sp_model.encode(a    ,		out_type=a    )






 def 						_UpperCamelCase (self       :  Tuple    ,		a       :  List[Any]    )       ->   List[Any]:






    """simple docstring"""


    return self.encoder.get(a    ,		self.encoder[self.unk_token]    )






 def 						_UpperCamelCase (self       :  List[Any]    ,		a       :  int    )       ->   str:






    """simple docstring"""


    return self.decoder.get(a    ,		self.unk_token    )






 def 						_UpperCamelCase (self       :  Optional[int]    ,		a       :  List[str]    )       ->   str:






    """simple docstring"""


    A__       =     []
    A__       =     ''
    for token in tokens:
       # make sure that special tokens are not decoded using sentencepiece model
       if token in self.all_special_tokens:
          A__       =     self.sp_model.decode(a    )
          out_string += (decoded.upper() if self.do_upper_case else decoded) + token + " "
          A__       =     []
       else:
          current_sub_tokens.append(a    )
    A__       =     self.sp_model.decode(a    )
    out_string += decoded.upper() if self.do_upper_case else decoded
    return out_string.strip()






 def 						_UpperCamelCase (self       :  str    ,		a       :  List[str]    ,		a       :  Union[str, Any]=None    )       ->   List[int]:






    """simple docstring"""


    if token_ids_a is None:
       return self.prefix_tokens + token_ids_a + [self.eos_token_id]
    # 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.eos_token_id]






 def 						_UpperCamelCase (self       :  int    ,		a       :  List[int]    ,		a       :  Optional[List[int]] = None    ,		a       :  bool = False    )       ->   List[int]:






    """simple docstring"""


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

    A__       =     [1] * len(self.prefix_tokens    )
    A__       =     [1]
    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    )       ->   Dict:






    """simple docstring"""


    A__       =     self.encoder.copy()
    vocab.update(self.added_tokens_encoder    )
    return vocab






 def __getstate__(self       :  Tuple    )       ->   Dict:






    """simple docstring"""


    A__       =     self.__dict__.copy()
    A__       =     None
    return state






 def __setstate__(self       :  Any    ,		a       :  Dict    )       ->   None:






    """simple docstring"""


    A__       =     d

    # for backward compatibility
    if not hasattr(self    ,		'sp_model_kwargs'    ):
       A__       =     {}

    A__       =     load_spm(self.spm_file    ,		self.sp_model_kwargs    )






 def 						_UpperCamelCase (self       :  int    ,		a       :  str    ,		a       :  Optional[str] = None    )       ->   Tuple[str]:






    """simple docstring"""


    A__       =     Path(a    )
    assert save_dir.is_dir(), f"""{save_directory} should be a directory"""
    A__       =     save_dir / (
        (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['vocab_file']
    )
    A__       =     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:
          A__       =     self.sp_model.serialized_model_proto()
          fi.write(a    )

    return (str(a    ), str(a    ))







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     sentencepiece.SentencePieceProcessor(**UpperCAmelCase						)
   spm.Load(str(UpperCAmelCase						)						)
   return spm







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







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







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







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








'''simple docstring'''







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   A__       =     0
   while num > 0:
      digit_sum += num % 10
      num //= 10
   return digit_sum







def 						_A      ( UpperCAmelCase = 100						):






   '''simple docstring'''







   A__       =     1
   A__       =     2

   for i in range(2      ,max_n + 1						):
      A__       =     pre_numerator
      A__       =     2 * i // 3 if i % 3 == 0 else 1
      A__       =     cur_numerator
      A__       =     e_cont * pre_numerator + temp

   return sum_digits(UpperCAmelCase						)


if __name__ == "__main__":
    print(f'''{solution() = }''')


