



"""simple docstring"""






import re
import string

import numpy as np

import datasets


_lowercase			:			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'

_lowercase			:			Any										=						'\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'

_lowercase			:			Dict										=						'\n'







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


					'''simple docstring'''





					def 		snake_case	(	self							:  str					)-> List[str]:
								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 		snake_case	(	self							:  List[str],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  int=None,  lowerCamelCase							:  List[Any]=False,  lowerCamelCase							:  List[Any]=False,  lowerCamelCase							:  int=False,  )-> Optional[Any]:
								if regexes_to_ignore is not None:
											for s in regexes_to_ignore:
														lowerCamelCase__		:		int		     =np.array([re.sub(__SCREAMING_SNAKE_CASE,  '''''',  __SCREAMING_SNAKE_CASE					) for x in predictions]					)
														lowerCamelCase__		:		List[Any]		     =np.array([re.sub(__SCREAMING_SNAKE_CASE,  '''''',  __SCREAMING_SNAKE_CASE					) for x in references]					)
								else:
											lowerCamelCase__		:		Any		     =np.asarray(__SCREAMING_SNAKE_CASE					)
											lowerCamelCase__		:		List[Any]		     =np.asarray(__SCREAMING_SNAKE_CASE					)

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

								if ignore_punctuation:
											lowerCamelCase__		:		Optional[Any]		     =string.punctuation.maketrans('''''',  '''''',  string.punctuation					)
											lowerCamelCase__		:		Optional[int]		     =np.char.translate(__SCREAMING_SNAKE_CASE,  table=__SCREAMING_SNAKE_CASE					)
											lowerCamelCase__		:		int		     =np.char.translate(__SCREAMING_SNAKE_CASE,  table=__SCREAMING_SNAKE_CASE					)

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

								lowerCamelCase__		:		int		     =predictions == references

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









"""simple docstring"""






from ...processing_utils import ProcessorMixin

