





"""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


a						: Union[str, Any]     	=			''''''


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


		class        __UpperCamelCase				(						tr.AbstractTransform						):






									def __init__(   self      ,					lowerCAmelCase__ = " "      )	-> str:
										a      :		Optional[Any]	=				sentence_delimiter






									def     __a   (   self      ,					lowerCAmelCase__      )	-> Optional[int]:
										return list(lowerCAmelCase__      )






									def     __a   (   self      ,					lowerCAmelCase__      )	-> Optional[int]:
										a      :		Dict	=				[]
										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						: Optional[int]     	=			tr.Compose(
		    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
		)
else:
		a						: Any     	=			tr.Compose(
		    [
		        tr.RemoveMultipleSpaces(),
		        tr.Strip(),
		        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
		        tr.ReduceToListOfListOfChars(),
		    ]
		)


a						: Tuple     	=			'''\
@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						: Any     	=			'''\
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        __UpperCamelCase				(						datasets.Metric						):






							def     __a   (   self      )	-> int:
								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      ,					lowerCAmelCase__      ,					lowerCAmelCase__      ,					lowerCAmelCase__=False      )	-> Optional[int]:
								if concatenate_texts:
									return jiwer.compute_measures(
									    lowerCAmelCase__      ,					lowerCAmelCase__      ,					truth_transform=lowerCAmelCase__      ,					hypothesis_transform=lowerCAmelCase__      ,					)["wer"]

								a      :		str	=				0
								a      :		int	=				0
								for prediction, reference in zip(lowerCAmelCase__      ,					lowerCAmelCase__      ):
									a      :		Optional[int]	=				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










"""simple docstring"""





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_SCREAMING_SNAKE_CASE					:				Optional[int]					    =						'''
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
'''






class      a						(					unittest.TestCase  ,      __snake_case		):






    def    UpperCamelCase       (       self     :							int					)     ->		Optional[int]:
      lowerCamelCase_         =						load_tool('text-question-answering'					)
      self.tool.setup()
      lowerCamelCase_         =						load_tool('text-question-answering'       ,						remote=__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Dict					)     ->		Tuple:
      lowerCamelCase_         =						self.tool(__SCREAMING_SNAKE_CASE       ,						'What did Hugging Face do in April 2021?'					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						'launched the BigScience Research Workshop'					)






    def    UpperCamelCase       (       self     :							List[Any]					)     ->		Optional[int]:
      lowerCamelCase_         =						self.remote_tool(__SCREAMING_SNAKE_CASE       ,						'What did Hugging Face do in April 2021?'					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						'launched the BigScience Research Workshop'					)






    def    UpperCamelCase       (       self     :							List[str]					)     ->		Optional[int]:
      lowerCamelCase_         =						self.tool(text=__SCREAMING_SNAKE_CASE       ,						question='What did Hugging Face do in April 2021?'					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						'launched the BigScience Research Workshop'					)






    def    UpperCamelCase       (       self     :							Union[str, Any]					)     ->		int:
      lowerCamelCase_         =						self.remote_tool(text=__SCREAMING_SNAKE_CASE       ,						question='What did Hugging Face do in April 2021?'					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						'launched the BigScience Research Workshop'					)




