
'''simple docstring'''




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


lowercase     :							List[Any]       						=     logging.get_logger(__name__)

lowercase     :							int       						=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

lowercase     :							Optional[Any]       						=     [
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

lowercase     :							Dict       						=     {
    'vocab_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt',
        'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt',
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt',
        'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt',
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json',
        'funnel-transformer/small-base': (
            'https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json',
        'funnel-transformer/large-base': (
            'https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'
        ),
    },
}
lowercase     :							Optional[int]       						=     {f'''funnel-transformer/{name}''': 5_12 for name in _model_names}
lowercase     :							Optional[Any]       						=     {f'''funnel-transformer/{name}''': {'do_lower_case': True} for name in _model_names}





class 					A							(				__snake_case		):
     __magic_name__          =						VOCAB_FILES_NAMES
     __magic_name__          =						PRETRAINED_VOCAB_FILES_MAP
     __magic_name__          =						PRETRAINED_INIT_CONFIGURATION
     __magic_name__          =						FunnelTokenizer
     __magic_name__          =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __magic_name__          =						2





     def __init__(				self		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=True		,     SCREAMING_SNAKE_CASE="<unk>"		,     SCREAMING_SNAKE_CASE="<sep>"		,     SCREAMING_SNAKE_CASE="<pad>"		,     SCREAMING_SNAKE_CASE="<cls>"		,     SCREAMING_SNAKE_CASE="<mask>"		,     SCREAMING_SNAKE_CASE="<s>"		,     SCREAMING_SNAKE_CASE="</s>"		,     SCREAMING_SNAKE_CASE=True		,     SCREAMING_SNAKE_CASE=True		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE="##"		,     **SCREAMING_SNAKE_CASE		,     )					->							List[str]:






         """simple docstring"""






         super().__init__(
             SCREAMING_SNAKE_CASE		,     tokenizer_file=SCREAMING_SNAKE_CASE		,     do_lower_case=SCREAMING_SNAKE_CASE		,     unk_token=SCREAMING_SNAKE_CASE		,     sep_token=SCREAMING_SNAKE_CASE		,     pad_token=SCREAMING_SNAKE_CASE		,     cls_token=SCREAMING_SNAKE_CASE		,     mask_token=SCREAMING_SNAKE_CASE		,     bos_token=SCREAMING_SNAKE_CASE		,     eos_token=SCREAMING_SNAKE_CASE		,     clean_text=SCREAMING_SNAKE_CASE		,     tokenize_chinese_chars=SCREAMING_SNAKE_CASE		,     strip_accents=SCREAMING_SNAKE_CASE		,     wordpieces_prefix=SCREAMING_SNAKE_CASE		,     **SCREAMING_SNAKE_CASE		,     )

         A			:  Dict   =		json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
         if (
             normalizer_state.get('''lowercase'''		,     SCREAMING_SNAKE_CASE      ) != do_lower_case
             or normalizer_state.get('''strip_accents'''		,     SCREAMING_SNAKE_CASE      ) != strip_accents
             or normalizer_state.get('''handle_chinese_chars'''		,     SCREAMING_SNAKE_CASE      ) != tokenize_chinese_chars
         ):
             A			:  Optional[Any]   =		getattr(SCREAMING_SNAKE_CASE		,     normalizer_state.pop('''type'''      )      )
             A			:  str   =		do_lower_case
             A			:  List[str]   =		strip_accents
             A			:  Any   =		tokenize_chinese_chars
             A			:  List[Any]   =		normalizer_class(**SCREAMING_SNAKE_CASE      )

         A			:  Optional[Any]   =		do_lower_case





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE=None      )					->							int:






         """simple docstring"""






         A			:  Any   =		[self.cls_token_id] + token_ids_a + [self.sep_token_id]

         if token_ids_a:
             output += token_ids_a + [self.sep_token_id]

         return output





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE = None      )					->							List[int]:






         """simple docstring"""






         A			:  List[str]   =		[self.sep_token_id]
         A			:  int   =		[self.cls_token_id]
         if token_ids_a is None:
             return len(cls      ) * [self.cls_token_type_id] + len(token_ids_a + sep      ) * [0]
         return len(cls      ) * [self.cls_token_type_id] + len(token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE = None      )					->							Tuple[str]:






         """simple docstring"""






         A			:  Optional[int]   =		self._tokenizer.model.save(SCREAMING_SNAKE_CASE		,     name=SCREAMING_SNAKE_CASE      )
         return tuple(SCREAMING_SNAKE_CASE      )






'''simple docstring'''




import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowercase     :							int       						=     logging.get_logger(__name__)

