






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


   '''simple docstring'''

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

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


   def     _SCREAMING_SNAKE_CASE    (     self			:					Dict  ):

     '''simple docstring'''
     __A						      =			ids_tensor([self.batch_size, self.seq_length],	self.vocab_size  )

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

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

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

     __A						      =			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			:					str,	_lowerCamelCase			:					str,	_lowerCamelCase			:					Optional[Any],	_lowerCamelCase			:					Optional[Any],	_lowerCamelCase			:					str,	_lowerCamelCase			:					Any,	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					Optional[Any]  ):

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

     __A						      =			[input_ids, input_mask]
     __A						      =			model(_lowerCamelCase  )

     __A						      =			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     _SCREAMING_SNAKE_CASE    (     self			:					Tuple,	_lowerCamelCase			:					Union[str, Any],	_lowerCamelCase			:					Dict,	_lowerCamelCase			:					int,	_lowerCamelCase			:					List[Any],	_lowerCamelCase			:					int,	_lowerCamelCase			:					Optional[int],	_lowerCamelCase			:					Optional[int]  ):

     '''simple docstring'''
     __A						      =			self.num_labels
     __A						      =			TFAlbertForPreTraining(config=_lowerCamelCase  )
     __A						      =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A						      =			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     _SCREAMING_SNAKE_CASE    (     self			:					Tuple,	_lowerCamelCase			:					Optional[Any],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					List[Any],	_lowerCamelCase			:					Any,	_lowerCamelCase			:					Union[str, Any],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					Any  ):

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


   def     _SCREAMING_SNAKE_CASE    (     self			:					int,	_lowerCamelCase			:					Optional[int],	_lowerCamelCase			:					Dict,	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					Dict,	_lowerCamelCase			:					str  ):

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


   def     _SCREAMING_SNAKE_CASE    (     self			:					int,	_lowerCamelCase			:					Optional[Any],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					str,	_lowerCamelCase			:					List[Any],	_lowerCamelCase			:					Optional[Any],	_lowerCamelCase			:					List[Any]  ):

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

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


   def     _SCREAMING_SNAKE_CASE    (     self			:					Any,	_lowerCamelCase			:					Any,	_lowerCamelCase			:					Optional[int],	_lowerCamelCase			:					Dict,	_lowerCamelCase			:					Dict,	_lowerCamelCase			:					List[Any],	_lowerCamelCase			:					List[str],	_lowerCamelCase			:					int  ):

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






   def     _SCREAMING_SNAKE_CASE    (     self			:					int  ):

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





@require_tf
class  snake_case		(							_lowerCAmelCase       ,     _lowerCAmelCase       ,     unittest.TestCase						):


   '''simple docstring'''

   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     _SCREAMING_SNAKE_CASE    (     self			:					List[Any],	_lowerCamelCase			:					str,	_lowerCamelCase			:					Any,	_lowerCamelCase			:					Tuple=False  ):

     '''simple docstring'''
     __A						      =			super()._prepare_for_class(_lowerCamelCase,	_lowerCamelCase,	return_labels=_lowerCamelCase  )

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

     return inputs_dict


   def     _SCREAMING_SNAKE_CASE    (     self			:					int  ):

     '''simple docstring'''
     __A						      =			TFAlbertModelTester(self  )
     __A						      =			ConfigTester(self,	config_class=_lowerCamelCase,	hidden_size=37  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					Tuple  ):

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


   def     _SCREAMING_SNAKE_CASE    (     self			:					Optional[int]  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_model(*_lowerCamelCase  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					str  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_pretraining(*_lowerCamelCase  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					int  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_masked_lm(*_lowerCamelCase  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					Optional[int]  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_multiple_choice(*_lowerCamelCase  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					List[Any]  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_sequence_classification(*_lowerCamelCase  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					str  ):

     '''simple docstring'''
     __A						      =			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_question_answering(*_lowerCamelCase  )






   @slow
   def     _SCREAMING_SNAKE_CASE    (     self			:					Dict  ):

     '''simple docstring'''
     for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __A						      =			TFAlbertModel.from_pretrained(_lowerCamelCase  )
       self.assertIsNotNone(_lowerCamelCase  )





@require_tf
class  snake_case		(							unittest.TestCase						):


   '''simple docstring'''

   @slow
   def     _SCREAMING_SNAKE_CASE    (     self			:					Optional[Any]  ):

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

     __A						      =			[1, 6, 3_00_00]
     self.assertEqual(output.shape,	_lowerCamelCase  )

     __A						      =			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  lowerCAmelCase    (   __UpperCamelCase			):




  """simple docstring"""







  if not isinstance(__UpperCamelCase		,	__UpperCamelCase			):
    raise ValueError('''Input series is not valid, valid series - [2, 4, 8]'''			)
  if len(__UpperCamelCase			) == 0:
    raise ValueError('''Input list must be a non empty list'''			)
  if len(__UpperCamelCase			) == 1:
    return True
  try:
    __A						      =			series[1] / series[0]
    for index in range(len(__UpperCamelCase			) - 1			):
      if series[index + 1] / series[index] != common_ratio:
        return False
  except ZeroDivisionError:
    return False
  return True



def  lowerCAmelCase    (   __UpperCamelCase			):




  """simple docstring"""







  if not isinstance(__UpperCamelCase		,	__UpperCamelCase			):
    raise ValueError('''Input series is not valid, valid series - [2, 4, 8]'''			)
  if len(__UpperCamelCase			) == 0:
    raise ValueError('''Input list must be a non empty list'''			)
  __A						      =			1
  for value in series:
    answer *= value
  return pow(__UpperCamelCase		,	1 / len(__UpperCamelCase			)			)


if __name__ == "__main__":
       import doctest

       doctest.testmod()




