code: 
  
  
  
  """simple docstring"""
  
  
  
  
  from typing import Dict, List, Optional, Union
  
  import numpy as np
  
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
  from ...image_utils import (
      IMAGENET_STANDARD_MEAN,
      IMAGENET_STANDARD_STD,
      ChannelDimension,
      ImageInput,
      PILImageResampling,
      make_list_of_images,
      to_numpy_array,
      valid_images,
  )
  from ...utils import TensorType, is_vision_available, logging
  
  
  if is_vision_available():
   import PIL
  
  
  _lowerCAmelCase       :      Optional[Any]							=							logging.get_logger(__name__)
  
  
  
  
  
  
  class 			UpperCAmelCase_						(       lowerCAmelCase__		):
        __SCREAMING_SNAKE_CASE		:     Any				  =				['pixel_values']
  
  
  
        def __init__(  self  :			Tuple  ,			A  :			List[Any] = True  ,			A  :			List[Any] = None  ,			A  :			Optional[int] = PIL.Image.NEAREST  ,			A  :			Dict = False  ,			A  :			Any = None  ,			A  :			Optional[Any] = 1 / 2_5_5  ,			A  :			List[Any] = False  ,			A  :			Tuple = True  ,			A  :			List[Any] = True  ,			A  :			Optional[int] = None  ,			A  :			Tuple = None  ,			A  :			Optional[int] = True  ,			**A  :			Optional[Any]  ,			):
             super().__init__(**_lowerCamelCase		)
             _UpperCAmelCase    :			int              =					size if size is not None else {"""height""": 3_4_6, """width""": 3_4_6}
             _UpperCAmelCase    :			Tuple              =					get_size_dict(_lowerCamelCase		)
             _UpperCAmelCase    :			str              =					crop_size if crop_size is not None else {"""height""": 2_8_9, """width""": 2_8_9}
             _UpperCAmelCase    :			Tuple              =					get_size_dict(_lowerCamelCase  ,			param_name="crop_size"		)
  
             _UpperCAmelCase    :			Optional[int]              =					do_resize
             _UpperCAmelCase    :			str              =					size
             _UpperCAmelCase    :			Optional[int]              =					resample
             _UpperCAmelCase    :			Any              =					do_center_crop
             _UpperCAmelCase    :			Optional[int]              =					crop_size
             _UpperCAmelCase    :			List[str]              =					do_rescale
             _UpperCAmelCase    :			Tuple              =					rescale_factor
             _UpperCAmelCase    :			Dict              =					rescale_offset
             _UpperCAmelCase    :			List[str]              =					do_normalize
             _UpperCAmelCase    :			List[Any]              =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
             _UpperCAmelCase    :			int              =					image_std if image_std is not None else IMAGENET_STANDARD_STD
             _UpperCAmelCase    :			Optional[Any]              =					include_top
  
  
  
        def 		snake_case_      (  self  :			Union[str, Any]  ,			A  :			Optional[int]  ,			A  :			List[Any]  ,			A  :			Union[str, Any] = PIL.Image.NEAREST  ,			A  :			List[str] = None  ,			**A  :			Optional[Any]  ,			):
             _UpperCAmelCase    :			Any              =					get_size_dict(_lowerCamelCase		)
             if "height" not in size or "width" not in size:
                  raise ValueError(f'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'		)
             return resize(
                 _lowerCamelCase  ,			size=(size["height"], size["width"])  ,			resample=_lowerCamelCase  ,			data_format=_lowerCamelCase  ,			**_lowerCamelCase		)
  
  
  
        def 		snake_case_      (  self  :			Optional[int]  ,			A  :			str  ,			A  :			Dict  ,			A  :			Union[str, Any] = None  ,			**A  :			str  ,			):
             _UpperCAmelCase    :			Union[str, Any]              =					get_size_dict(_lowerCamelCase		)
             if "height" not in size or "width" not in size:
                  raise ValueError(f'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'		)
             return center_crop(_lowerCamelCase  ,			size=(size["height"], size["width"])  ,			data_format=_lowerCamelCase  ,			**_lowerCamelCase		)
  
  
  
        def 		snake_case_      (  self  :			Optional[int]  ,			A  :			Any  ,			A  :			Optional[Any]  ,			A  :			Any = True  ,			A  :			str = None  ,			**A  :			Optional[Any]  ,			):
  
             if offset:
                  _UpperCAmelCase    :			Tuple              =					(image - 127.5) * scale
                  if data_format is not None:
                       _UpperCAmelCase    :			int              =					to_channel_dimension_format(_lowerCamelCase  ,			_lowerCamelCase		)
                  _UpperCAmelCase    :			Tuple              =					rescaled_image.astype(np.floataa		)
             else:
                  _UpperCAmelCase    :			Dict              =					rescale(_lowerCamelCase  ,			scale=_lowerCamelCase  ,			data_format=_lowerCamelCase  ,			**_lowerCamelCase		)
             return rescaled_image
  
  
  
        def 		snake_case_      (  self  :			str  ,			A  :			Optional[Any]  ,			A  :			str  ,			A  :			Any  ,			A  :			Optional[int] = None  ,			**A  :			str  ,			):
             return normalize(_lowerCamelCase  ,			mean=_lowerCamelCase  ,			std=_lowerCamelCase  ,			data_format=_lowerCamelCase  ,			**_lowerCamelCase		)
  
  
  
        def 		snake_case_      (  self  :			Optional[int]  ,			A  :			Optional[int]  ,			A  :			Tuple = None  ,			A  :			Optional[Any] = None  ,			A  :			List[Any]=None  ,			A  :			Tuple = None  ,			A  :			str = None  ,			A  :			str = None  ,			A  :			int = None  ,			A  :			Optional[int] = None  ,			A  :			Optional[Any] = None  ,			A  :			Dict = None  ,			A  :			int = None  ,			A  :			Any = None  ,			A  :			List[Any] = None  ,			A  :			Any = ChannelDimension.FIRST  ,			**A  :			Optional[int]  ,			):
             _UpperCAmelCase    :			Union[str, Any]              =					do_resize if do_resize is not None else self.do_resize
             _UpperCAmelCase    :			str              =					resample if resample is not None else self.resample
             _UpperCAmelCase    :			List[str]              =					do_center_crop if do_center_crop is not None else self.do_center_crop
             _UpperCAmelCase    :			int              =					do_rescale if do_rescale is not None else self.do_rescale
             _UpperCAmelCase    :			List[str]              =					rescale_factor if rescale_factor is not None else self.rescale_factor
             _UpperCAmelCase    :			List[Any]              =					rescale_offset if rescale_offset is not None else self.rescale_offset
             _UpperCAmelCase    :			str              =					do_normalize if do_normalize is not None else self.do_normalize
             _UpperCAmelCase    :			List[str]              =					image_mean if image_mean is not None else self.image_mean
             _UpperCAmelCase    :			Union[str, Any]              =					image_std if image_std is not None else self.image_std
             _UpperCAmelCase    :			Dict              =					include_top if include_top is not None else self.include_top
  
             _UpperCAmelCase    :			Union[str, Any]              =					size if size is not None else self.size
             _UpperCAmelCase    :			Optional[int]              =					get_size_dict(_lowerCamelCase		)
             _UpperCAmelCase    :			str              =					crop_size if crop_size is not None else self.crop_size
             _UpperCAmelCase    :			Optional[Any]              =					get_size_dict(_lowerCamelCase  ,			param_name="crop_size"		)
  
             _UpperCAmelCase    :			List[str]              =					make_list_of_images(_lowerCamelCase		)
  
             if not valid_images(_lowerCamelCase		):
                  raise ValueError(
                      "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
                      "torch.Tensor, tf.Tensor or jax.ndarray."		)
  
             if do_resize and size is None or resample is None:
                  raise ValueError("Size and resample must be specified if do_resize is True."		)
  
             if do_center_crop and crop_size is None:
                  raise ValueError("Crop size must be specified if do_center_crop is True."		)
  
             if do_rescale and rescale_factor is None:
                  raise ValueError("Rescale factor must be specified if do_rescale is True."		)
  
             if do_normalize and (image_mean is None or image_std is None):
                  raise ValueError("Image mean and std must be specified if do_normalize is True."		)
  
             # All transformations expect numpy arrays.
             _UpperCAmelCase    :			Tuple              =					[to_numpy_array(_lowerCamelCase		) for image in images]
  
             if do_resize:
                  _UpperCAmelCase    :			Optional[Any]              =					[self.resize(image=_lowerCamelCase  ,			size=_lowerCamelCase  ,			resample=_lowerCamelCase		) for image in images]
  
             if do_center_crop:
                  _UpperCAmelCase    :			Optional[int]              =					[self.center_crop(image=_lowerCamelCase  ,			size=_lowerCamelCase		) for image in images]
  
             if do_rescale:
                  _UpperCAmelCase    :			str              =					[self.rescale(image=_lowerCamelCase  ,			scale=_lowerCamelCase  ,			offset=_lowerCamelCase		) for image in images]
  
             if do_normalize:
                  _UpperCAmelCase    :			List[Any]              =					[self.normalize(image=_lowerCamelCase  ,			mean=_lowerCamelCase  ,			std=_lowerCamelCase		) for image in images]
  
             if include_top:
                  _UpperCAmelCase    :			Optional[int]              =					[self.normalize(image=_lowerCamelCase  ,			mean=[0, 0, 0]  ,			std=_lowerCamelCase		) for image in images]
  
             _UpperCAmelCase    :			int              =					[to_channel_dimension_format(_lowerCamelCase  ,			_lowerCamelCase		) for image in images]
  
             _UpperCAmelCase    :			Dict              =					{"""pixel_values""": images}
             return BatchFeature(data=_lowerCamelCase  ,			tensor_type=_lowerCamelCase		)
  
