




'''simple docstring'''


from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...file_utils import TensorType, is_torch_available
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


_snake_case      :      str   							=		logging.get_logger(__name__)

_snake_case      :      str   							=		{
    'facebook/blenderbot-3B': 'https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json',
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}

class 			A    (		_a    ):
							lowercase_							=				'blenderbot'
							lowercase_							=				['past_key_values']
							lowercase_							=				{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}







							def __init__(  self       :  str							,			lowerCAmelCase_       :  Dict=80_08							,			lowerCAmelCase_       :  Any=1_28							,			lowerCAmelCase_       :  Optional[Any]=2							,			lowerCAmelCase_       :  Optional[int]=1_02_40							,			lowerCAmelCase_       :  List[str]=32							,			lowerCAmelCase_       :  int=24							,			lowerCAmelCase_       :  Optional[Any]=1_02_40							,			lowerCAmelCase_       :  int=32							,			lowerCAmelCase_       :  Optional[Any]=0.0							,			lowerCAmelCase_       :  List[str]=0.0							,			lowerCAmelCase_       :  Tuple=True							,			lowerCAmelCase_       :  str=True							,			lowerCAmelCase_       :  str="gelu"							,			lowerCAmelCase_       :  Dict=25_60							,			lowerCAmelCase_       :  Tuple=0.1							,			lowerCAmelCase_       :  List[Any]=0.0							,			lowerCAmelCase_       :  Optional[Any]=0.0							,			lowerCAmelCase_       :  Dict=0.0_2							,			lowerCAmelCase_       :  Dict=1							,			lowerCAmelCase_       :  Tuple=False							,			lowerCAmelCase_       :  Any=0							,			lowerCAmelCase_       :  Dict=1							,			lowerCAmelCase_       :  List[Any]=2							,			lowerCAmelCase_       :  str=3							,			lowerCAmelCase_       :  Tuple=2							,			**lowerCAmelCase_       :  List[Any]							,			)			->							Union[str, Any]:


														"""simple docstring"""


														_a	     =				vocab_size
														_a	     =				max_position_embeddings
														_a	     =				d_model
														_a	     =				encoder_ffn_dim
														_a	     =				encoder_layers
														_a	     =				encoder_attention_heads
														_a	     =				decoder_ffn_dim
														_a	     =				decoder_layers
														_a	     =				decoder_attention_heads
														_a	     =				dropout
														_a	     =				attention_dropout
														_a	     =				activation_dropout
														_a	     =				activation_function
														_a	     =				init_std
														_a	     =				encoder_layerdrop
														_a	     =				decoder_layerdrop
														_a	     =				use_cache
														_a	     =				encoder_layers
														_a	     =				scale_embedding  # scale factor will be sqrt(d_model) if True

														super().__init__(
														    pad_token_id=lowerCAmelCase_							,			bos_token_id=lowerCAmelCase_							,			eos_token_id=lowerCAmelCase_							,			is_encoder_decoder=lowerCAmelCase_							,			decoder_start_token_id=lowerCAmelCase_							,			encoder_no_repeat_ngram_size=lowerCAmelCase_							,			forced_eos_token_id=lowerCAmelCase_							,			**lowerCAmelCase_							,			)



