



'''simple docstring'''

import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_deberta import DebertaTokenizer


if TYPE_CHECKING:
     from transformers.pipelines.conversational import Conversation


UpperCamelCase_     			=       logging.get_logger(__name__)

UpperCamelCase_     			=       {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

UpperCamelCase_     			=       {
    """vocab_file""": {
        """microsoft/deberta-base""": """https://huggingface.co/microsoft/deberta-base/resolve/main/vocab.json""",
        """microsoft/deberta-large""": """https://huggingface.co/microsoft/deberta-large/resolve/main/vocab.json""",
        """microsoft/deberta-xlarge""": """https://huggingface.co/microsoft/deberta-xlarge/resolve/main/vocab.json""",
        """microsoft/deberta-base-mnli""": """https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/vocab.json""",
        """microsoft/deberta-large-mnli""": """https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/vocab.json""",
        """microsoft/deberta-xlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/vocab.json"""
        ),
    },
    """merges_file""": {
        """microsoft/deberta-base""": """https://huggingface.co/microsoft/deberta-base/resolve/main/merges.txt""",
        """microsoft/deberta-large""": """https://huggingface.co/microsoft/deberta-large/resolve/main/merges.txt""",
        """microsoft/deberta-xlarge""": """https://huggingface.co/microsoft/deberta-xlarge/resolve/main/merges.txt""",
        """microsoft/deberta-base-mnli""": """https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/merges.txt""",
        """microsoft/deberta-large-mnli""": """https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/merges.txt""",
        """microsoft/deberta-xlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/merges.txt"""
        ),
    },
}

UpperCamelCase_     			=       {
    """microsoft/deberta-base""": 5_12,
    """microsoft/deberta-large""": 5_12,
    """microsoft/deberta-xlarge""": 5_12,
    """microsoft/deberta-base-mnli""": 5_12,
    """microsoft/deberta-large-mnli""": 5_12,
    """microsoft/deberta-xlarge-mnli""": 5_12,
}

UpperCamelCase_     			=       {
    """microsoft/deberta-base""": {"""do_lower_case""": False},
    """microsoft/deberta-large""": {"""do_lower_case""": False},
}


class   a_  (_a    ):
       __lowerCAmelCase    :				Optional[Any]    =      VOCAB_FILES_NAMES
       __lowerCAmelCase    :				Optional[Any]    =      PRETRAINED_VOCAB_FILES_MAP
       __lowerCAmelCase    :				Optional[Any]    =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __lowerCAmelCase    :				Optional[Any]    =      ["""input_ids""", """attention_mask""", """token_type_ids"""]
       __lowerCAmelCase    :				Optional[int]    =      DebertaTokenizer




       def __init__(     self   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_=None   ,   snake_case_="replace"   ,   snake_case_="[CLS]"   ,   snake_case_="[SEP]"   ,   snake_case_="[SEP]"   ,   snake_case_="[CLS]"   ,   snake_case_="[UNK]"   ,   snake_case_="[PAD]"   ,   snake_case_="[MASK]"   ,   snake_case_=False   ,   **snake_case_   ,   ):
         super().__init__(
             snake_case_   ,   snake_case_   ,   tokenizer_file=snake_case_   ,   errors=snake_case_   ,   bos_token=snake_case_   ,   eos_token=snake_case_   ,   unk_token=snake_case_   ,   sep_token=snake_case_   ,   cls_token=snake_case_   ,   pad_token=snake_case_   ,   mask_token=snake_case_   ,   add_prefix_space=snake_case_   ,   **snake_case_   ,   )
         _lowerCAmelCase       :  Optional[Any]   				=					kwargs.pop("""add_bos_token"""   ,   snake_case_  )

         _lowerCAmelCase       :  Tuple   				=					json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()  )
         if pre_tok_state.get("""add_prefix_space"""   ,   snake_case_  ) != add_prefix_space:
           _lowerCAmelCase       :  int   				=					getattr(snake_case_   ,   pre_tok_state.pop("""type"""  )  )
           _lowerCAmelCase       :  str   				=					add_prefix_space
           _lowerCAmelCase       :  str   				=					pre_tok_class(**snake_case_  )

         _lowerCAmelCase       :  Tuple   				=					add_prefix_space




       @property
       def 							__UpperCamelCase       (     self  ):
         if self._mask_token is None:
           if self.verbose:
             logger.error("""Using mask_token, but it is not set yet."""  )
           return None
         return str(self._mask_token  )




       @mask_token.setter
       def 							__UpperCamelCase       (     self   ,   snake_case_  ):
         _lowerCAmelCase       :  Tuple   				=					AddedToken(snake_case_   ,   lstrip=snake_case_   ,   rstrip=snake_case_  ) if isinstance(snake_case_   ,   snake_case_  ) else value
         _lowerCAmelCase       :  Tuple   				=					value




       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       :  Optional[Any]   				=					[self.sep_token_id]
         return cls + token_ids_a + sep + token_ids_a + sep




       def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_ = None  ):
         _lowerCAmelCase       :  Dict   				=					[self.sep_token_id]
         _lowerCAmelCase       :  Optional[Any]   				=					[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_  ):
         _lowerCAmelCase       :  Union[str, Any]   				=					kwargs.get("""is_split_into_words"""   ,   snake_case_  )
         assert self.add_prefix_space or not is_split_into_words, (
             f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
             "to use it with pretokenized inputs."
         )

         return super()._batch_encode_plus(*snake_case_   ,   **snake_case_  )




       def 							__UpperCamelCase       (     self   ,   *snake_case_   ,   **snake_case_  ):
         _lowerCAmelCase       :  str   				=					kwargs.get("""is_split_into_words"""   ,   snake_case_  )

         assert self.add_prefix_space or not is_split_into_words, (
             f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
             "to use it with pretokenized inputs."
         )

         return super()._encode_plus(*snake_case_   ,   **snake_case_  )




       def 							__UpperCamelCase       (     self   ,   snake_case_   ,   snake_case_ = None  ):
         _lowerCAmelCase       :  Union[str, Any]   				=					self._tokenizer.model.save(snake_case_   ,   name=snake_case_  )
         return tuple(snake_case_  )







       def 							__UpperCamelCase       (     self   ,   snake_case_  ):
         _lowerCAmelCase       :  List[str]   				=					[]
         for is_user, text in conversation.iter_texts():
           input_ids.extend(self.encode(snake_case_   ,   add_special_tokens=snake_case_  ) + [self.eos_token_id]  )

         if len(snake_case_  ) > self.model_max_length:
           _lowerCAmelCase       :  Tuple   				=					input_ids[-self.model_max_length :]
         return input_ids




'''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