style_context: 
  
  
  
  """simple docstring"""
  
  
  
  
  import argparse
  import json
  import re
  import string
  import sys
  from collections import Counter
  
  def 		__snake_case		(   SCREAMING_SNAKE_CASE__			:		Optional[int]       )						->     Union[str, Any]:
  
  
  
  
  
       '''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__			:		Any       ):
            return " ".join(text.split()       )
  
       def remove_punc(SCREAMING_SNAKE_CASE__			:		Optional[int]       ):
            _UpperCAmelCase    :			List[str]              =					set(string.punctuation       )
            return "".join(ch for ch in text if ch not in exclude       )
  
       def lower(SCREAMING_SNAKE_CASE__			:		List[str]       ):
            return text.lower()
  
       return white_space_fix(remove_articles(remove_punc(lower(SCREAMING_SNAKE_CASE__       )       )       )       )
  
  def 		__snake_case		(   SCREAMING_SNAKE_CASE__			:		Union[str, Any]		,						SCREAMING_SNAKE_CASE__			:		str       )						->     Dict:
  
  
  
  
  
       '''simple docstring'''
  
       _UpperCAmelCase    :			List[Any]              =					normalize_answer(SCREAMING_SNAKE_CASE__       ).split()
       _UpperCAmelCase    :			Tuple              =					normalize_answer(SCREAMING_SNAKE_CASE__       ).split()
       _UpperCAmelCase    :			List[Any]              =					Counter(SCREAMING_SNAKE_CASE__       ) & Counter(SCREAMING_SNAKE_CASE__       )
       _UpperCAmelCase    :			List[str]              =					sum(common.values()       )
       if num_same == 0:
            return 0
       _UpperCAmelCase    :			Union[str, Any]              =					1.0 * num_same / len(SCREAMING_SNAKE_CASE__       )
       _UpperCAmelCase    :			Union[str, Any]              =					1.0 * num_same / len(SCREAMING_SNAKE_CASE__       )
       _UpperCAmelCase    :			Union[str, Any]              =					(2 * precision * recall) / (precision + recall)
       return fa
  
  def 		__snake_case		(   SCREAMING_SNAKE_CASE__			:		Union[str, Any]		,						SCREAMING_SNAKE_CASE__			:		Dict       )						->     str:
  
  
  
  
  
       '''simple docstring'''
  
       return normalize_answer(SCREAMING_SNAKE_CASE__       ) == normalize_answer(SCREAMING_SNAKE_CASE__       )
  
  def 		__snake_case		(   SCREAMING_SNAKE_CASE__			:		List[Any]		,						SCREAMING_SNAKE_CASE__			:		Dict		,						SCREAMING_SNAKE_CASE__			:		Optional[Any]       )						->     str:
  
  
  
  
  
       '''simple docstring'''
  
       _UpperCAmelCase    :			int              =					[]
       for ground_truth in ground_truths:
            _UpperCAmelCase    :			Dict              =					metric_fn(SCREAMING_SNAKE_CASE__		,						SCREAMING_SNAKE_CASE__       )
            scores_for_ground_truths.append(SCREAMING_SNAKE_CASE__       )
       return max(SCREAMING_SNAKE_CASE__       )
  
  def 		__snake_case		(   SCREAMING_SNAKE_CASE__			:		Optional[int]		,						SCREAMING_SNAKE_CASE__			:		Any       )						->     Tuple:
  
  
  
  
  
       '''simple docstring'''
  
       _UpperCAmelCase    :			str              =					0
       _UpperCAmelCase    :			int              =					[]
       for passage in dataset:
            for qa in passage["qas"]:
                 total += 1
                 if qa["id"] not in predictions:
                      _UpperCAmelCase    :			List[Any]              =					f'Unanswered question {qa["id"]} will receive score 0.'
                      print(SCREAMING_SNAKE_CASE__		,						file=sys.stderr       )
                      continue
  
                 _UpperCAmelCase    :			Union[str, Any]              =					[x["text"] for x in qa["answers"]]
                 _UpperCAmelCase    :			Optional[int]              =					predictions[qa["id"]]
  
                 _UpperCAmelCase    :			int              =					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    :			List[str]              =					exact_match / total
       _UpperCAmelCase    :			str              =					fa / total
  
       return {"exact_match": exact_match, "f1": fa}, correct_ids
  
  
  if __name__ == "__main__":
   _lowerCAmelCase       :      Any							=							"1.0"
   _lowerCAmelCase       :      Any							=							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.")
   _lowerCAmelCase       :      Tuple							=							parser.parse_args()
  
   with open(args.data_file) as data_file:
    _lowerCAmelCase       :      int							=							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,
     )
    _lowerCAmelCase       :      List[str]							=							dataset_json["data"]
  
   with open(args.pred_file) as pred_file:
    _lowerCAmelCase       :      str							=							json.load(pred_file)
  
   _lowerCAmelCase,		_lowerCAmelCase       :      List[Any]							=							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)
  