





import inspect
import unittest
import warnings

from transformers import DeiTConfig
from transformers.models.auto import get_values
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import (
          MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
          MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
          MODEL_MAPPING,
          DeiTForImageClassification,
          DeiTForImageClassificationWithTeacher,
          DeiTForMaskedImageModeling,
          DeiTModel,
      )
      from transformers.models.deit.modeling_deit import DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import DeiTImageProcessor

class 		UpperCamelCase__			:



     '''simple docstring'''

     def __init__(							self						:   Any						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   List[Any]=13						,lowerCamelCase__						:   Optional[Any]=30						,lowerCamelCase__						:   Optional[int]=2						,lowerCamelCase__						:   List[str]=3						,lowerCamelCase__						:   Dict=True						,lowerCamelCase__						:   Union[str, Any]=True						,lowerCamelCase__						:   Dict=32						,lowerCamelCase__						:   Optional[int]=5						,lowerCamelCase__						:   List[str]=4						,lowerCamelCase__						:   Any=37						,lowerCamelCase__						:   int="gelu"						,lowerCamelCase__						:   List[Any]=0.1						,lowerCamelCase__						:   List[str]=0.1						,lowerCamelCase__						:   Dict=10						,lowerCamelCase__						:   Optional[Any]=0.02						,lowerCamelCase__						:   Union[str, Any]=3						,lowerCamelCase__						:   Optional[Any]=None						,lowerCamelCase__						:   Dict=2						,)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						parent
           SCREAMING_SNAKE_CASE		=						batch_size
           SCREAMING_SNAKE_CASE		=						image_size
           SCREAMING_SNAKE_CASE		=						patch_size
           SCREAMING_SNAKE_CASE		=						num_channels
           SCREAMING_SNAKE_CASE		=						is_training
           SCREAMING_SNAKE_CASE		=						use_labels
           SCREAMING_SNAKE_CASE		=						hidden_size
           SCREAMING_SNAKE_CASE		=						num_hidden_layers
           SCREAMING_SNAKE_CASE		=						num_attention_heads
           SCREAMING_SNAKE_CASE		=						intermediate_size
           SCREAMING_SNAKE_CASE		=						hidden_act
           SCREAMING_SNAKE_CASE		=						hidden_dropout_prob
           SCREAMING_SNAKE_CASE		=						attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE		=						type_sequence_label_size
           SCREAMING_SNAKE_CASE		=						initializer_range
           SCREAMING_SNAKE_CASE		=						scope
           SCREAMING_SNAKE_CASE		=						encoder_stride

           # in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
           SCREAMING_SNAKE_CASE		=						(image_size // patch_size) ** 2
           SCREAMING_SNAKE_CASE		=						num_patches + 2






     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]	)					->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

           SCREAMING_SNAKE_CASE		=						None
           if self.use_labels:
                 SCREAMING_SNAKE_CASE		=						ids_tensor([self.batch_size]						,self.type_sequence_label_size	)

           SCREAMING_SNAKE_CASE		=						self.get_config()

           return config, pixel_values, labels






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		int:




           '''simple docstring'''


           return DeiTConfig(
               image_size=self.image_size						,patch_size=self.patch_size						,num_channels=self.num_channels						,hidden_size=self.hidden_size						,num_hidden_layers=self.num_hidden_layers						,num_attention_heads=self.num_attention_heads						,intermediate_size=self.intermediate_size						,hidden_act=self.hidden_act						,hidden_dropout_prob=self.hidden_dropout_prob						,attention_probs_dropout_prob=self.attention_probs_dropout_prob						,is_decoder=lowerCamelCase__						,initializer_range=self.initializer_range						,encoder_stride=self.encoder_stride						,)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   Dict	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DeiTModel(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)
           self.parent.assertEqual(result.last_hidden_state.shape						,(self.batch_size, self.seq_length, self.hidden_size)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   str						,lowerCamelCase__						:   int						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   Dict	)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DeiTForMaskedImageModeling(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)
           self.parent.assertEqual(
               result.reconstruction.shape						,(self.batch_size, self.num_channels, self.image_size, self.image_size)	)

           # test greyscale images
           SCREAMING_SNAKE_CASE		=						1
           SCREAMING_SNAKE_CASE		=						DeiTForMaskedImageModeling(lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()

           SCREAMING_SNAKE_CASE		=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]	)
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)
           self.parent.assertEqual(result.reconstruction.shape						,(self.batch_size, 1, self.image_size, self.image_size)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]						,lowerCamelCase__						:   int						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   List[str]	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.type_sequence_label_size
           SCREAMING_SNAKE_CASE		=						DeiTForImageClassification(lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,labels=lowerCamelCase__	)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.type_sequence_label_size)	)

           # test greyscale images
           SCREAMING_SNAKE_CASE		=						1
           SCREAMING_SNAKE_CASE		=						DeiTForImageClassification(lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()

           SCREAMING_SNAKE_CASE		=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]	)
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,labels=lowerCamelCase__	)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.type_sequence_label_size)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.prepare_config_and_inputs()
           (
               (
               SCREAMING_SNAKE_CASE
           ), (
               SCREAMING_SNAKE_CASE
           ), (
               SCREAMING_SNAKE_CASE
           ), 
           )		=						config_and_inputs
           SCREAMING_SNAKE_CASE		=						{"""pixel_values""": pixel_values}
           return config, inputs_dict

