code: 
  from ..utils import DummyObject, requires_backends
  
  
  
  
  class      __lowercase	(	metaclass=__snake_case					):
  	_A   			=      ["tensorflow_text"]
  
  
  
  
  
  
  	def __init__(self							:   List[Any]			,  *snake_case							:   List[str]			,  **snake_case							:   str						)   -> List[str]:
  							requires_backends(self			,  ["tensorflow_text"]						)
  
  
  
  
  
style_context: 
  import unittest
  
  from transformers import ElectraConfig, is_torch_available
  from transformers.models.auto import get_values
  from transformers.testing_utils import require_torch, slow, torch_device
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  							import torch
  
  							from transformers import (
  							    MODEL_FOR_PRETRAINING_MAPPING,
  							    ElectraForCausalLM,
  							    ElectraForMaskedLM,
  							    ElectraForMultipleChoice,
  							    ElectraForPreTraining,
  							    ElectraForQuestionAnswering,
  							    ElectraForSequenceClassification,
  							    ElectraForTokenClassification,
  							    ElectraModel,
  							)
  							from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  
  
  class      __lowercase	:
  
  
  
  
  
  
  	def __init__(self							:   List[Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[Any]=13			,  snake_case							:   Optional[Any]=7			,  snake_case							:   Optional[int]=True			,  snake_case							:   str=True			,  snake_case							:   Dict=True			,  snake_case							:   str=True			,  snake_case							:   int=99			,  snake_case							:   int=32			,  snake_case							:   Union[str, Any]=5			,  snake_case							:   Any=4			,  snake_case							:   Tuple=37			,  snake_case							:   Tuple="gelu"			,  snake_case							:   Tuple=0.1			,  snake_case							:   Optional[int]=0.1			,  snake_case							:   Optional[Any]=512			,  snake_case							:   Dict=16			,  snake_case							:   Optional[int]=2			,  snake_case							:   int=0.02			,  snake_case							:   int=3			,  snake_case							:   str=4			,  snake_case							:   Optional[Any]=None			,  )   -> List[Any]:
  							_lowercase					:  Dict    			=      parent
  							_lowercase					:  List[str]    			=      batch_size
  							_lowercase					:  int    			=      seq_length
  							_lowercase					:  Optional[Any]    			=      is_training
  							_lowercase					:  Tuple    			=      use_input_mask
  							_lowercase					:  Optional[int]    			=      use_token_type_ids
  							_lowercase					:  Optional[int]    			=      use_labels
  							_lowercase					:  List[Any]    			=      vocab_size
  							_lowercase					:  Union[str, Any]    			=      hidden_size
  							_lowercase					:  Dict    			=      num_hidden_layers
  							_lowercase					:  str    			=      num_attention_heads
  							_lowercase					:  int    			=      intermediate_size
  							_lowercase					:  Union[str, Any]    			=      hidden_act
  							_lowercase					:  Tuple    			=      hidden_dropout_prob
  							_lowercase					:  Union[str, Any]    			=      attention_probs_dropout_prob
  							_lowercase					:  Optional[Any]    			=      max_position_embeddings
  							_lowercase					:  str    			=      type_vocab_size
  							_lowercase					:  Dict    			=      type_sequence_label_size
  							_lowercase					:  List[Any]    			=      initializer_range
  							_lowercase					:  List[str]    			=      num_labels
  							_lowercase					:  Any    			=      num_choices
  							_lowercase					:  Any    			=      scope
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Tuple:
  							_lowercase					:  List[str]    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.vocab_size						)
  
  							_lowercase					:  Dict    			=      None
  							if self.use_input_mask:
  													_lowercase					:  List[str]    			=      random_attention_mask([self.batch_size, self.seq_length]						)
  
  							_lowercase					:  Optional[Any]    			=      None
  							if self.use_token_type_ids:
  													_lowercase					:  Tuple    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.type_vocab_size						)
  
  							_lowercase					:  str    			=      None
  							_lowercase					:  Optional[int]    			=      None
  							_lowercase					:  int    			=      None
  							if self.use_labels:
  													_lowercase					:  str    			=      ids_tensor([self.batch_size]			,  self.type_sequence_label_size						)
  													_lowercase					:  Any    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.num_labels						)
  													_lowercase					:  Any    			=      ids_tensor([self.batch_size]			,  self.num_choices						)
  													_lowercase					:  Optional[Any]    			=      ids_tensor([self.batch_size, self.seq_length]			,  1						)
  
  							_lowercase					:  Optional[Any]    			=      self.get_config()
  
  							return (
  							    config,
  							    input_ids,
  							    token_type_ids,
  							    input_mask,
  							    sequence_labels,
  							    token_labels,
  							    choice_labels,
  							    fake_token_labels,
  							)
  
  
  
  
  
  
  	def 			_a(self							:   int						)   -> Optional[Any]:
  							return ElectraConfig(
  							    vocab_size=self.vocab_size			,  hidden_size=self.hidden_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			,  is_decoder=snake_case			,  initializer_range=self.initializer_range			,  )
  
  
  
  
  
  
  	def 			_a(self							:   List[str]						)   -> Optional[Any]:
  							(
  							    (
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						
  							)					:  Any    			=      self.prepare_config_and_inputs()
  
  							_lowercase					:  Union[str, Any]    			=      True
  							_lowercase					:  Dict    			=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
  							_lowercase					:  Tuple    			=      ids_tensor([self.batch_size, self.seq_length]			,  vocab_size=2						)
  
  							return (
  							    config,
  							    input_ids,
  							    token_type_ids,
  							    input_mask,
  							    sequence_labels,
  							    token_labels,
  							    choice_labels,
  							    encoder_hidden_states,
  							    encoder_attention_mask,
  							)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  snake_case							:   List[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   Tuple			,  )   -> str:
  							_lowercase					:  Tuple    			=      ElectraModel(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  str    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case						)
  							_lowercase					:  Optional[Any]    			=      model(snake_case			,  token_type_ids=snake_case						)
  							_lowercase					:  Optional[int]    			=      model(snake_case						)
  							self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   List[str]			,  snake_case							:   int			,  snake_case							:   Dict			,  snake_case							:   Any			,  snake_case							:   int			,  snake_case							:   Optional[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   str			,  snake_case							:   Optional[Any]			,  snake_case							:   Optional[int]			,  )   -> Dict:
  							_lowercase					:  Tuple    			=      True
  							_lowercase					:  Optional[int]    			=      ElectraModel(snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  int    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  encoder_hidden_states=snake_case			,  encoder_attention_mask=snake_case			,  )
  							_lowercase					:  Optional[Any]    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  encoder_hidden_states=snake_case			,  )
  							_lowercase					:  int    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case						)
  							self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple			,  snake_case							:   int			,  snake_case							:   Tuple			,  snake_case							:   List[Any]			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   Optional[Any]			,  )   -> Any:
  							_lowercase					:  Dict    			=      ElectraForMaskedLM(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Optional[int]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[int]			,  snake_case							:   Any			,  snake_case							:   List[Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   List[str]			,  snake_case							:   Dict			,  snake_case							:   str			,  snake_case							:   str			,  )   -> Any:
  							_lowercase					:  int    			=      ElectraForCausalLM(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Union[str, Any]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Dict			,  snake_case							:   Union[str, Any]			,  snake_case							:   List[str]			,  snake_case							:   Any			,  snake_case							:   Dict			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[int]			,  )   -> Tuple:
  							_lowercase					:  List[Any]    			=      self.num_labels
  							_lowercase					:  Dict    			=      ElectraForTokenClassification(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Tuple    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.num_labels)						)
  
  
  
  
  
  
  	def 			_a(self							:   str			,  snake_case							:   Union[str, Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   str			,  snake_case							:   int			,  snake_case							:   int			,  snake_case							:   Union[str, Any]			,  )   -> Union[str, Any]:
  							_lowercase					:  List[Any]    			=      self.num_labels
  							_lowercase					:  int    			=      ElectraForPreTraining(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  List[str]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length)						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   Tuple			,  snake_case							:   Optional[int]			,  snake_case							:   str			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   Union[str, Any]			,  snake_case							:   Dict			,  )   -> List[Any]:
  							_lowercase					:  List[str]    			=      self.num_labels
  							_lowercase					:  Tuple    			=      ElectraForSequenceClassification(snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Any    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_labels)						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple			,  snake_case							:   Optional[int]			,  snake_case							:   List[Any]			,  snake_case							:   List[str]			,  snake_case							:   Any			,  snake_case							:   Optional[int]			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  )   -> str:
  							_lowercase					:  int    			=      ElectraForQuestionAnswering(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Tuple    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  start_positions=snake_case			,  end_positions=snake_case			,  )
  							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 			_a(self							:   Dict			,  snake_case							:   str			,  snake_case							:   Dict			,  snake_case							:   Any			,  snake_case							:   Tuple			,  snake_case							:   str			,  snake_case							:   Optional[Any]			,  snake_case							:   str			,  snake_case							:   Tuple			,  )   -> Union[str, Any]:
  							_lowercase					:  List[Any]    			=      self.num_choices
  							_lowercase					:  Optional[Any]    			=      ElectraForMultipleChoice(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  str    			=      input_ids.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Dict    			=      token_type_ids.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Optional[Any]    			=      input_mask.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Optional[int]    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case			,  )
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_choices)						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]						)   -> Union[str, Any]:
  							_lowercase					:  Any    			=      self.prepare_config_and_inputs()
  							(
  							    (
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						
  							)					:  Optional[int]    			=      config_and_inputs
  							_lowercase					:  Optional[Any]    			=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
  							return config, inputs_dict
  
  
  
  
  @require_torch
  class      __lowercase	(	__snake_case      ,   __snake_case      ,   unittest.TestCase					):
  	_A   			=      (
  	    (
  	        ElectraModel,
  	        ElectraForPreTraining,
  	        ElectraForMaskedLM,
  	        ElectraForCausalLM,
  	        ElectraForMultipleChoice,
  	        ElectraForTokenClassification,
  	        ElectraForSequenceClassification,
  	        ElectraForQuestionAnswering,
  	    )
  	    if is_torch_available()
  	    else ()
  	)
  	_A   			=      (
  	    {
  	        "feature-extraction": ElectraModel,
  	        "fill-mask": ElectraForMaskedLM,
  	        "question-answering": ElectraForQuestionAnswering,
  	        "text-classification": ElectraForSequenceClassification,
  	        "text-generation": ElectraForCausalLM,
  	        "token-classification": ElectraForTokenClassification,
  	        "zero-shot": ElectraForSequenceClassification,
  	    }
  	    if is_torch_available()
  	    else {}
  	)
  	_A   			=      True
  
  
  
  
  
  
  	def 			_a(self							:   Union[str, Any]			,  snake_case							:   Any			,  snake_case							:   List[Any]			,  snake_case							:   Any=False						)   -> Optional[int]:
  							_lowercase					:  Any    			=      super()._prepare_for_class(snake_case			,  snake_case			,  return_labels=snake_case						)
  
  							if return_labels:
  													if model_class in get_values(snake_case						):
  																			_lowercase					:  List[str]    			=      torch.zeros(
  																			    (self.model_tester.batch_size, self.model_tester.seq_length)			,  dtype=torch.long			,  device=snake_case						)
  							return inputs_dict
  
  
  
  
  
  
  	def 			_a(self							:   List[str]						)   -> List[Any]:
  							_lowercase					:  Tuple    			=      ElectraModelTester(self						)
  							_lowercase					:  int    			=      ConfigTester(self			,  config_class=snake_case			,  hidden_size=37						)
  
  
  
  
  
  
  	def 			_a(self							:   int						)   -> Any:
  							self.config_tester.run_common_tests()
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]						)   -> str:
  							_lowercase					:  List[str]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_model(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]						)   -> str:
  							_lowercase					:  Union[str, Any]    			=      self.model_tester.prepare_config_and_inputs_for_decoder()
  							self.model_tester.create_and_check_electra_model_as_decoder(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Dict:
  							_lowercase					:  str    			=      self.model_tester.prepare_config_and_inputs()
  							for type in ["absolute", "relative_key", "relative_key_query"]:
  													_lowercase					:  List[Any]    			=      type
  													self.model_tester.create_and_check_electra_model(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[int]						)   -> str:
  							_lowercase					:  int    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_masked_lm(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   str						)   -> Dict:
  							_lowercase					:  Optional[Any]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_token_classification(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Dict						)   -> Optional[Any]:
  							_lowercase					:  Any    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_pretraining(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Union[str, Any]						)   -> Optional[int]:
  							_lowercase					:  Dict    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Any						)   -> Dict:
  							_lowercase					:  Any    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_question_answering(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Tuple:
  							_lowercase					:  Union[str, Any]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case						)
  
  
  
  
  
  
  	@slow
  	def 			_a(self							:   List[str]						)   -> List[Any]:
  							for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  													_lowercase					:  Optional[int]    			=      ElectraModel.from_pretrained(snake_case						)
  													self.assertIsNotNone(snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]						)   -> List[Any]:
  							_lowercase					:  int    			=      self.model_tester.prepare_config_and_inputs_for_decoder()
  							self.model_tester.create_and_check_electra_for_causal_lm(*snake_case						)
  
  
  
  
  @require_torch
  class      __lowercase	(	unittest.TestCase					):
  
  
  
  
  
  
  	@slow
  	def 			_a(self							:   str						)   -> Optional[int]:
  							_lowercase					:  int    			=      ElectraModel.from_pretrained("google/electra-small-discriminator"						)
  							_lowercase					:  Dict    			=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]						)
  							_lowercase					:  Union[str, Any]    			=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
  							_lowercase					:  Optional[Any]    			=      model(snake_case			,  attention_mask=snake_case						)[0]
  							_lowercase					:  Union[str, Any]    			=      torch.Size((1, 11, 256)						)
  							self.assertEqual(output.shape			,  snake_case						)
  							_lowercase					:  List[Any]    			=      torch.tensor(
  							    [[[0.44_71, 0.68_21, -0.32_65], [0.46_27, 0.52_55, -0.36_68], [0.45_32, 0.33_13, -0.43_44]]]						)
  
  							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,  snake_case			,  atol=1e-4						)						)
  
  
  
  
  