






"""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			,				)	-> int:




          '''simple docstring'''




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





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




          '''simple docstring'''




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

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

          lowercase__:    Optional[Any]        =      None
          if self.use_token_type_ids:
                 lowercase__:    Optional[int]        =      ids_tensor([self.batch_size, self.seq_length]			,				self.type_vocab_size)

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

          lowercase__:    Optional[int]        =      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_)	-> Any:




          '''simple docstring'''




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

          lowercase__:    Tuple        =      [input_ids, input_mask]
          lowercase__:    str        =      model(SCREAMING_SNAKE_CASE_)

          lowercase__:    str        =      model(SCREAMING_SNAKE_CASE_)

          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_)	-> str:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      self.num_labels
          lowercase__:    Union[str, Any]        =      TFAlbertForPreTraining(config=SCREAMING_SNAKE_CASE_)
          lowercase__:    Optional[int]        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    Union[str, Any]        =      model(SCREAMING_SNAKE_CASE_)
          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__:    Dict        =      TFAlbertForMaskedLM(config=SCREAMING_SNAKE_CASE_)
          lowercase__:    int        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    List[str]        =      model(SCREAMING_SNAKE_CASE_)
          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_)	-> Optional[Any]:




          '''simple docstring'''




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





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




          '''simple docstring'''




          lowercase__:    Tuple        =      TFAlbertForQuestionAnswering(config=SCREAMING_SNAKE_CASE_)
          lowercase__:    Optional[int]        =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
          lowercase__:    int        =      model(SCREAMING_SNAKE_CASE_)
          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_)	-> int:




          '''simple docstring'''




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





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




          '''simple docstring'''




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





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




          '''simple docstring'''




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







@require_tf
class 		_a       (						SCREAMING_SNAKE_CASE_    ,					SCREAMING_SNAKE_CASE_    ,					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__:    Tuple        =      super()._prepare_for_class(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			,				return_labels=SCREAMING_SNAKE_CASE_)

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

          return inputs_dict





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




          '''simple docstring'''




          lowercase__:    Tuple        =      TFAlbertModelTester(self)
          lowercase__:    Any        =      ConfigTester(self			,				config_class=SCREAMING_SNAKE_CASE_			,				hidden_size=37)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          self.config_tester.run_common_tests()





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




          '''simple docstring'''




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





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




          '''simple docstring'''




          lowercase__:    Dict        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_pretraining(*SCREAMING_SNAKE_CASE_)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    List[str]        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_masked_lm(*SCREAMING_SNAKE_CASE_)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    List[str]        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_multiple_choice(*SCREAMING_SNAKE_CASE_)





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Tuple        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_sequence_classification(*SCREAMING_SNAKE_CASE_)





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Any        =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_albert_for_question_answering(*SCREAMING_SNAKE_CASE_)





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




          '''simple docstring'''




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







@require_tf
class 		_a       (						unittest.TestCase   ):





   '''simple docstring'''






   @slow
   def __lowercase    (   self)	-> Tuple:




          '''simple docstring'''




          lowercase__:    List[Any]        =      TFAlbertForPreTraining.from_pretrained("albert-base-v2")
          lowercase__:    Any        =      tf.constant([[0, 1, 2, 3, 4, 5]])
          lowercase__:    Tuple        =      model(SCREAMING_SNAKE_CASE_)[0]

          lowercase__:    List[str]        =      [1, 6, 30_000]
          self.assertEqual(output.shape			,				SCREAMING_SNAKE_CASE_)

          lowercase__:    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]			,				SCREAMING_SNAKE_CASE_			,				atol=1E-4)














"""simple docstring"""





class 		_a       :





   '''simple docstring'''






   def __init__(   self			,				UpperCAmelCase_=None)	-> List[Any]:




          '''simple docstring'''




          lowercase__:    str        =      data
          lowercase__:    Any        =      None





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




          '''simple docstring'''




          lowercase__:    Any        =      ""
          lowercase__:    Dict        =      self
          while temp:
                 string_rep += F"""<{temp.data}> ---> """
                 lowercase__:    Tuple        =      temp.next
          string_rep += "<END>"
          return string_rep







def     A(  snake_case_		):
       """simple docstring"""





       if not elements_list:
              raise Exception("The Elements List is empty"		)

       # Set first element as Head
       lowercase__:    Any        =      Node(elements_list[0]		)
       lowercase__:    Optional[int]        =      head
       # Loop through elements from position 1
       for data in elements_list[1:]:
              lowercase__:    Dict        =      Node(snake_case_		)
              lowercase__:    Dict        =      current.next
       return head


UpperCamelCase			=      [1, 3, 5, 32, 44, 12, 43]
print(F"List: {list_data}")
print("""Creating Linked List from List.""")
UpperCamelCase			=      make_linked_list(list_data)
print("""Linked List:""")







print(linked_list)