class 			A    (		_a    ):







							@property
							def    __lowerCAmelCase			(  self       :  Optional[int]					)			->							Mapping[str, Mapping[int, str]]:


														"""simple docstring"""


														if self.task in ["default", "seq2seq-lm"]:
																					_a	     =				OrderedDict(
																					    [
																					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					    ]					)
																					if self.use_past:
																												_a	     =				{0: '''batch'''}
																												_a	     =				{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
																					else:
																												_a	     =				{0: '''batch''', 1: '''decoder_sequence'''}
																												_a	     =				{0: '''batch''', 1: '''decoder_sequence'''}
																					if self.use_past:
																												self.fill_with_past_key_values_(lowerCAmelCase_							,			direction='''inputs'''					)
														elif self.task == "causal-lm":
																					_a	     =				OrderedDict(
																					    [
																					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					    ]					)
																					if self.use_past:
																												_a     ,							_a	     =				self.num_layers
																												for i in range(lowerCAmelCase_					):
																																			_a	     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
																																			_a	     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
														else:
																					_a	     =				OrderedDict(
																					    [
																					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																					        ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
																					        ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
																					    ]					)

														return common_inputs







							@property
							# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
							def    __lowerCAmelCase			(  self       :  Optional[Any]					)			->							Mapping[str, Mapping[int, str]]:


														"""simple docstring"""


														if self.task in ["default", "seq2seq-lm"]:
																					_a	     =				super().outputs
														else:
																					_a	     =				super(lowerCAmelCase_							,			self					).outputs
																					if self.use_past:
																												_a     ,							_a	     =				self.num_layers
																												for i in range(lowerCAmelCase_					):
																																			_a	     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
																																			_a	     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
														return common_outputs







							def    __lowerCAmelCase			(  self       :  List[str]							,			lowerCAmelCase_       :  PreTrainedTokenizer							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  bool = False							,			lowerCAmelCase_       :  Optional[TensorType] = None							,			)			->							Mapping[str, Any]:


														"""simple docstring"""


														_a	     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
														    lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)
														# Generate decoder inputs
														_a	     =				seq_length if not self.use_past else 1
														_a	     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
														    lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)
														_a	     =				{F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
														_a	     =				dict(**lowerCAmelCase_							,			**lowerCAmelCase_					)

														if self.use_past:
																					if not is_torch_available():
																												raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''					)
																					else:
																												import torch
																					_a     ,							_a	     =				common_inputs['''input_ids'''].shape
																					_a	     =				common_inputs['''decoder_input_ids'''].shape[1]
																					_a     ,							_a	     =				self.num_attention_heads
																					_a	     =				(
																					    batch,
																					    num_encoder_attention_heads,
																					    encoder_seq_length,
																					    self._config.hidden_size // num_encoder_attention_heads,
																					)
																					_a	     =				decoder_seq_length
																					_a	     =				(
																					    batch,
																					    num_decoder_attention_heads,
																					    decoder_past_length,
																					    self._config.hidden_size // num_decoder_attention_heads,
																					)
																					_a	     =				torch.cat(
																					    [common_inputs['''decoder_attention_mask'''], torch.ones(lowerCAmelCase_							,			lowerCAmelCase_					)]							,			dim=1					)
																					_a	     =				[]
																					_a     ,							_a	     =				self.num_layers

																					for _ in range(lowerCAmelCase_					):
																												common_inputs["past_key_values"].append(
																												    (
																												        torch.zeros(lowerCAmelCase_					),
																												        torch.zeros(lowerCAmelCase_					),
																												        torch.zeros(lowerCAmelCase_					),
																												        torch.zeros(lowerCAmelCase_					),
																												    )					)
														return common_inputs







							def    __lowerCAmelCase			(  self       :  Optional[int]							,			lowerCAmelCase_       :  PreTrainedTokenizer							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  bool = False							,			lowerCAmelCase_       :  Optional[TensorType] = None							,			)			->							Mapping[str, Any]:


														"""simple docstring"""


														_a	     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
														    lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)

														if self.use_past:
																					if not is_torch_available():
																												raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''					)
																					else:
																												import torch
																					_a     ,							_a	     =				common_inputs['''input_ids'''].shape
																					_a	     =				seqlen
																					_a     ,							_a	     =				self.num_layers
																					_a     ,							_a	     =				self.num_attention_heads
																					_a	     =				(
																					    batch,
																					    num_encoder_attention_heads,
																					    past_key_values_length,
																					    self._config.hidden_size // num_encoder_attention_heads,
																					)
																					_a	     =				common_inputs['''attention_mask'''].dtype
																					_a	     =				torch.cat(
																					    [common_inputs['''attention_mask'''], torch.ones(lowerCAmelCase_							,			lowerCAmelCase_							,			dtype=lowerCAmelCase_					)]							,			dim=1					)
																					_a	     =				[
																					    (torch.zeros(lowerCAmelCase_					), torch.zeros(lowerCAmelCase_					)) for _ in range(lowerCAmelCase_					)
																					]
														return common_inputs







							def    __lowerCAmelCase			(  self       :  int							,			lowerCAmelCase_       :  PreTrainedTokenizer							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  bool = False							,			lowerCAmelCase_       :  Optional[TensorType] = None							,			)			->							Mapping[str, Any]:


														"""simple docstring"""


														_a	     =				compute_effective_axis_dimension(
														    lowerCAmelCase_							,			fixed_dimension=OnnxConfig.default_fixed_batch							,			num_token_to_add=0					)

														# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
														_a	     =				tokenizer.num_special_tokens_to_add(lowerCAmelCase_					)
														_a	     =				compute_effective_axis_dimension(
														    lowerCAmelCase_							,			fixed_dimension=OnnxConfig.default_fixed_sequence							,			num_token_to_add=lowerCAmelCase_					)

														# Generate dummy inputs according to compute batch and sequence
														_a	     =				[''' '''.join([tokenizer.unk_token]					) * seq_length] * batch_size
														_a	     =				dict(tokenizer(lowerCAmelCase_							,			return_tensors=lowerCAmelCase_					)					)
														return common_inputs







							def    __lowerCAmelCase			(  self       :  str							,			lowerCAmelCase_       :  PreTrainedTokenizer							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  int = -1							,			lowerCAmelCase_       :  bool = False							,			lowerCAmelCase_       :  Optional[TensorType] = None							,			)			->							Mapping[str, Any]:


														"""simple docstring"""


														if self.task in ["default", "seq2seq-lm"]:
																					_a	     =				self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																					    lowerCAmelCase_							,			batch_size=lowerCAmelCase_							,			seq_length=lowerCAmelCase_							,			is_pair=lowerCAmelCase_							,			framework=lowerCAmelCase_					)

														elif self.task == "causal-lm":
																					_a	     =				self._generate_dummy_inputs_for_causal_lm(
																					    lowerCAmelCase_							,			batch_size=lowerCAmelCase_							,			seq_length=lowerCAmelCase_							,			is_pair=lowerCAmelCase_							,			framework=lowerCAmelCase_					)
														else:
																					_a	     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
																					    lowerCAmelCase_							,			batch_size=lowerCAmelCase_							,			seq_length=lowerCAmelCase_							,			is_pair=lowerCAmelCase_							,			framework=lowerCAmelCase_					)

														return common_inputs







							def    __lowerCAmelCase			(  self       :  Union[str, Any]							,			lowerCAmelCase_       :  List[str]							,			lowerCAmelCase_       :  List[str]							,			lowerCAmelCase_       :  Optional[Any]							,			lowerCAmelCase_       :  List[Any]					)			->							List[str]:


														"""simple docstring"""


														if self.task in ["default", "seq2seq-lm"]:
																					_a	     =				super()._flatten_past_key_values_(lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)
														else:
																					_a	     =				super(lowerCAmelCase_							,			self					)._flatten_past_key_values_(
																					    lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)







							def    __lowerCAmelCase			(  self       :  Dict							,			lowerCAmelCase_       :  Mapping[str, Mapping[int, str]]							,			lowerCAmelCase_       :  str					)			->							Dict:


														"""simple docstring"""


														if direction not in ["inputs", "outputs"]:
																					raise ValueError(F'direction must either be "inputs" or "outputs", but {direction} was given'					)

														_a	     =				'''past_key_values''' if direction == '''inputs''' else '''present'''
														_a     ,							_a	     =				self.num_layers

														_a	     =				'''past_encoder_sequence'''
														_a	     =				'''past_decoder_sequence''' if direction == '''inputs''' else '''past_decoder_sequence + sequence'''

														for i in range(lowerCAmelCase_					):
																					_a	     =				{0: '''batch''', 2: decoder_sequence}
																					_a	     =				{0: '''batch''', 2: decoder_sequence}
																					_a	     =				{0: '''batch''', 2: encoder_sequence}
																					_a	     =				{0: '''batch''', 2: encoder_sequence}







