



'''simple docstring'''

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

from ...file_utils import is_sentencepiece_available
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if is_sentencepiece_available():
     from .tokenization_deberta_va import DebertaVaTokenizer
else:
     UpperCamelCase_     			=       None

UpperCamelCase_     			=       logging.get_logger(__name__)

UpperCamelCase_     			=       {"""vocab_file""": """spm.model""", """tokenizer_file""": """tokenizer.json"""}

UpperCamelCase_     			=       {
    """vocab_file""": {
        """microsoft/deberta-v2-xlarge""": """https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/spm.model""",
        """microsoft/deberta-v2-xxlarge""": """https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/spm.model""",
        """microsoft/deberta-v2-xlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/spm.model"""
        ),
        """microsoft/deberta-v2-xxlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/spm.model"""
        ),
    }
}

UpperCamelCase_     			=       {
    """microsoft/deberta-v2-xlarge""": 5_12,
    """microsoft/deberta-v2-xxlarge""": 5_12,
    """microsoft/deberta-v2-xlarge-mnli""": 5_12,
    """microsoft/deberta-v2-xxlarge-mnli""": 5_12,
}

UpperCamelCase_     			=       {
    """microsoft/deberta-v2-xlarge""": {"""do_lower_case""": False},
    """microsoft/deberta-v2-xxlarge""": {"""do_lower_case""": False},
    """microsoft/deberta-v2-xlarge-mnli""": {"""do_lower_case""": False},
    """microsoft/deberta-v2-xxlarge-mnli""": {"""do_lower_case""": False},
}


class   a_  (_a    ):
       __lowerCAmelCase    :				Tuple    =      VOCAB_FILES_NAMES
       __lowerCAmelCase    :				Optional[Any]    =      PRETRAINED_VOCAB_FILES_MAP
       __lowerCAmelCase    :				Any    =      PRETRAINED_INIT_CONFIGURATION
       __lowerCAmelCase    :				int    =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __lowerCAmelCase    :				Union[str, Any]    =      DebertaVaTokenizer




       def __init__(     self   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_=False   ,   snake_case_=False   ,   snake_case_="[CLS]"   ,   snake_case_="[SEP]"   ,   snake_case_="[UNK]"   ,   snake_case_="[SEP]"   ,   snake_case_="[PAD]"   ,   snake_case_="[CLS]"   ,   snake_case_="[MASK]"   ,   **snake_case_   ,   ):
         super().__init__(
             snake_case_   ,   tokenizer_file=snake_case_   ,   do_lower_case=snake_case_   ,   bos_token=snake_case_   ,   eos_token=snake_case_   ,   unk_token=snake_case_   ,   sep_token=snake_case_   ,   pad_token=snake_case_   ,   cls_token=snake_case_   ,   mask_token=snake_case_   ,   split_by_punct=snake_case_   ,   **snake_case_   ,   )

         _lowerCAmelCase       :  str   				=					do_lower_case
         _lowerCAmelCase       :  str   				=					split_by_punct
         _lowerCAmelCase       :  Union[str, Any]   				=					vocab_file
         _lowerCAmelCase       :  Any   				=					False if not self.vocab_file else True




       def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_=None  ):

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




       def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_=None   ,   snake_case_=False  ):

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

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




       def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_=None  ):
         _lowerCAmelCase       :  Optional[int]   				=					[self.sep_token_id]
         _lowerCAmelCase       :  Tuple   				=					[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   ,   snake_case_   ,   snake_case_ = None  ):
         if not self.can_save_slow_tokenizer:
           raise ValueError(
               """Your fast tokenizer does not have the necessary information to save the vocabulary for a slow """
               """tokenizer."""  )

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

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

         return (out_vocab_file,)




'''simple docstring'''

import json
import os
import unittest

