
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__  :





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



											"""simple docstring"""


											__lowercase								=   parent
											__lowercase								=   13
											__lowercase								=   7
											__lowercase								=   True
											__lowercase								=   True
											__lowercase								=   True
											__lowercase								=   True
											__lowercase								=   99
											__lowercase								=   16
											__lowercase								=   32
											__lowercase								=   2
											__lowercase								=   4
											__lowercase								=   37
											__lowercase								=   'gelu'
											__lowercase								=   0.1
											__lowercase								=   0.1
											__lowercase								=   5_12
											__lowercase								=   16
											__lowercase								=   2
											__lowercase								=   0.02
											__lowercase								=   3
											__lowercase								=   4
											__lowercase								=   None





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



											"""simple docstring"""


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

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

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

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

											__lowercase								=   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      a__					(					self    :  Any	,					_UpperCAmelCase    :  Union[str, Any]	,					_UpperCAmelCase    :  List[str]	,					_UpperCAmelCase    :  Optional[int]	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  Optional[int]	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  str							)		->						Tuple:



											"""simple docstring"""


											__lowercase								=   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								=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
											__lowercase								=   model(_UpperCAmelCase							)

											__lowercase								=   [input_ids, input_mask]
											__lowercase								=   model(_UpperCAmelCase							)

											__lowercase								=   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      a__					(					self    :  Optional[int]	,					_UpperCAmelCase    :  Dict	,					_UpperCAmelCase    :  Optional[Any]	,					_UpperCAmelCase    :  Optional[Any]	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  int	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  Tuple							)		->						List[str]:



											"""simple docstring"""


											__lowercase								=   self.num_labels
											__lowercase								=   TFAlbertForPreTraining(config=_UpperCAmelCase							)
											__lowercase								=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
											__lowercase								=   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      a__					(					self    :  Optional[Any]	,					_UpperCAmelCase    :  Union[str, Any]	,					_UpperCAmelCase    :  Any	,					_UpperCAmelCase    :  Dict	,					_UpperCAmelCase    :  Optional[Any]	,					_UpperCAmelCase    :  Any	,					_UpperCAmelCase    :  Dict	,					_UpperCAmelCase    :  int							)		->						Union[str, Any]:



											"""simple docstring"""


											__lowercase								=   TFAlbertForMaskedLM(config=_UpperCAmelCase							)
											__lowercase								=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
											__lowercase								=   model(_UpperCAmelCase							)
											self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.seq_length, self.vocab_size)							)





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



											"""simple docstring"""


											__lowercase								=   self.num_labels
											__lowercase								=   TFAlbertForSequenceClassification(config=_UpperCAmelCase							)
											__lowercase								=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
											__lowercase								=   model(_UpperCAmelCase							)
											self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.num_labels)							)





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



											"""simple docstring"""


											__lowercase								=   TFAlbertForQuestionAnswering(config=_UpperCAmelCase							)
											__lowercase								=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
											__lowercase								=   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      a__					(					self    :  List[str]	,					_UpperCAmelCase    :  Tuple	,					_UpperCAmelCase    :  Any	,					_UpperCAmelCase    :  Dict	,					_UpperCAmelCase    :  List[str]	,					_UpperCAmelCase    :  List[Any]	,					_UpperCAmelCase    :  int	,					_UpperCAmelCase    :  str							)		->						Any:



											"""simple docstring"""


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





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



											"""simple docstring"""


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





							def      a__					(					self    :  List[str]							)		->						Dict:



											"""simple docstring"""


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