'''simple docstring'''


from typing import List

from packaging import version
from sklearn.metrics import fa_score

import datasets
from datasets.config import PY_VERSION


if PY_VERSION < version.parse('3.8'):
				import importlib_metadata
else:
				import importlib.metadata as importlib_metadata


# TODO(Patrick/Anton)
_snake_case      :      Optional[int]   							=		'\\n'

_snake_case      :      Optional[Any]   							=		'\\n    XTREME-S is a benchmark to evaluate universal cross-lingual speech representations in many languages.\n    XTREME-S covers four task families: speech recognition, classification, speech-to-text translation and retrieval.\n'

_snake_case      :      Union[str, Any]   							=		'\nCompute XTREME-S evaluation metric associated to each XTREME-S dataset.\nArgs:\n    predictions: list of predictions to score.\n        Each translation should be tokenized into a list of tokens.\n    references: list of lists of references for each translation.\n        Each reference should be tokenized into a list of tokens.\n    bleu_kwargs: optional dict of keywords to be passed when computing \'bleu\'.\n        Keywords include Dict can be one of \'smooth_method\', \'smooth_value\', \'force\', \'lowercase\',\n        \'tokenize\', \'use_effective_order\'.\n    wer_kwargs: optional dict of keywords to be passed when computing \'wer\' and \'cer\'.\n        Keywords include \'concatenate_texts\'.\nReturns: depending on the XTREME-S task, one or several of:\n    "accuracy": Accuracy - for \'fleurs-lang_id\', \'minds14\'\n    "f1": F1 score - for \'minds14\'\n    "wer": Word error rate - for \'mls\', \'fleurs-asr\', \'voxpopuli\', \'babel\'\n    "cer": Character error rate - for \'mls\', \'fleurs-asr\', \'voxpopuli\', \'babel\'\n    "bleu": BLEU score according to the `sacrebleu` metric - for \'covost2\'\nExamples:\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'mls\')  # \'mls\', \'voxpopuli\', \'fleurs-asr\' or \'babel\'\n    >>> references = ["it is sunny here", "paper and pen are essentials"]\n    >>> predictions = ["it\'s sunny", "paper pen are essential"]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'wer\': 0.56, \'cer\': 0.27}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'covost2\')\n    >>> references = ["bonjour paris", "il est necessaire de faire du sport de temps en temp"]\n    >>> predictions = ["bonjour paris", "il est important de faire du sport souvent"]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'bleu\': 31.65}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'fleurs-lang_id\')\n    >>> references = [0, 1, 0, 0, 1]\n    >>> predictions = [0, 1, 1, 0, 0]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'accuracy\': 0.6}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'minds14\')\n    >>> references = [0, 1, 0, 0, 1]\n    >>> predictions = [0, 1, 1, 0, 0]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'f1\': 0.58, \'accuracy\': 0.6}\n'

