





import re
import string

import numpy as np

import datasets


snake_case_           =      '\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'

snake_case_           =      '\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'

snake_case_           =      '\n'

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


      def        a			(self	:				Optional[Any]				):





         """simple docstring"""



         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        a			(self	:				List[Any]    ,      a__	:				int    ,      a__	:				Optional[int]    ,      a__	:				Optional[Any]=None    ,      a__	:				Any=False    ,      a__	:				Dict=False    ,      a__	:				Tuple=False    ,      ):





         """simple docstring"""



         if regexes_to_ignore is not None:
            for s in regexes_to_ignore:
               __snake_case								=       np.array([re.sub(a__    ,      ''''''    ,      a__				) for x in predictions]				)
               __snake_case								=       np.array([re.sub(a__    ,      ''''''    ,      a__				) for x in references]				)
         else:
            __snake_case								=       np.asarray(a__				)
            __snake_case								=       np.asarray(a__				)

         if ignore_case:
            __snake_case								=       np.char.lower(a__				)
            __snake_case								=       np.char.lower(a__				)

         if ignore_punctuation:
            __snake_case								=       string.punctuation.maketrans(''''''    ,      ''''''    ,      string.punctuation				)
            __snake_case								=       np.char.translate(a__    ,      table=a__				)
            __snake_case								=       np.char.translate(a__    ,      table=a__				)

         if ignore_numbers:
            __snake_case								=       string.digits.maketrans(''''''    ,      ''''''    ,      string.digits				)
            __snake_case								=       np.char.translate(a__    ,      table=a__				)
            __snake_case								=       np.char.translate(a__    ,      table=a__				)

         __snake_case								=       predictions == references

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








# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
    import torch

class 		SCREAMING_SNAKE_CASE__    (	TensorFormatter[Mapping, 'torch.Tensor', Mapping]  ):


      def __init__(self	:				Optional[int]    ,      a__	:				Tuple=None    ,      **a__	:				Optional[int]				):





         """simple docstring"""



         super().__init__(features=a__				)
         __snake_case								=       torch_tensor_kwargs
         import torch  # noqa import torch at initialization


      def        a			(self	:				Union[str, Any]    ,      a__	:				Union[str, Any]				):





         """simple docstring"""



         import torch

         if isinstance(a__    ,      a__				) and column:
            if all(
                isinstance(a__    ,      torch.Tensor				) and x.shape == column[0].shape and x.dtype == column[0].dtype
                for x in column				):
               return torch.stack(a__				)
         return column


      def        a			(self	:				Optional[Any]    ,      a__	:				str				):





         """simple docstring"""



         import torch

         if isinstance(a__    ,      (str, bytes, type(a__				))				):
            return value
         elif isinstance(a__    ,      (np.character, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.character				):
            return value.tolist()

         __snake_case								=       {}

         if isinstance(a__    ,      (np.number, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.integer				):
            __snake_case								=       {'''dtype''': torch.intaa}
         elif isinstance(a__    ,      (np.number, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.floating				):
            __snake_case								=       {'''dtype''': torch.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
            import PIL.Image

            if isinstance(a__    ,      PIL.Image.Image				):
               __snake_case								=       np.asarray(a__				)
         return torch.tensor(a__    ,      **{**default_dtype, **self.torch_tensor_kwargs}				)


      def        a			(self	:				Optional[int]    ,      a__	:				str				):





         """simple docstring"""



         import torch

         # support for torch, tf, jax etc.
         if hasattr(a__    ,      '''__array__'''				) and not isinstance(a__    ,      torch.Tensor				):
            __snake_case								=       data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(a__    ,      np.ndarray				):
            if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
               return self._consolidate([self.recursive_tensorize(a__				) for substruct in data_struct]				)
         elif isinstance(a__    ,      (list, tuple)				):
            return self._consolidate([self.recursive_tensorize(a__				) for substruct in data_struct]				)
         return self._tensorize(a__				)


      def        a			(self	:				Optional[Any]    ,      a__	:				dict				):





         """simple docstring"""



         return map_nested(self._recursive_tensorize    ,      a__    ,      map_list=a__				)


      def        a			(self	:				Optional[int]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_row(a__				)
         __snake_case								=       self.python_features_decoder.decode_row(a__				)
         return self.recursive_tensorize(a__				)


      def        a			(self	:				List[Any]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_column(a__				)
         __snake_case								=       self.python_features_decoder.decode_column(a__    ,      pa_table.column_names[0]				)
         __snake_case								=       self.recursive_tensorize(a__				)
         __snake_case								=       self._consolidate(a__				)
         return column


      def        a			(self	:				Optional[int]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_batch(a__				)
         __snake_case								=       self.python_features_decoder.decode_batch(a__				)
         __snake_case								=       self.recursive_tensorize(a__				)
         for column_name in batch:
            __snake_case								=       self._consolidate(batch[column_name]				)
         return batch

