



"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
       TFFunnelBaseModel,
       TFFunnelForMaskedLM,
       TFFunnelForMultipleChoice,
       TFFunnelForPreTraining,
       TFFunnelForQuestionAnswering,
       TFFunnelForSequenceClassification,
       TFFunnelForTokenClassification,
       TFFunnelModel,
   )
class     a		:



  def __init__(  self       :    List[str]				,						lowerCAmelCase       :    Optional[int]				,						lowerCAmelCase       :    Dict=13				,						lowerCAmelCase       :    List[Any]=7				,						lowerCAmelCase       :    List[Any]=True				,						lowerCAmelCase       :    Any=True				,						lowerCAmelCase       :    Union[str, Any]=True				,						lowerCAmelCase       :    Optional[int]=True				,						lowerCAmelCase       :    int=99				,						lowerCAmelCase       :    List[Any]=[1, 1, 2]				,						lowerCAmelCase       :    Any=1				,						lowerCAmelCase       :    List[str]=32				,						lowerCAmelCase       :    List[str]=4				,						lowerCAmelCase       :    List[Any]=8				,						lowerCAmelCase       :    Optional[Any]=37				,						lowerCAmelCase       :    Any="gelu_new"				,						lowerCAmelCase       :    Tuple=0.1				,						lowerCAmelCase       :    Dict=0.1				,						lowerCAmelCase       :    Optional[Any]=0.0				,						lowerCAmelCase       :    Any=512				,						lowerCAmelCase       :    Union[str, Any]=3				,						lowerCAmelCase       :    List[str]=0.0_2				,						lowerCAmelCase       :    Tuple=3				,						lowerCAmelCase       :    str=4				,						lowerCAmelCase       :    Any=None				,						lowerCAmelCase       :    List[str]=False				,						)   ->    List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[Any]   	=parent
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=batch_size
     SCREAMING_SNAKE_CASE_:       Dict   	=seq_length
     SCREAMING_SNAKE_CASE_:       List[str]   	=is_training
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=use_input_mask
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=use_token_type_ids
     SCREAMING_SNAKE_CASE_:       Dict   	=use_labels
     SCREAMING_SNAKE_CASE_:       Dict   	=vocab_size
     SCREAMING_SNAKE_CASE_:       Any   	=block_sizes
     SCREAMING_SNAKE_CASE_:       Optional[int]   	=num_decoder_layers
     SCREAMING_SNAKE_CASE_:       Optional[int]   	=d_model
     SCREAMING_SNAKE_CASE_:       Any   	=n_head
     SCREAMING_SNAKE_CASE_:       Optional[int]   	=d_head
     SCREAMING_SNAKE_CASE_:       str   	=d_inner
     SCREAMING_SNAKE_CASE_:       Any   	=hidden_act
     SCREAMING_SNAKE_CASE_:       Any   	=hidden_dropout
     SCREAMING_SNAKE_CASE_:       Tuple   	=attention_dropout
     SCREAMING_SNAKE_CASE_:       List[Any]   	=activation_dropout
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=max_position_embeddings
     SCREAMING_SNAKE_CASE_:       List[Any]   	=type_vocab_size
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=2
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=num_labels
     SCREAMING_SNAKE_CASE_:       List[Any]   	=num_choices
     SCREAMING_SNAKE_CASE_:       int   	=scope
     SCREAMING_SNAKE_CASE_:       Optional[int]   	=initializer_std

     # Used in the tests to check the size of the first attention layer
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=n_head
     # Used in the tests to check the size of the first hidden state
     SCREAMING_SNAKE_CASE_:       List[Any]   	=self.d_model
     # Used in the tests to check the number of output hidden states/attentions
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=sum(self.block_sizes						) + (0 if base else self.num_decoder_layers)
     # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
     # the last hidden state of the first block (which is the first hidden state of the decoder).
     if not base:
        SCREAMING_SNAKE_CASE_:       Dict   	=self.num_hidden_layers + 2



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       str   	=ids_tensor([self.batch_size, self.seq_length]				,						self.vocab_size						)

     SCREAMING_SNAKE_CASE_:       List[Any]   	=None
     if self.use_input_mask:
        SCREAMING_SNAKE_CASE_:       Dict   	=random_attention_mask([self.batch_size, self.seq_length]						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=None
     if self.use_token_type_ids:
        SCREAMING_SNAKE_CASE_:       Optional[int]   	=ids_tensor([self.batch_size, self.seq_length]				,						self.type_vocab_size						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=None
     SCREAMING_SNAKE_CASE_:       List[Any]   	=None
     SCREAMING_SNAKE_CASE_:       str   	=None
     if self.use_labels:
        SCREAMING_SNAKE_CASE_:       List[str]   	=ids_tensor([self.batch_size]				,						self.type_sequence_label_size						)
        SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=ids_tensor([self.batch_size, self.seq_length]				,						self.num_labels						)
        SCREAMING_SNAKE_CASE_:       Tuple   	=ids_tensor([self.batch_size]				,						self.num_choices						)

     SCREAMING_SNAKE_CASE_:       str   	=FunnelConfig(
         vocab_size=self.vocab_size				,						block_sizes=self.block_sizes				,						num_decoder_layers=self.num_decoder_layers				,						d_model=self.d_model				,						n_head=self.n_head				,						d_head=self.d_head				,						d_inner=self.d_inner				,						hidden_act=self.hidden_act				,						hidden_dropout=self.hidden_dropout				,						attention_dropout=self.attention_dropout				,						activation_dropout=self.activation_dropout				,						max_position_embeddings=self.max_position_embeddings				,						type_vocab_size=self.type_vocab_size				,						initializer_std=self.initializer_std				,						)

     return (
         config,
         input_ids,
         token_type_ids,
         input_mask,
         sequence_labels,
         token_labels,
         choice_labels,
     )



  def 		lowerCamelCase__				(  self       :    int				,						lowerCAmelCase       :    str				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    str				,						lowerCAmelCase       :    Optional[int]				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    List[Any]				,						)   ->    Optional[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       str   	=TFFunnelModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       List[str]   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       str   	=model(lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=[input_ids, input_mask]
     SCREAMING_SNAKE_CASE_:       Any   	=model(lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, self.seq_length, self.d_model)						)

     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=False
     SCREAMING_SNAKE_CASE_:       Optional[int]   	=TFFunnelModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Tuple   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, self.seq_length, self.d_model)						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=False
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=TFFunnelModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Tuple   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, self.seq_length, self.d_model)						)



  def 		lowerCamelCase__				(  self       :    Tuple				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    int				,						lowerCAmelCase       :    Optional[int]				,						lowerCAmelCase       :    List[str]				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    List[Any]				,						)   ->    Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Any   	=TFFunnelBaseModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       Tuple   	=model(lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=[input_ids, input_mask]
     SCREAMING_SNAKE_CASE_:       List[str]   	=model(lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:       List[str]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, 2, self.d_model)						)

     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=False
     SCREAMING_SNAKE_CASE_:       int   	=TFFunnelBaseModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, 3, self.d_model)						)

     SCREAMING_SNAKE_CASE_:       str   	=False
     SCREAMING_SNAKE_CASE_:       Dict   	=TFFunnelBaseModel(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.last_hidden_state.shape				,						(self.batch_size, 2, self.d_model)						)



  def 		lowerCamelCase__				(  self       :    List[Any]				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    str				,						)   ->    List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=TFFunnelForPreTraining(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Tuple   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.seq_length)						)



  def 		lowerCamelCase__				(  self       :    Tuple				,						lowerCAmelCase       :    str				,						lowerCAmelCase       :    List[str]				,						lowerCAmelCase       :    List[str]				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    int				,						lowerCAmelCase       :    int				,						)   ->    List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       str   	=TFFunnelForMaskedLM(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       Dict   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.seq_length, self.vocab_size)						)



  def 		lowerCamelCase__				(  self       :    Dict				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    List[Any]				,						lowerCAmelCase       :    List[Any]				,						lowerCAmelCase       :    List[str]				,						lowerCAmelCase       :    int				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    Any				,						)   ->    List[str]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Tuple   	=self.num_labels
     SCREAMING_SNAKE_CASE_:       Tuple   	=TFFunnelForSequenceClassification(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Optional[Any]   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       List[str]   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.num_labels)						)



  def 		lowerCamelCase__				(  self       :    Any				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    List[Any]				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Union[str, Any]				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    List[Any]				,						)   ->    Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[str]   	=self.num_choices
     SCREAMING_SNAKE_CASE_:       List[str]   	=TFFunnelForMultipleChoice(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Any   	=tf.tile(tf.expand_dims(lowerCAmelCase				,						1						)				,						(1, self.num_choices, 1)						)
     SCREAMING_SNAKE_CASE_:       int   	=tf.tile(tf.expand_dims(lowerCAmelCase				,						1						)				,						(1, self.num_choices, 1)						)
     SCREAMING_SNAKE_CASE_:       Union[str, Any]   	=tf.tile(tf.expand_dims(lowerCAmelCase				,						1						)				,						(1, self.num_choices, 1)						)
     SCREAMING_SNAKE_CASE_:       Dict   	={
         '''input_ids''': multiple_choice_inputs_ids,
         '''attention_mask''': multiple_choice_input_mask,
         '''token_type_ids''': multiple_choice_token_type_ids,
     }
     SCREAMING_SNAKE_CASE_:       Tuple   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.num_choices)						)



  def 		lowerCamelCase__				(  self       :    List[str]				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Optional[Any]				,						lowerCAmelCase       :    int				,						lowerCAmelCase       :    List[str]				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    Dict				,						)   ->    Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       int   	=self.num_labels
     SCREAMING_SNAKE_CASE_:       Any   	=TFFunnelForTokenClassification(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       int   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       str   	=model(lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape				,						(self.batch_size, self.seq_length, self.num_labels)						)



  def 		lowerCamelCase__				(  self       :    Any				,						lowerCAmelCase       :    Optional[int]				,						lowerCAmelCase       :    int				,						lowerCAmelCase       :    str				,						lowerCAmelCase       :    Tuple				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    Dict				,						lowerCAmelCase       :    List[Any]				,						)   ->    Dict:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Optional[int]   	=TFFunnelForQuestionAnswering(config=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       Dict   	={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     SCREAMING_SNAKE_CASE_:       int   	=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       :    str						)   ->    List[str]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[str]   	=self.prepare_config_and_inputs()
     (
         SCREAMING_SNAKE_CASE_   
     ):       List[str]   	=config_and_inputs
     SCREAMING_SNAKE_CASE_:       Dict   	={'''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				):
  UpperCamelCase		: Optional[Any]     =    (
      (
          TFFunnelModel,
          TFFunnelForMaskedLM,
          TFFunnelForPreTraining,
          TFFunnelForQuestionAnswering,
          TFFunnelForTokenClassification,
      )
      if is_tf_available()
      else ()
  )
  UpperCamelCase		: Optional[int]     =    (
      {
          'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
          'fill-mask': TFFunnelForMaskedLM,
          'question-answering': TFFunnelForQuestionAnswering,
          'text-classification': TFFunnelForSequenceClassification,
          'token-classification': TFFunnelForTokenClassification,
          'zero-shot': TFFunnelForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  UpperCamelCase		: Optional[int]     =    False
  UpperCamelCase		: Union[str, Any]     =    False



  def 		lowerCamelCase__				(  self       :    Dict						)   ->    List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Tuple   	=TFFunnelModelTester(self						)
     SCREAMING_SNAKE_CASE_:       str   	=ConfigTester(self				,						config_class=lowerCAmelCase						)



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


     '''simple docstring'''




     self.config_tester.run_common_tests()



  def 		lowerCamelCase__				(  self       :    Dict						)   ->    str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[Any]   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*lowerCAmelCase						)



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       int   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*lowerCAmelCase						)



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[Any]   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase						)



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Tuple   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase						)





  def 		lowerCamelCase__				(  self       :    Tuple						)   ->    str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Optional[int]   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase						)







@require_tf
class     a		(     lowerCAmelCase_		,					unittest.TestCase				):
  UpperCamelCase		: str     =    (
      (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
  )
  UpperCamelCase		: List[str]     =    False
  UpperCamelCase		: str     =    False



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       List[Any]   	=TFFunnelModelTester(self				,						base=lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:       str   	=ConfigTester(self				,						config_class=lowerCAmelCase						)



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


     '''simple docstring'''




     self.config_tester.run_common_tests()



  def 		lowerCamelCase__				(  self       :    Dict						)   ->    Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Any   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_base_model(*lowerCAmelCase						)



  def 		lowerCamelCase__				(  self       :    Optional[int]						)   ->    Dict:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       str   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase						)





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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:       Optional[Any]   	=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase						)








"""simple docstring"""






from __future__ import annotations

_lowercase : Dict      						=						1.6_021E-19  # units = C






def      snake_case__   (		__lowerCamelCase				:    float							,		__lowerCamelCase				:    float							,		__lowerCamelCase				:    float							,		):
			"""simple docstring"""
			if (conductivity, electron_conc, mobility).count(0	) != 1:
						raise ValueError('''You cannot supply more or less than 2 values'''	)
			elif conductivity < 0:
						raise ValueError('''Conductivity cannot be negative'''	)
			elif electron_conc < 0:
						raise ValueError('''Electron concentration cannot be negative'''	)
			elif mobility < 0:
						raise ValueError('''mobility cannot be negative'''	)
			elif conductivity == 0:
						return (
						    "conductivity",
						    mobility * electron_conc * ELECTRON_CHARGE,
						)
			elif electron_conc == 0:
						return (
						    "electron_conc",
						    conductivity / (mobility * ELECTRON_CHARGE),
						)
			else:
						return (
						    "mobility",
						    conductivity / (electron_conc * ELECTRON_CHARGE),
						)


if __name__ == "__main__":
		import doctest

		doctest.testmod()