_snake_case      :      Dict   							=		['fleurs-asr', 'mls', 'voxpopuli', 'babel', 'covost2', 'fleurs-lang_id', 'minds14']
_snake_case      :      List[str]   							=		''

try:
				from jiwer import transforms as tr

				_snake_case      :      Optional[Any]   							=		True
except ImportError:
				_snake_case      :      Any   							=		False

if _jiwer_available and version.parse(importlib_metadata.version('jiwer')) < version.parse('2.3.0'):

				class 			A    (		tr.AbstractTransform    ):







											def __init__(  self       :  Any							,			lowerCAmelCase_       :  str = " "					)			->							Dict:


																		"""simple docstring"""


																		_a	     =				sentence_delimiter







											def    __lowerCAmelCase			(  self       :  Union[str, Any]							,			lowerCAmelCase_       :  str					)			->							Tuple:


																		"""simple docstring"""


																		return list(lowerCAmelCase_					)







											def    __lowerCAmelCase			(  self       :  Optional[int]							,			lowerCAmelCase_       :  List[str]					)			->							List[str]:


																		"""simple docstring"""


																		_a	     =				[]
																		for sent_idx, sentence in enumerate(lowerCAmelCase_					):
																									chars.extend(self.process_string(lowerCAmelCase_					)					)
																									if self.sentence_delimiter is not None and self.sentence_delimiter != "" and sent_idx < len(lowerCAmelCase_					) - 1:
																																chars.append(self.sentence_delimiter					)
																		return chars



				_snake_case      :      List[Any]   							=		tr.Compose(
				    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
				)