@require_torch
class 		UpperCamelCase__			(				lowerCAmelCase_							,				lowerCAmelCase_							,				unittest.TestCase       ):



     '''simple docstring'''

     __snake_case   :     int		     =      (
         (
             DeiTModel,
             DeiTForImageClassification,
             DeiTForImageClassificationWithTeacher,
             DeiTForMaskedImageModeling,
         )
         if is_torch_available()
         else ()
     )
     __snake_case   :     Union[str, Any]		     =      (
         {
             "feature-extraction": DeiTModel,
             "image-classification": (DeiTForImageClassification, DeiTForImageClassificationWithTeacher),
         }
         if is_torch_available()
         else {}
     )

     __snake_case   :     str		     =      False
     __snake_case   :     str		     =      False
     __snake_case   :     Optional[int]		     =      False






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DeiTModelTester(self	)
           SCREAMING_SNAKE_CASE		=						ConfigTester(self						,config_class=lowerCamelCase__						,has_text_modality=lowerCamelCase__						,hidden_size=37	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		int:




           '''simple docstring'''


           self.config_tester.run_common_tests()






     @unittest.skip(reason="""DeiT does not use inputs_embeds"""	)
     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		List[str]:




           '''simple docstring'''


           pass






     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE, SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 SCREAMING_SNAKE_CASE		=						model_class(lowerCamelCase__	)
                 self.assertIsInstance(model.get_input_embeddings()						,(nn.Module)	)
                 SCREAMING_SNAKE_CASE		=						model.get_output_embeddings()
                 self.assertTrue(x is None or isinstance(lowerCamelCase__						,nn.Linear	)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Tuple	)					->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE, SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 SCREAMING_SNAKE_CASE		=						model_class(lowerCamelCase__	)
                 SCREAMING_SNAKE_CASE		=						inspect.signature(model.forward	)
                 # signature.parameters is an OrderedDict => so arg_names order is deterministic
                 SCREAMING_SNAKE_CASE		=						[*signature.parameters.keys()]

                 SCREAMING_SNAKE_CASE		=						["""pixel_values"""]
                 self.assertListEqual(arg_names[:1]						,lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int	)					->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_image_modeling(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   int						,lowerCamelCase__						:   Any=False	)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						super()._prepare_for_class(lowerCamelCase__						,lowerCamelCase__						,return_labels=lowerCamelCase__	)

           if return_labels:
                 if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
                       del inputs_dict["labels"]

           return inputs_dict






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Optional[Any]:




           '''simple docstring'''


           if not self.model_tester.is_training:
                 return

           SCREAMING_SNAKE_CASE, SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs_for_common()
           SCREAMING_SNAKE_CASE		=						True

           for model_class in self.all_model_classes:
                 # DeiTForImageClassificationWithTeacher supports inference-only
                 if (
                     model_class in get_values(lowerCamelCase__	)
                     or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
                 ):
                       continue
                 SCREAMING_SNAKE_CASE		=						model_class(lowerCamelCase__	)
                 model.to(lowerCamelCase__	)
                 model.train()
                 SCREAMING_SNAKE_CASE		=						self._prepare_for_class(lowerCamelCase__						,lowerCamelCase__						,return_labels=lowerCamelCase__	)
                 SCREAMING_SNAKE_CASE		=						model(**lowerCamelCase__	).loss
                 loss.backward()






     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]	)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE, SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs_for_common()
           if not self.model_tester.is_training:
                 return

           SCREAMING_SNAKE_CASE		=						False
           SCREAMING_SNAKE_CASE		=						True

           for model_class in self.all_model_classes:
                 if model_class in get_values(lowerCamelCase__	) or not model_class.supports_gradient_checkpointing:
                       continue
                 # DeiTForImageClassificationWithTeacher supports inference-only
                 if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
                       continue
                 SCREAMING_SNAKE_CASE		=						model_class(lowerCamelCase__	)
                 model.gradient_checkpointing_enable()
                 model.to(lowerCamelCase__	)
                 model.train()
                 SCREAMING_SNAKE_CASE		=						self._prepare_for_class(lowerCamelCase__						,lowerCamelCase__						,return_labels=lowerCamelCase__	)
                 SCREAMING_SNAKE_CASE		=						model(**lowerCamelCase__	).loss
                 loss.backward()






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE, SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs_for_common()

           SCREAMING_SNAKE_CASE		=						[
               {"""title""": """multi_label_classification""", """num_labels""": 2, """dtype""": torch.float},
               {"""title""": """single_label_classification""", """num_labels""": 1, """dtype""": torch.long},
               {"""title""": """regression""", """num_labels""": 1, """dtype""": torch.float},
           ]

           for model_class in self.all_model_classes:
                 if (
                     model_class
                     not in [
                         *get_values(lowerCamelCase__	),
                         *get_values(lowerCamelCase__	),
                     ]
                     or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
                 ):
                       continue

                 for problem_type in problem_types:
                       with self.subTest(msg=F"""Testing {model_class} with {problem_type['title']}"""	):
                             SCREAMING_SNAKE_CASE		=						problem_type["""title"""]
                             SCREAMING_SNAKE_CASE		=						problem_type["""num_labels"""]

                             SCREAMING_SNAKE_CASE		=						model_class(lowerCamelCase__	)
                             model.to(lowerCamelCase__	)
                             model.train()

                             SCREAMING_SNAKE_CASE		=						self._prepare_for_class(lowerCamelCase__						,lowerCamelCase__						,return_labels=lowerCamelCase__	)

                             if problem_type["num_labels"] > 1:
                                   SCREAMING_SNAKE_CASE		=						inputs["""labels"""].unsqueeze(1	).repeat(1						,problem_type["""num_labels"""]	)

                             SCREAMING_SNAKE_CASE		=						inputs["""labels"""].to(problem_type["""dtype"""]	)

                             # This tests that we do not trigger the warning form PyTorch "Using a target size that is different
                             # to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
                             # they have the same size." which is a symptom something in wrong for the regression problem.
                             # See https://github.com/huggingface/transformers/issues/11780
                             with warnings.catch_warnings(record=lowerCamelCase__	) as warning_list:
                                   SCREAMING_SNAKE_CASE		=						model(**lowerCamelCase__	).loss
                             for w in warning_list:
                                   if "Using a target size that is different to the input size" in str(w.message	):
                                         raise ValueError(
                                             F"""Something is going wrong in the regression problem: intercepted {w.message}"""	)

                             loss.backward()






     @slow
     def     SCREAMING_SNAKE_CASE__  (							self						:   List[Any]	)					->		Tuple:




           '''simple docstring'''


           for model_name in DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 SCREAMING_SNAKE_CASE		=						DeiTModel.from_pretrained(lowerCamelCase__	)
                 self.assertIsNotNone(lowerCamelCase__	)



