





from typing import List

import jiwer
import jiwer.transforms as tr
from packaging import version

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


A    :					Dict =      ''''''


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


					class   A			(tr.AbstractTransform    ):
								'''simple docstring'''




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







										"""simple docstring"""






										A__        =   sentence_delimiter






								def    a_       (			self   :    Any							,	__lowerCAmelCase   :    str   )	->	int:







										"""simple docstring"""






										return list(__lowerCAmelCase   )







								def    a_       (			self   :    Any							,	__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

					A    :					Union[str, Any] =      tr.Compose(
					    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
					)
else:
					A    :					int =      tr.Compose(
					    [
					        tr.RemoveMultipleSpaces(),
					        tr.Strip(),
					        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
					        tr.ReduceToListOfListOfChars(),
					    ]
					)


A    :					List[str] =      '''\
@inproceedings{inproceedings,
    author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
    year = {2004},
    month = {01},
    pages = {},
    title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
}
'''

A    :					Optional[int] =      '''\
Character error rate (CER) is a common metric of the performance of an automatic speech recognition system.

CER is similar to Word Error Rate (WER), but operates on character instead of word. Please refer to docs of WER for further information.

Character error rate can be computed as:

CER = (S + D + I) / N = (S + D + I) / (S + D + C)

where

S is the number of substitutions,
D is the number of deletions,
I is the number of insertions,
C is the number of correct characters,
N is the number of characters in the reference (N=S+D+C).

CER\'s output is not always a number between 0 and 1, in particular when there is a high number of insertions. This value is often associated to the percentage of characters that were incorrectly predicted. The lower the value, the better the
performance of the ASR system with a CER of 0 being a perfect score.
'''

A    :					Optional[Any] =      '''
Computes CER score of transcribed segments against references.
Args:
    references: list of references for each speech input.
    predictions: list of transcribtions to score.
    concatenate_texts: Whether or not to concatenate sentences before evaluation, set to True for more accurate result.
Returns:
    (float): the character error rate

Examples:

    >>> predictions = ["this is the prediction", "there is an other sample"]
    >>> references = ["this is the reference", "there is another one"]
    >>> cer = datasets.load_metric("cer")
    >>> cer_score = cer.compute(predictions=predictions, references=references)
    >>> print(cer_score)
    0.34146341463414637
'''


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




			def    a_       (			self   :    Optional[int]   )	->	Dict:







					"""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"""   ),
					        }   )							,	codebase_urls=["""https://github.com/jitsi/jiwer/"""]							,	reference_urls=[
					        """https://en.wikipedia.org/wiki/Word_error_rate""",
					        """https://sites.google.com/site/textdigitisation/qualitymeasures/computingerrorrates""",
					    ]							,	)







			def    a_       (			self   :    Any							,	__lowerCAmelCase   :    Dict							,	__lowerCAmelCase   :    str							,	__lowerCAmelCase   :    List[str]=False   )	->	Any:







					"""simple docstring"""






					if concatenate_texts:
							return jiwer.compute_measures(
							    __lowerCAmelCase							,	__lowerCAmelCase							,	truth_transform=__lowerCAmelCase							,	hypothesis_transform=__lowerCAmelCase							,	)["wer"]

					A__        =   0
					A__        =   0
					for prediction, reference in zip(__lowerCAmelCase							,	__lowerCAmelCase   ):
							A__        =   jiwer.compute_measures(
							    __lowerCAmelCase							,	__lowerCAmelCase							,	truth_transform=__lowerCAmelCase							,	hypothesis_transform=__lowerCAmelCase							,	)
							incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
							total += measures["substitutions"] + measures["deletions"] + measures["hits"]

					return incorrect / total










from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A    :					Union[str, Any] =      logging.get_logger(__name__)

A    :					int =      {
    '''xlm-roberta-base''': '''https://huggingface.co/xlm-roberta-base/resolve/main/config.json''',
    '''xlm-roberta-large''': '''https://huggingface.co/xlm-roberta-large/resolve/main/config.json''',
    '''xlm-roberta-large-finetuned-conll02-dutch''': (
        '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-dutch/resolve/main/config.json'''
    ),
    '''xlm-roberta-large-finetuned-conll02-spanish''': (
        '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-spanish/resolve/main/config.json'''
    ),
    '''xlm-roberta-large-finetuned-conll03-english''': (
        '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/resolve/main/config.json'''
    ),
    '''xlm-roberta-large-finetuned-conll03-german''': (
        '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-german/resolve/main/config.json'''
    ),
}


class   A			(SCREAMING_SNAKE_CASE    ):
			'''simple docstring'''




			__lowerCamelCase	:       Any							=    '''xlm-roberta'''






			def __init__(			self   :    Optional[Any]							,	__lowerCAmelCase   :    List[Any]=3_05_22							,	__lowerCAmelCase   :    int=7_68							,	__lowerCAmelCase   :    Tuple=12							,	__lowerCAmelCase   :    str=12							,	__lowerCAmelCase   :    Union[str, Any]=30_72							,	__lowerCAmelCase   :    Union[str, Any]="gelu"							,	__lowerCAmelCase   :    Optional[int]=0.1							,	__lowerCAmelCase   :    Dict=0.1							,	__lowerCAmelCase   :    List[str]=5_12							,	__lowerCAmelCase   :    Tuple=2							,	__lowerCAmelCase   :    Dict=0.0_2							,	__lowerCAmelCase   :    List[str]=1e-12							,	__lowerCAmelCase   :    Union[str, Any]=1							,	__lowerCAmelCase   :    str=0							,	__lowerCAmelCase   :    Optional[int]=2							,	__lowerCAmelCase   :    Tuple="absolute"							,	__lowerCAmelCase   :    Any=True							,	__lowerCAmelCase   :    Any=None							,	**__lowerCAmelCase   :    str							,	)	->	Optional[Any]:







					"""simple docstring"""






					super().__init__(pad_token_id=__lowerCAmelCase							,	bos_token_id=__lowerCAmelCase							,	eos_token_id=__lowerCAmelCase							,	**__lowerCAmelCase   )

					A__        =   vocab_size
					A__        =   hidden_size
					A__        =   num_hidden_layers
					A__        =   num_attention_heads
					A__        =   hidden_act
					A__        =   intermediate_size
					A__        =   hidden_dropout_prob
					A__        =   attention_probs_dropout_prob
					A__        =   max_position_embeddings
					A__        =   type_vocab_size
					A__        =   initializer_range
					A__        =   layer_norm_eps
					A__        =   position_embedding_type
					A__        =   use_cache
					A__        =   classifier_dropout


class   A			(SCREAMING_SNAKE_CASE    ):
			'''simple docstring'''




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







					"""simple docstring"""






					if self.task == "multiple-choice":
							A__        =   {0: """batch""", 1: """choice""", 2: """sequence"""}
					else:
							A__        =   {0: """batch""", 1: """sequence"""}
					return OrderedDict(
					    [
					        ("""input_ids""", dynamic_axis),
					        ("""attention_mask""", dynamic_axis),
					    ]   )



