



import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
					from transformers.models.electra.modeling_flax_electra import (
					    FlaxElectraForCausalLM,
					    FlaxElectraForMaskedLM,
					    FlaxElectraForMultipleChoice,
					    FlaxElectraForPreTraining,
					    FlaxElectraForQuestionAnswering,
					    FlaxElectraForSequenceClassification,
					    FlaxElectraForTokenClassification,
					    FlaxElectraModel,
					)





class 							lowerCAmelCase_		(		unittest.TestCase     ):







		def __init__(    self  :   Any       ,		UpperCAmelCase_  :   Any       ,		UpperCAmelCase_  :   Tuple=13       ,		UpperCAmelCase_  :   int=7       ,		UpperCAmelCase_  :   Optional[Any]=True       ,		UpperCAmelCase_  :   List[str]=True       ,		UpperCAmelCase_  :   Union[str, Any]=True       ,		UpperCAmelCase_  :   Any=True       ,		UpperCAmelCase_  :   Tuple=99       ,		UpperCAmelCase_  :   Optional[int]=24       ,		UpperCAmelCase_  :   str=32       ,		UpperCAmelCase_  :   Optional[int]=5       ,		UpperCAmelCase_  :   Optional[Any]=4       ,		UpperCAmelCase_  :   Dict=37       ,		UpperCAmelCase_  :   List[str]="gelu"       ,		UpperCAmelCase_  :   Tuple=0.1       ,		UpperCAmelCase_  :   str=0.1       ,		UpperCAmelCase_  :   str=512       ,		UpperCAmelCase_  :   str=16       ,		UpperCAmelCase_  :   str=2       ,		UpperCAmelCase_  :   List[Any]=0.02       ,		UpperCAmelCase_  :   List[str]=4       ,		)       ->		Optional[Any]:


						'''simple docstring'''







						_UpperCAmelCase						:  Dict     					=	parent
						_UpperCAmelCase						:  str     					=	batch_size
						_UpperCAmelCase						:  str     					=	seq_length
						_UpperCAmelCase						:  Optional[int]     					=	is_training
						_UpperCAmelCase						:  str     					=	use_attention_mask
						_UpperCAmelCase						:  Union[str, Any]     					=	use_token_type_ids
						_UpperCAmelCase						:  Optional[Any]     					=	use_labels
						_UpperCAmelCase						:  int     					=	vocab_size
						_UpperCAmelCase						:  List[str]     					=	hidden_size
						_UpperCAmelCase						:  int     					=	embedding_size
						_UpperCAmelCase						:  Optional[int]     					=	num_hidden_layers
						_UpperCAmelCase						:  List[str]     					=	num_attention_heads
						_UpperCAmelCase						:  Optional[Any]     					=	intermediate_size
						_UpperCAmelCase						:  Any     					=	hidden_act
						_UpperCAmelCase						:  Optional[int]     					=	hidden_dropout_prob
						_UpperCAmelCase						:  Dict     					=	attention_probs_dropout_prob
						_UpperCAmelCase						:  Any     					=	max_position_embeddings
						_UpperCAmelCase						:  Tuple     					=	type_vocab_size
						_UpperCAmelCase						:  Optional[Any]     					=	type_sequence_label_size
						_UpperCAmelCase						:  List[Any]     					=	initializer_range
						_UpperCAmelCase						:  Any     					=	num_choices







		def 					a_  (    self  :   Optional[int]					)       ->		Optional[Any]:


						'''simple docstring'''







						_UpperCAmelCase						:  Optional[int]     					=	ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size					)

						_UpperCAmelCase						:  int     					=	None
						if self.use_attention_mask:
										_UpperCAmelCase						:  List[Any]     					=	random_attention_mask([self.batch_size, self.seq_length]					)

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

						_UpperCAmelCase						:  Optional[int]     					=	ElectraConfig(
						    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, attention_mask







		def 					a_  (    self  :   Tuple					)       ->		str:


						'''simple docstring'''







						_UpperCAmelCase						:  List[str]     					=	self.prepare_config_and_inputs()
						_UpperCAmelCase						:  Tuple     					=	config_and_inputs
						_UpperCAmelCase						:  int     					=	{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
						return config, inputs_dict





@require_flax
class 							lowerCAmelCase_		(		UpperCAmelCase__							,		unittest.TestCase     ):
		SCREAMING_SNAKE_CASE_       :			str					       =	True

		SCREAMING_SNAKE_CASE_       :			Tuple					       =	(
		    (
		        FlaxElectraModel,
		        FlaxElectraForCausalLM,
		        FlaxElectraForMaskedLM,
		        FlaxElectraForPreTraining,
		        FlaxElectraForTokenClassification,
		        FlaxElectraForQuestionAnswering,
		        FlaxElectraForMultipleChoice,
		        FlaxElectraForSequenceClassification,
		    )
		    if is_flax_available()
		    else ()
		)







		def 					a_  (    self  :   Optional[int]					)       ->		Optional[int]:


						'''simple docstring'''







						_UpperCAmelCase						:  Dict     					=	FlaxElectraModelTester(self					)







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


						'''simple docstring'''







						for model_class_name in self.all_model_classes:
										if model_class_name == FlaxElectraForMaskedLM:
														_UpperCAmelCase						:  Dict     					=	model_class_name.from_pretrained('''google/electra-small-generator'''					)
										else:
														_UpperCAmelCase						:  Optional[Any]     					=	model_class_name.from_pretrained('''google/electra-small-discriminator'''					)
										_UpperCAmelCase						:  str     					=	model(np.ones((1, 1)					)					)
										self.assertIsNotNone(__lowercase					)




import numpy as np

_UpperCAmelCase      :	int  =[
    ["""a""", """b""", """c""", """d""", """e"""],
    ["""f""", """g""", """h""", """i""", """k"""],
    ["""l""", """m""", """n""", """o""", """p"""],
    ["""q""", """r""", """s""", """t""", """u"""],
    ["""v""", """w""", """x""", """y""", """z"""],
]







class 					snake_case__:







						'''simple docstring'''




						def __init__(					self				)       ->     None:
										lowerCAmelCase_			:   List[Any]     					=					np.array(__lowercase				)




						def     lowercase_			(					self ,    __lowercase				)       ->     np.ndarray:
										lowerCAmelCase_					,	lowerCAmelCase_			:   List[str]     					=					np.where(letter == self.SQUARE				)
										lowerCAmelCase_			:   Union[str, Any]     					=					np.concatenate([indexa + 1, indexa + 1]				)
										return indexes




						def     lowercase_			(					self ,    __lowercase ,    __lowercase				)       ->     str:
										return self.SQUARE[indexa - 1, indexa - 1]




						def     lowercase_			(					self ,    __lowercase				)       ->     str:
										lowerCAmelCase_			:   Dict     					=					message.lower()
										lowerCAmelCase_			:   Any     					=					message.replace('''j''' ,    '''i'''				)

										lowerCAmelCase_			:   Optional[Any]     					=					''''''
										for letter_index in range(len(__lowercase				)				):
														if message[letter_index] != " ":
																		lowerCAmelCase_			:   Optional[Any]     					=					self.letter_to_numbers(message[letter_index]				)
																		lowerCAmelCase_			:   List[Any]     					=					encoded_message + str(numbers[0]				) + str(numbers[1]				)
														elif message[letter_index] == " ":
																		lowerCAmelCase_			:   Optional[Any]     					=					encoded_message + ''' '''

										return encoded_message




						def     lowercase_			(					self ,    __lowercase				)       ->     str:
										lowerCAmelCase_			:   List[str]     					=					message.replace(''' ''' ,    '''  '''				)
										lowerCAmelCase_			:   Union[str, Any]     					=					''''''
										for numbers_index in range(int(len(__lowercase				) / 2				)				):
														if message[numbers_index * 2] != " ":
																		lowerCAmelCase_			:   Any     					=					message[numbers_index * 2]
																		lowerCAmelCase_			:   Dict     					=					message[numbers_index * 2 + 1]

																		lowerCAmelCase_			:   Dict     					=					self.numbers_to_letter(int(__lowercase				) ,    int(__lowercase				)				)
																		lowerCAmelCase_			:   Tuple     					=					decoded_message + letter
														elif message[numbers_index * 2] == " ":
																		lowerCAmelCase_			:   List[str]     					=					decoded_message + ''' '''

										return decoded_message