

'''simple docstring'''






import unittest

from transformers import GPTSwaTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase__											=	get_tests_dir('''fixtures/test_sentencepiece_with_bytefallback.model''')






@require_sentencepiece
@require_tokenizers
class 			lowercase_	(_lowerCamelCase				,       unittest.TestCase      ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE    :  List[Any]							=			GPTSwaTokenizer
  SCREAMING_SNAKE_CASE    :  int							=			False
  SCREAMING_SNAKE_CASE    :  Optional[int]							=			True
  SCREAMING_SNAKE_CASE    :  Optional[int]							=			False






  def 					SCREAMING_SNAKE_CASE      (      self   :     str			):
   super().setUp()

   # We have a SentencePiece fixture for testing
   __lowercase							  = GPTSwaTokenizer(_UpperCamelCase					,eos_token='''<unk>'''					,bos_token='''<unk>'''					,pad_token='''<unk>'''			)

   tokenizer.save_pretrained(self.tmpdirname			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     int					,lowercase__   :     Optional[int]			):
   __lowercase							  = '''This is a test'''
   __lowercase							  = '''This is a test'''
   return input_text, output_text






  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[int]			):
   __lowercase							  = '''<s>'''
   __lowercase							  = 1

   self.assertEqual(self.get_tokenizer()._convert_token_to_id(_UpperCamelCase			)					,_UpperCamelCase			)
   self.assertEqual(self.get_tokenizer()._convert_id_to_token(_UpperCamelCase			)					,_UpperCamelCase			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[int]			):
   __lowercase							  = list(self.get_tokenizer().get_vocab().keys()			)

   self.assertEqual(vocab_keys[0]					,'''<unk>'''			)
   self.assertEqual(vocab_keys[1]					,'''<s>'''			)
   self.assertEqual(vocab_keys[-1]					,'''j'''			)
   self.assertEqual(len(_UpperCamelCase			)					,2_0_0_0			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     List[str]			):
   self.assertEqual(self.get_tokenizer().vocab_size					,2_0_0_0			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   __lowercase							  = GPTSwaTokenizer(_UpperCamelCase			)

   __lowercase							  = tokenizer.tokenize('''This is a test'''			)
   self.assertListEqual(_UpperCamelCase					,['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']			)

   self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCamelCase			)					,[4_6_5, 2_8_7, 2_6_5, 6_3_1, 8_4_2]			)

   __lowercase							  = tokenizer.tokenize('''I was born in 92000, and this is falsé.'''			)
   # fmt: off
   self.assertListEqual(
       _UpperCamelCase					,['''▁I''', '''▁was''', '''▁bor''', '''n''', '''▁in''', '''▁''', '''<0x39>''', '''2''', '''0''', '''0''', '''0''', ''',''', '''▁and''', '''▁this''', '''▁is''', '''▁f''', '''al''', '''s''', '''<0xC3>''', '''<0xA9>''', '''.''']					,)
   # fmt: on

   __lowercase							  = tokenizer.convert_tokens_to_ids(_UpperCamelCase			)
   self.assertListEqual(
       _UpperCamelCase					,[2_6_2, 2_7_2, 1_5_2_5, 2_8_6, 2_7_1, 2_6_8, 6_0, 9_1_6, 6_3_3, 6_3_3, 6_3_3, 2_5_9, 2_6_6, 3_0_1, 2_8_7, 3_8_4, 3_6_7, 2_6_3, 1_9_8, 1_7_2, 2_6_0]					,)

   __lowercase							  = tokenizer.convert_ids_to_tokens(_UpperCamelCase			)
   # fmt: off
   self.assertListEqual(
       _UpperCamelCase					,['''▁I''', '''▁was''', '''▁bor''', '''n''', '''▁in''', '''▁''', '''<0x39>''', '''2''', '''0''', '''0''', '''0''', ''',''', '''▁and''', '''▁this''', '''▁is''', '''▁f''', '''al''', '''s''', '''<0xC3>''', '''<0xA9>''', '''.''']			)
   # fmt: on






  def 					SCREAMING_SNAKE_CASE      (      self   :     Any			):
   __lowercase							  = GPTSwaTokenizer(_UpperCamelCase			)
   __lowercase							  = ['''This is a test''', '''I was born in 92000, and this is falsé.''']
   __lowercase							  = [
       [4_6_5, 2_8_7, 2_6_5, 6_3_1, 8_4_2],
       [2_6_2, 2_7_2, 1_5_2_5, 2_8_6, 2_7_1, 2_6_8, 6_0, 9_1_6, 6_3_3, 6_3_3, 6_3_3, 2_5_9, 2_6_6, 3_0_1, 2_8_7, 3_8_4, 3_6_7, 2_6_3, 1_9_8, 1_7_2, 2_6_0],
   ]

   # Test that encode_fast returns the same as tokenize + convert_tokens_to_ids
   for text, expected_ids in zip(_UpperCamelCase					,_UpperCamelCase			):
    self.assertListEqual(tokenizer.encode_fast(_UpperCamelCase			)					,_UpperCamelCase			)

   # Test that decode_fast returns the input text
   for text, token_ids in zip(_UpperCamelCase					,_UpperCamelCase			):
    self.assertEqual(tokenizer.decode_fast(_UpperCamelCase			)					,_UpperCamelCase			)






  @slow
  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]			):
   __lowercase							  = [
       '''<|python|>def fibonacci(n)\n    if n < 0:\n        print(\'Incorrect input\')''',
       '''Hey there, how are you doing this fine day?''',
       '''This is a text with a trailing spaces followed by a dot     .''',
       '''Häj sväjs lillebrör! =)''',
       '''Det är inget fel på Mr. Cool''',
   ]

   # fmt: off
   __lowercase							  = {'''input_ids''': [[6_3_4_2_3, 5, 6_8_1_1, 1_4_9_5_4, 2_8_2, 8_1_6, 3_8_2_1, 6_3_4_6_6, 6_3_4_2_5, 6_3_4_6_2, 1_8, 6_3_9_7_8, 6_7_8, 3_0_1, 1_3_2_0, 6_3_4_2_3, 6_3_4_5_5, 6_3_4_5_8, 1_8, 6_3_9_8_2, 4_2_4_6, 3_9_4_0, 1_9_0_1, 4_7_7_8_9, 5_5_4_7, 1_8_9_9_4], [1_9_6_3_0, 1_1_0_0, 6_3_4_4_6, 1_3_4_2, 6_3_3, 5_4_4, 4_4_8_8, 5_9_3, 5_1_0_2, 2_4_1_6, 6_3_4_9_5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1_6_5_2, 4_2_8, 2_6_8, 1_9_3_6, 5_1_5, 2_6_8, 5_8_5_9_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, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}
   # fmt: on
   self.tokenizer_integration_test_util(
       expected_encoding=_UpperCamelCase					,model_name='''AI-Sweden/gpt-sw3-126m'''					,sequences=_UpperCamelCase					,)








import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


snake_case__					:							List[Any]													=     logging.get_logger(__name__)

snake_case__					:							Union[str, Any]													=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

snake_case__					:							int													=     {
    'vocab_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/vocab.txt',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/vocab.txt',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt'
        ),
        'bert-base-multilingual-cased': 'https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt',
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt'
        ),
        'bert-base-german-dbmdz-cased': 'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt',
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json'
        ),
        'bert-base-multilingual-cased': (
            'https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-cased': (
            'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json'
        ),
    },
}

