


"""simple docstring"""
from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__SCREAMING_SNAKE_CASE							:    int		=    {'configuration_mmbt': ['MMBTConfig']}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__SCREAMING_SNAKE_CASE							:    List[Any]		=    ['MMBTForClassification', 'MMBTModel', 'ModalEmbeddings']


if TYPE_CHECKING:
				from .configuration_mmbt import MMBTConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
				import sys

				__SCREAMING_SNAKE_CASE							:    Any		=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)







"""simple docstring"""
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


__SCREAMING_SNAKE_CASE							:    List[str]		=    logging.get_logger(__name__)
__SCREAMING_SNAKE_CASE							:    Optional[int]		=    {'vocab_file': 'spiece.model'}

__SCREAMING_SNAKE_CASE							:    List[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',
    }
}

__SCREAMING_SNAKE_CASE							:    List[str]		=    {
    'albert-base-v1': 512,
    'albert-large-v1': 512,
    'albert-xlarge-v1': 512,
    'albert-xxlarge-v1': 512,
    'albert-base-v2': 512,
    'albert-large-v2': 512,
    'albert-xlarge-v2': 512,
    'albert-xxlarge-v2': 512,
}

__SCREAMING_SNAKE_CASE							:    int		=    '▁'





class      __A     (snake_case__):





							'''simple docstring'''

							__lowercase:		Optional[Any]							      =    VOCAB_FILES_NAMES
							__lowercase:		Optional[int]							      =    PRETRAINED_VOCAB_FILES_MAP
							__lowercase:		Tuple							      =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES



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



														"""simple docstring"""



														snake_case_           =		(
														    AddedToken(UpperCAmelCase_		,       lstrip=UpperCAmelCase_		,       rstrip=UpperCAmelCase_		,       normalized=UpperCAmelCase_       )
														    if isinstance(UpperCAmelCase_		,       UpperCAmelCase_       )
														    else mask_token
														)

														snake_case_           =		{} if sp_model_kwargs is None else sp_model_kwargs

														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_		,       sp_model_kwargs=self.sp_model_kwargs		,       **UpperCAmelCase_		,       )

														snake_case_           =		do_lower_case
														snake_case_           =		remove_space
														snake_case_           =		keep_accents
														snake_case_           =		vocab_file

														snake_case_           =		spm.SentencePieceProcessor(**self.sp_model_kwargs       )
														self.sp_model.Load(UpperCAmelCase_       )



							@property
							def 		lowerCAmelCase       (				self							:      List[Any]       )					->Dict:



														"""simple docstring"""



														return len(self.sp_model       )



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



														"""simple docstring"""



														snake_case_           =		{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							:      Dict       )					->List[str]:



														"""simple docstring"""



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



							def __setstate__(				self							:      Tuple		,       UpperCAmelCase_							:      Optional[int]       )					->Optional[int]:



														"""simple docstring"""



														snake_case_           =		d

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

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



							def 		lowerCAmelCase       (				self							:      Tuple		,       UpperCAmelCase_							:      Any       )					->str:



														"""simple docstring"""



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

														if not self.keep_accents:
																					snake_case_           =		unicodedata.normalize("""NFKD"""		,       UpperCAmelCase_       )
																					snake_case_           =		"""""".join([c for c in outputs if not unicodedata.combining(UpperCAmelCase_       )]       )
														if self.do_lower_case:
																					snake_case_           =		outputs.lower()

														return outputs



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



														"""simple docstring"""



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

														return new_pieces



							def 		lowerCAmelCase       (				self							:      Optional[int]		,       UpperCAmelCase_							:      Optional[int]       )					->Dict:



														"""simple docstring"""



														return self.sp_model.PieceToId(UpperCAmelCase_       )



							def 		lowerCAmelCase       (				self							:      str		,       UpperCAmelCase_							:      Union[str, Any]       )					->Optional[int]:



														"""simple docstring"""



														return self.sp_model.IdToPiece(UpperCAmelCase_       )



							def 		lowerCAmelCase       (				self							:      str		,       UpperCAmelCase_							:      Dict       )					->Any:



														"""simple docstring"""



														snake_case_           =		[]
														snake_case_           =		""""""
														snake_case_           =		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(UpperCAmelCase_       ) + token
																												snake_case_           =		True
																												snake_case_           =		[]
																					else:
																												current_sub_tokens.append(UpperCAmelCase_       )
																												snake_case_           =		False
														out_string += self.sp_model.decode(UpperCAmelCase_       )
														return out_string.strip()



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



														"""simple docstring"""



														snake_case_           =		[self.sep_token_id]
														snake_case_           =		[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 		lowerCAmelCase       (				self							:      Tuple		,       UpperCAmelCase_							:      List[int]		,       UpperCAmelCase_							:      Optional[List[int]] = None		,       UpperCAmelCase_							:      bool = False       )					->List[int]:



														"""simple docstring"""



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

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



							def 		lowerCAmelCase       (				self							:      Dict		,       UpperCAmelCase_							:      List[int]		,       UpperCAmelCase_							:      Optional[List[int]] = None       )					->List[int]:



														"""simple docstring"""



														snake_case_           =		[self.sep_token_id]
														snake_case_           =		[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							:      str		,       UpperCAmelCase_							:      str		,       UpperCAmelCase_							:      Optional[str] = None       )					->Tuple[str]:



														"""simple docstring"""



														if not os.path.isdir(UpperCAmelCase_       ):
																					logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""       )
																					return
														snake_case_           =		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_       ) and os.path.isfile(self.vocab_file       ):
																					copyfile(self.vocab_file		,       UpperCAmelCase_       )
														elif not os.path.isfile(self.vocab_file       ):
																					with open(UpperCAmelCase_		,       """wb"""       ) as fi:
																												snake_case_           =		self.sp_model.serialized_model_proto()
																												fi.write(UpperCAmelCase_       )

														return (out_vocab_file,)



