code: 
  
  
  
  
  
  
  import argparse
  import json
  import re
  import string
  import sys
  from collections import Counter
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			Union[str, Any] ):
  
  				def remove_articles(SCREAMING_SNAKE_CASE__						:			Optional[Any] ):
  								return re.sub(R'''\b(a|an|the)\b'''  ,						''' '''  ,						SCREAMING_SNAKE_CASE__ )
  
  				def white_space_fix(SCREAMING_SNAKE_CASE__						:			str ):
  								return " ".join(text.split() )
  
  				def remove_punc(SCREAMING_SNAKE_CASE__						:			Union[str, Any] ):
  								UpperCamelCase :Dict										=     set(string.punctuation )
  								return "".join(ch for ch in text if ch not in exclude )
  
  				def lower(SCREAMING_SNAKE_CASE__						:			str ):
  								return text.lower()
  
  				return white_space_fix(remove_articles(remove_punc(lower(SCREAMING_SNAKE_CASE__ ) ) ) )
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			int  ,						SCREAMING_SNAKE_CASE__						:			Any ):
  				UpperCamelCase :str										=     normalize_answer(SCREAMING_SNAKE_CASE__ ).split()
  				UpperCamelCase :List[Any]										=     normalize_answer(SCREAMING_SNAKE_CASE__ ).split()
  				UpperCamelCase :List[Any]										=     Counter(SCREAMING_SNAKE_CASE__ ) & Counter(SCREAMING_SNAKE_CASE__ )
  				UpperCamelCase :Optional[Any]										=     sum(common.values() )
  				if num_same == 0:
  								return 0
  				UpperCamelCase :List[Any]										=     1.0 * num_same / len(SCREAMING_SNAKE_CASE__ )
  				UpperCamelCase :List[Any]										=     1.0 * num_same / len(SCREAMING_SNAKE_CASE__ )
  				UpperCamelCase :List[Any]										=     (2 * precision * recall) / (precision + recall)
  				return fa
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			Union[str, Any]  ,						SCREAMING_SNAKE_CASE__						:			str ):
  				return normalize_answer(SCREAMING_SNAKE_CASE__ ) == normalize_answer(SCREAMING_SNAKE_CASE__ )
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			int  ,						SCREAMING_SNAKE_CASE__						:			int  ,						SCREAMING_SNAKE_CASE__						:			List[Any] ):
  				UpperCamelCase :Dict										=     []
  				for ground_truth in ground_truths:
  								UpperCamelCase :int										=     metric_fn(SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__ )
  								scores_for_ground_truths.append(SCREAMING_SNAKE_CASE__ )
  				return max(SCREAMING_SNAKE_CASE__ )
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			Union[str, Any]  ,						SCREAMING_SNAKE_CASE__						:			Any ):
  				UpperCamelCase :Dict										=     0
  				UpperCamelCase :Dict										=     []
  				for passage in dataset:
  								for qa in passage["qas"]:
  												total += 1
  												if qa["id"] not in predictions:
  																UpperCamelCase :int										=     F'''Unanswered question {qa["id"]} will receive score 0.'''
  																print(SCREAMING_SNAKE_CASE__  ,						file=sys.stderr )
  																continue
  
  												UpperCamelCase :List[str]										=     [x['''text'''] for x in qa['''answers''']]
  												UpperCamelCase :int										=     predictions[qa['''id''']]
  
  												UpperCamelCase :List[str]										=     metric_max_over_ground_truths(SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__ )
  												if int(_exact_match ) == 1:
  																correct_ids.append(qa['''id'''] )
  												exact_match += _exact_match
  
  												fa += metric_max_over_ground_truths(SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__ )
  
  				UpperCamelCase :Optional[Any]										=     exact_match / total
  				UpperCamelCase :int										=     fa / total
  
  				return {"exact_match": exact_match, "f1": fa}, correct_ids
  
  
  if __name__ == "__main__":
  	__snake_case							      =						"""1.0"""
  	__snake_case							      =						argparse.ArgumentParser("""Official evaluation script for ReCoRD v1.0.""")
  	parser.add_argument("""data_file""", help="""The dataset file in JSON format.""")
  	parser.add_argument("""pred_file""", help="""The model prediction file in JSON format.""")
  	parser.add_argument("""--output_correct_ids""", action="""store_true""", help="""Output the correctly answered query IDs.""")
  	__snake_case							      =						parser.parse_args()
  
  	with open(args.data_file) as data_file:
  		__snake_case							      =						json.load(data_file)
  		if dataset_json["version"] != expected_version:
  			print(
  			    f'''Evaluation expects v-{expected_version}, but got dataset with v-{dataset_json["version"]}''',
  			    file=sys.stderr,
  			)
  		__snake_case							      =						dataset_json["""data"""]
  
  	with open(args.pred_file) as pred_file:
  		__snake_case							      =						json.load(pred_file)
  
  	__snake_case      ,   __snake_case							      =						evaluate(dataset, predictions)
  
  	if args.output_correct_ids:
  		print(f'''Output {len(correct_ids)} correctly answered question IDs.''')
  		with open("""correct_ids.json""", """w""") as f:
  			json.dump(correct_ids, f)
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
        """simple docstring"""
        def __init__(       self					,       SCREAMING_SNAKE_CASE_				)       ->   None:
            UpperCamelCase :Tuple										=     value
            UpperCamelCase :Node | None										=     None
            UpperCamelCase :Node | None										=     None
  
  
  
  
  
  
  
  class     UpperCAmelCase_		:
  
  
  
        """simple docstring"""
        UpperCamelCase_       :      int
        def __init__(       self				)       ->   None:
            UpperCamelCase :List[Any]										=     0
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)       ->   None:
            if node is None:
                return
  
            if path_sum == self.target:
                self.paths += 1
  
            if node.left:
                self.depth_first_search(node.left					,       path_sum + node.left.value				)
            if node.right:
                self.depth_first_search(node.right					,       path_sum + node.right.value				)
  
  
  
  
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_ = None				)       ->   int:
            if node is None:
                return 0
            if target is not None:
                UpperCamelCase :Tuple										=     target
  
            self.depth_first_search(SCREAMING_SNAKE_CASE_					,       node.value				)
            self.path_sum(node.left				)
            self.path_sum(node.right				)
  
            return self.paths
  
  
  if __name__ == "__main__":
   import doctest
  
   doctest.testmod()
  
  
  
  
  
  