snake_case__					:							int													=     {
    'bert-base-uncased': 512,
    'bert-large-uncased': 512,
    'bert-base-cased': 512,
    'bert-large-cased': 512,
    'bert-base-multilingual-uncased': 512,
    'bert-base-multilingual-cased': 512,
    'bert-base-chinese': 512,
    'bert-base-german-cased': 512,
    'bert-large-uncased-whole-word-masking': 512,
    'bert-large-cased-whole-word-masking': 512,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 512,
    'bert-large-cased-whole-word-masking-finetuned-squad': 512,
    'bert-base-cased-finetuned-mrpc': 512,
    'bert-base-german-dbmdz-cased': 512,
    'bert-base-german-dbmdz-uncased': 512,
    'TurkuNLP/bert-base-finnish-cased-v1': 512,
    'TurkuNLP/bert-base-finnish-uncased-v1': 512,
    'wietsedv/bert-base-dutch-cased': 512,
}

snake_case__					:							str													=     {
    'bert-base-uncased': {'do_lower_case': True},
    'bert-large-uncased': {'do_lower_case': True},
    'bert-base-cased': {'do_lower_case': False},
    'bert-large-cased': {'do_lower_case': False},
    'bert-base-multilingual-uncased': {'do_lower_case': True},
    'bert-base-multilingual-cased': {'do_lower_case': False},
    'bert-base-chinese': {'do_lower_case': False},
    'bert-base-german-cased': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking-finetuned-squad': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking-finetuned-squad': {'do_lower_case': False},
    'bert-base-cased-finetuned-mrpc': {'do_lower_case': False},
    'bert-base-german-dbmdz-cased': {'do_lower_case': False},
    'bert-base-german-dbmdz-uncased': {'do_lower_case': True},
    'TurkuNLP/bert-base-finnish-cased-v1': {'do_lower_case': False},
    'TurkuNLP/bert-base-finnish-uncased-v1': {'do_lower_case': True},
    'wietsedv/bert-base-dutch-cased': {'do_lower_case': False},
}





