from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
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 (
           TFRoFormerForCausalLM,
           TFRoFormerForMaskedLM,
           TFRoFormerForMultipleChoice,
           TFRoFormerForQuestionAnswering,
           TFRoFormerForSequenceClassification,
           TFRoFormerForTokenClassification,
           TFRoFormerModel,
       )
       from transformers.models.roformer.modeling_tf_roformer import (
           TFRoFormerSelfAttention,
           TFRoFormerSinusoidalPositionalEmbedding,
       )


class 			UpperCAmelCase__    :



  """simple docstring"""






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




    '''simple docstring'''




    __UpperCAmelCase						    =       parent
    __UpperCAmelCase						    =       13
    __UpperCAmelCase						    =       7
    __UpperCAmelCase						    =       True
    __UpperCAmelCase						    =       True
    __UpperCAmelCase						    =       True
    __UpperCAmelCase						    =       True
    __UpperCAmelCase						    =       99
    __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






  def 	_UpperCAmelCase				(				self:			Optional[Any]   ) -> str:




    '''simple docstring'''




    __UpperCAmelCase						    =       ids_tensor([self.batch_size, self.seq_length]				,				self.vocab_size   )

    __UpperCAmelCase						    =       None
    if self.use_input_mask:
      __UpperCAmelCase						    =       random_attention_mask([self.batch_size, self.seq_length]   )

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

    __UpperCAmelCase						    =       None
    __UpperCAmelCase						    =       None
    __UpperCAmelCase						    =       None
    if self.use_labels:
      __UpperCAmelCase						    =       ids_tensor([self.batch_size]				,				self.type_sequence_label_size   )
      __UpperCAmelCase						    =       ids_tensor([self.batch_size, self.seq_length]				,				self.num_labels   )
      __UpperCAmelCase						    =       ids_tensor([self.batch_size]				,				self.num_choices   )

    __UpperCAmelCase						    =       RoFormerConfig(
        vocab_size=self.vocab_size				,				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				,				max_position_embeddings=self.max_position_embeddings				,				type_vocab_size=self.type_vocab_size				,				initializer_range=self.initializer_range				,				return_dict=__UpperCamelCase				,				)

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






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




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerModel(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

    __UpperCAmelCase						    =       [input_ids, input_mask]
    __UpperCAmelCase						    =       model(__UpperCamelCase   )

    __UpperCAmelCase						    =       model(__UpperCamelCase   )

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






  def 	_UpperCAmelCase				(				self:			Tuple				,				__lowerCAmelCase:			List[Any]				,				__lowerCAmelCase:			int				,				__lowerCAmelCase:			Union[str, Any]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Optional[int]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Tuple   ) -> List[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       True
    __UpperCAmelCase						    =       TFRoFormerForCausalLM(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {
        "input_ids": input_ids,
        "attention_mask": input_mask,
        "token_type_ids": token_type_ids,
    }
    __UpperCAmelCase						    =       model(__UpperCamelCase   )["logits"]
    self.parent.assertListEqual(
        list(prediction_scores.numpy().shape   )				,				[self.batch_size, self.seq_length, self.vocab_size]   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerForMaskedLM(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {
        "input_ids": input_ids,
        "attention_mask": input_mask,
        "token_type_ids": token_type_ids,
    }
    __UpperCAmelCase						    =       model(__UpperCamelCase   )
    self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size)   )






  def 	_UpperCAmelCase				(				self:			List[Any]				,				__lowerCAmelCase:			Optional[Any]				,				__lowerCAmelCase:			Dict				,				__lowerCAmelCase:			str				,				__lowerCAmelCase:			str				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Tuple				,				__lowerCAmelCase:			Optional[int]   ) -> List[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       self.num_labels
    __UpperCAmelCase						    =       TFRoFormerForSequenceClassification(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {
        "input_ids": input_ids,
        "attention_mask": input_mask,
        "token_type_ids": token_type_ids,
    }

    __UpperCAmelCase						    =       model(__UpperCamelCase   )
    self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_labels)   )






  def 	_UpperCAmelCase				(				self:			int				,				__lowerCAmelCase:			List[Any]				,				__lowerCAmelCase:			int				,				__lowerCAmelCase:			Union[str, Any]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			List[str]				,				__lowerCAmelCase:			Tuple				,				__lowerCAmelCase:			Union[str, Any]   ) -> int:




    '''simple docstring'''




    __UpperCAmelCase						    =       self.num_choices
    __UpperCAmelCase						    =       TFRoFormerForMultipleChoice(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       tf.tile(tf.expand_dims(__UpperCamelCase				,				1   )				,				(1, self.num_choices, 1)   )
    __UpperCAmelCase						    =       tf.tile(tf.expand_dims(__UpperCamelCase				,				1   )				,				(1, self.num_choices, 1)   )
    __UpperCAmelCase						    =       tf.tile(tf.expand_dims(__UpperCamelCase				,				1   )				,				(1, self.num_choices, 1)   )
    __UpperCAmelCase						    =       {
        "input_ids": multiple_choice_inputs_ids,
        "attention_mask": multiple_choice_input_mask,
        "token_type_ids": multiple_choice_token_type_ids,
    }
    __UpperCAmelCase						    =       model(__UpperCamelCase   )
    self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_choices)   )






  def 	_UpperCAmelCase				(				self:			str				,				__lowerCAmelCase:			Optional[int]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Dict				,				__lowerCAmelCase:			List[Any]				,				__lowerCAmelCase:			Optional[int]				,				__lowerCAmelCase:			str				,				__lowerCAmelCase:			Tuple   ) -> str:




    '''simple docstring'''




    __UpperCAmelCase						    =       self.num_labels
    __UpperCAmelCase						    =       TFRoFormerForTokenClassification(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {
        "input_ids": input_ids,
        "attention_mask": input_mask,
        "token_type_ids": token_type_ids,
    }
    __UpperCAmelCase						    =       model(__UpperCamelCase   )
    self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.num_labels)   )






  def 	_UpperCAmelCase				(				self:			Dict				,				__lowerCAmelCase:			Optional[Any]				,				__lowerCAmelCase:			Optional[int]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Optional[Any]				,				__lowerCAmelCase:			int				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Optional[int]   ) -> Optional[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerForQuestionAnswering(config=__UpperCamelCase   )
    __UpperCAmelCase						    =       {
        "input_ids": input_ids,
        "attention_mask": input_mask,
        "token_type_ids": token_type_ids,
    }

    __UpperCAmelCase						    =       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 	_UpperCAmelCase				(				self:			int   ) -> Optional[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       self.prepare_config_and_inputs()
    (
        (
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		(
        __UpperCAmelCase
    )    ,		
    )						    =       config_and_inputs
    __UpperCAmelCase						    =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
    return config, inputs_dict






@require_tf
class 			UpperCAmelCase__    (		_UpperCAmelCase		,	_UpperCAmelCase		,	unittest.TestCase					):



  """simple docstring"""






  lowerCAmelCase__		:	Any    		= (
      (
          TFRoFormerModel,
          TFRoFormerForCausalLM,
          TFRoFormerForMaskedLM,
          TFRoFormerForQuestionAnswering,
          TFRoFormerForSequenceClassification,
          TFRoFormerForTokenClassification,
          TFRoFormerForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  lowerCAmelCase__		:	int    		= (
      {
          'feature-extraction': TFRoFormerModel,
          'fill-mask': TFRoFormerForMaskedLM,
          'question-answering': TFRoFormerForQuestionAnswering,
          'text-classification': TFRoFormerForSequenceClassification,
          'text-generation': TFRoFormerForCausalLM,
          'token-classification': TFRoFormerForTokenClassification,
          'zero-shot': TFRoFormerForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )

  lowerCAmelCase__		:	Tuple    		= False
  lowerCAmelCase__		:	Optional[Any]    		= False






  def 	_UpperCAmelCase				(				self:			List[str]				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Optional[int]				,				__lowerCAmelCase:			int				,				__lowerCAmelCase:			Any				,				__lowerCAmelCase:			Union[str, Any]   ) -> List[str]:




    '''simple docstring'''




    if pipeline_test_casse_name == "TextGenerationPipelineTests":
      return True

    return False






  def 	_UpperCAmelCase				(				self:			int   ) -> Dict:




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerModelTester(self   )
    __UpperCAmelCase						    =       ConfigTester(self				,				config_class=__UpperCamelCase				,				hidden_size=37   )






  def 	_UpperCAmelCase				(				self:			str   ) -> Dict:




    '''simple docstring'''




    self.config_tester.run_common_tests()






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__UpperCamelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_lm_head(*__UpperCamelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase   )






  def 	_UpperCAmelCase				(				self:			str   ) -> Optional[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase   )






  @slow
  def 	_UpperCAmelCase				(				self:			Dict   ) -> Optional[int]:




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerModel.from_pretrained("junnyu/roformer_chinese_base"   )
    self.assertIsNotNone(__UpperCamelCase   )






@require_tf
class 			UpperCAmelCase__    (		unittest.TestCase					):



  """simple docstring"""






  @slow
  def 	_UpperCAmelCase				(				self:			Dict   ) -> List[str]:




    '''simple docstring'''




    __UpperCAmelCase						    =       TFRoFormerForMaskedLM.from_pretrained("junnyu/roformer_chinese_base"   )
    __UpperCAmelCase						    =       tf.constant([[0, 1, 2, 3, 4, 5]]   )
    __UpperCAmelCase						    =       model(__UpperCamelCase   )[0]

    # TODO Replace vocab size
    __UpperCAmelCase						    =       50_000

    __UpperCAmelCase						    =       [1, 6, vocab_size]
    self.assertEqual(output.shape				,				__UpperCamelCase   )

    print(output[:, :3, :3]   )

    # TODO Replace values below with what was printed above.
    __UpperCAmelCase						    =       tf.constant(
        [
            [
                [-0.12053341, -1.0264901, 0.29221946],
                [-1.5133783, 0.197433, 0.15190607],
                [-5.0135403, -3.900256, -0.84038764],
            ]
        ]   )
    tf.debugging.assert_near(output[:, :3, :3]				,				__UpperCamelCase				,				atol=1E-4   )






@require_tf
class 			UpperCAmelCase__    (		unittest.TestCase					):



  """simple docstring"""






  lowerCAmelCase__		:	Union[str, Any]    		= 1E-4






  def 	_UpperCAmelCase				(				self:			Tuple   ) -> List[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       tf.constant([[4, 10]]   )
    __UpperCAmelCase						    =       TFRoFormerSinusoidalPositionalEmbedding(num_positions=6				,				embedding_dim=6   )

    __UpperCAmelCase						    =       emba(input_ids.shape   )
    __UpperCAmelCase						    =       tf.constant(
        [[0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000], [0.8415, 0.0464, 0.0022, 0.5403, 0.9989, 1.0000]]   )

    tf.debugging.assert_near(__UpperCamelCase				,				__UpperCamelCase				,				atol=self.tolerance   )






  def 	_UpperCAmelCase				(				self:			Tuple   ) -> int:




    '''simple docstring'''




    __UpperCAmelCase						    =       tf.constant(
        [
            [0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
            [0.8415, 0.8219, 0.8020, 0.7819, 0.7617],
            [0.9093, 0.9364, 0.9581, 0.9749, 0.9870],
        ]   )
    __UpperCAmelCase						    =       TFRoFormerSinusoidalPositionalEmbedding(num_positions=512				,				embedding_dim=512   )
    emba([2, 16, 512]   )
    __UpperCAmelCase						    =       emba.weight[:3, :5]

    tf.debugging.assert_near(__UpperCamelCase				,				__UpperCamelCase				,				atol=self.tolerance   )






@require_tf
class 			UpperCAmelCase__    (		unittest.TestCase					):



  """simple docstring"""






  lowerCAmelCase__		:	List[str]    		= 1E-4






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




    '''simple docstring'''




    __UpperCAmelCase						    =       tf.reshape(tf.range(2 * 12 * 16 * 64				,				dtype=tf.floataa   )				,				shape=(2, 12, 16, 64)   ) / 100

    __UpperCAmelCase						    =       -tf.reshape(tf.range(2 * 12 * 16 * 64				,				dtype=tf.floataa   )				,				shape=(2, 12, 16, 64)   ) / 100

    __UpperCAmelCase						    =       TFRoFormerSinusoidalPositionalEmbedding(num_positions=32				,				embedding_dim=64   )
    __UpperCAmelCase						    =       embed_positions([2, 16, 768]   )[None, None, :, :]

    __UpperCAmelCase    ,		__UpperCAmelCase						    =       TFRoFormerSelfAttention.apply_rotary_position_embeddings(
        __UpperCamelCase				,				__UpperCamelCase				,				__UpperCamelCase   )

    __UpperCAmelCase						    =       tf.constant(
        [
            [0.0000, 0.0100, 0.0200, 0.0300, 0.0400, 0.0500, 0.0600, 0.0700],
            [-0.2012, 0.8897, 0.0263, 0.9401, 0.2074, 0.9463, 0.3481, 0.9343],
            [-1.7057, 0.6271, -1.2145, 1.3897, -0.6303, 1.7647, -0.1173, 1.8985],
            [-2.1731, -1.6397, -2.7358, 0.2854, -2.1840, 1.7183, -1.3018, 2.4871],
            [0.2717, -3.6173, -2.9206, -2.1988, -3.6638, 0.3858, -2.9155, 2.2980],
            [3.9859, -2.1580, -0.7984, -4.4904, -4.1181, -2.0252, -4.4782, 1.1253],
        ]   )
    __UpperCAmelCase						    =       tf.constant(
        [
            [0.0000, -0.0100, -0.0200, -0.0300, -0.0400, -0.0500, -0.0600, -0.0700],
            [0.2012, -0.8897, -0.0263, -0.9401, -0.2074, -0.9463, -0.3481, -0.9343],
            [1.7057, -0.6271, 1.2145, -1.3897, 0.6303, -1.7647, 0.1173, -1.8985],
            [2.1731, 1.6397, 2.7358, -0.2854, 2.1840, -1.7183, 1.3018, -2.4871],
            [-0.2717, 3.6173, 2.9206, 2.1988, 3.6638, -0.3858, 2.9155, -2.2980],
            [-3.9859, 2.1580, 0.7984, 4.4904, 4.1181, 2.0252, 4.4782, -1.1253],
        ]   )

    tf.debugging.assert_near(query_layer[0, 0, :6, :8]				,				__UpperCamelCase				,				atol=self.tolerance   )
    tf.debugging.assert_near(key_layer[0, 0, :6, :8]				,				__UpperCamelCase				,				atol=self.tolerance   )





import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


a_							=      get_tests_dir("""fixtures/spiece.model""")


@require_sentencepiece
@require_tokenizers
class 			UpperCAmelCase__    (		snake_case		,	unittest.TestCase					):



  """simple docstring"""






  lowerCAmelCase__		:	List[Any]    		= AlbertTokenizer
  lowerCAmelCase__		:	int    		= AlbertTokenizerFast
  lowerCAmelCase__		:	str    		= True
  lowerCAmelCase__		:	Union[str, Any]    		= True
  lowerCAmelCase__		:	int    		= True






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




    '''simple docstring'''




    super().setUp()

    # We have a SentencePiece fixture for testing
    __UpperCAmelCase						    =       AlbertTokenizer(__lowerCAmelCase   )
    tokenizer.save_pretrained(self.tmpdirname   )






  def 	_UpperCAmelCase				(				self:			Any				,				__lowerCAmelCase:			Tuple   ) -> Union[str, Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       "this is a test"
    __UpperCAmelCase						    =       "this is a test"
    return input_text, output_text






  def 	_UpperCAmelCase				(				self:			Dict   ) -> List[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       "<pad>"
    __UpperCAmelCase						    =       0

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






  def 	_UpperCAmelCase				(				self:			str   ) -> Optional[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       list(self.get_tokenizer().get_vocab().keys()   )

    self.assertEqual(vocab_keys[0]				,				"<pad>"   )
    self.assertEqual(vocab_keys[1]				,				"<unk>"   )
    self.assertEqual(vocab_keys[-1]				,				"▁eloquent"   )
    self.assertEqual(len(__lowerCAmelCase   )				,				30_000   )






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




    '''simple docstring'''




    self.assertEqual(self.get_tokenizer().vocab_size				,				30_000   )






  def 	_UpperCAmelCase				(				self:			str   ) -> int:




    '''simple docstring'''




    if not self.test_rust_tokenizer:
      return

    __UpperCAmelCase						    =       self.get_tokenizer()
    __UpperCAmelCase						    =       self.get_rust_tokenizer()

    __UpperCAmelCase						    =       "I was born in 92000, and this is falsé."

    __UpperCAmelCase						    =       tokenizer.tokenize(__lowerCAmelCase   )
    __UpperCAmelCase						    =       rust_tokenizer.tokenize(__lowerCAmelCase   )
    self.assertListEqual(__lowerCAmelCase				,				__lowerCAmelCase   )

    __UpperCAmelCase						    =       tokenizer.encode(__lowerCAmelCase				,				add_special_tokens=__lowerCAmelCase   )
    __UpperCAmelCase						    =       rust_tokenizer.encode(__lowerCAmelCase				,				add_special_tokens=__lowerCAmelCase   )
    self.assertListEqual(__lowerCAmelCase				,				__lowerCAmelCase   )

    __UpperCAmelCase						    =       self.get_rust_tokenizer()
    __UpperCAmelCase						    =       tokenizer.encode(__lowerCAmelCase   )
    __UpperCAmelCase						    =       rust_tokenizer.encode(__lowerCAmelCase   )
    self.assertListEqual(__lowerCAmelCase				,				__lowerCAmelCase   )






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




    '''simple docstring'''




    __UpperCAmelCase						    =       AlbertTokenizer(__lowerCAmelCase				,				keep_accents=__lowerCAmelCase   )

    __UpperCAmelCase						    =       tokenizer.tokenize("This is a test"   )
    self.assertListEqual(__lowerCAmelCase				,				["▁this", "▁is", "▁a", "▁test"]   )

    self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowerCAmelCase   )				,				[48, 25, 21, 1_289]   )

    __UpperCAmelCase						    =       tokenizer.tokenize("I was born in 92000, and this is falsé."   )
    self.assertListEqual(
        __lowerCAmelCase				,				["▁i", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "é", "."]   )
    __UpperCAmelCase						    =       tokenizer.convert_tokens_to_ids(__lowerCAmelCase   )
    self.assertListEqual(__lowerCAmelCase				,				[31, 23, 386, 19, 561, 3_050, 15, 17, 48, 25, 8_256, 18, 1, 9]   )

    __UpperCAmelCase						    =       tokenizer.convert_ids_to_tokens(__lowerCAmelCase   )
    self.assertListEqual(
        __lowerCAmelCase				,				["▁i", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "."]				,				)






  def 	_UpperCAmelCase				(				self:			str   ) -> Dict:




    '''simple docstring'''




    __UpperCAmelCase						    =       AlbertTokenizer(__lowerCAmelCase   )

    __UpperCAmelCase						    =       tokenizer.encode("sequence builders"   )
    __UpperCAmelCase						    =       tokenizer.encode("multi-sequence build"   )

    __UpperCAmelCase						    =       tokenizer.build_inputs_with_special_tokens(__lowerCAmelCase   )
    __UpperCAmelCase						    =       tokenizer.build_inputs_with_special_tokens(__lowerCAmelCase				,				__lowerCAmelCase   )

    assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
    assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
        tokenizer.sep_token_id
    ]






  @slow
  def 	_UpperCAmelCase				(				self:			Optional[int]   ) -> str:




    '''simple docstring'''




    __UpperCAmelCase						    =       {"attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "input_ids": [[2, 21_970, 13, 5, 6_092, 167, 28, 7_103, 2_153, 673, 8, 7_028, 12_051, 18, 17, 7_103, 2_153, 673, 8, 3_515, 18_684, 8, 4_461, 6, 1_927, 297, 8, 12_060, 2_607, 18, 13, 5, 4_461, 15, 10_538, 38, 8, 135, 15, 822, 58, 15, 993, 10_363, 15, 1_460, 8_005, 4_461, 15, 993, 255, 2_328, 9, 9, 9, 6, 26, 1_112, 816, 3_260, 13, 5, 103, 2_377, 6, 17, 1_112, 816, 2_782, 13, 5, 103, 10_641, 6, 29, 84, 2_512, 2_430, 782, 18_684, 2_761, 19, 808, 2_430, 2_556, 17, 855, 1_480, 9_477, 4_091, 128, 11_712, 15, 7_103, 2_153, 673, 17, 24_883, 9_990, 9, 3], [2, 11_502, 25, 1_006, 20, 782, 8, 11_809, 855, 1_732, 19_393, 18_667, 37, 367, 21_018, 69, 1_854, 34, 11_860, 19_124, 27, 156, 225, 17, 193, 4_141, 19, 65, 9_124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 14, 2_231, 886, 2_385, 17_659, 84, 14, 16_792, 1_952, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "token_type_ids": [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
    # fmt: on

    self.tokenizer_integration_test_util(
        expected_encoding=__lowerCAmelCase				,				model_name="albert-base-v2"				,				revision="6b6560eaf5ff2e250b00c50f380c5389a9c2d82e"				,				)



