




'''simple docstring'''


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


SCREAMING_SNAKE_CASE__				:				str       							=		''


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

				class       A   (		tr.AbstractTransform   ):







											def __init__(  self	:  Union[str, Any]							,      lowerCAmelCase_	:  int = " " )      ->							Optional[int]:


																		"""simple docstring"""


																		_a     					=    sentence_delimiter







											def        __lowerCAmelCase      (  self	:  Any							,      lowerCAmelCase_	:  Dict )      ->							Dict:


																		"""simple docstring"""


																		return list(snake_case__ )







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


																		"""simple docstring"""


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



				SCREAMING_SNAKE_CASE__				:				Optional[Any]       							=		tr.Compose(
				    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
				)
else:
				SCREAMING_SNAKE_CASE__				:				Optional[Any]       							=		tr.Compose(
				    [
				        tr.RemoveMultipleSpaces(),
				        tr.Strip(),
				        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
				        tr.ReduceToListOfListOfChars(),
				    ]
				)


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

SCREAMING_SNAKE_CASE__				:				Any       							=		'\\nCharacter error rate (CER) is a common metric of the performance of an automatic speech recognition system.\n\nCER is similar to Word Error Rate (WER), but operates on character instead of word. Please refer to docs of WER for further information.\n\nCharacter error rate can be computed as:\n\nCER = (S + D + I) / N = (S + D + I) / (S + D + C)\n\nwhere\n\nS is the number of substitutions,\nD is the number of deletions,\nI is the number of insertions,\nC is the number of correct characters,\nN is the number of characters in the reference (N=S+D+C).\n\nCER\'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\nperformance of the ASR system with a CER of 0 being a perfect score.\n'

SCREAMING_SNAKE_CASE__				:				List[Any]       							=		'\nComputes CER score of transcribed segments against references.\nArgs:\n    references: list of references for each speech input.\n    predictions: list of transcribtions to score.\n    concatenate_texts: Whether or not to concatenate sentences before evaluation, set to True for more accurate result.\nReturns:\n    (float): the character error rate\n\nExamples:\n\n    >>> predictions = ["this is the prediction", "there is an other sample"]\n    >>> references = ["this is the reference", "there is another one"]\n    >>> cer = datasets.load_metric("cer")\n    >>> cer_score = cer.compute(predictions=predictions, references=references)\n    >>> print(cer_score)\n    0.34146341463414637\n'

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







							def        __lowerCAmelCase      (  self	:  Tuple )      ->							Tuple:


														"""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        __lowerCAmelCase      (  self	:  List[Any]							,      lowerCAmelCase_	:  Union[str, Any]							,      lowerCAmelCase_	:  List[str]							,      lowerCAmelCase_	:  str=False )      ->							List[Any]:


														"""simple docstring"""


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

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

														return incorrect / total







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_snake_case				:				List[str]       							=		{'configuration_xlnet': ['XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP', 'XLNetConfig']}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case				:				List[Any]       							=		['XLNetTokenizer']

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case				:				int       							=		['XLNetTokenizerFast']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case				:				Optional[int]       							=		[
				    'XLNET_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'XLNetForMultipleChoice',
				    'XLNetForQuestionAnswering',
				    'XLNetForQuestionAnsweringSimple',
				    'XLNetForSequenceClassification',
				    'XLNetForTokenClassification',
				    'XLNetLMHeadModel',
				    'XLNetModel',
				    'XLNetPreTrainedModel',
				    'load_tf_weights_in_xlnet',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case				:				str       							=		[
				    'TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'TFXLNetForMultipleChoice',
				    'TFXLNetForQuestionAnsweringSimple',
				    'TFXLNetForSequenceClassification',
				    'TFXLNetForTokenClassification',
				    'TFXLNetLMHeadModel',
				    'TFXLNetMainLayer',
				    'TFXLNetModel',
				    'TFXLNetPreTrainedModel',
				]


if TYPE_CHECKING:
				from .configuration_xlnet import XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLNetConfig

				try:
								if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_xlnet import XLNetTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_xlnet_fast import XLNetTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_xlnet import (
								    XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
								    XLNetForMultipleChoice,
								    XLNetForQuestionAnswering,
								    XLNetForQuestionAnsweringSimple,
								    XLNetForSequenceClassification,
								    XLNetForTokenClassification,
								    XLNetLMHeadModel,
								    XLNetModel,
								    XLNetPreTrainedModel,
								    load_tf_weights_in_xlnet,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_xlnet import (
								    TF_XLNET_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFXLNetForMultipleChoice,
								    TFXLNetForQuestionAnsweringSimple,
								    TFXLNetForSequenceClassification,
								    TFXLNetForTokenClassification,
								    TFXLNetLMHeadModel,
								    TFXLNetMainLayer,
								    TFXLNetModel,
								    TFXLNetPreTrainedModel,
								)

else:
				import sys

				_snake_case				:				Union[str, Any]       							=		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