class A_					(			_lowerCamelCase   ):
   lowerCAmelCase__        = VOCAB_FILES_NAMES
   lowerCAmelCase__        = PRETRAINED_VOCAB_FILES_MAP
   lowerCAmelCase__        = PRETRAINED_INIT_CONFIGURATION
   lowerCAmelCase__        = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowerCAmelCase__        = BertTokenizer




   def __init__(self	:List[str]    ,   _UpperCamelCase	:List[str]=None    ,   _UpperCamelCase	:Optional[Any]=None    ,   _UpperCamelCase	:str=True    ,   _UpperCamelCase	:Optional[Any]="[UNK]"    ,   _UpperCamelCase	:Tuple="[SEP]"    ,   _UpperCamelCase	:List[Any]="[PAD]"    ,   _UpperCamelCase	:int="[CLS]"    ,   _UpperCamelCase	:Optional[int]="[MASK]"    ,   _UpperCamelCase	:Union[str, Any]=True    ,   _UpperCamelCase	:str=None    ,   **_UpperCamelCase	:List[str]    ,   )->					str:
         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    ,   )

         __A          =				json.loads(self.backend_tokenizer.normalizer.__getstate__() )
         if (
             normalizer_state.get('''lowercase'''    ,   _UpperCamelCase ) != do_lower_case
             or normalizer_state.get('''strip_accents'''    ,   _UpperCamelCase ) != strip_accents
             or normalizer_state.get('''handle_chinese_chars'''    ,   _UpperCamelCase ) != tokenize_chinese_chars
         ):
               __A          =				getattr(_UpperCamelCase    ,   normalizer_state.pop('''type''' ) )
               __A          =				do_lower_case
               __A          =				strip_accents
               __A          =				tokenize_chinese_chars
               __A          =				normalizer_class(**_UpperCamelCase )

         __A          =				do_lower_case




   def _lowerCAmelCase      (self	:Any    ,   _UpperCamelCase	:int    ,   _UpperCamelCase	:List[str]=None )->					List[Any]:
         __A          =				[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	:List[str]    ,   _UpperCamelCase	:List[int]    ,   _UpperCamelCase	:Optional[List[int]] = None )->					List[int]:
         __A          =				[self.sep_token_id]
         __A          =				[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	:Any    ,   _UpperCamelCase	:str    ,   _UpperCamelCase	:Optional[str] = None )->					Tuple[str]:
         __A          =				self._tokenizer.model.save(_UpperCamelCase    ,   name=_UpperCamelCase )
         return tuple(_UpperCamelCase )





