


'''simple docstring'''


import re
import string

import numpy as np

import datasets


UpperCAmelCase_						:  List[str]				  =						'\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

UpperCAmelCase_						:  List[str]				  =						'\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results[\"exact_match\"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]\n    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results[\"exact_match\"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric(\"exact_match\")\n    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It\'s like comparing oranges and apples.\"]\n    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It\'s like comparing apples and oranges.\"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results[\"exact_match\"], 1))\n    33.3\n\n'

UpperCAmelCase_						:  Any				  =						'\n'





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION	,	_KWARGS_DESCRIPTION   )
class        lowercase__    (		datasets.Metric   ):





							'''simple docstring'''


							def UpperCAmelCase_      (       self    ):
											return datasets.MetricInfo(
											    description=_DESCRIPTION       ,   citation=_CITATION       ,   inputs_description=_KWARGS_DESCRIPTION       ,   features=datasets.Features(
											        {
											            """predictions""": datasets.Value("""string"""       ,   id="""sequence"""    ),
											            """references""": datasets.Value("""string"""       ,   id="""sequence"""    ),
											        }    )       ,   reference_urls=[]       ,   )






							def UpperCAmelCase_      (       self       ,   __snake_case       ,   __snake_case       ,   __snake_case=None       ,   __snake_case=False       ,   __snake_case=False       ,   __snake_case=False       ,   ):
											if regexes_to_ignore is not None:
															for s in regexes_to_ignore:
																			_SCREAMING_SNAKE_CASE					:			Optional[int]							= np.array([re.sub(_lowerCAmelCase       ,   """"""       ,   _lowerCAmelCase    ) for x in predictions]    )
																			_SCREAMING_SNAKE_CASE					:			List[str]							= np.array([re.sub(_lowerCAmelCase       ,   """"""       ,   _lowerCAmelCase    ) for x in references]    )
											else:
															_SCREAMING_SNAKE_CASE					:			List[Any]							= np.asarray(_lowerCAmelCase    )
															_SCREAMING_SNAKE_CASE					:			Optional[Any]							= np.asarray(_lowerCAmelCase    )

											if ignore_case:
															_SCREAMING_SNAKE_CASE					:			List[str]							= np.char.lower(_lowerCAmelCase    )
															_SCREAMING_SNAKE_CASE					:			Dict							= np.char.lower(_lowerCAmelCase    )

											if ignore_punctuation:
															_SCREAMING_SNAKE_CASE					:			List[Any]							= string.punctuation.maketrans(""""""       ,   """"""       ,   string.punctuation    )
															_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= np.char.translate(_lowerCAmelCase       ,   table=_lowerCAmelCase    )
															_SCREAMING_SNAKE_CASE					:			List[Any]							= np.char.translate(_lowerCAmelCase       ,   table=_lowerCAmelCase    )

											if ignore_numbers:
															_SCREAMING_SNAKE_CASE					:			int							= string.digits.maketrans(""""""       ,   """"""       ,   string.digits    )
															_SCREAMING_SNAKE_CASE					:			str							= np.char.translate(_lowerCAmelCase       ,   table=_lowerCAmelCase    )
															_SCREAMING_SNAKE_CASE					:			List[Any]							= np.char.translate(_lowerCAmelCase       ,   table=_lowerCAmelCase    )

											_SCREAMING_SNAKE_CASE					:			Dict							= predictions == references

											return {"exact_match": np.mean(_lowerCAmelCase    ) * 100}











'''simple docstring'''


