
'''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	:				List[Any]					,							__magic_name__	:				int					,							__magic_name__	:				Tuple=13					,							__magic_name__	:				Optional[Any]=7					,							__magic_name__	:				List[str]=True					,							__magic_name__	:				Dict=True					,							__magic_name__	:				List[Any]=True					,							__magic_name__	:				List[str]=True					,							__magic_name__	:				str=99					,							__magic_name__	:				Union[str, Any]=16					,							__magic_name__	:				Tuple=32					,							__magic_name__	:				Union[str, Any]=2					,							__magic_name__	:				List[Any]=4					,							__magic_name__	:				str=37					,							__magic_name__	:				Optional[int]="gelu"					,							__magic_name__	:				int=0.1					,							__magic_name__	:				Optional[Any]=0.1					,							__magic_name__	:				Dict=512					,							__magic_name__	:				Dict=16					,							__magic_name__	:				Dict=2					,							__magic_name__	:				str=0.02					,							__magic_name__	:				Union[str, Any]=3					,							__magic_name__	:				Tuple=4					,							__magic_name__	:				Optional[Any]=None					,							):


				"""simple docstring"""

				lowerCAmelCase__									=							parent
				lowerCAmelCase__									=							13
				lowerCAmelCase__									=							7
				lowerCAmelCase__									=							True
				lowerCAmelCase__									=							True
				lowerCAmelCase__									=							True
				lowerCAmelCase__									=							True
				lowerCAmelCase__									=							99
				lowerCAmelCase__									=							16
				lowerCAmelCase__									=							32
				lowerCAmelCase__									=							2
				lowerCAmelCase__									=							4
				lowerCAmelCase__									=							37
				lowerCAmelCase__									=							"gelu"
				lowerCAmelCase__									=							0.1
				lowerCAmelCase__									=							0.1
				lowerCAmelCase__									=							512
				lowerCAmelCase__									=							16
				lowerCAmelCase__									=							2
				lowerCAmelCase__									=							0.02
				lowerCAmelCase__									=							3
				lowerCAmelCase__									=							4
				lowerCAmelCase__									=							None





	def 							__SCREAMING_SNAKE_CASE     (    self	:				List[Any]							):


				"""simple docstring"""

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

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

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

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

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


				"""simple docstring"""

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

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

				lowerCAmelCase__									=							model(a__							)

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


				"""simple docstring"""

				lowerCAmelCase__									=							self.num_labels
				lowerCAmelCase__									=							TFAlbertForPreTraining(config=a__							)
				lowerCAmelCase__									=							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				lowerCAmelCase__									=							model(a__							)
				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 							__SCREAMING_SNAKE_CASE     (    self	:				Tuple					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				List[Any]					,							__magic_name__	:				List[Any]					,							__magic_name__	:				Optional[int]					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				Any							):


				"""simple docstring"""

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





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Optional[Any]					,							__magic_name__	:				str					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				str					,							__magic_name__	:				List[Any]					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				Optional[int]					,							__magic_name__	:				Union[str, Any]							):


				"""simple docstring"""

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





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Optional[Any]					,							__magic_name__	:				List[Any]					,							__magic_name__	:				List[str]					,							__magic_name__	:				List[str]					,							__magic_name__	:				List[str]					,							__magic_name__	:				str					,							__magic_name__	:				str					,							__magic_name__	:				Union[str, Any]							):


				"""simple docstring"""

				lowerCAmelCase__									=							TFAlbertForQuestionAnswering(config=a__							)
				lowerCAmelCase__									=							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				lowerCAmelCase__									=							model(a__							)
				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 							__SCREAMING_SNAKE_CASE     (    self	:				Dict					,							__magic_name__	:				Dict					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				List[str]					,							__magic_name__	:				Dict					,							__magic_name__	:				Optional[Any]					,							__magic_name__	:				int					,							__magic_name__	:				Dict							):


				"""simple docstring"""

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





	def 							__SCREAMING_SNAKE_CASE     (    self	:				int					,							__magic_name__	:				List[str]					,							__magic_name__	:				Tuple					,							__magic_name__	:				Union[str, Any]					,							__magic_name__	:				Optional[int]					,							__magic_name__	:				Any					,							__magic_name__	:				Dict					,							__magic_name__	:				Union[str, Any]							):


				"""simple docstring"""

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







	def 							__SCREAMING_SNAKE_CASE     (    self	:				Optional[Any]							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.prepare_config_and_inputs()
				(
				    (
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,(
				    lowerCAmelCase__	
				)		,	
				)									=							config_and_inputs
				lowerCAmelCase__									=							{"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			):
	snake_case__					:Optional[Any]         =   (
	    (
	        TFAlbertModel,
	        TFAlbertForPreTraining,
	        TFAlbertForMaskedLM,
	        TFAlbertForSequenceClassification,
	        TFAlbertForQuestionAnswering,
	        TFAlbertForTokenClassification,
	        TFAlbertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	snake_case__					: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__					:Union[str, Any]         =   False
	snake_case__					:str         =   False





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Dict					,							__magic_name__	:				Union[str, Any]					,							__magic_name__	:				Dict					,							__magic_name__	:				int=False							):


				"""simple docstring"""

				lowerCAmelCase__									=							super()._prepare_for_class(a__					,							a__					,							return_labels=a__							)

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

				return inputs_dict





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Optional[Any]							):


				"""simple docstring"""

				lowerCAmelCase__									=							TFAlbertModelTester(self							)
				lowerCAmelCase__									=							ConfigTester(self					,							config_class=a__					,							hidden_size=37							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Dict							):


				"""simple docstring"""

				self.config_tester.run_common_tests()





	def 							__SCREAMING_SNAKE_CASE     (    self	:				str							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_model(*a__							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				int							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_for_pretraining(*a__							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				List[str]							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_for_masked_lm(*a__							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				int							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_for_multiple_choice(*a__							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				int							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_for_sequence_classification(*a__							)





	def 							__SCREAMING_SNAKE_CASE     (    self	:				Dict							):


				"""simple docstring"""

				lowerCAmelCase__									=							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_albert_for_question_answering(*a__							)







	@slow
	def 							__SCREAMING_SNAKE_CASE     (    self	:				Tuple							):


				"""simple docstring"""

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






@require_tf
class       A   (		unittest.TestCase			):





	@slow
	def 							__SCREAMING_SNAKE_CASE     (    self	:				int							):


				"""simple docstring"""

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

				lowerCAmelCase__									=							[1, 6, 30000]
				self.assertEqual(output.shape					,							a__							)

				lowerCAmelCase__									=							tf.constant(
				    [
				        [
				            [4.59_5668, 0.7446_2754, -1.81_8147],
				            [4.595_4347, 0.745_4184, -1.818_8258],
				            [4.595_4905, 0.744_8235, -1.818_2316],
				        ]
				    ]							)
				tf.debugging.assert_near(output[:, :3, :3]					,							a__					,							atol=1E-4							)












"""simple docstring"""


from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
A_     :      List[str]								=load_iris()
iris.keys()


print(f'Target names: \n {iris.target_names} ')
print(f'\n Features: \n {iris.feature_names}')

# Train set e Test set
A_							,	A_							,	A_							,	A_     :      List[Any]								=train_test_split(
    iris["""data"""], iris["""target"""], random_state=4
)

# KNN

A_     :      str								=KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
A_     :      Any								=[[1, 2, 1, 4], [2, 3, 4, 5]]

A_     :      int								=knn.predict(X_new)

print(
    f'\nNew array: \n {X_new}\n\nTarget Names Prediction: \n'
    f' {iris["target_names"][prediction]}'
)






