




import argparse
import json
import re
import string
import sys
from collections import Counter






def 					snake_case					(							A			)							->							int:




	'''simple docstring'''


	def remove_articles(A			):
		return re.sub(R'\b(a|an|the)\b'						,   ' '						,   A			)

	def white_space_fix(A			):
		return " ".join(text.split()			)

	def remove_punc(A			):
		lowerCamelCase_							:		str							   =							set(string.punctuation			)
		return "".join(ch for ch in text if ch not in exclude			)

	def lower(A			):
		return text.lower()

	return white_space_fix(remove_articles(remove_punc(lower(A			)			)			)			)






def 					snake_case					(							A						,   A			)							->							int:




	'''simple docstring'''


	lowerCamelCase_							:		Any							   =							normalize_answer(A			).split()
	lowerCamelCase_							:		Any							   =							normalize_answer(A			).split()
	lowerCamelCase_							:		str							   =							Counter(A			) & Counter(A			)
	lowerCamelCase_							:		Optional[int]							   =							sum(common.values()			)
	if num_same == 0:
		return 0
	lowerCamelCase_							:		Union[str, Any]							   =							1.0 * num_same / len(A			)
	lowerCamelCase_							:		Optional[int]							   =							1.0 * num_same / len(A			)
	lowerCamelCase_							:		int							   =							(2 * precision * recall) / (precision + recall)
	return fa






def 					snake_case					(							A						,   A			)							->							int:




	'''simple docstring'''


	return normalize_answer(A			) == normalize_answer(A			)






def 					snake_case					(							A						,   A						,   A			)							->							int:




	'''simple docstring'''


	lowerCamelCase_							:		List[Any]							   =							[]
	for ground_truth in ground_truths:
		lowerCamelCase_							:		str							   =							metric_fn(A						,   A			)
		scores_for_ground_truths.append(A			)
	return max(A			)






def 					snake_case					(							A						,   A			)							->							Dict:




	'''simple docstring'''


	lowerCamelCase_							:		List[Any]							   =							0
	for article in dataset:
		for paragraph in article["paragraphs"]:
			for qa in paragraph["qas"]:
				total += 1
				if qa["id"] not in predictions:
					lowerCamelCase_							:		int							   =							'Unanswered question ' + qa['id'] + ' will receive score 0.'
					print(A						,   file=sys.stderr			)
					continue
				lowerCamelCase_							:		Dict							   =							[x['text'] for x in qa['answers']]
				lowerCamelCase_							:		str							   =							predictions[qa['id']]
				exact_match += metric_max_over_ground_truths(A						,   A						,   A			)
				fa += metric_max_over_ground_truths(A						,   A						,   A			)

	lowerCamelCase_							:		str							   =							100.0 * exact_match / total
	lowerCamelCase_							:		int							   =							100.0 * fa / total

	return {"exact_match": exact_match, "f1": fa}


if __name__ == "__main__":
							UpperCamelCase__              =						'1.1'
							UpperCamelCase__              =						argparse.ArgumentParser(description='Evaluation for SQuAD ' + expected_version)
							parser.add_argument('dataset_file', help='Dataset file')
							parser.add_argument('prediction_file', help='Prediction File')
							UpperCamelCase__              =						parser.parse_args()
							with open(args.dataset_file) as dataset_file:
														UpperCamelCase__              =						json.load(dataset_file)
														if dataset_json["version"] != expected_version:
																					print(
																					    'Evaluation expects v-' + expected_version + ', but got dataset with v-' + dataset_json['version'],
																					    file=sys.stderr,
																					)
														UpperCamelCase__              =						dataset_json['data']
							with open(args.prediction_file) as prediction_file:
														UpperCamelCase__              =						json.load(prediction_file)
							print(json.dumps(evaluate(dataset, predictions)))






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 				__SCREAMING_SNAKE_CASE							(		unittest.TestCase  ):

					def __init__(				self ,       __lowercase ,       __lowercase=13 ,       __lowercase=7 ,       __lowercase=True ,       __lowercase=True ,       __lowercase=True ,       __lowercase=True ,       __lowercase=99 ,       __lowercase=24 ,       __lowercase=32 ,       __lowercase=5 ,       __lowercase=4 ,       __lowercase=37 ,       __lowercase="gelu" ,       __lowercase=0.1 ,       __lowercase=0.1 ,       __lowercase=512 ,       __lowercase=16 ,       __lowercase=2 ,       __lowercase=0.02 ,       __lowercase=4 ,       ):







						'''simple docstring'''




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

					def 	lowercase_							(				self					):







						'''simple docstring'''




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

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

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

						lowerCamelCase_							:		List[str]							   =							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 	lowercase_							(				self					):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							   =							self.prepare_config_and_inputs()
						lowerCamelCase_   ,			lowerCamelCase_   ,			lowerCamelCase_   ,			lowerCamelCase_							:		Tuple							   =							config_and_inputs
						lowerCamelCase_							:		Union[str, Any]							   =							{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
						return config, inputs_dict


@require_flax
class 				__SCREAMING_SNAKE_CASE							(		lowerCamelCase   ,     unittest.TestCase  ):
					_lowerCamelCase		  = True

					_lowerCamelCase		  = (
					    (
					        FlaxElectraModel,
					        FlaxElectraForCausalLM,
					        FlaxElectraForMaskedLM,
					        FlaxElectraForPreTraining,
					        FlaxElectraForTokenClassification,
					        FlaxElectraForQuestionAnswering,
					        FlaxElectraForMultipleChoice,
					        FlaxElectraForSequenceClassification,
					    )
					    if is_flax_available()
					    else ()
					)

					def 	lowercase_							(				self					):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							   =							FlaxElectraModelTester(self					)





					@slow
					def 	lowercase_							(				self					):







						'''simple docstring'''




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