class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_       ):


					'''simple docstring'''





					_a             =							'SpeechT5FeatureExtractor'
					_a             =							'SpeechT5Tokenizer'



					def __init__(	self							:  Dict,  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  str					)-> Any:
								super().__init__(lowerCamelCase,  lowerCamelCase					)



					def __call__(	self							:  Tuple,  *lowerCamelCase							:  List[str],  **lowerCamelCase							:  Optional[int]					)-> List[str]:
								lowerCamelCase__		:		List[Any]		     =kwargs.pop('''audio''',  lowerCamelCase					)
								lowerCamelCase__		:		List[str]		     =kwargs.pop('''text''',  lowerCamelCase					)
								lowerCamelCase__		:		int		     =kwargs.pop('''text_target''',  lowerCamelCase					)
								lowerCamelCase__		:		Dict		     =kwargs.pop('''audio_target''',  lowerCamelCase					)
								lowerCamelCase__		:		Any		     =kwargs.pop('''sampling_rate''',  lowerCamelCase					)

								if audio is not None and text is not None:
											raise ValueError(
											    '''Cannot process both `audio` and `text` inputs. Did you mean `audio_target` or `text_target`?'''					)
								if audio_target is not None and text_target is not None:
											raise ValueError(
											    '''Cannot process both `audio_target` and `text_target` inputs. Did you mean `audio` or `text`?'''					)
								if audio is None and audio_target is None and text is None and text_target is None:
											raise ValueError(
											    '''You need to specify either an `audio`, `audio_target`, `text`, or `text_target` input to process.'''					)

								if audio is not None:
											lowerCamelCase__		:		Union[str, Any]		     =self.feature_extractor(lowerCamelCase,  *lowerCamelCase,  sampling_rate=lowerCamelCase,  **lowerCamelCase					)
								elif text is not None:
											lowerCamelCase__		:		List[Any]		     =self.tokenizer(lowerCamelCase,  **lowerCamelCase					)
								else:
											lowerCamelCase__		:		Any		     =None

								if audio_target is not None:
											lowerCamelCase__		:		List[str]		     =self.feature_extractor(audio_target=lowerCamelCase,  *lowerCamelCase,  sampling_rate=lowerCamelCase,  **lowerCamelCase					)
											lowerCamelCase__		:		Tuple		     =targets['''input_values''']
								elif text_target is not None:
											lowerCamelCase__		:		Dict		     =self.tokenizer(lowerCamelCase,  **lowerCamelCase					)
											lowerCamelCase__		:		int		     =targets['''input_ids''']
								else:
											lowerCamelCase__		:		List[str]		     =None

								if inputs is None:
											return targets

								if targets is not None:
											lowerCamelCase__		:		Dict		     =labels

											lowerCamelCase__		:		Any		     =targets.get('''attention_mask'''					)
											if decoder_attention_mask is not None:
														lowerCamelCase__		:		Dict		     =decoder_attention_mask

								return inputs



					def 		snake_case	(	self							:  int,  *lowerCamelCase							:  Optional[Any],  **lowerCamelCase							:  Optional[int]					)-> Optional[Any]:
								lowerCamelCase__		:		List[Any]		     =kwargs.pop('''input_values''',  lowerCamelCase					)
								lowerCamelCase__		:		Union[str, Any]		     =kwargs.pop('''input_ids''',  lowerCamelCase					)
								lowerCamelCase__		:		Optional[Any]		     =kwargs.pop('''labels''',  lowerCamelCase					)

								if input_values is not None and input_ids is not None:
											raise ValueError('''Cannot process both `input_values` and `input_ids` inputs.'''					)
								if input_values is None and input_ids is None and labels is None:
											raise ValueError(
											    '''You need to specify either an `input_values`, `input_ids`, or `labels` input to be padded.'''					)

								if input_values is not None:
											lowerCamelCase__		:		List[str]		     =self.feature_extractor.pad(lowerCamelCase,  *lowerCamelCase,  **lowerCamelCase					)
								elif input_ids is not None:
											lowerCamelCase__		:		Tuple		     =self.tokenizer.pad(lowerCamelCase,  **lowerCamelCase					)
								else:
											lowerCamelCase__		:		Any		     =None

								if labels is not None:
											if "input_ids" in labels or (isinstance(lowerCamelCase,  lowerCamelCase					) and "input_ids" in labels[0]):
														lowerCamelCase__		:		str		     =self.tokenizer.pad(lowerCamelCase,  **lowerCamelCase					)
														lowerCamelCase__		:		List[Any]		     =targets['''input_ids''']
											else:
														lowerCamelCase__		:		Any		     =self.feature_extractor.feature_size
														lowerCamelCase__		:		Optional[Any]		     =self.feature_extractor.num_mel_bins
														lowerCamelCase__		:		Optional[int]		     =self.feature_extractor.pad(lowerCamelCase,  *lowerCamelCase,  **lowerCamelCase					)
														lowerCamelCase__		:		List[Any]		     =feature_size_hack
														lowerCamelCase__		:		Tuple		     =targets['''input_values''']
								else:
											lowerCamelCase__		:		Optional[Any]		     =None

								if inputs is None:
											return targets

								if targets is not None:
											lowerCamelCase__		:		Tuple		     =labels

											lowerCamelCase__		:		Optional[int]		     =targets.get('''attention_mask'''					)
											if decoder_attention_mask is not None:
														lowerCamelCase__		:		Optional[Any]		     =decoder_attention_mask

								return inputs



					def 		snake_case	(	self							:  List[str],  *lowerCamelCase							:  Union[str, Any],  **lowerCamelCase							:  List[Any]					)-> List[Any]:
								return self.tokenizer.batch_decode(*lowerCamelCase,  **lowerCamelCase					)




					def 		snake_case	(	self							:  List[str],  *lowerCamelCase							:  List[Any],  **lowerCamelCase							:  Tuple					)-> int:
								return self.tokenizer.decode(*lowerCamelCase,  **lowerCamelCase					)




