






"""simple docstring"""





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






def 							A(    snake_case_						):
       """simple docstring"""





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

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

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

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

       return white_space_fix(remove_articles(remove_punc(lower(snake_case_						)						)						)						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							Dict         =     normalize_answer(snake_case_						).split()
       lowercase__:							List[str]         =     normalize_answer(snake_case_						).split()
       lowercase__:							Optional[int]         =     Counter(snake_case_						) & Counter(snake_case_						)
       lowercase__:							Any         =     sum(common.values()						)
       if num_same == 0:
              return 0
       lowercase__:							Any         =     1.0 * num_same / len(snake_case_						)
       lowercase__:							List[Any]         =     1.0 * num_same / len(snake_case_						)
       lowercase__:							int         =     (2 * precision * recall) / (precision + recall)
       return fa






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       return normalize_answer(snake_case_						) == normalize_answer(snake_case_						)






def 							A(    snake_case_		,  snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							int         =     []
       for ground_truth in ground_truths:
              lowercase__:							str         =     metric_fn(snake_case_		,  snake_case_						)
              scores_for_ground_truths.append(snake_case_						)
       return max(snake_case_						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





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

       lowercase__:							Union[str, Any]         =     1_00.0 * exact_match / total
       lowercase__:							str         =     1_00.0 * fa / total

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


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








'''simple docstring'''







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import TvltImageProcessor

def 				_snake_case (		lowercase			,    lowercase=1_0			,    lowercase=1_0			,    lowercase=False			,    lowercase=False						)       ->       Any:
				__a       :     Union[str, Any]								=	[]
				for i in range(image_processor_tester.num_frames						):
								video.append(np.random.randint(2_5_5			,    size=(image_processor_tester.num_channels, width, height)			,    dtype=np.uinta						)						)

				if not numpify and not torchify:
								# PIL expects the channel dimension as last dimension
								__a       :     Optional[Any]								=	[Image.fromarray(np.moveaxis(lowercase			,    0			,    -1						)						) for frame in video]

				if torchify:
								__a       :     List[str]								=	[torch.from_numpy(lowercase						) for frame in video]

				return video

def 				_snake_case (		lowercase			,    lowercase=False			,    lowercase=False			,    lowercase=False						)       ->       Optional[Any]:
				assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

				__a       :     str								=	[]
				for i in range(image_processor_tester.batch_size						):
								if equal_resolution:
												__a       :     int								=	image_processor_tester.max_resolution
								else:
												__a							,	__a       :     Any								=	np.random.choice(
												    np.arange(image_processor_tester.min_resolution			,    image_processor_tester.max_resolution						)			,    2						)
												__a       :     Any								=	prepare_video(
												    image_processor_tester=lowercase			,    width=lowercase			,    height=lowercase			,    numpify=lowercase			,    torchify=lowercase			,    )
								video_inputs.append(lowercase						)

				return video_inputs
class  SCREAMING_SNAKE_CASE__       (  unittest.TestCase   ):
	def __init__(				self  ,    __UpperCamelCase  ,    __UpperCamelCase=7  ,    __UpperCamelCase=3  ,    __UpperCamelCase=4  ,    __UpperCamelCase=18  ,    __UpperCamelCase=30  ,    __UpperCamelCase=400  ,    __UpperCamelCase=True  ,    __UpperCamelCase=None  ,    __UpperCamelCase=True  ,    __UpperCamelCase=[0.5, 0.5, 0.5]  ,    __UpperCamelCase=[0.5, 0.5, 0.5]  ,    __UpperCamelCase=True  ,    __UpperCamelCase=None  ,    ):



					'''simple docstring'''






					__a       :     int								=	size if size is not None else {"""shortest_edge""": 18}
					__a       :     Optional[int]								=	crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

					__a       :     Optional[Any]								=	parent
					__a       :     Dict								=	batch_size
					__a       :     Optional[Any]								=	num_channels
					__a       :     Dict								=	num_frames
					__a       :     Dict								=	image_size
					__a       :     int								=	min_resolution
					__a       :     Tuple								=	max_resolution
					__a       :     Optional[Any]								=	do_resize
					__a       :     str								=	size
					__a       :     int								=	do_normalize
					__a       :     Any								=	image_mean
					__a       :     Optional[Any]								=	image_std
					__a       :     List[Any]								=	do_center_crop
					__a       :     List[Any]								=	crop_size

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					return {
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_normalize": self.do_normalize,
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					}







@require_torch
@require_vision
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase			,					unittest.TestCase   ):
	lowercase__	    =							TvltImageProcessor if is_vision_available() else None
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Optional[int]								=	TvltImageProcessorTester(self			)
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					return self.image_processor_tester.prepare_image_processor_dict()
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Optional[Any]								=	self.image_processing_class(**self.image_processor_dict			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """image_mean"""			)			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """image_std"""			)			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """do_normalize"""			)			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """do_resize"""			)			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """do_center_crop"""			)			)
					self.assertTrue(hasattr(__UpperCamelCase  ,    """size"""			)			)
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	self.image_processing_class(**self.image_processor_dict			)
					# create random PIL videos
					__a       :     List[str]								=	prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=__UpperCamelCase			)
					for video in video_inputs:
									self.assertIsInstance(__UpperCamelCase  ,    __UpperCamelCase			)
									self.assertIsInstance(video[0]  ,    Image.Image			)

					# Test not batched input
					__a       :     int								=	image_processor(video_inputs[0]  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )

					# Test batched
					__a       :     int								=	image_processor(__UpperCamelCase  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	self.image_processing_class(**self.image_processor_dict			)
					# create random numpy tensors
					__a       :     Union[str, Any]								=	prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=__UpperCamelCase  ,    numpify=__UpperCamelCase			)
					for video in video_inputs:
									self.assertIsInstance(__UpperCamelCase  ,    __UpperCamelCase			)
									self.assertIsInstance(video[0]  ,    np.ndarray			)

					# Test not batched input
					__a       :     Optional[int]								=	image_processor(video_inputs[0]  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )

					# Test batched
					__a       :     Dict								=	image_processor(__UpperCamelCase  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Optional[Any]								=	self.image_processing_class(**self.image_processor_dict			)
					# create random PyTorch tensors
					__a       :     Optional[int]								=	prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=__UpperCamelCase  ,    torchify=__UpperCamelCase			)
					for video in video_inputs:
									self.assertIsInstance(__UpperCamelCase  ,    __UpperCamelCase			)
									self.assertIsInstance(video[0]  ,    torch.Tensor			)

					# Test not batched input
					__a       :     Optional[int]								=	image_processor(video_inputs[0]  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )

					# Test batched
					__a       :     int								=	image_processor(__UpperCamelCase  ,    return_tensors="""pt"""			).pixel_values
					self.assertEqual(
					    encoded_videos.shape  ,    (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    )  ,    )