




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

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







													"""simple docstring"""
													UpperCAmelCase_     : List[Any]         =					parent
													UpperCAmelCase_     : Dict         =					13
													UpperCAmelCase_     : Tuple         =					7
													UpperCAmelCase_     : Optional[int]         =					True
													UpperCAmelCase_     : Dict         =					True
													UpperCAmelCase_     : str         =					True
													UpperCAmelCase_     : Union[str, Any]         =					True
													UpperCAmelCase_     : Optional[int]         =					99
													UpperCAmelCase_     : Any         =					16
													UpperCAmelCase_     : List[str]         =					32
													UpperCAmelCase_     : Tuple         =					2
													UpperCAmelCase_     : str         =					4
													UpperCAmelCase_     : Dict         =					37
													UpperCAmelCase_     : Tuple         =					'''gelu'''
													UpperCAmelCase_     : str         =					0.1
													UpperCAmelCase_     : Tuple         =					0.1
													UpperCAmelCase_     : Optional[Any]         =					5_12
													UpperCAmelCase_     : Optional[int]         =					16
													UpperCAmelCase_     : List[Any]         =					2
													UpperCAmelCase_     : int         =					0.0_2
													UpperCAmelCase_     : str         =					3
													UpperCAmelCase_     : Union[str, Any]         =					4
													UpperCAmelCase_     : Optional[int]         =					None

							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : List[Any]         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.vocab_size				)

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

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

													UpperCAmelCase_     : Any         =					None
													UpperCAmelCase_     : Any         =					None
													UpperCAmelCase_     : Union[str, Any]         =					None
													if self.use_labels:
																			UpperCAmelCase_     : int         =					ids_tensor([self.batch_size]    ,       self.type_sequence_label_size				)
																			UpperCAmelCase_     : Dict         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.num_labels				)
																			UpperCAmelCase_     : int         =					ids_tensor([self.batch_size]    ,       self.num_choices				)

													UpperCAmelCase_     : Tuple         =					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    ,       __magic_name__							:       Any    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Dict    ,       __magic_name__							:       int    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]				)   ->    Any:







													"""simple docstring"""
													UpperCAmelCase_     : Optional[Any]         =					TFAlbertModel(config=lowerCAmelCase__				)
													# inputs = {'input_ids': input_ids,
													#           'attention_mask': input_mask,
													#           'token_type_ids': token_type_ids}
													# sequence_output, pooled_output = model(**inputs)
													UpperCAmelCase_     : int         =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													UpperCAmelCase_     : Union[str, Any]         =					model(lowerCAmelCase__				)

													UpperCAmelCase_     : int         =					[input_ids, input_mask]
													UpperCAmelCase_     : Optional[int]         =					model(lowerCAmelCase__				)

													UpperCAmelCase_     : str         =					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    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Any    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Optional[int]				)   ->    List[str]:







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







													"""simple docstring"""
													UpperCAmelCase_     : Optional[int]         =					TFAlbertForMaskedLM(config=lowerCAmelCase__				)
													UpperCAmelCase_     : List[Any]         =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													UpperCAmelCase_     : Any         =					model(lowerCAmelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.vocab_size)				)

							def       UpperCAmelCase__		(							self							:       Optional[int]    ,       __magic_name__							:       int    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       str    ,       __magic_name__							:       str    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       List[str]				)   ->    List[str]:







													"""simple docstring"""
													UpperCAmelCase_     : Tuple         =					self.num_labels
													UpperCAmelCase_     : Union[str, Any]         =					TFAlbertForSequenceClassification(config=lowerCAmelCase__				)
													UpperCAmelCase_     : Dict         =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													UpperCAmelCase_     : List[Any]         =					model(lowerCAmelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_labels)				)

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







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







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

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







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					self.num_labels
													UpperCAmelCase_     : int         =					TFAlbertForTokenClassification(config=lowerCAmelCase__				)
													UpperCAmelCase_     : str         =					{
													    '''input_ids''': input_ids,
													    '''attention_mask''': input_mask,
													    '''token_type_ids''': token_type_ids,
													}
													UpperCAmelCase_     : str         =					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"""
													UpperCAmelCase_     : Optional[int]         =					self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,    (
													    UpperCAmelCase_ 
													)  ,     
													)     : Tuple         =					config_and_inputs
													UpperCAmelCase_     : Optional[Any]         =					{'''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       ):
							__a   :				Dict       =    (
							    (
							        TFAlbertModel,
							        TFAlbertForPreTraining,
							        TFAlbertForMaskedLM,
							        TFAlbertForSequenceClassification,
							        TFAlbertForQuestionAnswering,
							        TFAlbertForTokenClassification,
							        TFAlbertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							__a   :				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 {}
							)
							__a   :				List[Any]       =    False
							__a   :				List[Any]       =    False

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







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					super()._prepare_for_class(lowerCAmelCase__    ,       lowerCAmelCase__    ,       return_labels=lowerCAmelCase__				)

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

													return inputs_dict

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







													"""simple docstring"""
													UpperCAmelCase_     : str         =					TFAlbertModelTester(self				)
													UpperCAmelCase_     : str         =					ConfigTester(self    ,       config_class=lowerCAmelCase__    ,       hidden_size=37				)

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







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

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







													"""simple docstring"""
													UpperCAmelCase_     : Tuple         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_model(*lowerCAmelCase__				)

							def       UpperCAmelCase__		(							self							:       int				)   ->    Dict:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					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"""
													UpperCAmelCase_     : Optional[Any]         =					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"""
													UpperCAmelCase_     : Union[str, Any]         =					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"""
													UpperCAmelCase_     : Tuple         =					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"""
													UpperCAmelCase_     : Optional[int]         =					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]:
																			UpperCAmelCase_     : List[Any]         =					TFAlbertModel.from_pretrained(lowerCAmelCase__				)
																			self.assertIsNotNone(lowerCAmelCase__				)





@require_tf
class    __a (unittest.TestCase       ):

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







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

													UpperCAmelCase_     : Union[str, Any]         =					[1, 6, 3_00_00]
													self.assertEqual(output.shape    ,       lowerCAmelCase__				)

													UpperCAmelCase_     : Optional[Any]         =					tf.constant(
													    [
													        [
													            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
													            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
													            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
													        ]
													    ]				)
													tf.debugging.assert_near(output[:, :3, :3]    ,       lowerCAmelCase__    ,       atol=1E-4				)












'''simple docstring'''







from transformers import SqueezeBertTokenizer, SqueezeBertTokenizerFast
from transformers.testing_utils import require_tokenizers, slow

from ..bert.test_tokenization_bert import BertTokenizationTest


@require_tokenizers
class    __a (lowerCamelCase       ):
							__a   :				Any       =    SqueezeBertTokenizer
							__a   :				Dict       =    SqueezeBertTokenizerFast
							__a   :				Any       =    True

							def       UpperCAmelCase__		(							self							:       Union[str, Any]    ,       **__magic_name__							:       Dict				)   ->    int:







													"""simple docstring"""
													return SqueezeBertTokenizerFast.from_pretrained(self.tmpdirname    ,       **__magic_name__				)



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







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					SqueezeBertTokenizer.from_pretrained('''squeezebert/squeezebert-mnli-headless'''				)

													UpperCAmelCase_     : Any         =					tokenizer.encode('''sequence builders'''    ,       add_special_tokens=__magic_name__				)
													UpperCAmelCase_     : Optional[Any]         =					tokenizer.encode('''multi-sequence build'''    ,       add_special_tokens=__magic_name__				)

													UpperCAmelCase_     : List[Any]         =					tokenizer.build_inputs_with_special_tokens(__magic_name__				)
													UpperCAmelCase_     : Any         =					tokenizer.build_inputs_with_special_tokens(__magic_name__    ,       __magic_name__				)

													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
													]





