

'''simple docstring'''






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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Union[str, Any]    )							->   Optional[int]:
      """simple docstring"""

      def remove_articles(SCREAMING_SNAKE_CASE_     :	Tuple    ):
            return re.sub(R"\b(a|an|the)\b"  ,  " "  ,  SCREAMING_SNAKE_CASE_    )

      def white_space_fix(SCREAMING_SNAKE_CASE_     :	Union[str, Any]    ):
            return " ".join(text.split()    )

      def remove_punc(SCREAMING_SNAKE_CASE_     :	List[Any]    ):
            SCREAMING_SNAKE_CASE_      :			str     =       set(string.punctuation    )
            return "".join(ch for ch in text if ch not in exclude    )

      def lower(SCREAMING_SNAKE_CASE_     :	Any    ):
            return text.lower()

      return white_space_fix(remove_articles(remove_punc(lower(SCREAMING_SNAKE_CASE_    )    )    )    )


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	str  ,  SCREAMING_SNAKE_CASE_     :	Union[str, Any]    )							->   Dict:
      """simple docstring"""

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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Any  ,  SCREAMING_SNAKE_CASE_     :	List[str]    )							->   Tuple:
      """simple docstring"""

      return normalize_answer(SCREAMING_SNAKE_CASE_    ) == normalize_answer(SCREAMING_SNAKE_CASE_    )


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Dict  ,  SCREAMING_SNAKE_CASE_     :	Optional[Any]  ,  SCREAMING_SNAKE_CASE_     :	str    )							->   Any:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			Any     =       []
      for ground_truth in ground_truths:
            SCREAMING_SNAKE_CASE_      :			Tuple     =       metric_fn(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    )
            scores_for_ground_truths.append(SCREAMING_SNAKE_CASE_    )
      return max(SCREAMING_SNAKE_CASE_    )


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Union[str, Any]  ,  SCREAMING_SNAKE_CASE_     :	Union[str, Any]    )							->   Optional[int]:
      """simple docstring"""

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

      SCREAMING_SNAKE_CASE_      :			Dict     =       100.0 * exact_match / total
      SCREAMING_SNAKE_CASE_      :			int     =       100.0 * fa / total

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


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


import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
				import tensorflow as tf

				from transformers.activations_tf import get_tf_activation



@require_tf
class    lowercase_    (     unittest.TestCase		):



							def        UpperCamelCase       (						self				):
													_snake_case						:     int				=    tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]				)
													_snake_case						:     List[Any]				=    get_tf_activation("gelu"				)
													_snake_case						:     Any				=    get_tf_activation("gelu_10"				)

													_snake_case						:     Dict				=    gelu(lowercase_				)
													_snake_case						:     Optional[int]				=    geluaa(lowercase_				)

													_snake_case						:     Tuple				=    tf.where(y_gelu_aa < 10.0      ,				1.0      ,				0.0				)

													self.assertEqual(tf.math.reduce_max(lowercase_				).numpy().item()      ,				10.0				)
													self.assertTrue(np.allclose(y_gelu * clipped_mask      ,				y_gelu_aa * clipped_mask				)				)



							def        UpperCamelCase       (						self				):
													get_tf_activation("gelu"				)
													get_tf_activation("gelu_10"				)
													get_tf_activation("gelu_fast"				)
													get_tf_activation("gelu_new"				)
													get_tf_activation("glu"				)
													get_tf_activation("mish"				)
													get_tf_activation("quick_gelu"				)
													get_tf_activation("relu"				)
													get_tf_activation("sigmoid"				)
													get_tf_activation("silu"				)
													get_tf_activation("swish"				)
													get_tf_activation("tanh"				)
													with self.assertRaises(lowercase_				):
																			get_tf_activation("bogus"				)
													with self.assertRaises(lowercase_				):
																			get_tf_activation(lowercase_				)