



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


_lowerCamelCase	:       int      	=	""


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

   class  SCREAMING_SNAKE_CASE (  tr.AbstractTransform		):






       """simple docstring"""





       def __init__(  self      :					Optional[Any]  ,						UpperCamelCase__      :					str = " " ):


          """simple docstring"""







          UpperCamelCase					=  sentence_delimiter






       def  A       (  self      :					Union[str, Any]  ,						UpperCamelCase__      :					str ):


          """simple docstring"""







          return list(UpperCamelCase__ )






       def  A       (  self      :					List[str]  ,						UpperCamelCase__      :					List[str] ):


          """simple docstring"""







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

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


_lowerCamelCase	:       str      	=	"\\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"

_lowerCamelCase	:       List[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"

_lowerCamelCase	:       Tuple      	=	"\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  SCREAMING_SNAKE_CASE (  datasets.Metric		):






    """simple docstring"""





    def  A       (  self      :					Optional[Any] ):


       """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      :					List[str]  ,						UpperCamelCase__      :					Optional[Any]  ,						UpperCamelCase__      :					List[str]  ,						UpperCamelCase__      :					Union[str, Any]=False ):


       """simple docstring"""







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

       UpperCamelCase					=  0
       UpperCamelCase					=  0
       for prediction, reference in zip(UpperCamelCase__  ,						UpperCamelCase__ ):
          UpperCamelCase					=  jiwer.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





import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_A		       =						logging.get_logger(__name__)

_A		       =						{
    'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/config.json',
}






class     UpperCAmelCase__       (					A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]      =  "mvp"
    UpperCAmelCase__						:		Tuple      =  ["past_key_values"]
    UpperCAmelCase__						:		Union[str, Any]      =  {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}






    def __init__(			self					,   A_=50267					,   A_=1024					,   A_=12					,   A_=4096					,   A_=16					,   A_=12					,   A_=4096					,   A_=16					,   A_=0.0					,   A_=0.0					,   A_="gelu"					,   A_=1024					,   A_=0.1					,   A_=0.0					,   A_=0.0					,   A_=0.02					,   A_=0.0					,   A_=False					,   A_=True					,   A_=1					,   A_=0					,   A_=2					,   A_=True					,   A_=2					,   A_=2					,   A_=False					,   A_=100					,   A_=800					,   **A_					,   )  ->       Union[str, Any]:
         __UpperCamelCase    							=vocab_size
         __UpperCamelCase    							=max_position_embeddings
         __UpperCamelCase    							=d_model
         __UpperCamelCase    							=encoder_ffn_dim
         __UpperCamelCase    							=encoder_layers
         __UpperCamelCase    							=encoder_attention_heads
         __UpperCamelCase    							=decoder_ffn_dim
         __UpperCamelCase    							=decoder_layers
         __UpperCamelCase    							=decoder_attention_heads
         __UpperCamelCase    							=dropout
         __UpperCamelCase    							=attention_dropout
         __UpperCamelCase    							=activation_dropout
         __UpperCamelCase    							=activation_function
         __UpperCamelCase    							=init_std
         __UpperCamelCase    							=encoder_layerdrop
         __UpperCamelCase    							=decoder_layerdrop
         __UpperCamelCase    							=classifier_dropout
         __UpperCamelCase    							=use_cache
         __UpperCamelCase    							=encoder_layers
         __UpperCamelCase    							=scale_embedding  # scale factor will be sqrt(d_model) if True
         __UpperCamelCase    							=use_prompt
         __UpperCamelCase    							=prompt_length
         __UpperCamelCase    							=prompt_mid_dim

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

         if self.forced_bos_token_id is None and kwargs.get('force_bos_token_to_be_generated'					,   A_    ):
              __UpperCamelCase    							=self.bos_token_id
              warnings.warn(
                  f'Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. '
                  'The config can simply be saved and uploaded again to be fixed.'    )