elif _jiwer_available:
				_snake_case      :      Dict   							=		tr.Compose(
				    [
				        tr.RemoveMultipleSpaces(),
				        tr.Strip(),
				        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
				        tr.ReduceToListOfListOfChars(),
				    ]
				)
else:
				_snake_case      :      Dict   							=		None
def 		snake_case_    (UpperCamelCase       :  Optional[Any] ,						UpperCamelCase       :  List[str]      ):





							'''simple docstring'''


							return float((preds == labels).mean()      )
def 		snake_case_    (UpperCamelCase       :  Optional[int] ,						UpperCamelCase       :  Optional[int]      ):





							'''simple docstring'''


							return {
							    "f1": float(fa_score(y_true=UpperCamelCase ,						y_pred=UpperCamelCase ,						average='''macro'''      )      ),
							    "accuracy": simple_accuracy(UpperCamelCase ,						UpperCamelCase      ),
							}
def 		snake_case_    (UpperCamelCase       :  Optional[int] ,						UpperCamelCase       :  Any ,						UpperCamelCase       :  Optional[Any]="exp" ,						UpperCamelCase       :  Optional[int]=None ,						UpperCamelCase       :  Tuple=False ,						UpperCamelCase       :  Dict=False ,						UpperCamelCase       :  List[str]=None ,						UpperCamelCase       :  Tuple=False ,						):





							'''simple docstring'''


							_a	     =				[[label] for label in labels]
							_a	     =				list(UpperCamelCase      )
							try:
														import sacrebleu as scb
							except ImportError:
														raise ValueError(
														    '''sacrebleu has to be installed in order to apply the bleu metric for covost2.'''
														    '''You can install it via `pip install sacrebleu`.'''      )

							if version.parse(scb.__version__      ) < version.parse('''1.4.12'''      ):
														raise ImportWarning(
														    '''To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn\'t match this condition.\n'''
														    '''You can install it with `pip install "sacrebleu>=1.4.12"`.'''      )

							_a	     =				len(labels[0]      )
							if any(len(UpperCamelCase      ) != references_per_prediction for refs in labels      ):
														raise ValueError('''Sacrebleu requires the same number of references for each prediction'''      )
							_a	     =				[[refs[i] for refs in labels] for i in range(UpperCamelCase      )]
							_a	     =				scb.corpus_bleu(
							    UpperCamelCase ,						UpperCamelCase ,						smooth_method=UpperCamelCase ,						smooth_value=UpperCamelCase ,						force=UpperCamelCase ,						lowercase=UpperCamelCase ,						use_effective_order=UpperCamelCase ,						**({'''tokenize''': tokenize} if tokenize else {}) ,						)
							return {"bleu": output.score}