from typing import Dict, Iterable, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				int								=       ["pixel_values"]




 def __init__(						self      ,  _lowerCAmelCase = True      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = PILImageResampling.BICUBIC      ,  _lowerCAmelCase = True      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = True      ,  _lowerCAmelCase = 1 / 255      ,  _lowerCAmelCase = True      ,  _lowerCAmelCase = IMAGENET_DEFAULT_MEAN      ,  _lowerCAmelCase = IMAGENET_DEFAULT_STD      ,  **_lowerCAmelCase      ,  )     ->				None:
     super().__init__(**_lowerCAmelCase		)
     _lowerCAmelCase						      =   size if size is not None else {"shortest_edge": 224}
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase      ,  default_to_square=_lowerCAmelCase		)
     _lowerCAmelCase						      =   crop_size if crop_size is not None else {"height": 224, "width": 224}
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase      ,  param_name="crop_size"		)

     _lowerCAmelCase						      =   do_resize
     _lowerCAmelCase						      =   size
     _lowerCAmelCase						      =   resample
     _lowerCAmelCase						      =   do_center_crop
     _lowerCAmelCase						      =   crop_size
     _lowerCAmelCase						      =   do_rescale
     _lowerCAmelCase						      =   rescale_factor
     _lowerCAmelCase						      =   do_normalize
     _lowerCAmelCase						      =   image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
     _lowerCAmelCase						      =   image_std if image_std is not None else IMAGENET_DEFAULT_STD




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase = PILImageResampling.BICUBIC      ,  _lowerCAmelCase = None      ,  **_lowerCAmelCase      ,  )     ->				np.ndarray:
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase      ,  default_to_square=_lowerCAmelCase		)
     # size_dict is a dict with either keys "height" and "width" or "shortest_edge"
     if "shortest_edge" in size:
         _lowerCAmelCase						      =   int((256 / 224) * size["shortest_edge"]		)
         _lowerCAmelCase						      =   get_resize_output_image_size(_lowerCAmelCase      ,  size=_lowerCAmelCase      ,  default_to_square=_lowerCAmelCase		)
         _lowerCAmelCase						      =   {"height": output_size[0], "width": output_size[1]}
     if "height" not in size_dict or "width" not in size_dict:
         raise ValueError(
             f'''Size dict must have keys \'height\' and \'width\' or \'shortest_edge\'. Got {size_dict.keys()}'''		)
     return resize(
         _lowerCAmelCase      ,  size=(size_dict["height"], size_dict["width"])      ,  resample=_lowerCAmelCase      ,  data_format=_lowerCAmelCase      ,  **_lowerCAmelCase		)




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase = None      ,  **_lowerCAmelCase      ,  )     ->				np.ndarray:
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase		)
     if "height" not in size or "width" not in size:
         raise ValueError(f'''Size dict 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      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase = None      ,  **_lowerCAmelCase      ,  )     ->				np.ndarray:
     return rescale(_lowerCAmelCase      ,  scale=_lowerCAmelCase      ,  data_format=_lowerCAmelCase      ,  **_lowerCAmelCase		)




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase = None      ,  **_lowerCAmelCase      ,  )     ->				np.ndarray:
     return normalize(_lowerCAmelCase      ,  mean=_lowerCAmelCase      ,  std=_lowerCAmelCase      ,  data_format=_lowerCAmelCase      ,  **_lowerCAmelCase		)





 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = None      ,  _lowerCAmelCase = ChannelDimension.FIRST      ,  **_lowerCAmelCase      ,  )     ->				BatchFeature:
     _lowerCAmelCase						      =   do_resize if do_resize is not None else self.do_resize
     _lowerCAmelCase						      =   resample if resample is not None else self.resample
     _lowerCAmelCase						      =   do_center_crop if do_center_crop is not None else self.do_center_crop
     _lowerCAmelCase						      =   do_rescale if do_rescale is not None else self.do_rescale
     _lowerCAmelCase						      =   rescale_factor if rescale_factor is not None else self.rescale_factor
     _lowerCAmelCase						      =   do_normalize if do_normalize is not None else self.do_normalize
     _lowerCAmelCase						      =   image_mean if image_mean is not None else self.image_mean
     _lowerCAmelCase						      =   image_std if image_std is not None else self.image_std

     _lowerCAmelCase						      =   size if size is not None else self.size
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase      ,  default_to_square=_lowerCAmelCase		)
     _lowerCAmelCase						      =   crop_size if crop_size is not None else self.crop_size
     _lowerCAmelCase						      =   get_size_dict(_lowerCAmelCase      ,  param_name="crop_size"		)

     _lowerCAmelCase						      =   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:
         raise ValueError("Size 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.
     _lowerCAmelCase						      =   [to_numpy_array(_lowerCAmelCase		) for image in images]

     if do_resize:
         _lowerCAmelCase						      =   [self.resize(_lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase		) for image in images]

     if do_center_crop:
         _lowerCAmelCase						      =   [self.center_crop(_lowerCAmelCase      ,  _lowerCAmelCase		) for image in images]

     if do_rescale:
         _lowerCAmelCase						      =   [self.rescale(_lowerCAmelCase      ,  _lowerCAmelCase		) for image in images]

     if do_normalize:
         _lowerCAmelCase						      =   [self.normalize(_lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase		) for image in images]

     _lowerCAmelCase						      =   [to_channel_dimension_format(_lowerCAmelCase      ,  _lowerCAmelCase		) for image in images]

     _lowerCAmelCase						      =   {"pixel_values": images}
     return BatchFeature(data=_lowerCAmelCase      ,  tensor_type=_lowerCAmelCase		)


