






import math
class 					a_:



     """simple docstring"""



     def __init__(						self			:					Any       ,       lowerCAmelCase__			:					List[str]       ,       lowerCAmelCase__			:					Tuple       ,       lowerCAmelCase__			:					Optional[Any])    ->					Optional[int]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						x
      SCREAMING_SNAKE_CASE							  =						y
      SCREAMING_SNAKE_CASE							  =						z





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

      """simple docstring"""
      return f'''Point({self.x}, {self.y}, {self.z})'''





def 		A_			(		lowercase_					,       lowercase_	)							->Dict:







 """simple docstring"""

 return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2	)	)


if __name__ == "__main__":
      import doctest

      doctest.testmod()












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			:					Tuple       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					List[str]=1_3       ,       lowerCAmelCase__			:					List[str]=7       ,       lowerCAmelCase__			:					Any=True       ,       lowerCAmelCase__			:					Any=True       ,       lowerCAmelCase__			:					Any=True       ,       lowerCAmelCase__			:					int=True       ,       lowerCAmelCase__			:					Tuple=9_9       ,       lowerCAmelCase__			:					List[Any]=1_6       ,       lowerCAmelCase__			:					Union[str, Any]=3_2       ,       lowerCAmelCase__			:					Union[str, Any]=2       ,       lowerCAmelCase__			:					int=4       ,       lowerCAmelCase__			:					Any=3_7       ,       lowerCAmelCase__			:					Dict="gelu"       ,       lowerCAmelCase__			:					Any=0.1       ,       lowerCAmelCase__			:					Dict=0.1       ,       lowerCAmelCase__			:					List[str]=5_1_2       ,       lowerCAmelCase__			:					Any=1_6       ,       lowerCAmelCase__			:					List[Any]=2       ,       lowerCAmelCase__			:					Dict=0.02       ,       lowerCAmelCase__			:					Optional[Any]=3       ,       lowerCAmelCase__			:					str=4       ,       lowerCAmelCase__			:					List[str]=None       ,       )    ->					str:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						parent
      SCREAMING_SNAKE_CASE							  =						1_3
      SCREAMING_SNAKE_CASE							  =						7
      SCREAMING_SNAKE_CASE							  =						True
      SCREAMING_SNAKE_CASE							  =						True
      SCREAMING_SNAKE_CASE							  =						True
      SCREAMING_SNAKE_CASE							  =						True
      SCREAMING_SNAKE_CASE							  =						9_9
      SCREAMING_SNAKE_CASE							  =						1_6
      SCREAMING_SNAKE_CASE							  =						3_2
      SCREAMING_SNAKE_CASE							  =						2
      SCREAMING_SNAKE_CASE							  =						4
      SCREAMING_SNAKE_CASE							  =						3_7
      SCREAMING_SNAKE_CASE							  =						'gelu'
      SCREAMING_SNAKE_CASE							  =						0.1
      SCREAMING_SNAKE_CASE							  =						0.1
      SCREAMING_SNAKE_CASE							  =						5_1_2
      SCREAMING_SNAKE_CASE							  =						1_6
      SCREAMING_SNAKE_CASE							  =						2
      SCREAMING_SNAKE_CASE							  =						0.02
      SCREAMING_SNAKE_CASE							  =						3
      SCREAMING_SNAKE_CASE							  =						4
      SCREAMING_SNAKE_CASE							  =						None





     def   __UpperCamelCase		(						self			:					Tuple)    ->					Tuple:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						ids_tensor([self.batch_size, self.seq_length]       ,       self.vocab_size)

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

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

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

      SCREAMING_SNAKE_CASE							  =						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   __UpperCamelCase		(						self			:					int       ,       lowerCAmelCase__			:					Any       ,       lowerCAmelCase__			:					Optional[int]       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					Dict       ,       lowerCAmelCase__			:					int       ,       lowerCAmelCase__			:					Optional[int]       ,       lowerCAmelCase__			:					Union[str, Any])    ->					Any:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						TFAlbertModel(config=lowerCAmelCase__)
      # inputs = {'input_ids': input_ids,
      #           'attention_mask': input_mask,
      #           'token_type_ids': token_type_ids}
      # sequence_output, pooled_output = model(**inputs)
      SCREAMING_SNAKE_CASE							  =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)

      SCREAMING_SNAKE_CASE							  =						[input_ids, input_mask]
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)

      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)

      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   __UpperCamelCase		(						self			:					Tuple       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					List[Any]       ,       lowerCAmelCase__			:					Any       ,       lowerCAmelCase__			:					List[Any]       ,       lowerCAmelCase__			:					Optional[Any]       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					Optional[int])    ->					List[str]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.num_labels
      SCREAMING_SNAKE_CASE							  =						TFAlbertForPreTraining(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      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   __UpperCamelCase		(						self			:					Optional[int]       ,       lowerCAmelCase__			:					str       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					List[Any]       ,       lowerCAmelCase__			:					Any       ,       lowerCAmelCase__			:					Optional[int]       ,       lowerCAmelCase__			:					Dict       ,       lowerCAmelCase__			:					str)    ->					Tuple:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						TFAlbertForMaskedLM(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.vocab_size))





     def   __UpperCamelCase		(						self			:					Optional[int]       ,       lowerCAmelCase__			:					int       ,       lowerCAmelCase__			:					List[str]       ,       lowerCAmelCase__			:					str       ,       lowerCAmelCase__			:					str       ,       lowerCAmelCase__			:					Optional[Any]       ,       lowerCAmelCase__			:					Optional[int]       ,       lowerCAmelCase__			:					List[str])    ->					List[str]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.num_labels
      SCREAMING_SNAKE_CASE							  =						TFAlbertForSequenceClassification(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_labels))





     def   __UpperCamelCase		(						self			:					str       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					List[str]       ,       lowerCAmelCase__			:					int       ,       lowerCAmelCase__			:					Dict       ,       lowerCAmelCase__			:					List[str]       ,       lowerCAmelCase__			:					Dict)    ->					List[Any]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						TFAlbertForQuestionAnswering(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      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			:					Optional[Any]       ,       lowerCAmelCase__			:					Dict       ,       lowerCAmelCase__			:					List[Any]       ,       lowerCAmelCase__			:					List[str]       ,       lowerCAmelCase__			:					Any       ,       lowerCAmelCase__			:					Any       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					int)    ->					str:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.num_choices
      SCREAMING_SNAKE_CASE							  =						TFAlbertForMultipleChoice(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						tf.tile(tf.expand_dims(lowerCAmelCase__       ,       1)       ,       (1, self.num_choices, 1))
      SCREAMING_SNAKE_CASE							  =						tf.tile(tf.expand_dims(lowerCAmelCase__       ,       1)       ,       (1, self.num_choices, 1))
      SCREAMING_SNAKE_CASE							  =						tf.tile(tf.expand_dims(lowerCAmelCase__       ,       1)       ,       (1, self.num_choices, 1))
      SCREAMING_SNAKE_CASE							  =						{
          'input_ids': multiple_choice_inputs_ids,
          'attention_mask': multiple_choice_input_mask,
          'token_type_ids': multiple_choice_token_type_ids,
      }
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      self.parent.assertListEqual(list(result['logits'].shape)       ,       [self.batch_size, self.num_choices])





     def   __UpperCamelCase		(						self			:					Any       ,       lowerCAmelCase__			:					Optional[Any]       ,       lowerCAmelCase__			:					Dict       ,       lowerCAmelCase__			:					str       ,       lowerCAmelCase__			:					Optional[Any]       ,       lowerCAmelCase__			:					Tuple       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					Optional[Any])    ->					Dict:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.num_labels
      SCREAMING_SNAKE_CASE							  =						TFAlbertForTokenClassification(config=lowerCAmelCase__)
      SCREAMING_SNAKE_CASE							  =						{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)
      self.parent.assertListEqual(list(result['logits'].shape)       ,       [self.batch_size, self.seq_length, self.num_labels])





     def   __UpperCamelCase		(						self			:					Tuple)    ->					Optional[int]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.prepare_config_and_inputs()
      (
          (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , (
          SCREAMING_SNAKE_CASE
      )  , 
      )							  =						config_and_inputs
      SCREAMING_SNAKE_CASE							  =						{'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"""



     __snake_case						:							Dict       			=(
         (
             TFAlbertModel,
             TFAlbertForPreTraining,
             TFAlbertForMaskedLM,
             TFAlbertForSequenceClassification,
             TFAlbertForQuestionAnswering,
             TFAlbertForTokenClassification,
             TFAlbertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     __snake_case						:							Optional[int]       			=(
         {
             '''feature-extraction''': TFAlbertModel,
             '''fill-mask''': TFAlbertForMaskedLM,
             '''question-answering''': TFAlbertForQuestionAnswering,
             '''text-classification''': TFAlbertForSequenceClassification,
             '''token-classification''': TFAlbertForTokenClassification,
             '''zero-shot''': TFAlbertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __snake_case						:							List[Any]       			=False
     __snake_case						:							List[Any]       			=False





     def   __UpperCamelCase		(						self			:					Union[str, Any]       ,       lowerCAmelCase__			:					Union[str, Any]       ,       lowerCAmelCase__			:					List[Any]       ,       lowerCAmelCase__			:					Tuple=False)    ->					Optional[int]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						super()._prepare_for_class(lowerCAmelCase__       ,       lowerCAmelCase__       ,       return_labels=lowerCAmelCase__)

      if return_labels:
       if model_class in get_values(lowerCAmelCase__):
        SCREAMING_SNAKE_CASE							  =						tf.zeros(self.model_tester.batch_size       ,       dtype=tf.intaa)

      return inputs_dict





     def   __UpperCamelCase		(						self			:					Dict)    ->					Optional[Any]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						TFAlbertModelTester(self)
      SCREAMING_SNAKE_CASE							  =						ConfigTester(self       ,       config_class=lowerCAmelCase__       ,       hidden_size=3_7)





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

      """simple docstring"""
      self.config_tester.run_common_tests()





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

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_model(*lowerCAmelCase__)





     def   __UpperCamelCase		(						self			:					int)    ->					Dict:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_for_pretraining(*lowerCAmelCase__)





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

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_for_masked_lm(*lowerCAmelCase__)





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

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_for_multiple_choice(*lowerCAmelCase__)





     def   __UpperCamelCase		(						self			:					Any)    ->					Dict:

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_for_sequence_classification(*lowerCAmelCase__)





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

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_albert_for_question_answering(*lowerCAmelCase__)





     @slow
     def   __UpperCamelCase		(						self			:					Tuple)    ->					List[str]:

      """simple docstring"""
      for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       SCREAMING_SNAKE_CASE							  =						TFAlbertModel.from_pretrained(lowerCAmelCase__)
       self.assertIsNotNone(lowerCAmelCase__)

@require_tf
class 					a_(						unittest.TestCase					):



     """simple docstring"""



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

      """simple docstring"""
      SCREAMING_SNAKE_CASE							  =						TFAlbertForPreTraining.from_pretrained('albert-base-v2')
      SCREAMING_SNAKE_CASE							  =						tf.constant([[0, 1, 2, 3, 4, 5]])
      SCREAMING_SNAKE_CASE							  =						model(lowerCAmelCase__)[0]

      SCREAMING_SNAKE_CASE							  =						[1, 6, 3_0_0_0_0]
      self.assertEqual(output.shape       ,       lowerCAmelCase__)

      SCREAMING_SNAKE_CASE							  =						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]       ,       lowerCAmelCase__       ,       atol=1e-4)




