

'''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""": 1536,
    """junnyu/roformer_chinese_base""": 1536,
    """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 		__SCREAMING_SNAKE_CASE       ( _snake_case			):
				lowerCamelCase_							=						VOCAB_FILES_NAMES
				lowerCamelCase_							=						PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase_							=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase_							=						PRETRAINED_INIT_CONFIGURATION
				lowerCamelCase_							=						RoFormerTokenizer







				def __init__(					self    :		Optional[int]		,				UpperCAmelCase__    :		Optional[int]=None		,				UpperCAmelCase__    :		Union[str, Any]=None		,				UpperCAmelCase__    :		Tuple=True		,				UpperCAmelCase__    :		List[str]="[UNK]"		,				UpperCAmelCase__    :		Optional[int]="[SEP]"		,				UpperCAmelCase__    :		Union[str, Any]="[PAD]"		,				UpperCAmelCase__    :		List[str]="[CLS]"		,				UpperCAmelCase__    :		Optional[Any]="[MASK]"		,				UpperCAmelCase__    :		int=True		,				UpperCAmelCase__    :		Dict=None		,				**UpperCAmelCase__    :		List[Any]		,				):
										'''simple docstring'''
										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   :       Optional[Any]								=json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
										if (
										    pre_tok_state.get('''lowercase'''		,				UpperCAmelCase__      ) != do_lower_case
										    or pre_tok_state.get('''strip_accents'''		,				UpperCAmelCase__      ) != strip_accents
										):
																lowercase   :       int								=getattr(UpperCAmelCase__		,				pre_tok_state.pop('''type'''      )      )
																lowercase   :       Optional[Any]								=do_lower_case
																lowercase   :       Any								=strip_accents
																lowercase   :       List[Any]								=pre_tok_class(**UpperCAmelCase__      )

										lowercase   :       str								=do_lower_case







				def __getstate__(					self    :		Dict      ):
										'''simple docstring'''
										lowercase   :       int								=self.__dict__.copy()
										lowercase   :       Union[str, Any]								=BertPreTokenizer()
										return state







				def __setstate__(					self    :		List[Any]		,				UpperCAmelCase__    :		Optional[int]      ):
										'''simple docstring'''
										lowercase   :       Union[str, Any]								=d
										lowercase   :       str								=self.__dict__['''_tokenizer'''].get_vocab()
										lowercase   :       List[Any]								=PreTokenizer.custom(JiebaPreTokenizer(UpperCAmelCase__      )      )







				def    lowerCamelCase_  (					self    :		List[str]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		List[Any]=None      ):
										'''simple docstring'''
										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    :		int		,				UpperCAmelCase__    :		List[int]		,				UpperCAmelCase__    :		Optional[List[int]] = None      ):
										'''simple docstring'''
										lowercase   :       List[str]								=[self.sep_token_id]
										lowercase   :       List[str]								=[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    :		Tuple		,				UpperCAmelCase__    :		str		,				UpperCAmelCase__    :		Optional[str] = None      ):
										'''simple docstring'''
										lowercase   :       List[str]								=self._tokenizer.model.save(UpperCAmelCase__		,				name=UpperCAmelCase__      )
										return tuple(UpperCAmelCase__      )







				def    lowerCamelCase_  (					self    :		int		,				UpperCAmelCase__    :		str		,				UpperCAmelCase__    :		Dict=None		,				UpperCAmelCase__    :		Union[str, Any]=None		,				UpperCAmelCase__    :		Union[str, Any]=False		,				**UpperCAmelCase__    :		str		,				):
										'''simple docstring'''
										lowercase   :       List[str]								=BertPreTokenizer()
										return super().save_pretrained(UpperCAmelCase__		,				UpperCAmelCase__		,				UpperCAmelCase__		,				UpperCAmelCase__		,				**UpperCAmelCase__      )








'''simple docstring'''





import json
import os
import unittest

from transformers.models.biogpt.tokenization_biogpt import VOCAB_FILES_NAMES, BioGptTokenizer
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin





class 		__SCREAMING_SNAKE_CASE       ( lowercase__	,       unittest.TestCase			):
				lowerCamelCase_							=						BioGptTokenizer
				lowerCamelCase_							=						False







				def    lowerCamelCase_  (					self    :		Optional[Any]      ):
										'''simple docstring'''
										super().setUp()

										# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
										lowercase   :       List[str]								=[
										    '''l''',
										    '''o''',
										    '''w''',
										    '''e''',
										    '''r''',
										    '''s''',
										    '''t''',
										    '''i''',
										    '''d''',
										    '''n''',
										    '''w</w>''',
										    '''r</w>''',
										    '''t</w>''',
										    '''lo''',
										    '''low''',
										    '''er</w>''',
										    '''low</w>''',
										    '''lowest</w>''',
										    '''newer</w>''',
										    '''wider</w>''',
										    '''<unk>''',
										]
										lowercase   :       Any								=dict(zip(UpperCAmelCase__		,				range(len(UpperCAmelCase__      )      )      )      )
										lowercase   :       Union[str, Any]								=['''l o 123''', '''lo w 1456''', '''e r</w> 1789''', '''''']

										lowercase   :       Optional[int]								=os.path.join(self.tmpdirname		,				VOCAB_FILES_NAMES['''vocab_file''']      )
										lowercase   :       Union[str, Any]								=os.path.join(self.tmpdirname		,				VOCAB_FILES_NAMES['''merges_file''']      )
										with open(self.vocab_file		,				'''w'''      ) as fp:
																fp.write(json.dumps(UpperCAmelCase__      )      )
										with open(self.merges_file		,				'''w'''      ) as fp:
																fp.write('''\n'''.join(UpperCAmelCase__      )      )







				def    lowerCamelCase_  (					self    :		List[Any]		,				UpperCAmelCase__    :		Union[str, Any]      ):
										'''simple docstring'''
										lowercase   :       Dict								='''lower newer'''
										lowercase   :       str								='''lower newer'''
										return input_text, output_text







				def    lowerCamelCase_  (					self    :		List[Any]      ):
										'''simple docstring'''
										lowercase   :       List[Any]								=BioGptTokenizer(self.vocab_file		,				self.merges_file      )

										lowercase   :       Any								='''lower'''
										lowercase   :       int								=['''low''', '''er</w>''']
										lowercase   :       Optional[Any]								=tokenizer.tokenize(UpperCAmelCase__      )
										self.assertListEqual(UpperCAmelCase__		,				UpperCAmelCase__      )

										lowercase   :       Optional[int]								=tokens + ['''<unk>''']
										lowercase   :       Any								=[14, 15, 20]
										self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCAmelCase__      )		,				UpperCAmelCase__      )







				@slow
				def    lowerCamelCase_  (					self    :		int      ):
										'''simple docstring'''
										lowercase   :       Dict								=BioGptTokenizer.from_pretrained('''microsoft/biogpt'''      )

										lowercase   :       List[str]								=tokenizer.encode('''sequence builders'''		,				add_special_tokens=UpperCAmelCase__      )
										lowercase   :       Optional[int]								=tokenizer.encode('''multi-sequence build'''		,				add_special_tokens=UpperCAmelCase__      )

										lowercase   :       str								=tokenizer.build_inputs_with_special_tokens(UpperCAmelCase__      )
										lowercase   :       Optional[Any]								=tokenizer.build_inputs_with_special_tokens(UpperCAmelCase__		,				UpperCAmelCase__      )

										self.assertTrue(encoded_sentence == [2] + text      )
										self.assertTrue(encoded_pair == [2] + text + [2] + text_a      )





