

"""simple docstring"""




import argparse
import json
import re
import string
import sys
from collections import Counter
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""

					def remove_articles(lowercase__ ):
										return re.sub(r"\b(a|an|the)\b"     ,				" "     ,				lowercase__ )

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

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

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

					return white_space_fix(remove_articles(remove_punc(lower(lowercase__ ) ) ) )
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					A     =   normalize_answer(lowercase__ ).split()
					A     =   normalize_answer(lowercase__ ).split()
					A     =   Counter(lowercase__ ) & Counter(lowercase__ )
					A     =   sum(common.values() )
					if num_same == 0:
										return 0
					A     =   1.0 * num_same / len(lowercase__ )
					A     =   1.0 * num_same / len(lowercase__ )
					A     =   (2 * precision * recall) / (precision + recall)
					return fa
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					return normalize_answer(lowercase__ ) == normalize_answer(lowercase__ )
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					A     =   []
					for ground_truth in ground_truths:
										A     =   metric_fn(lowercase__     ,				lowercase__ )
										scores_for_ground_truths.append(lowercase__ )
					return max(lowercase__ )
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					A     =   A     =   A     =   0
					for article in dataset:
										for paragraph in article["paragraphs"]:
															for qa in paragraph["qas"]:
																				total += 1
																				if qa["id"] not in predictions:
																									A     =   "Unanswered question " + qa["id"] + " will receive score 0."
																									print(lowercase__     ,				file=sys.stderr )
																									continue
																				A     =   [x["text"] for x in qa["answers"]]
																				A     =   predictions[qa["id"]]
																				exact_match += metric_max_over_ground_truths(lowercase__     ,				lowercase__     ,				lowercase__ )
																				fa += metric_max_over_ground_truths(lowercase__     ,				lowercase__     ,				lowercase__ )

					A     =   1_00.0 * exact_match / total
					A     =   1_00.0 * fa / total

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


if __name__ == "__main__":
	__A	:       Union[str, Any]        =						'1.1'
	__A	:       List[str]        =						argparse.ArgumentParser(description='Evaluation for SQuAD ' + expected_version)
	parser.add_argument('dataset_file', help='Dataset file')
	parser.add_argument('prediction_file', help='Prediction File')
	__A	:       int        =						parser.parse_args()
	with open(args.dataset_file) as dataset_file:
		__A	:       Optional[Any]        =						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,
			)
		__A	:       int        =						dataset_json['data']
	with open(args.prediction_file) as prediction_file:
		__A	:       Union[str, Any]        =						json.load(prediction_file)
	print(json.dumps(evaluate(dataset, predictions)))













'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_A      :     Optional[int]       	={'''configuration_visual_bert''': ['''VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''VisualBertConfig''']}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A      :     Optional[int]       	=[
			    '''VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''VisualBertForMultipleChoice''',
			    '''VisualBertForPreTraining''',
			    '''VisualBertForQuestionAnswering''',
			    '''VisualBertForRegionToPhraseAlignment''',
			    '''VisualBertForVisualReasoning''',
			    '''VisualBertLayer''',
			    '''VisualBertModel''',
			    '''VisualBertPreTrainedModel''',
			]


if TYPE_CHECKING:
			from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_visual_bert import (
						    VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    VisualBertForMultipleChoice,
						    VisualBertForPreTraining,
						    VisualBertForQuestionAnswering,
						    VisualBertForRegionToPhraseAlignment,
						    VisualBertForVisualReasoning,
						    VisualBertLayer,
						    VisualBertModel,
						    VisualBertPreTrainedModel,
						)


else:
			import sys

			_A      :     int       	=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

