




'''simple docstring'''







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






def 		_lowercase		(     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_  ):
				_snake_case     	=	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 		_lowercase		(     lowercase_						,							lowercase_  ):



		'''simple docstring'''







		_snake_case     	=	normalize_answer(lowercase_  ).split()
		_snake_case     	=	normalize_answer(lowercase_  ).split()
		_snake_case     	=	Counter(lowercase_  ) & Counter(lowercase_  )
		_snake_case     	=	sum(common.values()  )
		if num_same == 0:
				return 0
		_snake_case     	=	1.0 * num_same / len(lowercase_  )
		_snake_case     	=	1.0 * num_same / len(lowercase_  )
		_snake_case     	=	(2 * precision * recall) / (precision + recall)
		return fa






def 		_lowercase		(     lowercase_						,							lowercase_  ):



		'''simple docstring'''







		return normalize_answer(lowercase_  ) == normalize_answer(lowercase_  )






def 		_lowercase		(     lowercase_						,							lowercase_						,							lowercase_  ):



		'''simple docstring'''







		_snake_case     	=	[]
		for ground_truth in ground_truths:
				_snake_case     	=	metric_fn(lowercase_						,							lowercase_  )
				scores_for_ground_truths.append(lowercase_  )
		return max(lowercase_  )






def 		_lowercase		(     lowercase_						,							lowercase_  ):



		'''simple docstring'''







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

		_snake_case     	=	100.0 * exact_match / total
		_snake_case     	=	100.0 * fa / total

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


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











'''simple docstring'''







import os
import tempfile
import unittest
from typing import List

from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
from transformers.testing_utils import require_tokenizers
from transformers.tokenization_utils import PreTrainedTokenizer
from transformers.tokenization_utils_base import PreTrainedTokenizerBase





@require_tokenizers
class 					lowerCamelCase_							(	unittest.TestCase							):




					'''simple docstring'''






					lowercase__   =			EsmTokenizer






					def     __SCREAMING_SNAKE_CASE     (   self			):
							super().setUp()
							_snake_case     	=	tempfile.mkdtemp()
							# fmt: off
							_snake_case     	=	["<cls>", "<pad>", "<eos>", "<unk>", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "<null_1>", "<mask>"]  # noqa: E501
							# fmt: on
							_snake_case     	=	os.path.join(self.tmpdirname,  VOCAB_FILES_NAMES["vocab_file"]			)
							with open(self.vocab_file,  "w",  encoding="utf-8"			) as vocab_writer:
									vocab_writer.write("".join([x + "\n" for x in vocab_tokens]			)			)






					def     __SCREAMING_SNAKE_CASE     (   self,  **__UpperCamelCase			):
							return [self.get_tokenizer(**__UpperCamelCase			)]






					def     __SCREAMING_SNAKE_CASE     (   self,  **__UpperCamelCase			):
							return self.tokenizer_class.from_pretrained(self.tmpdirname,  **__UpperCamelCase			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	tokenizer.tokenize("LAGVS"			)
							self.assertListEqual(__UpperCamelCase,  ["L", "A", "G", "V", "S"]			)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCamelCase			),  [4, 5, 6, 7, 8]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	"LAGVS"
							self.assertListEqual(tokenizer.encode(__UpperCamelCase			),  [0, 4, 5, 6, 7, 8, 2]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	["LAGVS", "WCB"]
							_snake_case     	=	tokenizer(__UpperCamelCase,  padding=__UpperCamelCase			)["input_ids"]

							self.assertListEqual(__UpperCamelCase,  [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2]]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.tokenizer_class(self.vocab_file			)

							_snake_case     	=	["LAGVS", "WCB"]
							_snake_case     	=	tokenizer(__UpperCamelCase,  padding=__UpperCamelCase			)["input_ids"]

							self.assertListEqual(__UpperCamelCase,  [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2, 1, 1]]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.get_tokenizers(fast=__UpperCamelCase			)
							for tokenizer in tokenizers:
									with self.subTest(f'''{tokenizer.__class__.__name__}'''			):
											_snake_case     	=	"<unk>"
											_snake_case     	=	"<mask>"

											_snake_case     	=	tokenizer.tokenize(__UpperCamelCase			)
											_snake_case     	=	tokenizer.tokenize(__UpperCamelCase			)

											self.assertEqual(len(__UpperCamelCase			),  1			)
											self.assertEqual(len(__UpperCamelCase			),  1			)
											self.assertEqual(token_a[0],  __UpperCamelCase			)
											self.assertEqual(token_a[0],  __UpperCamelCase			)





