






"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
  import tensorflow as tf

  from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
  from transformers.models.albert.modeling_tf_albert import (
      TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFAlbertForMaskedLM,
      TFAlbertForMultipleChoice,
      TFAlbertForPreTraining,
      TFAlbertForQuestionAnswering,
      TFAlbertForSequenceClassification,
      TFAlbertForTokenClassification,
      TFAlbertModel,
  )







class 		_a       :





   '''simple docstring'''






   def __init__(   self			,				UpperCAmelCase_			,				UpperCAmelCase_=13			,				UpperCAmelCase_=7			,				UpperCAmelCase_=True			,				UpperCAmelCase_=True			,				UpperCAmelCase_=True			,				UpperCAmelCase_=True			,				UpperCAmelCase_=99			,				UpperCAmelCase_=16			,				UpperCAmelCase_=32			,				UpperCAmelCase_=2			,				UpperCAmelCase_=4			,				UpperCAmelCase_=37			,				UpperCAmelCase_="gelu"			,				UpperCAmelCase_=0.1			,				UpperCAmelCase_=0.1			,				UpperCAmelCase_=512			,				UpperCAmelCase_=16			,				UpperCAmelCase_=2			,				UpperCAmelCase_=0.02			,				UpperCAmelCase_=3			,				UpperCAmelCase_=4			,				UpperCAmelCase_=None			,				)	-> Optional[int]:




          '''simple docstring'''




          lowercase__:    List[str]        =      parent
          lowercase__:    int        =      13
          lowercase__:    Optional[Any]        =      7
          lowercase__:    Tuple        =      True
          lowercase__:    List[Any]        =      True
          lowercase__:    Dict        =      True
          lowercase__:    Tuple        =      True
          lowercase__:    Tuple        =      99
          lowercase__:    Any        =      16
          lowercase__:    str        =      32
          lowercase__:    Tuple        =      2
          lowercase__:    Tuple        =      4
          lowercase__:    Any        =      37
          lowercase__:    Optional[int]        =      "gelu"
          lowercase__:    Union[str, Any]        =      0.1
          lowercase__:    Tuple        =      0.1
          lowercase__:    Union[str, Any]        =      512
          lowercase__:    Optional[Any]        =      16
          lowercase__:    Dict        =      2
          lowercase__:    Tuple        =      0.02
          lowercase__:    Union[str, Any]        =      3
          lowercase__:    Optional[Any]        =      4
          lowercase__:    List[str]        =      None





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




          '''simple docstring'''




          lowercase__:    str        =      ids_tensor([self.batch_size, self.seq_length]			,				self.vocab_size)

          lowercase__:    Dict        =      None
          if self.use_input_mask:
                 lowercase__:    Tuple        =      random_attention_mask([self.batch_size, self.seq_length])

          lowercase__:    Tuple        =      None
          if self.use_token_type_ids:
                 lowercase__:    str        =      ids_tensor([self.batch_size, self.seq_length]			,				self.type_vocab_size)

          lowercase__:    Dict        =      None
          lowercase__:    int        =      None
          lowercase__:    Optional[int]        =      None
          if self.use_labels:
                 lowercase__:    Optional[int]        =      ids_tensor([self.batch_size]			,				self.type_sequence_label_size)
                 lowercase__:    Optional[int]        =      ids_tensor([self.batch_size, self.seq_length]			,				self.num_labels)
                 lowercase__:    Dict        =      ids_tensor([self.batch_size]			,				self.num_choices)

          lowercase__:    str        =      AlbertConfig(
              vocab_size=self.vocab_size			,				hidden_size=self.hidden_size			,				embedding_size=self.embedding_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			,				max_position_embeddings=self.max_position_embeddings			,				type_vocab_size=self.type_vocab_size			,				initializer_range=self.initializer_range			,				)

          return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> int:




          '''simple docstring'''




          lowercase__:    Tuple        =      TFAlbertModel(config=UpperCAmelCase_)
          # inputs = {'input_ids': input_ids,
          #           'attention_mask': input_mask,
          #           'token_type_ids': token_type_ids}
          # sequence_output, pooled_output = model(**inputs)
          lowercase__:    Optional[int]        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    List[str]        =      model(UpperCAmelCase_)

          lowercase__:    int        =      [input_ids, input_mask]
          lowercase__:    Tuple        =      model(UpperCAmelCase_)

          lowercase__:    Optional[int]        =      model(UpperCAmelCase_)

          self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size))
          self.parent.assertEqual(result.pooler_output.shape			,				(self.batch_size, self.hidden_size))





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> List[str]:




          '''simple docstring'''




          lowercase__:    Tuple        =      self.num_labels
          lowercase__:    str        =      TFAlbertForPreTraining(config=UpperCAmelCase_)
          lowercase__:    Tuple        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    str        =      model(UpperCAmelCase_)
          self.parent.assertEqual(result.prediction_logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size))
          self.parent.assertEqual(result.sop_logits.shape			,				(self.batch_size, self.num_labels))





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




          '''simple docstring'''




          lowercase__:    Optional[int]        =      TFAlbertForMaskedLM(config=UpperCAmelCase_)
          lowercase__:    Dict        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    Any        =      model(UpperCAmelCase_)
          self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size))





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    Dict        =      self.num_labels
          lowercase__:    str        =      TFAlbertForSequenceClassification(config=UpperCAmelCase_)
          lowercase__:    Union[str, Any]        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    Optional[Any]        =      model(UpperCAmelCase_)
          self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels))





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




          '''simple docstring'''




          lowercase__:    Dict        =      TFAlbertForQuestionAnswering(config=UpperCAmelCase_)
          lowercase__:    List[Any]        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    List[str]        =      model(UpperCAmelCase_)
          self.parent.assertEqual(result.start_logits.shape			,				(self.batch_size, self.seq_length))
          self.parent.assertEqual(result.end_logits.shape			,				(self.batch_size, self.seq_length))





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> Tuple:




          '''simple docstring'''




          lowercase__:    List[str]        =      self.num_choices
          lowercase__:    Optional[int]        =      TFAlbertForMultipleChoice(config=UpperCAmelCase_)
          lowercase__:    Tuple        =      tf.tile(tf.expand_dims(UpperCAmelCase_			,				1)			,				(1, self.num_choices, 1))
          lowercase__:    Optional[int]        =      tf.tile(tf.expand_dims(UpperCAmelCase_			,				1)			,				(1, self.num_choices, 1))
          lowercase__:    Optional[int]        =      tf.tile(tf.expand_dims(UpperCAmelCase_			,				1)			,				(1, self.num_choices, 1))
          lowercase__:    Optional[Any]        =      {
              "input_ids": multiple_choice_inputs_ids,
              "attention_mask": multiple_choice_input_mask,
              "token_type_ids": multiple_choice_token_type_ids,
          }
          lowercase__:    Dict        =      model(UpperCAmelCase_)
          self.parent.assertListEqual(list(result["logits"].shape)			,				[self.batch_size, self.num_choices])





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> str:




          '''simple docstring'''




          lowercase__:    Tuple        =      self.num_labels
          lowercase__:    int        =      TFAlbertForTokenClassification(config=UpperCAmelCase_)
          lowercase__:    Union[str, Any]        =      {
              "input_ids": input_ids,
              "attention_mask": input_mask,
              "token_type_ids": token_type_ids,
          }
          lowercase__:    List[str]        =      model(UpperCAmelCase_)
          self.parent.assertListEqual(list(result["logits"].shape)			,				[self.batch_size, self.seq_length, self.num_labels])





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




          '''simple docstring'''




          lowercase__:    str        =      self.prepare_config_and_inputs()
          (
              (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     (
              lowercase__
          )  ,     
          ):    Any        =      config_and_inputs
          lowercase__:    Optional[Any]        =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
          return config, inputs_dict







@require_tf
class 		_a       (						lowercase_    ,					lowercase_    ,					unittest.TestCase   ):





   '''simple docstring'''






   UpperCamelCase__      					=    (
       (
           TFAlbertModel,
           TFAlbertForPreTraining,
           TFAlbertForMaskedLM,
           TFAlbertForSequenceClassification,
           TFAlbertForQuestionAnswering,
           TFAlbertForTokenClassification,
           TFAlbertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   UpperCamelCase__      					=    (
       {
           """feature-extraction""": TFAlbertModel,
           """fill-mask""": TFAlbertForMaskedLM,
           """question-answering""": TFAlbertForQuestionAnswering,
           """text-classification""": TFAlbertForSequenceClassification,
           """token-classification""": TFAlbertForTokenClassification,
           """zero-shot""": TFAlbertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   UpperCamelCase__      					=    False
   UpperCamelCase__      					=    False





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_=False)	-> Optional[int]:




          '''simple docstring'''




          lowercase__:    List[Any]        =      super()._prepare_for_class(UpperCAmelCase_			,				UpperCAmelCase_			,				return_labels=UpperCAmelCase_)

          if return_labels:
                 if model_class in get_values(UpperCAmelCase_):
                        lowercase__:    Union[str, Any]        =      tf.zeros(self.model_tester.batch_size			,				dtype=tf.intaa)

          return inputs_dict





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




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      TFAlbertModelTester(self)
          lowercase__:    str        =      ConfigTester(self			,				config_class=UpperCAmelCase_			,				hidden_size=37)





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          self.config_tester.run_common_tests()





   def __lowercase    (   self)	-> Tuple:




          '''simple docstring'''




          lowercase__:    Dict        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_model(*UpperCAmelCase_)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    int        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_pretraining(*UpperCAmelCase_)





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




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_masked_lm(*UpperCAmelCase_)





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




          '''simple docstring'''




          lowercase__:    Optional[int]        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_multiple_choice(*UpperCAmelCase_)





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Dict        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_sequence_classification(*UpperCAmelCase_)





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




          '''simple docstring'''




          lowercase__:    List[Any]        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_question_answering(*UpperCAmelCase_)





   @slow
   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowercase__:    str        =      TFAlbertModel.from_pretrained(UpperCAmelCase_)
                 self.assertIsNotNone(UpperCAmelCase_)







@require_tf
class 		_a       (						unittest.TestCase   ):





   '''simple docstring'''






   @slow
   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      TFAlbertForPreTraining.from_pretrained("albert-base-v2")
          lowercase__:    Any        =      tf.constant([[0, 1, 2, 3, 4, 5]])
          lowercase__:    Union[str, Any]        =      model(UpperCAmelCase_)[0]

          lowercase__:    Optional[Any]        =      [1, 6, 30_000]
          self.assertEqual(output.shape			,				UpperCAmelCase_)

          lowercase__:    Union[str, Any]        =      tf.constant(
              [
                  [
                      [4.59_56_68, 0.74_46_27_54, -1.81_81_47],
                      [4.5_95_43_47, 0.7_45_41_84, -1.8_18_82_58],
                      [4.5_95_49_05, 0.7_44_82_35, -1.8_18_23_16],
                  ]
              ])
          tf.debugging.assert_near(output[:, :3, :3]			,				UpperCAmelCase_			,				atol=1E-4)














"""simple docstring"""





import os
import unittest

from transformers import ElectraTokenizerFast
from transformers.models.electra.tokenization_electra import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    ElectraTokenizer,
    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 		_a       (						lowercase_    ,					unittest.TestCase   ):





   '''simple docstring'''






   UpperCamelCase__      					=    ElectraTokenizer
   UpperCamelCase__      					=    ElectraTokenizerFast
   UpperCamelCase__      					=    True
   UpperCamelCase__      					=    True
   UpperCamelCase__      					=    filter_non_english





   def __lowercase    (   self)	-> str:




          '''simple docstring'''




          super().setUp()

          lowercase__:    List[str]        =      [
              "[UNK]",
              "[CLS]",
              "[SEP]",
              "[PAD]",
              "[MASK]",
              "want",
              "##want",
              "##ed",
              "wa",
              "un",
              "runn",
              "##ing",
              ",",
              "low",
              "lowest",
          ]
          lowercase__:    int        =      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 __lowercase    (   self			,				UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    str        =      "UNwant\u00E9d,running"
          lowercase__:    List[Any]        =      "unwanted, running"
          return input_text, output_text





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




          '''simple docstring'''




          lowercase__:    str        =      self.tokenizer_class(self.vocab_file)

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





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




          '''simple docstring'''




          if not self.test_rust_tokenizer:
                 return

          lowercase__:    Dict        =      self.get_tokenizer()
          lowercase__:    List[Any]        =      self.get_rust_tokenizer()

          lowercase__:    Optional[Any]        =      "UNwant\u00E9d,running"

          lowercase__:    Tuple        =      tokenizer.tokenize(UpperCAmelCase_)
          lowercase__:    Tuple        =      rust_tokenizer.tokenize(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[str]        =      tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    Optional[Any]        =      rust_tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[Any]        =      self.get_rust_tokenizer()
          lowercase__:    int        =      tokenizer.encode(UpperCAmelCase_)
          lowercase__:    str        =      rust_tokenizer.encode(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          # With lower casing
          lowercase__:    Optional[Any]        =      self.get_tokenizer(do_lower_case=UpperCAmelCase_)
          lowercase__:    List[Any]        =      self.get_rust_tokenizer(do_lower_case=UpperCAmelCase_)

          lowercase__:    str        =      "UNwant\u00E9d,running"

          lowercase__:    str        =      tokenizer.tokenize(UpperCAmelCase_)
          lowercase__:    Tuple        =      rust_tokenizer.tokenize(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[Any]        =      tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    List[str]        =      rust_tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    Any        =      self.get_rust_tokenizer()
          lowercase__:    Dict        =      tokenizer.encode(UpperCAmelCase_)
          lowercase__:    List[Any]        =      rust_tokenizer.encode(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      BasicTokenizer()

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





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




          '''simple docstring'''




          lowercase__:    str        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

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





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




          '''simple docstring'''




          lowercase__:    Any        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Tuple        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





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




          '''simple docstring'''




          lowercase__:    int        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

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





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




          '''simple docstring'''




          lowercase__:    Optional[int]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

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





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




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





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




          '''simple docstring'''




          lowercase__:    Any        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    List[Any]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				never_split=["[UNK]"])

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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    List[str]        =      ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

          lowercase__:    Dict        =      {}
          for i, token in enumerate(UpperCAmelCase_):
                 lowercase__:    Optional[int]        =      i
          lowercase__:    str        =      WordpieceTokenizer(vocab=UpperCAmelCase_			,				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 __lowercase    (   self)	-> 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 __lowercase    (   self)	-> List[Any]:




          '''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 __lowercase    (   self)	-> List[Any]:




          '''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 __lowercase    (   self)	-> Tuple:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      self.get_tokenizer()
          lowercase__:    str        =      self.get_rust_tokenizer()

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

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





   @slow
   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Dict        =      self.tokenizer_class.from_pretrained("google/electra-base-discriminator")

          lowercase__:    Optional[int]        =      tokenizer.encode("sequence builders"			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    List[str]        =      tokenizer.encode("multi-sequence build"			,				add_special_tokens=UpperCAmelCase_)

          lowercase__:    Dict        =      tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_)
          lowercase__:    Union[str, Any]        =      tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_			,				UpperCAmelCase_)

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





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




          '''simple docstring'''




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

                        lowercase__:    int        =      F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                        lowercase__:    Tuple        =      tokenizer_r.encode_plus(
                            UpperCAmelCase_			,				return_attention_mask=UpperCAmelCase_			,				return_token_type_ids=UpperCAmelCase_			,				return_offsets_mapping=UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_			,				)

                        lowercase__:    str        =      tokenizer_r.do_lower_case if hasattr(UpperCAmelCase_			,				"do_lower_case") else False
                        lowercase__:    List[Any]        =      (
                            [
                                ((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 __lowercase    (   self)	-> List[Any]:




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      ["的", "人", "有"]
          lowercase__:    Any        =      "".join(UpperCAmelCase_)
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
                        lowercase__:    Optional[Any]        =      True
                        lowercase__:    List[str]        =      self.tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)
                        lowercase__:    Dict        =      self.rust_tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)

                        lowercase__:    str        =      tokenizer_p.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
                        lowercase__:    Optional[int]        =      tokenizer_r.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)

                        lowercase__:    Union[str, Any]        =      tokenizer_r.convert_ids_to_tokens(UpperCAmelCase_)
                        lowercase__:    List[str]        =      tokenizer_p.convert_ids_to_tokens(UpperCAmelCase_)

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

                        lowercase__:    Dict        =      False
                        lowercase__:    Optional[int]        =      self.rust_tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)
                        lowercase__:    int        =      self.tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)

                        lowercase__:    str        =      tokenizer_r.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
                        lowercase__:    Tuple        =      tokenizer_p.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)

                        lowercase__:    Union[str, Any]        =      tokenizer_r.convert_ids_to_tokens(UpperCAmelCase_)
                        lowercase__:    List[str]        =      tokenizer_p.convert_ids_to_tokens(UpperCAmelCase_)

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






