
'''simple docstring'''





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





def 							snake_case				(		UpperCAmelCase						)->      Optional[Any]:







      """simple docstring"""

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

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

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

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

      return white_space_fix(remove_articles(remove_punc(lower(UpperCAmelCase						)						)						)						)





def 							snake_case				(		UpperCAmelCase   ,	UpperCAmelCase						)->      Union[str, Any]:







      """simple docstring"""
      __A													=      normalize_answer(UpperCAmelCase						).split()
      __A													=      normalize_answer(UpperCAmelCase						).split()
      __A													=      Counter(UpperCAmelCase						) & Counter(UpperCAmelCase						)
      __A													=      sum(common.values()						)
      if num_same == 0:
            return 0
      __A													=      1.0 * num_same / len(UpperCAmelCase						)
      __A													=      1.0 * num_same / len(UpperCAmelCase						)
      __A													=      (2 * precision * recall) / (precision + recall)
      return fa





def 							snake_case				(		UpperCAmelCase   ,	UpperCAmelCase						)->      Tuple:







      """simple docstring"""
      return normalize_answer(UpperCAmelCase						) == normalize_answer(UpperCAmelCase						)





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







      """simple docstring"""
      __A													=      []
      for ground_truth in ground_truths:
            __A													=      metric_fn(UpperCAmelCase   ,	UpperCAmelCase						)
            scores_for_ground_truths.append(UpperCAmelCase						)
      return max(UpperCAmelCase						)





def 							snake_case				(		UpperCAmelCase   ,	UpperCAmelCase						)->      Optional[Any]:







      """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(UpperCAmelCase   ,	file=sys.stderr						)
                              continue
                        __A													=      [x['text'] for x in qa['answers']]
                        __A													=      predictions[qa['id']]
                        exact_match += metric_max_over_ground_truths(UpperCAmelCase   ,	UpperCAmelCase   ,	UpperCAmelCase						)
                        fa += metric_max_over_ground_truths(UpperCAmelCase   ,	UpperCAmelCase   ,	UpperCAmelCase						)

      __A													=      100.0 * exact_match / total
      __A													=      100.0 * fa / total

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


if __name__ == "__main__":
 a__		: Dict  							=							"1.1"
 a__		: List[Any]  							=							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__		: List[str]  							=							parser.parse_args()
 with open(args.dataset_file) as dataset_file:
  a__		: Tuple  							=							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__		: Optional[Any]  							=							dataset_json["data"]
 with open(args.prediction_file) as prediction_file:
  a__		: List[Any]  							=							json.load(prediction_file)
 print(json.dumps(evaluate(dataset, predictions)))








'''simple docstring'''





import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

a__		: Tuple  							=							[(1,)]





def 							snake_case				(		)->      Union[str, Any]:







      """simple docstring"""
      __A													=      bool(os.getenv('RUN_SLOW'   ,	0						)						)
      if run_slow:
            assert True
      else:
            assert False, "should have been skipped"





def 							snake_case				(		)->      Tuple:







      """simple docstring"""
      __A													=      bool(os.getenv('RUN_SLOW'   ,	0						)						)
      if run_slow and torch_device == "cuda":
            assert True
      else:
            assert False, "should have been skipped"


@require_torch
class 			UpperCamelCase__	(     unittest.TestCase):






 @slow
 @require_torch_gpu
 def 						lowercase_    (      self	:Dict      )					->      List[Any]:







       '''simple docstring'''



       check_slow_torch_cuda()






 @require_torch_gpu
 @slow
 def 						lowercase_    (      self	:int      )					->      int:







       '''simple docstring'''



       check_slow_torch_cuda()






 @parameterized.expand(_A      )
 @slow
 def 						lowercase_    (      self	:Dict						,					_A	:Union[str, Any]=None      )					->      Dict:







       '''simple docstring'''



       check_slow()





@slow
@require_torch_gpu
def 							snake_case				(		)->      Optional[int]:







      """simple docstring"""
      check_slow_torch_cuda()





@require_torch_gpu
@slow
def 							snake_case				(		)->      List[str]:







      """simple docstring"""
      check_slow_torch_cuda()





@slow
@pytest.mark.parametrize('param'   ,	[1]						)
def 							snake_case				(		UpperCAmelCase						)->      int:







      """simple docstring"""
      check_slow()





@pytest.mark.parametrize('param'   ,	[1]						)
@slow
def 							snake_case				(		UpperCAmelCase						)->      Any:







      """simple docstring"""
      check_slow()