def 		snake_case_    (UpperCamelCase       :  Optional[Any] ,						UpperCamelCase       :  Dict ,						UpperCamelCase       :  str ,						UpperCamelCase       :  List[Any]      ):





							'''simple docstring'''


							try:
														from jiwer import compute_measures
							except ImportError:
														raise ValueError(
														    f'jiwer has to be installed in order to apply the wer metric for {config_name}.'
														    '''You can install it via `pip install jiwer`.'''      )

							if concatenate_texts:
														_a	     =				compute_measures(UpperCamelCase ,						UpperCamelCase      )['''wer''']

														_a	     =				compute_measures(UpperCamelCase ,						UpperCamelCase ,						truth_transform=UpperCamelCase ,						hypothesis_transform=UpperCamelCase      )['''wer''']
														return {"wer": wer, "cer": cer}
							else:

														def compute_score(UpperCamelCase       :  Tuple ,						UpperCamelCase       :  Optional[int] ,						UpperCamelCase       :  Dict="wer"      ):
																					_a	     =				0
																					_a	     =				0
																					for prediction, reference in zip(UpperCamelCase ,						UpperCamelCase      ):
																												if score_type == "wer":
																																			_a	     =				compute_measures(UpperCamelCase ,						UpperCamelCase      )
																												elif score_type == "cer":
																																			_a	     =				compute_measures(
																																			    UpperCamelCase ,						UpperCamelCase ,						truth_transform=UpperCamelCase ,						hypothesis_transform=UpperCamelCase      )
																												incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
																												total += measures["substitutions"] + measures["deletions"] + measures["hits"]
																					return incorrect / total

														return {"wer": compute_score(UpperCamelCase ,						UpperCamelCase ,						'''wer'''      ), "cer": compute_score(UpperCamelCase ,						UpperCamelCase ,						'''cer'''      )}

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







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Dict:


														"""simple docstring"""


														if self.config_name not in _CONFIG_NAMES:
																					raise KeyError(F'You should supply a configuration name selected in {_CONFIG_NAMES}'					)

														_a	     =				'''int64''' if self.config_name in ['''fleurs-lang_id''', '''minds14'''] else '''string'''

														return datasets.MetricInfo(
														    description=_DESCRIPTION							,			citation=_CITATION							,			inputs_description=_KWARGS_DESCRIPTION							,			features=datasets.Features(
														        {'''predictions''': datasets.Value(lowerCAmelCase_					), '''references''': datasets.Value(lowerCAmelCase_					)}					)							,			codebase_urls=[]							,			reference_urls=[]							,			format='''numpy'''							,			)







							def    __lowerCAmelCase			(  self       :  Optional[int]							,			lowerCAmelCase_       :  Union[str, Any]							,			lowerCAmelCase_       :  Optional[Any]							,			lowerCAmelCase_       :  List[Any]=None							,			lowerCAmelCase_       :  int=None					)			->							Tuple:


														"""simple docstring"""


														_a	     =				bleu_kwargs if bleu_kwargs is not None else {}
														_a	     =				wer_kwargs if wer_kwargs is not None else {}

														if self.config_name == "fleurs-lang_id":
																					return {"accuracy": simple_accuracy(lowerCAmelCase_							,			lowerCAmelCase_					)}
														elif self.config_name == "minds14":
																					return fa_and_simple_accuracy(lowerCAmelCase_							,			lowerCAmelCase_					)
														elif self.config_name == "covost2":
																					_a	     =				bleu_kwargs.pop('''smooth_method'''							,			'''exp'''					)
																					_a	     =				bleu_kwargs.pop('''smooth_value'''							,			lowerCAmelCase_					)
																					_a	     =				bleu_kwargs.pop('''force'''							,			lowerCAmelCase_					)
																					_a	     =				bleu_kwargs.pop('''lowercase'''							,			lowerCAmelCase_					)
																					_a	     =				bleu_kwargs.pop('''tokenize'''							,			lowerCAmelCase_					)
																					_a	     =				bleu_kwargs.pop('''use_effective_order'''							,			lowerCAmelCase_					)
																					return bleu(
																					    preds=lowerCAmelCase_							,			labels=lowerCAmelCase_							,			smooth_method=lowerCAmelCase_							,			smooth_value=lowerCAmelCase_							,			force=lowerCAmelCase_							,			lowercase=lowerCAmelCase_							,			tokenize=lowerCAmelCase_							,			use_effective_order=lowerCAmelCase_							,			)
														elif self.config_name in ["fleurs-asr", "mls", "voxpopuli", "babel"]:
																					_a	     =				wer_kwargs.pop('''concatenate_texts'''							,			lowerCAmelCase_					)
																					return wer_and_cer(lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_							,			self.config_name					)
														else:
																					raise KeyError(F'You should supply a configuration name selected in {_CONFIG_NAMES}'					)

