




"""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      lowerCamelCase__      :


			def __init__(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE=13			,	SCREAMING_SNAKE_CASE=7			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=True			,	SCREAMING_SNAKE_CASE=99			,	SCREAMING_SNAKE_CASE=16			,	SCREAMING_SNAKE_CASE=32			,	SCREAMING_SNAKE_CASE=2			,	SCREAMING_SNAKE_CASE=4			,	SCREAMING_SNAKE_CASE=37			,	SCREAMING_SNAKE_CASE="gelu"			,	SCREAMING_SNAKE_CASE=0.1			,	SCREAMING_SNAKE_CASE=0.1			,	SCREAMING_SNAKE_CASE=512			,	SCREAMING_SNAKE_CASE=16			,	SCREAMING_SNAKE_CASE=2			,	SCREAMING_SNAKE_CASE=0.02			,	SCREAMING_SNAKE_CASE=3			,	SCREAMING_SNAKE_CASE=4			,	SCREAMING_SNAKE_CASE=None			,	):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size							)

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

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

					snake_case						:  Dict        =			None
					snake_case						:  List[str]        =			None
					snake_case						:  str        =			None
					if self.use_labels:
							snake_case						:  Dict        =			ids_tensor([self.batch_size]			,	self.type_sequence_label_size							)
							snake_case						:  str        =			ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels							)
							snake_case						:  List[str]        =			ids_tensor([self.batch_size]			,	self.num_choices							)

					snake_case						:  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 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







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

					snake_case						:  List[str]        =			[input_ids, input_mask]
					snake_case						:  str        =			model(_lowerCamelCase							)

					snake_case						:  Dict        =			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 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					snake_case						:  Optional[int]        =			self.num_labels
					snake_case						:  str        =			TFAlbertForPreTraining(config=_lowerCamelCase							)
					snake_case						:  List[str]        =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
					snake_case						:  int        =			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 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					snake_case						:  Dict        =			TFAlbertForMaskedLM(config=_lowerCamelCase							)
					snake_case						:  Any        =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
					snake_case						:  str        =			model(_lowerCamelCase							)
					self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size)							)


			def 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					snake_case						:  Tuple        =			self.num_labels
					snake_case						:  str        =			TFAlbertForSequenceClassification(config=_lowerCamelCase							)
					snake_case						:  List[str]        =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
					snake_case						:  Union[str, Any]        =			model(_lowerCamelCase							)
					self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_labels)							)


			def 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					snake_case						:  Tuple        =			TFAlbertForQuestionAnswering(config=_lowerCamelCase							)
					snake_case						:  List[Any]        =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
					snake_case						:  Optional[Any]        =			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 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







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



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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







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


			def 							lowerCamelCase_			(       self			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE			,	SCREAMING_SNAKE_CASE=False							):



					"""simple docstring"""







					snake_case						:  int        =			super()._prepare_for_class(_lowerCamelCase			,	_lowerCamelCase			,	return_labels=_lowerCamelCase							)

					if return_labels:
							if model_class in get_values(_lowerCamelCase							):
									snake_case						:  List[str]        =			tf.zeros(self.model_tester.batch_size			,	dtype=tf.intaa							)

					return inputs_dict


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Optional[Any]        =			TFAlbertModelTester(self							)
					snake_case						:  Tuple        =			ConfigTester(self			,	config_class=_lowerCamelCase			,	hidden_size=37							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					self.config_tester.run_common_tests()


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Dict        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_model(*_lowerCamelCase							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  str        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_for_pretraining(*_lowerCamelCase							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_for_masked_lm(*_lowerCamelCase							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_for_multiple_choice(*_lowerCamelCase							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  int        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_for_sequence_classification(*_lowerCamelCase							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Optional[Any]        =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_albert_for_question_answering(*_lowerCamelCase							)



			@slow
			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							snake_case						:  List[str]        =			TFAlbertModel.from_pretrained(_lowerCamelCase							)
							self.assertIsNotNone(_lowerCamelCase							)







@require_tf
class      lowerCamelCase__      (					unittest.TestCase     ):


			@slow
			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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

					snake_case						:  Tuple        =			[1, 6, 30_000]
					self.assertEqual(output.shape			,	_lowerCamelCase							)

					snake_case						:  List[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]			,	_lowerCamelCase			,	atol=1E-4							)







"""simple docstring"""

def 					UpperCamelCase__       (						lowercase__					:       set    ,       lowercase__					:       set				):
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_a={set_a}] is not a set'''
		assert isinstance(lowercase__    ,       lowercase__				), F'''The input value of [set_b={set_b}] is not a set'''

		return {a + b for a in set_a for b in set_b}


if __name__ == "__main__":
							from doctest import testmod

							testmod()

