


'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__UpperCAmelCase       =							{'''configuration_xglm''': ['''XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XGLMConfig''']}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase       =							['''XGLMTokenizer''']

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase       =							['''XGLMTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase       =							[
		    '''XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''XGLMForCausalLM''',
		    '''XGLMModel''',
		    '''XGLMPreTrainedModel''',
		]


try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase       =							[
		    '''FlaxXGLMForCausalLM''',
		    '''FlaxXGLMModel''',
		    '''FlaxXGLMPreTrainedModel''',
		]


try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase       =							[
		    '''TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFXGLMForCausalLM''',
		    '''TFXGLMModel''',
		    '''TFXGLMPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xglm import XGLMTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xglm_fast import XGLMTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_xglm import (
				    TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFXGLMForCausalLM,
				    TFXGLMModel,
				    TFXGLMPreTrainedModel,
				)


else:
		import sys

		__UpperCAmelCase       =							_LazyModule(__name__, globals()['''__file__'''], _import_structure)



'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers
from tokenizers.pre_tokenizers import BertPreTokenizer, PreTokenizer

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roformer import RoFormerTokenizer
from .tokenization_utils import JiebaPreTokenizer


__UpperCAmelCase       =							logging.get_logger(__name__)

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

__UpperCAmelCase       =							{
    '''vocab_file''': {
        '''junnyu/roformer_chinese_small''': '''https://huggingface.co/junnyu/roformer_chinese_small/resolve/main/vocab.txt''',
        '''junnyu/roformer_chinese_base''': '''https://huggingface.co/junnyu/roformer_chinese_base/resolve/main/vocab.txt''',
        '''junnyu/roformer_chinese_char_small''': (
            '''https://huggingface.co/junnyu/roformer_chinese_char_small/resolve/main/vocab.txt'''
        ),
        '''junnyu/roformer_chinese_char_base''': (
            '''https://huggingface.co/junnyu/roformer_chinese_char_base/resolve/main/vocab.txt'''
        ),
        '''junnyu/roformer_small_discriminator''': (
            '''https://huggingface.co/junnyu/roformer_small_discriminator/resolve/main/vocab.txt'''
        ),
        '''junnyu/roformer_small_generator''': (
            '''https://huggingface.co/junnyu/roformer_small_generator/resolve/main/vocab.txt'''
        ),
    }
}

__UpperCAmelCase       =							{
    '''junnyu/roformer_chinese_small''': 1_536,
    '''junnyu/roformer_chinese_base''': 1_536,
    '''junnyu/roformer_chinese_char_small''': 512,
    '''junnyu/roformer_chinese_char_base''': 512,
    '''junnyu/roformer_small_discriminator''': 128,
    '''junnyu/roformer_small_generator''': 128,
}


__UpperCAmelCase       =							{
    '''junnyu/roformer_chinese_small''': {'''do_lower_case''': True},
    '''junnyu/roformer_chinese_base''': {'''do_lower_case''': True},
    '''junnyu/roformer_chinese_char_small''': {'''do_lower_case''': True},
    '''junnyu/roformer_chinese_char_base''': {'''do_lower_case''': True},
    '''junnyu/roformer_small_discriminator''': {'''do_lower_case''': True},
    '''junnyu/roformer_small_generator''': {'''do_lower_case''': True},
}




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       int     						=				VOCAB_FILES_NAMES
							lowercase__      :       Optional[int]     						=				PRETRAINED_VOCAB_FILES_MAP
							lowercase__      :       Any     						=				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowercase__      :       Union[str, Any]     						=				PRETRAINED_INIT_CONFIGURATION
							lowercase__      :       Tuple     						=				RoFormerTokenizer







							def __init__(		self ,   lowerCamelCase_=None ,   lowerCamelCase_=None ,   lowerCamelCase_=True ,   lowerCamelCase_="[UNK]" ,   lowerCamelCase_="[SEP]" ,   lowerCamelCase_="[PAD]" ,   lowerCamelCase_="[CLS]" ,   lowerCamelCase_="[MASK]" ,   lowerCamelCase_=True ,   lowerCamelCase_=None ,   **lowerCamelCase_ ,   )	->							Tuple:
														super().__init__(
														    lowerCamelCase_ ,   tokenizer_file=lowerCamelCase_ ,   do_lower_case=lowerCamelCase_ ,   unk_token=lowerCamelCase_ ,   sep_token=lowerCamelCase_ ,   pad_token=lowerCamelCase_ ,   cls_token=lowerCamelCase_ ,   mask_token=lowerCamelCase_ ,   tokenize_chinese_chars=lowerCamelCase_ ,   strip_accents=lowerCamelCase_ ,   **lowerCamelCase_ ,   )

														lowerCAmelCase__	       =     json.loads(self.backend_tokenizer.normalizer.__getstate__()       )
														if (
														    pre_tok_state.get('''lowercase''' ,   lowerCamelCase_       ) != do_lower_case
														    or pre_tok_state.get('''strip_accents''' ,   lowerCamelCase_       ) != strip_accents
														):
																					lowerCAmelCase__	       =     getattr(lowerCamelCase_ ,   pre_tok_state.pop('''type'''       )       )
																					lowerCAmelCase__	       =     do_lower_case
																					lowerCAmelCase__	       =     strip_accents
																					lowerCAmelCase__	       =     pre_tok_class(**lowerCamelCase_       )

														lowerCAmelCase__	       =     do_lower_case







							def __getstate__(		self       )	->							Any:
														lowerCAmelCase__	       =     self.__dict__.copy()
														lowerCAmelCase__	       =     BertPreTokenizer()
														return state







							def __setstate__(		self ,   lowerCamelCase_       )	->							List[Any]:
														lowerCAmelCase__	       =     d
														lowerCAmelCase__	       =     self.__dict__['''_tokenizer'''].get_vocab()
														lowerCAmelCase__	       =     PreTokenizer.custom(JiebaPreTokenizer(lowerCamelCase_       )       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_=None       )	->							Union[str, Any]:
														lowerCAmelCase__	       =     [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   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = None       )	->							List[int]:
														lowerCAmelCase__	       =     [self.sep_token_id]
														lowerCAmelCase__	       =     [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   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = None       )	->							Tuple[str]:
														lowerCAmelCase__	       =     self._tokenizer.model.save(lowerCamelCase_ ,   name=lowerCamelCase_       )
														return tuple(lowerCamelCase_       )







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_=None ,   lowerCamelCase_=None ,   lowerCamelCase_=False ,   **lowerCamelCase_ ,   )	->							Union[str, Any]:
														lowerCAmelCase__	       =     BertPreTokenizer()
														return super().save_pretrained(lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_ ,   **lowerCamelCase_       )