



'''simple docstring'''

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

import sentencepiece as spm

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


snake_case_			=     logging.get_logger(__name__)

snake_case_			=     {"""vocab_file""": """sentencepiece.model"""}

snake_case_			=     {
    """vocab_file""": {
        """google/rembert""": """https://huggingface.co/google/rembert/resolve/main/sentencepiece.model""",
    },
}

snake_case_			=     {
    """google/rembert""": 256,
}


class 	a__     (				_lowercase	):
	__magic_name__		:    List[str]	    =     VOCAB_FILES_NAMES
	__magic_name__		:    int	    =     PRETRAINED_VOCAB_FILES_MAP
	__magic_name__		:    Optional[Any]	    =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES


	def __init__(self : Union[str, Any],					__UpperCAmelCase : str,					__UpperCAmelCase : Any=False,					__UpperCAmelCase : int=True,					__UpperCAmelCase : Tuple=True,					__UpperCAmelCase : List[str]="[CLS]",					__UpperCAmelCase : List[str]="[SEP]",					__UpperCAmelCase : Any="[UNK]",					__UpperCAmelCase : Any="[SEP]",					__UpperCAmelCase : Union[str, Any]="[PAD]",					__UpperCAmelCase : str="[CLS]",					__UpperCAmelCase : Tuple="[MASK]",					**__UpperCAmelCase : Optional[Any],					)     ->			Any:

					"""simple docstring"""

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

					SCREAMING_SNAKE_CASE  :						int      					= do_lower_case
					SCREAMING_SNAKE_CASE  :						str      					= remove_space
					SCREAMING_SNAKE_CASE  :						str      					= keep_accents
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= vocab_file

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= spm.SentencePieceProcessor()
					self.sp_model.Load(__UpperCAmelCase      )


	@property
	def 				lowercase__  (self : Optional[int]      )     ->			str:

					"""simple docstring"""

					return len(self.sp_model      )


	def 				lowercase__  (self : str      )     ->			List[str]:

					"""simple docstring"""

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


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

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						str      					= self.__dict__.copy()
					SCREAMING_SNAKE_CASE  :						Tuple      					= None
					return state


	def __setstate__(self : str,					__UpperCAmelCase : str      )     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= d
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= spm.SentencePieceProcessor()
					self.sp_model.Load(self.vocab_file      )


	def 				lowercase__  (self : Optional[int],					__UpperCAmelCase : int,					__UpperCAmelCase : Any=False      )     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.sp_model.EncodeAsPieces(__UpperCAmelCase      )
					return pieces


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

					"""simple docstring"""

					return self.sp_model.PieceToId(__UpperCAmelCase      )


	def 				lowercase__  (self : List[Any],					__UpperCAmelCase : int      )     ->			Dict:

					"""simple docstring"""

					return self.sp_model.IdToPiece(__UpperCAmelCase      )


	def 				lowercase__  (self : List[str],					__UpperCAmelCase : Any      )     ->			Dict:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.sp_model.decode_pieces(__UpperCAmelCase      )
					return out_string


	def 				lowercase__  (self : Optional[Any],					__UpperCAmelCase : List[int],					__UpperCAmelCase : Optional[List[int]] = None      )     ->			List[int]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						List[str]      					= [self.sep_token_id]
					SCREAMING_SNAKE_CASE  :						List[Any]      					= [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 				lowercase__  (self : str,					__UpperCAmelCase : List[int],					__UpperCAmelCase : Optional[List[int]] = None,					__UpperCAmelCase : bool = False      )     ->			List[int]:

					"""simple docstring"""

					if already_has_special_tokens:
									if token_ids_a is not None:
													raise ValueError(
													    '''You should not supply a second sequence if the provided sequence of '''
													    '''ids is already formatted with special tokens for the model.'''      )
									return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

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


	def 				lowercase__  (self : Tuple,					__UpperCAmelCase : List[int],					__UpperCAmelCase : Optional[List[int]] = None      )     ->			List[int]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= [self.sep_token_id]
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= [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 				lowercase__  (self : List[Any],					__UpperCAmelCase : str,					__UpperCAmelCase : Optional[str] = None      )     ->			Tuple[str]:

					"""simple docstring"""

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

					if os.path.abspath(self.vocab_file      ) != os.path.abspath(__UpperCAmelCase      ):
									copyfile(self.vocab_file,					__UpperCAmelCase      )

					return (out_vocab_file,)









'''simple docstring'''

from ..utils import DummyObject, requires_backends


class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["sentencepiece"]


	def __init__(self : Optional[Any],					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : List[Any]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Tuple	    =     ["sentencepiece"]


	def __init__(self : Optional[int],					*__UpperCAmelCase : int,					**__UpperCAmelCase : List[str]      )     ->			int:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : List[str],					*__UpperCAmelCase : str,					**__UpperCAmelCase : List[Any]      )     ->			str:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : Optional[int],					*__UpperCAmelCase : str,					**__UpperCAmelCase : Optional[Any]      )     ->			List[Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[str]	    =     ["sentencepiece"]


	def __init__(self : Tuple,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Tuple      )     ->			Any:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Union[str, Any]	    =     ["sentencepiece"]


	def __init__(self : List[Any],					*__UpperCAmelCase : List[Any],					**__UpperCAmelCase : Optional[Any]      )     ->			str:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    int	    =     ["sentencepiece"]


	def __init__(self : Tuple,					*__UpperCAmelCase : int,					**__UpperCAmelCase : Any      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    str	    =     ["sentencepiece"]


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

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    str	    =     ["sentencepiece"]


	def __init__(self : Tuple,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : Tuple      )     ->			Dict:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["sentencepiece"]


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

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Tuple	    =     ["sentencepiece"]


	def __init__(self : List[Any],					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : Optional[int]      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    int	    =     ["sentencepiece"]


	def __init__(self : str,					*__UpperCAmelCase : str,					**__UpperCAmelCase : str      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[str]	    =     ["sentencepiece"]


	def __init__(self : int,					*__UpperCAmelCase : List[str],					**__UpperCAmelCase : str      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    str	    =     ["sentencepiece"]


	def __init__(self : Tuple,					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : str      )     ->			List[Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Any	    =     ["sentencepiece"]


	def __init__(self : Dict,					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : List[str]      )     ->			Optional[Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : str,					*__UpperCAmelCase : Optional[int],					**__UpperCAmelCase : Tuple      )     ->			Dict:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[Any]	    =     ["sentencepiece"]


	def __init__(self : Union[str, Any],					*__UpperCAmelCase : int,					**__UpperCAmelCase : str      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : Any,					*__UpperCAmelCase : str,					**__UpperCAmelCase : List[Any]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : List[Any],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : List[Any]      )     ->			List[Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : Dict,					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : str      )     ->			List[Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["sentencepiece"]


	def __init__(self : List[Any],					*__UpperCAmelCase : Any,					**__UpperCAmelCase : str      )     ->			int:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    str	    =     ["sentencepiece"]


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

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[int]	    =     ["sentencepiece"]


	def __init__(self : Union[str, Any],					*__UpperCAmelCase : Dict,					**__UpperCAmelCase : Optional[int]      )     ->			Tuple:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Tuple	    =     ["sentencepiece"]


	def __init__(self : List[str],					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Dict      )     ->			List[str]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Any	    =     ["sentencepiece"]


	def __init__(self : int,					*__UpperCAmelCase : Union[str, Any],					**__UpperCAmelCase : Optional[Any]      )     ->			Union[str, Any]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["sentencepiece"]


	def __init__(self : Union[str, Any],					*__UpperCAmelCase : Tuple,					**__UpperCAmelCase : List[str]      )     ->			Optional[int]:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Any	    =     ["sentencepiece"]


	def __init__(self : Optional[int],					*__UpperCAmelCase : str,					**__UpperCAmelCase : str      )     ->			str:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    int	    =     ["sentencepiece"]


	def __init__(self : Dict,					*__UpperCAmelCase : Any,					**__UpperCAmelCase : List[str]      )     ->			Dict:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    Optional[Any]	    =     ["sentencepiece"]


	def __init__(self : List[Any],					*__UpperCAmelCase : Optional[Any],					**__UpperCAmelCase : int      )     ->			Any:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    int	    =     ["sentencepiece"]


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

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )



class 	a__     (				metaclass=_lowercase	):
	__magic_name__		:    List[Any]	    =     ["sentencepiece"]


	def __init__(self : Optional[int],					*__UpperCAmelCase : str,					**__UpperCAmelCase : List[str]      )     ->			str:

					"""simple docstring"""

					requires_backends(self,					['''sentencepiece''']      )