def        __lowercase       (				)			->       Optional[int]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
      return image



@require_torch
@require_vision
class 		UpperCamelCase__			(				unittest.TestCase       ):



     '''simple docstring'''

     @cached_property
     def     SCREAMING_SNAKE_CASE__  (							self						:   Tuple	)					->		int:




           '''simple docstring'''


           return (
               DeiTImageProcessor.from_pretrained("""facebook/deit-base-distilled-patch16-224"""	)
               if is_vision_available()
               else None
           )






     @slow
     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DeiTForImageClassificationWithTeacher.from_pretrained("""facebook/deit-base-distilled-patch16-224"""	).to(
               lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						self.default_image_processor
           SCREAMING_SNAKE_CASE		=						prepare_img()
           SCREAMING_SNAKE_CASE		=						image_processor(images=lowerCamelCase__						,return_tensors="""pt"""	).to(lowerCamelCase__	)

           # forward pass
           with torch.no_grad():
                 SCREAMING_SNAKE_CASE		=						model(**lowerCamelCase__	)

           # verify the logits
           SCREAMING_SNAKE_CASE		=						torch.Size((1, 1000)	)
           self.assertEqual(outputs.logits.shape						,lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						torch.tensor([-1.0266, 0.1912, -1.2861]	).to(lowerCamelCase__	)

           self.assertTrue(torch.allclose(outputs.logits[0, :3]						,lowerCamelCase__						,atol=1e-4	)	)






     @slow
     @require_accelerate
     @require_torch_gpu
     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DeiTModel.from_pretrained(
               """facebook/deit-base-distilled-patch16-224"""						,torch_dtype=torch.floataa						,device_map="""auto"""	)
           SCREAMING_SNAKE_CASE		=						self.default_image_processor

           SCREAMING_SNAKE_CASE		=						prepare_img()
           SCREAMING_SNAKE_CASE		=						image_processor(images=lowerCamelCase__						,return_tensors="""pt"""	)
           SCREAMING_SNAKE_CASE		=						inputs.pixel_values.to(lowerCamelCase__	)

           # forward pass to make sure inference works in fp16
           with torch.no_grad():
                 SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)









import os
import unittest

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    BertTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english

@require_tokenizers
class 		UpperCamelCase__			(				lowerCAmelCase_							,				unittest.TestCase       ):



     '''simple docstring'''

     __snake_case   :     Any		     =      BertTokenizer
     __snake_case   :     Dict		     =      BertTokenizerFast
     __snake_case   :     Tuple		     =      True
     __snake_case   :     List[Any]		     =      True
     __snake_case   :     Optional[Any]		     =      filter_non_english






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Any:




           '''simple docstring'''


           super().setUp()

           SCREAMING_SNAKE_CASE		=						[
               """[UNK]""",
               """[CLS]""",
               """[SEP]""",
               """[PAD]""",
               """[MASK]""",
               """want""",
               """##want""",
               """##ed""",
               """wa""",
               """un""",
               """runn""",
               """##ing""",
               """,""",
               """low""",
               """lowest""",
           ]
           SCREAMING_SNAKE_CASE		=						os.path.join(self.tmpdirname						,VOCAB_FILES_NAMES["""vocab_file"""]	)
           with open(self.vocab_file						,"""w"""						,encoding="""utf-8"""	) as vocab_writer:
                 vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]	)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   str						,lowerCamelCase__						:   List[Any]	)					->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						"""UNwant\u00E9d,running"""
           SCREAMING_SNAKE_CASE		=						"""unwanted, running"""
           return input_text, output_text






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.tokenizer_class(self.vocab_file	)

           SCREAMING_SNAKE_CASE		=						tokenizer.tokenize("""UNwant\u00E9d,running"""	)
           self.assertListEqual(lowerCamelCase__						,["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]	)
           self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__	)						,[9, 6, 7, 12, 10, 11]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		List[Any]:




           '''simple docstring'''


           if not self.test_rust_tokenizer:
                 return

           SCREAMING_SNAKE_CASE		=						self.get_tokenizer()
           SCREAMING_SNAKE_CASE		=						self.get_rust_tokenizer()

           SCREAMING_SNAKE_CASE		=						"""UNwant\u00E9d,running"""

           SCREAMING_SNAKE_CASE		=						tokenizer.tokenize(lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.tokenize(lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						tokenizer.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						self.get_rust_tokenizer()
           SCREAMING_SNAKE_CASE		=						tokenizer.encode(lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.encode(lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

           # With lower casing
           SCREAMING_SNAKE_CASE		=						self.get_tokenizer(do_lower_case=lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						self.get_rust_tokenizer(do_lower_case=lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						"""UNwant\u00E9d,running"""

           SCREAMING_SNAKE_CASE		=						tokenizer.tokenize(lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.tokenize(lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						tokenizer.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						self.get_rust_tokenizer()
           SCREAMING_SNAKE_CASE		=						tokenizer.encode(lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						rust_tokenizer.encode(lowerCamelCase__	)
           self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer()

           self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""	)						,["""ah""", """\u535A""", """\u63A8""", """zz"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """	)						,["""hello""", """!""", """how""", """are""", """you""", """?"""]	)
           self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""	)						,["""hello"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__						,strip_accents=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """	)						,["""hällo""", """!""", """how""", """are""", """you""", """?"""]	)
           self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""	)						,["""h\u00E9llo"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__						,strip_accents=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """	)						,["""hallo""", """!""", """how""", """are""", """you""", """?"""]	)
           self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""	)						,["""hello"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """	)						,["""hallo""", """!""", """how""", """are""", """you""", """?"""]	)
           self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""	)						,["""hello"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """	)						,["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__						,strip_accents=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """	)						,["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__						,strip_accents=lowerCamelCase__	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """	)						,["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer(do_lower_case=lowerCamelCase__						,never_split=["""[UNK]"""]	)

           self.assertListEqual(
               tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""	)						,["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						BasicTokenizer()
           SCREAMING_SNAKE_CASE		=						"""a\n'll !!to?'d of, can't."""
           SCREAMING_SNAKE_CASE		=						["""a""", """'""", """ll""", """!""", """!""", """to""", """?""", """'""", """d""", """of""", """,""", """can""", """'""", """t""", """."""]
           self.assertListEqual(tokenizer.tokenize(lowerCamelCase__	)						,lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

           SCREAMING_SNAKE_CASE		=						{}
           for i, token in enumerate(lowerCamelCase__	):
                 SCREAMING_SNAKE_CASE		=						i
           SCREAMING_SNAKE_CASE		=						WordpieceTokenizer(vocab=lowerCamelCase__						,unk_token="""[UNK]"""	)

           self.assertListEqual(tokenizer.tokenize(""""""	)						,[]	)

           self.assertListEqual(tokenizer.tokenize("""unwanted running"""	)						,["""un""", """##want""", """##ed""", """runn""", """##ing"""]	)

           self.assertListEqual(tokenizer.tokenize("""unwantedX running"""	)						,["""[UNK]""", """runn""", """##ing"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Dict:




           '''simple docstring'''


           self.assertTrue(_is_whitespace(""" """	)	)
           self.assertTrue(_is_whitespace("""\t"""	)	)
           self.assertTrue(_is_whitespace("""\r"""	)	)
           self.assertTrue(_is_whitespace("""\n"""	)	)
           self.assertTrue(_is_whitespace("""\u00A0"""	)	)

           self.assertFalse(_is_whitespace("""A"""	)	)
           self.assertFalse(_is_whitespace("""-"""	)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Optional[int]:




           '''simple docstring'''


           self.assertTrue(_is_control("""\u0005"""	)	)

           self.assertFalse(_is_control("""A"""	)	)
           self.assertFalse(_is_control(""" """	)	)
           self.assertFalse(_is_control("""\t"""	)	)
           self.assertFalse(_is_control("""\r"""	)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Tuple	)					->		List[str]:




           '''simple docstring'''


           self.assertTrue(_is_punctuation("""-"""	)	)
           self.assertTrue(_is_punctuation("""$"""	)	)
           self.assertTrue(_is_punctuation("""`"""	)	)
           self.assertTrue(_is_punctuation("""."""	)	)

           self.assertFalse(_is_punctuation("""A"""	)	)
           self.assertFalse(_is_punctuation(""" """	)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.get_tokenizer()
           SCREAMING_SNAKE_CASE		=						self.get_rust_tokenizer()

           # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
           self.assertListEqual([tokenizer.tokenize(lowerCamelCase__	) for t in ["""Test""", """\xad""", """test"""]]						,[["""[UNK]"""], [], ["""[UNK]"""]]	)

           self.assertListEqual(
               [rust_tokenizer.tokenize(lowerCamelCase__	) for t in ["""Test""", """\xad""", """test"""]]						,[["""[UNK]"""], [], ["""[UNK]"""]]	)






     @slow
     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.tokenizer_class.from_pretrained("""bert-base-uncased"""	)

           SCREAMING_SNAKE_CASE		=						tokenizer.encode("""sequence builders"""						,add_special_tokens=lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						tokenizer.encode("""multi-sequence build"""						,add_special_tokens=lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						tokenizer.build_inputs_with_special_tokens(lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						tokenizer.build_inputs_with_special_tokens(lowerCamelCase__						,lowerCamelCase__	)

           assert encoded_sentence == [101] + text + [102]
           assert encoded_pair == [101] + text + [102] + text_a + [102]






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		str:




           '''simple docstring'''


           for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""	):
                       SCREAMING_SNAKE_CASE		=						self.rust_tokenizer_class.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                       SCREAMING_SNAKE_CASE		=						tokenizer_r.encode_plus(
                           lowerCamelCase__						,return_attention_mask=lowerCamelCase__						,return_token_type_ids=lowerCamelCase__						,return_offsets_mapping=lowerCamelCase__						,add_special_tokens=lowerCamelCase__						,)

                       SCREAMING_SNAKE_CASE		=						tokenizer_r.do_lower_case if hasattr(lowerCamelCase__						,"""do_lower_case"""	) else False
                       SCREAMING_SNAKE_CASE		=						(
                           [
                               ((0, 0), tokenizer_r.cls_token),
                               ((0, 1), """A"""),
                               ((1, 2), ""","""),
                               ((3, 5), """na"""),
                               ((5, 6), """##ï"""),
                               ((6, 8), """##ve"""),
                               ((9, 15), tokenizer_r.mask_token),
                               ((16, 21), """Allen"""),
                               ((21, 23), """##NL"""),
                               ((23, 24), """##P"""),
                               ((25, 33), """sentence"""),
                               ((33, 34), """."""),
                               ((0, 0), tokenizer_r.sep_token),
                           ]
                           if not do_lower_case
                           else [
                               ((0, 0), tokenizer_r.cls_token),
                               ((0, 1), """a"""),
                               ((1, 2), ""","""),
                               ((3, 8), """naive"""),
                               ((9, 15), tokenizer_r.mask_token),
                               ((16, 21), """allen"""),
                               ((21, 23), """##nl"""),
                               ((23, 24), """##p"""),
                               ((25, 33), """sentence"""),
                               ((33, 34), """."""),
                               ((0, 0), tokenizer_r.sep_token),
                           ]
                       )

                       self.assertEqual(
                           [e[1] for e in expected_results]						,tokenizer_r.convert_ids_to_tokens(tokens["""input_ids"""]	)	)
                       self.assertEqual([e[0] for e in expected_results]						,tokens["""offset_mapping"""]	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						["""的""", """人""", """有"""]
           SCREAMING_SNAKE_CASE		=						"""""".join(lowerCamelCase__	)
           for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""	):
                       SCREAMING_SNAKE_CASE		=						True
                       SCREAMING_SNAKE_CASE		=						self.tokenizer_class.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						self.rust_tokenizer_class.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						tokenizer_p.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						tokenizer_r.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						tokenizer_r.convert_ids_to_tokens(lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						tokenizer_p.convert_ids_to_tokens(lowerCamelCase__	)

                       # it is expected that each Chinese character is not preceded by "##"
                       self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)
                       self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						False
                       SCREAMING_SNAKE_CASE		=						self.rust_tokenizer_class.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						self.tokenizer_class.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						tokenizer_r.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						tokenizer_p.encode(lowerCamelCase__						,add_special_tokens=lowerCamelCase__	)

                       SCREAMING_SNAKE_CASE		=						tokenizer_r.convert_ids_to_tokens(lowerCamelCase__	)
                       SCREAMING_SNAKE_CASE		=						tokenizer_p.convert_ids_to_tokens(lowerCamelCase__	)

                       # it is expected that only the first Chinese character is not preceded by "##".
                       SCREAMING_SNAKE_CASE		=						[
                           F"""##{token}""" if idx != 0 else token for idx, token in enumerate(lowerCamelCase__	)
                       ]
                       self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)
                       self.assertListEqual(lowerCamelCase__						,lowerCamelCase__	)


