



import re
import string

import numpy as np

import datasets


_lowerCamelCase    :		Any		      =    """
Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
"""

_lowerCamelCase    :		Optional[Any]		      =    """
Args:
    predictions: List of predicted texts.
    references: List of reference texts.
    regexes_to_ignore: List, defaults to None. Regex expressions of characters to
        ignore when calculating the exact matches. Note: these regexes are removed
        from the input data before the changes based on the options below (e.g. ignore_case,
        ignore_punctuation, ignore_numbers) are applied.
    ignore_case: Boolean, defaults to False. If true, turns everything
        to lowercase so that capitalization differences are ignored.
    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
Returns:
    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.
Examples:
    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    25.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    50.0


    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    75.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
    >>> print(round(results[\"exact_match\"], 1))
    100.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It's like comparing oranges and apples.\"]
    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It's like comparing apples and oranges.\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    33.3

"""

_lowerCamelCase    :		List[str]		      =    """
"""


@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,    _KWARGS_DESCRIPTION)
class 						lowercase    (							datasets.Metric):
						'''simple docstring'''


						def       lowerCamelCase_				(  self    :				str	):



											'''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       lowerCamelCase_				(  self    :				Tuple       ,	snake_case    :				Union[str, Any]       ,	snake_case    :				List[Any]       ,	snake_case    :				Any=None       ,	snake_case    :				int=False       ,	snake_case    :				Any=False       ,	snake_case    :				List[str]=False       ,	):



											'''simple docstring'''


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

											if ignore_case:
																SCREAMING_SNAKE_CASE							:     Optional[int]						=				np.char.lower(snake_case	)
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				np.char.lower(snake_case	)

											if ignore_punctuation:
																SCREAMING_SNAKE_CASE							:     Optional[int]						=				string.punctuation.maketrans(''       ,	''       ,	string.punctuation	)
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				np.char.translate(snake_case       ,	table=snake_case	)
																SCREAMING_SNAKE_CASE							:     List[str]						=				np.char.translate(snake_case       ,	table=snake_case	)

											if ignore_numbers:
																SCREAMING_SNAKE_CASE							:     Tuple						=				string.digits.maketrans(''       ,	''       ,	string.digits	)
																SCREAMING_SNAKE_CASE							:     Tuple						=				np.char.translate(snake_case       ,	table=snake_case	)
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				np.char.translate(snake_case       ,	table=snake_case	)

											SCREAMING_SNAKE_CASE							:     Optional[int]						=				predictions == references

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




from datetime import datetime

import matplotlib.pyplot as plt
import torch

def        __a			(   __lowerCAmelCase   )     ->     int:
					for param in module.parameters():
										SCREAMING_SNAKE_CASE							:     List[Any]						=				False

def        __a			(   )     ->     List[str]:
					SCREAMING_SNAKE_CASE							:     List[Any]						=				'cuda' if torch.cuda.is_available() else 'cpu'
					if torch.backends.mps.is_available() and torch.backends.mps.is_built():
										SCREAMING_SNAKE_CASE							:     List[str]						=				'mps'
					if device == "mps":
										print(
										    'WARNING: MPS currently doesn\'t seem to work, and messes up backpropagation without any visible torch'
										    ' errors. I recommend using CUDA on a colab notebook or CPU instead if you\'re facing inexplicable issues'
										    ' with generations.'   )
					return device

def        __a			(   __lowerCAmelCase   )     ->     List[Any]:
					SCREAMING_SNAKE_CASE							:     Optional[int]						=				plt.imshow(__lowerCAmelCase   )
					fig.axes.get_xaxis().set_visible(__lowerCAmelCase   )
					fig.axes.get_yaxis().set_visible(__lowerCAmelCase   )
					plt.show()



def        __a			(   )     ->     Optional[Any]:
					SCREAMING_SNAKE_CASE							:     str						=				datetime.now()
					SCREAMING_SNAKE_CASE							:     Optional[int]						=				current_time.strftime('%H:%M:%S'   )
					return timestamp