from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import (
    VOCAB_FILES_NAMES,
    GPTNeoXJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class   a_  (_a							,			unittest.TestCase    ):
       __lowerCAmelCase    :				List[Any]    =      GPTNeoXJapaneseTokenizer
       __lowerCAmelCase    :				Any    =      False
       __lowerCAmelCase    :				List[Any]    =      {"""do_clean_text""": False, """add_prefix_space""": False}




       def 							__UpperCamelCase       (     self  ):
         super().setUp()

         _lowerCAmelCase       :  Any   				=					[
             """こん""",
             """こんに""",
             """にちは""",
             """ばんは""",
             """世界,㔺界""",
             """、""",
             """。""",
             """<BR>""",
             """<SP>""",
             """<TAB>""",
             """<URL>""",
             """<EMAIL>""",
             """<TEL>""",
             """<DATE>""",
             """<PRICE>""",
             """<BLOCK>""",
             """<KIGOU>""",
             """<U2000U2BFF>""",
             """<|emoji1|>""",
             """<unk>""",
             """<|startoftext|>""",
             """<|endoftext|>""",
         ]
         _lowerCAmelCase       :  Union[str, Any]   				=					{"""emoji""": {"""\ud83d\ude00""": """<|emoji1|>"""}, """emoji_inv""": {"""<|emoji1|>""": """\ud83d\ude00"""}}  # 😀
         _lowerCAmelCase       :  Any   				=					{"""unk_token""": """<unk>"""}

         _lowerCAmelCase       :  Optional[int]   				=					os.path.join(self.tmpdirname   ,   VOCAB_FILES_NAMES["""vocab_file"""]  )
         _lowerCAmelCase       :  Any   				=					os.path.join(self.tmpdirname   ,   VOCAB_FILES_NAMES["""emoji_file"""]  )
         with open(self.vocab_file   ,   """w"""   ,   encoding="""utf-8"""  ) as vocab_writer:
           vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]  )  )
         with open(self.emoji_file   ,   """w"""  ) as emoji_writer:
           emoji_writer.write(json.dumps(snake_case_  )  )




       def 							__UpperCamelCase       (     self   ,   **snake_case_  ):
         kwargs.update(self.special_tokens_map  )
         return GPTNeoXJapaneseTokenizer.from_pretrained(self.tmpdirname   ,   **snake_case_  )




       def 							__UpperCamelCase       (     self   ,   snake_case_  ):
         _lowerCAmelCase       :  Tuple   				=					"""こんにちは、世界。 \nこんばんは、㔺界。😀"""
         _lowerCAmelCase       :  str   				=					"""こんにちは、世界。 \nこんばんは、世界。😀"""
         return input_text, output_text




       def 							__UpperCamelCase       (     self   ,   snake_case_  ):
         _lowerCAmelCase				,					_lowerCAmelCase       :  str   				=					self.get_input_output_texts(snake_case_  )
         _lowerCAmelCase       :  Tuple   				=					tokenizer.encode(snake_case_   ,   add_special_tokens=snake_case_  )
         _lowerCAmelCase       :  Optional[Any]   				=					tokenizer.decode(snake_case_   ,   clean_up_tokenization_spaces=snake_case_  )
         return text, ids




       def 							__UpperCamelCase       (     self  ):
         pass  # TODO add if relevant




       def 							__UpperCamelCase       (     self  ):
         pass  # TODO add if relevant




       def 							__UpperCamelCase       (     self  ):
         pass  # TODO add if relevant




       def 							__UpperCamelCase       (     self  ):
         _lowerCAmelCase       :  List[Any]   				=					self.get_tokenizer()

         # Testing tokenization
         _lowerCAmelCase       :  Tuple   				=					"""こんにちは、世界。　こんばんは、㔺界。"""
         _lowerCAmelCase       :  Optional[Any]   				=					["""こん""", """にちは""", """、""", """世界""", """。""", """<SP>""", """こん""", """ばんは""", """、""", """㔺界""", """。"""]
         _lowerCAmelCase       :  Tuple   				=					tokenizer.tokenize(snake_case_  )
         self.assertListEqual(snake_case_   ,   snake_case_  )

         # Testing conversion to ids without special tokens
         _lowerCAmelCase       :  Optional[int]   				=					[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
         _lowerCAmelCase       :  Optional[int]   				=					tokenizer.convert_tokens_to_ids(snake_case_  )
         self.assertListEqual(snake_case_   ,   snake_case_  )

         # Testing conversion to ids with special tokens
         _lowerCAmelCase       :  Optional[Any]   				=					tokens + [tokenizer.unk_token]
         _lowerCAmelCase       :  List[str]   				=					[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 1_9]
         _lowerCAmelCase       :  Dict   				=					tokenizer.convert_tokens_to_ids(snake_case_  )
         self.assertListEqual(snake_case_   ,   snake_case_  )




       @slow
       def 							__UpperCamelCase       (     self  ):
         _lowerCAmelCase       :  int   				=					self.tokenizer_class.from_pretrained("""abeja/gpt-neox-japanese-2.7b"""  )

         _lowerCAmelCase       :  List[Any]   				=					tokenizer.encode("""ありがとう。"""   ,   add_special_tokens=snake_case_  )
         _lowerCAmelCase       :  List[str]   				=					tokenizer.encode("""どういたしまして。"""   ,   add_special_tokens=snake_case_  )

         _lowerCAmelCase       :  int   				=					tokenizer.build_inputs_with_special_tokens(snake_case_  )
         _lowerCAmelCase       :  Any   				=					tokenizer.build_inputs_with_special_tokens(snake_case_   ,   snake_case_  )

         assert encoded_sentence == ids_a
         assert encoded_pair == ids_a + ids_a




       def 							__UpperCamelCase       (     self  ):
         # Intentionally convert some words to accommodate character fluctuations unique to Japanese
         pass







       def 							__UpperCamelCase       (     self  ):
         # tokenizer has no padding token
         pass


