
"""simple docstring"""




import re
import string

import numpy as np

import datasets


UpperCAmelCase__      :    List[Any]    							= '\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__      :    Optional[int]    							= '\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 	lowerCAmelCase_						(datasets.Metric  ):


				"""simple docstring"""



				def 	__magic_name__    (self    )					->		int:



											"""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 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__=None   ,       SCREAMING_SNAKE_CASE__=False   ,       SCREAMING_SNAKE_CASE__=False   ,       SCREAMING_SNAKE_CASE__=False   ,       )					->		Optional[int]:



											"""simple docstring"""




											if regexes_to_ignore is not None:
																		for s in regexes_to_ignore:
																									SCREAMING_SNAKE_CASE__						:       Optional[int]           =   np.array([re.sub(SCREAMING_SNAKE_CASE__   ,       """"""   ,       SCREAMING_SNAKE_CASE__    ) for x in predictions]    )
																									SCREAMING_SNAKE_CASE__						:       List[Any]           =   np.array([re.sub(SCREAMING_SNAKE_CASE__   ,       """"""   ,       SCREAMING_SNAKE_CASE__    ) for x in references]    )
											else:
																		SCREAMING_SNAKE_CASE__						:       Optional[int]           =   np.asarray(SCREAMING_SNAKE_CASE__    )
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   np.asarray(SCREAMING_SNAKE_CASE__    )

											if ignore_case:
																		SCREAMING_SNAKE_CASE__						:       Optional[int]           =   np.char.lower(SCREAMING_SNAKE_CASE__    )
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   np.char.lower(SCREAMING_SNAKE_CASE__    )

											if ignore_punctuation:
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   string.punctuation.maketrans(""""""   ,       """"""   ,       string.punctuation    )
																		SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   np.char.translate(SCREAMING_SNAKE_CASE__   ,       table=SCREAMING_SNAKE_CASE__    )
																		SCREAMING_SNAKE_CASE__						:       Optional[int]           =   np.char.translate(SCREAMING_SNAKE_CASE__   ,       table=SCREAMING_SNAKE_CASE__    )

											if ignore_numbers:
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   string.digits.maketrans(""""""   ,       """"""   ,       string.digits    )
																		SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   np.char.translate(SCREAMING_SNAKE_CASE__   ,       table=SCREAMING_SNAKE_CASE__    )
																		SCREAMING_SNAKE_CASE__						:       str           =   np.char.translate(SCREAMING_SNAKE_CASE__   ,       table=SCREAMING_SNAKE_CASE__    )

											SCREAMING_SNAKE_CASE__						:       Tuple           =   predictions == references

											return {"exact_match": np.mean(SCREAMING_SNAKE_CASE__    ) * 1_00}






"""simple docstring"""




import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp

def lowercase_  (   ):
							SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   ArgumentParser(
							    description=(
							        """PyTorch TPU distributed training launch """
							        """helper utility that will spawn up """
							        """multiple distributed processes"""
							    )						)

							# Optional arguments for the launch helper
							parser.add_argument("""--num_cores"""   ,type=_snake_case   ,default=1   ,help="""Number of TPU cores to use (1 or 8)."""						)

							# positional
							parser.add_argument(
							    """training_script"""   ,type=_snake_case   ,help=(
							        """The full path to the single TPU training """
							        """program/script to be launched in parallel, """
							        """followed by all the arguments for the """
							        """training script"""
							    )   ,)

							# rest from the training program
							parser.add_argument("""training_script_args"""   ,nargs=_snake_case						)

							return parser.parse_args()

def lowercase_  (   ):
							SCREAMING_SNAKE_CASE__						:       int           =   parse_args()

							# Import training_script as a module.
							SCREAMING_SNAKE_CASE__						:       Dict           =   Path(args.training_script						)
							sys.path.append(str(script_fpath.parent.resolve()						)						)
							SCREAMING_SNAKE_CASE__						:       int           =   script_fpath.stem
							SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   importlib.import_module(_snake_case						)

							# Patch sys.argv
							SCREAMING_SNAKE_CASE__						:       str           =   [args.training_script] + args.training_script_args + ["""--tpu_num_cores""", str(args.num_cores						)]
							xmp.spawn(mod._mp_fn   ,args=()   ,nprocs=args.num_cores						)


if __name__ == "__main__":
					main()