@require_tf
class       A__  (		lowerCAmelCase__       ,		lowerCAmelCase__       ,		unittest.TestCase							):
							lowerCAmelCase__						:		List[Any]            =				(
							    (
							        TFAlbertModel,
							        TFAlbertForPreTraining,
							        TFAlbertForMaskedLM,
							        TFAlbertForSequenceClassification,
							        TFAlbertForQuestionAnswering,
							        TFAlbertForTokenClassification,
							        TFAlbertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							lowerCAmelCase__						:		List[Any]            =				(
							    {
							        "feature-extraction": TFAlbertModel,
							        "fill-mask": TFAlbertForMaskedLM,
							        "question-answering": TFAlbertForQuestionAnswering,
							        "text-classification": TFAlbertForSequenceClassification,
							        "token-classification": TFAlbertForTokenClassification,
							        "zero-shot": TFAlbertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							lowerCAmelCase__						:		Dict            =				False
							lowerCAmelCase__						:		Tuple            =				False





							def      a__					(					self    :  Optional[Any]	,					_UpperCAmelCase    :  Union[str, Any]	,					_UpperCAmelCase    :  str	,					_UpperCAmelCase    :  Tuple=False							)		->						Tuple:



											"""simple docstring"""


											__lowercase								=   super()._prepare_for_class(_UpperCAmelCase	,					_UpperCAmelCase	,					return_labels=_UpperCAmelCase							)

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

											return inputs_dict





							def      a__					(					self    :  Tuple							)		->						str:



											"""simple docstring"""


											__lowercase								=   TFAlbertModelTester(self							)
											__lowercase								=   ConfigTester(self	,					config_class=_UpperCAmelCase	,					hidden_size=37							)





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



											"""simple docstring"""


											self.config_tester.run_common_tests()





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



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_model(*_UpperCAmelCase							)





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



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_for_pretraining(*_UpperCAmelCase							)





							def      a__					(					self    :  Any							)		->						str:



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_for_masked_lm(*_UpperCAmelCase							)





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



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_for_multiple_choice(*_UpperCAmelCase							)





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



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_for_sequence_classification(*_UpperCAmelCase							)





							def      a__					(					self    :  str							)		->						Tuple:



											"""simple docstring"""


											__lowercase								=   self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_albert_for_question_answering(*_UpperCAmelCase							)





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



											"""simple docstring"""


											for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															__lowercase								=   TFAlbertModel.from_pretrained(_UpperCAmelCase							)
															self.assertIsNotNone(_UpperCAmelCase							)






@require_tf
class       A__  (		unittest.TestCase							):





							@slow
							def      a__					(					self    :  Optional[int]							)		->						Union[str, Any]:



											"""simple docstring"""


											__lowercase								=   TFAlbertForPreTraining.from_pretrained('albert-base-v2'							)
											__lowercase								=   tf.constant([[0, 1, 2, 3, 4, 5]]							)
											__lowercase								=   model(_UpperCAmelCase							)[0]

											__lowercase								=   [1, 6, 3_00_00]
											self.assertEqual(output.shape	,					_UpperCAmelCase							)

											__lowercase								=   tf.constant(
											    [
											        [
											            [4.595_668, 0.74_462_754, -1.818_147],
											            [4.5_954_347, 0.7_454_184, -1.8_188_258],
											            [4.5_954_905, 0.7_448_235, -1.8_182_316],
											        ]
											    ]							)
											tf.debugging.assert_near(output[:, :3, :3]	,					_UpperCAmelCase	,					atol=1e-4							)







def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: Union[str, Any]       ,				SCREAMING_SNAKE_CASE			: Any     )	->		Tuple:
				# "Simpson Rule"
				# int(f) = delta_x/2 * (b-a)/3*(f1 + 4f2 + 2f_3 + ... + fn)
				__lowercase								=   (boundary[1] - boundary[0]) / steps
				__lowercase								=   boundary[0]
				__lowercase								=   boundary[1]
				__lowercase								=   make_points(SCREAMING_SNAKE_CASE       ,				SCREAMING_SNAKE_CASE       ,				SCREAMING_SNAKE_CASE     )
				__lowercase								=   0.0
				y += (h / 3.0) * f(SCREAMING_SNAKE_CASE     )
				__lowercase								=   2
				for i in x_i:
								y += (h / 3) * (4 - 2 * (cnt % 2)) * f(SCREAMING_SNAKE_CASE     )
								cnt += 1
				y += (h / 3.0) * f(SCREAMING_SNAKE_CASE     )
				return y




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: List[Any]       ,				SCREAMING_SNAKE_CASE			: Dict       ,				SCREAMING_SNAKE_CASE			: int     )	->		Any:
				__lowercase								=   a + h
				while x < (b - h):
								yield x
								__lowercase								=   x + h




def 				__SCREAMING_SNAKE_CASE  (						SCREAMING_SNAKE_CASE			: Any     )	->		List[Any]:  # enter your function here
				__lowercase								=   (x - 0) * (x - 0)
				return y




def 				__SCREAMING_SNAKE_CASE  (						)	->		List[str]:
				__lowercase								=   0.0  # Lower bound of integration
				__lowercase								=   1.0  # Upper bound of integration
				__lowercase								=   10.0  # define number of steps or resolution
				__lowercase								=   [a, b]  # define boundary of integration
				__lowercase								=   method_a(SCREAMING_SNAKE_CASE       ,				SCREAMING_SNAKE_CASE     )
				print(F"""y = {y}"""     )


if __name__ == "__main__":
							main()