lowercase     :							Dict       						=     {'vocab_file': 'spiece.model'}

lowercase     :							Tuple       						=     {
    'vocab_file': {
        'bert_for_seq_generation': (
            'https://huggingface.co/google/bert_for_seq_generation_L-24_bbc_encoder/resolve/main/spiece.model'
        ),
    }
}

lowercase     :							Tuple       						=     {'bert_for_seq_generation': 5_12}





class 					A							(				__snake_case		):
     __magic_name__          =						VOCAB_FILES_NAMES
     __magic_name__          =						PRETRAINED_VOCAB_FILES_MAP
     __magic_name__          =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __magic_name__          =						[]
     __magic_name__          =						['''input_ids''', '''attention_mask''']





     def __init__(				self		,     SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE="<s>"		,     SCREAMING_SNAKE_CASE="</s>"		,     SCREAMING_SNAKE_CASE="<unk>"		,     SCREAMING_SNAKE_CASE="<pad>"		,     SCREAMING_SNAKE_CASE="<::::>"		,     SCREAMING_SNAKE_CASE = None		,     **SCREAMING_SNAKE_CASE		,     )					->							None:






         """simple docstring"""






         A			:  str   =		{} if sp_model_kwargs is None else sp_model_kwargs

         # Add extra_ids to the special token list
         super().__init__(
             bos_token=SCREAMING_SNAKE_CASE		,     eos_token=SCREAMING_SNAKE_CASE		,     unk_token=SCREAMING_SNAKE_CASE		,     pad_token=SCREAMING_SNAKE_CASE		,     sep_token=SCREAMING_SNAKE_CASE		,     sp_model_kwargs=self.sp_model_kwargs		,     **SCREAMING_SNAKE_CASE		,     )

         A			:  List[Any]   =		vocab_file

         A			:  List[Any]   =		spm.SentencePieceProcessor(**self.sp_model_kwargs      )
         self.sp_model.Load(SCREAMING_SNAKE_CASE      )





     @property
     def 							__lowerCAmelCase				(				self      )					->							int:






         """simple docstring"""






         return self.sp_model.get_piece_size()





     def 							__lowerCAmelCase				(				self      )					->							Any:






         """simple docstring"""






         A			:  Any   =		{self.convert_ids_to_tokens(SCREAMING_SNAKE_CASE      ): i for i in range(self.vocab_size      )}
         vocab.update(self.added_tokens_encoder      )
         return vocab





     def __getstate__(				self      )					->							Tuple:






         """simple docstring"""






         A			:  Dict   =		self.__dict__.copy()
         A			:  int   =		None
         return state





     def __setstate__(				self		,     SCREAMING_SNAKE_CASE      )					->							str:






         """simple docstring"""






         A			:  Union[str, Any]   =		d

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

         A			:  Optional[int]   =		spm.SentencePieceProcessor(**self.sp_model_kwargs      )
         self.sp_model.Load(self.vocab_file      )





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE      )					->							List[str]:






         """simple docstring"""






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





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE      )					->							Optional[int]:






         """simple docstring"""






         return self.sp_model.piece_to_id(SCREAMING_SNAKE_CASE      )





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE      )					->							Optional[Any]:






         """simple docstring"""






         A			:  Tuple   =		self.sp_model.IdToPiece(SCREAMING_SNAKE_CASE      )
         return token





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE      )					->							Tuple:






         """simple docstring"""






         A			:  List[Any]   =		[]
         A			:  Dict   =		''''''
         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(SCREAMING_SNAKE_CASE      ) + token
                 A			:  str   =		[]
             else:
                 current_sub_tokens.append(SCREAMING_SNAKE_CASE      )
         out_string += self.sp_model.decode(SCREAMING_SNAKE_CASE      )
         return out_string.strip()





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE = None      )					->							Tuple[str]:






         """simple docstring"""






         if not os.path.isdir(SCREAMING_SNAKE_CASE      ):
             logger.error(F'Vocabulary path ({save_directory}) should be a directory'      )
             return
         A			:  int   =		os.path.join(
             SCREAMING_SNAKE_CASE		,     (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']      )

         if os.path.abspath(self.vocab_file      ) != os.path.abspath(SCREAMING_SNAKE_CASE      ) and os.path.isfile(self.vocab_file      ):
             copyfile(self.vocab_file		,     SCREAMING_SNAKE_CASE      )
         elif not os.path.isfile(self.vocab_file      ):
             with open(SCREAMING_SNAKE_CASE		,     '''wb'''      ) as fi:
                 A			:  str   =		self.sp_model.serialized_model_proto()
                 fi.write(SCREAMING_SNAKE_CASE      )

         return (out_vocab_file,)




