




"""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_convbert import ConvBertTokenizer


a_        =       logging.get_logger(__name__)

a_        =       {'vocab_file': 'vocab.txt'}

a_        =       {
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

a_        =       {
    'YituTech/conv-bert-base': 5_1_2,
    'YituTech/conv-bert-medium-small': 5_1_2,
    'YituTech/conv-bert-small': 5_1_2,
}


a_        =       {
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}

class   UpperCAmelCase_    (			snake_case		):
		UpperCamelCase							=VOCAB_FILES_NAMES
		UpperCamelCase							=PRETRAINED_VOCAB_FILES_MAP
		UpperCamelCase							=PRETRAINED_INIT_CONFIGURATION
		UpperCamelCase							=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		UpperCamelCase							=ConvBertTokenizer
		def __init__(						self				,						UpperCamelCase_=None				,						UpperCamelCase_=None				,						UpperCamelCase_=True				,						UpperCamelCase_="[UNK]"				,						UpperCamelCase_="[SEP]"				,						UpperCamelCase_="[PAD]"				,						UpperCamelCase_="[CLS]"				,						UpperCamelCase_="[MASK]"				,						UpperCamelCase_=True				,						UpperCamelCase_=None				,						**UpperCamelCase_				,						)						->       List[Any]:
					super().__init__(
					    UpperCamelCase_				,						tokenizer_file=UpperCamelCase_				,						do_lower_case=UpperCamelCase_				,						unk_token=UpperCamelCase_				,						sep_token=UpperCamelCase_				,						pad_token=UpperCamelCase_				,						cls_token=UpperCamelCase_				,						mask_token=UpperCamelCase_				,						tokenize_chinese_chars=UpperCamelCase_				,						strip_accents=UpperCamelCase_				,						**UpperCamelCase_				,						)

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

					__lowercase			:  Union[str, Any]								=       do_lower_case
		def 	_lowerCamelCase							(						self				,						UpperCamelCase_				,						UpperCamelCase_=None       )						->       List[str]:
					__lowercase			:  Union[str, 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				,						UpperCamelCase_				,						UpperCamelCase_ = None       )						->       List[int]:
					__lowercase			:  List[Any]								=       [self.sep_token_id]
					__lowercase			:  Union[str, Any]								=       [self.cls_token_id]
					if token_ids_a is None:
								return len(cls + token_ids_a + sep       ) * [0]
					return len(cls + token_ids_a + sep       ) * [0] + len(token_ids_a + sep       ) * [1]
		def 	_lowerCamelCase							(						self				,						UpperCamelCase_				,						UpperCamelCase_ = None       )						->       Tuple[str]:
					__lowercase			:  str								=       self._tokenizer.model.save(UpperCamelCase_				,						name=UpperCamelCase_       )
					return tuple(UpperCamelCase_       )








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

import sentencepiece as spm

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


a__   :					Optional[int] 						=      logging.get_logger(__name__)
a__   :					Dict 						=      {"vocab_file": "spiece.model"}

a__   :					str 						=      {
    "vocab_file": {
        "albert-base-v1": "https://huggingface.co/albert-base-v1/resolve/main/spiece.model",
        "albert-large-v1": "https://huggingface.co/albert-large-v1/resolve/main/spiece.model",
        "albert-xlarge-v1": "https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model",
        "albert-xxlarge-v1": "https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model",
        "albert-base-v2": "https://huggingface.co/albert-base-v2/resolve/main/spiece.model",
        "albert-large-v2": "https://huggingface.co/albert-large-v2/resolve/main/spiece.model",
        "albert-xlarge-v2": "https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model",
        "albert-xxlarge-v2": "https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model",
    }
}

a__   :					Union[str, Any] 						=      {
    "albert-base-v1": 5_12,
    "albert-large-v1": 5_12,
    "albert-xlarge-v1": 5_12,
    "albert-xxlarge-v1": 5_12,
    "albert-base-v2": 5_12,
    "albert-large-v2": 5_12,
    "albert-xlarge-v2": 5_12,
    "albert-xxlarge-v2": 5_12,
}

a__   :					Optional[int] 						=      "▁"



class    UpperCAmelCase__(				lowerCamelCase						):

   '''simple docstring'''




   A     :	Tuple												=     VOCAB_FILES_NAMES
   A     :	Dict												=     PRETRAINED_VOCAB_FILES_MAP
   A     :	str												=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES


   def __init__(    self	:      List[str]      ,					lowerCAmelCase	:      Tuple      ,					lowerCAmelCase	:      Optional[int]=True      ,					lowerCAmelCase	:      List[Any]=True      ,					lowerCAmelCase	:      str=False      ,					lowerCAmelCase	:      str="[CLS]"      ,					lowerCAmelCase	:      Optional[int]="[SEP]"      ,					lowerCAmelCase	:      int="<unk>"      ,					lowerCAmelCase	:      str="[SEP]"      ,					lowerCAmelCase	:      Dict="<pad>"      ,					lowerCAmelCase	:      int="[CLS]"      ,					lowerCAmelCase	:      Tuple="[MASK]"      ,					lowerCAmelCase	:      Optional[Dict[str, Any]] = None      ,					**lowerCAmelCase	:      List[str]      ,					)						->					None:




         """simple docstring"""

         lowercase__  =	(
             AddedToken(lowerCAmelCase      ,					lstrip=lowerCAmelCase      ,					rstrip=lowerCAmelCase      ,					normalized=lowerCAmelCase)
             if isinstance(lowerCAmelCase      ,					lowerCAmelCase)
             else mask_token
         )

         lowercase__  =	{} if sp_model_kwargs is None else sp_model_kwargs

         super().__init__(
             do_lower_case=lowerCAmelCase      ,					remove_space=lowerCAmelCase      ,					keep_accents=lowerCAmelCase      ,					bos_token=lowerCAmelCase      ,					eos_token=lowerCAmelCase      ,					unk_token=lowerCAmelCase      ,					sep_token=lowerCAmelCase      ,					pad_token=lowerCAmelCase      ,					cls_token=lowerCAmelCase      ,					mask_token=lowerCAmelCase      ,					sp_model_kwargs=self.sp_model_kwargs      ,					**lowerCAmelCase      ,					)

         lowercase__  =	do_lower_case
         lowercase__  =	remove_space
         lowercase__  =	keep_accents
         lowercase__  =	vocab_file

         lowercase__  =	spm.SentencePieceProcessor(**self.sp_model_kwargs)
         self.sp_model.Load(lowerCAmelCase)


   @property
   def       UpperCAmelCase		(    self	:      Any)						->					Optional[int]:




         """simple docstring"""

         return len(self.sp_model)


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




         """simple docstring"""

         lowercase__  =	{self.convert_ids_to_tokens(lowerCAmelCase): i for i in range(self.vocab_size)}
         vocab.update(self.added_tokens_encoder)
         return vocab


   def __getstate__(    self	:      int)						->					List[str]:




         """simple docstring"""

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


   def __setstate__(    self	:      int      ,					lowerCAmelCase	:      str)						->					Any:




         """simple docstring"""

         lowercase__  =	d

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

         lowercase__  =	spm.SentencePieceProcessor(**self.sp_model_kwargs)
         self.sp_model.Load(self.vocab_file)


   def       UpperCAmelCase		(    self	:      Dict      ,					lowerCAmelCase	:      int)						->					List[str]:




         """simple docstring"""

         if self.remove_space:
               lowercase__  =	' '.join(inputs.strip().split())
         else:
               lowercase__  =	inputs
         lowercase__  =	outputs.replace('``'      ,					'"').replace('\'\''      ,					'"')

         if not self.keep_accents:
               lowercase__  =	unicodedata.normalize('NFKD'      ,					lowerCAmelCase)
               lowercase__  =	''.join([c for c in outputs if not unicodedata.combining(lowerCAmelCase)])
         if self.do_lower_case:
               lowercase__  =	outputs.lower()

         return outputs


   def       UpperCAmelCase		(    self	:      Any      ,					lowerCAmelCase	:      str)						->					List[str]:




         """simple docstring"""

         lowercase__  =	self.preprocess_text(lowerCAmelCase)
         lowercase__  =	self.sp_model.encode(lowerCAmelCase      ,					out_type=lowerCAmelCase)
         lowercase__  =	[]
         for piece in pieces:
               if len(lowerCAmelCase) > 1 and piece[-1] == str(',') and piece[-2].isdigit():
                     lowercase__  =	self.sp_model.EncodeAsPieces(piece[:-1].replace(lowerCAmelCase      ,					''))
                     if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                           if len(cur_pieces[0]) == 1:
                                 lowercase__  =	cur_pieces[1:]
                           else:
                                 lowercase__  =	cur_pieces[0][1:]
                     cur_pieces.append(piece[-1])
                     new_pieces.extend(lowerCAmelCase)
               else:
                     new_pieces.append(lowerCAmelCase)

         return new_pieces


   def       UpperCAmelCase		(    self	:      Any      ,					lowerCAmelCase	:      int)						->					int:




         """simple docstring"""

         return self.sp_model.PieceToId(lowerCAmelCase)


   def       UpperCAmelCase		(    self	:      List[str]      ,					lowerCAmelCase	:      Any)						->					Tuple:




         """simple docstring"""

         return self.sp_model.IdToPiece(lowerCAmelCase)


   def       UpperCAmelCase		(    self	:      Tuple      ,					lowerCAmelCase	:      Optional[Any])						->					List[Any]:




         """simple docstring"""

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


   def       UpperCAmelCase		(    self	:      Union[str, Any]      ,					lowerCAmelCase	:      List[int]      ,					lowerCAmelCase	:      Optional[List[int]] = None)						->					List[int]:




         """simple docstring"""

         lowercase__  =	[self.sep_token_id]
         lowercase__  =	[self.cls_token_id]
         if token_ids_a is None:
               return cls + token_ids_a + sep
         return cls + token_ids_a + sep + token_ids_a + sep


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




         """simple docstring"""

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

         if token_ids_a is not None:
               return [1] + ([0] * len(lowerCAmelCase)) + [1] + ([0] * len(lowerCAmelCase)) + [1]
         return [1] + ([0] * len(lowerCAmelCase)) + [1]


   def       UpperCAmelCase		(    self	:      Union[str, Any]      ,					lowerCAmelCase	:      List[int]      ,					lowerCAmelCase	:      Optional[List[int]] = None)						->					List[int]:




         """simple docstring"""

         lowercase__  =	[self.sep_token_id]
         lowercase__  =	[self.cls_token_id]

         if token_ids_a is None:
               return len(cls + token_ids_a + sep) * [0]
         return len(cls + token_ids_a + sep) * [0] + len(token_ids_a + sep) * [1]



   def       UpperCAmelCase		(    self	:      Dict      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      Optional[str] = None)						->					Tuple[str]:




         """simple docstring"""

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

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

         return (out_vocab_file,)
