





from jiwer import compute_measures

import datasets


lowercase				:	Dict      						=  """\
@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.}
}
"""

lowercase				:	str      						=  """\
Word error rate (WER) is a common metric of the performance of an automatic speech recognition system.

The general difficulty of measuring performance lies in the fact that the recognized word sequence can have a different length from the reference word sequence (supposedly the correct one). The WER is derived from the Levenshtein distance, working at the word level instead of the phoneme level. The WER is a valuable tool for comparing different systems as well as for evaluating improvements within one system. This kind of measurement, however, provides no details on the nature of translation errors and further work is therefore required to identify the main source(s) of error and to focus any research effort.

This problem is solved by first aligning the recognized word sequence with the reference (spoken) word sequence using dynamic string alignment. Examination of this issue is seen through a theory called the power law that states the correlation between perplexity and word error rate.

Word error rate can then be computed as:

WER = (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 words,
N is the number of words in the reference (N=S+D+C).

This value indicates the average number of errors per reference word. The lower the value, the better the
performance of the ASR system with a WER of 0 being a perfect score.
"""

lowercase				:	str      						=  """
Compute WER score of transcribed segments against references.

Args:
    references: List of references for each speech input.
    predictions: List of transcriptions to score.
    concatenate_texts (bool, default=False): Whether to concatenate all input texts or compute WER iteratively.

Returns:
    (float): the word error rate

Examples:

    >>> predictions = [\"this is the prediction\", \"there is an other sample\"]
    >>> references = [\"this is the reference\", \"there is another one\"]
    >>> wer = datasets.load_metric(\"wer\")
    >>> wer_score = wer.compute(predictions=predictions, references=references)
    >>> print(wer_score)
    0.5
"""





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




   """simple docstring"""



   def 							__lowercase		( self)      ->						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',
              ] ,  )

   def 							__lowercase		( self ,  lowercase=None ,  lowercase=None ,  lowercase=False)      ->						str:







          '''simple docstring'''

          if concatenate_texts:
                 return compute_measures(lowercase ,  lowercase)["wer"]
          else:
                 a__						:     List[Any]			=    0
                 a__						:     str			=    0
                 for prediction, reference in zip(lowercase ,  lowercase):
                        a__						:     Tuple			=    compute_measures(lowercase ,  lowercase)
                        incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
                        total += measures["substitutions"] + measures["deletions"] + measures["hits"]
                 return incorrect / total









import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mvp import MvpTokenizer


lowercase				:	List[Any]      						=  logging.get_logger(__name__)


lowercase				:	Any      						=  {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

# See all MVP models at https://huggingface.co/models?filter=mvp
lowercase				:	Optional[Any]      						=  {
    """vocab_file""": {
        """RUCAIBox/mvp""": """https://huggingface.co/RUCAIBox/mvp/resolve/main/vocab.json""",
    },
    """added_tokens.json""": {
        """RUCAIBox/mvp""": """https://huggingface.co/RUCAIBox/mvp/resolve/main/added_tokens.json""",
    },
    """merges_file""": {
        """RUCAIBox/mvp""": """https://huggingface.co/RUCAIBox/mvp/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """RUCAIBox/mvp""": """https://huggingface.co/RUCAIBox/mvp/resolve/main/tokenizer.json""",
    },
}

lowercase				:	List[str]      						=  {
    """RUCAIBox/mvp""": 1_0_2_4,
}





class 			A__   (							__UpperCAmelCase     ):




   """simple docstring"""



   __A       :    Dict	  =  VOCAB_FILES_NAMES
   __A       :    str	  =  PRETRAINED_VOCAB_FILES_MAP
   __A       :    Tuple	  =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __A       :    Any	  =  ['''input_ids''', '''attention_mask''']
   __A       :    Tuple	  =  MvpTokenizer

   def __init__( self ,  lowercase=None ,  lowercase=None ,  lowercase=None ,  lowercase="replace" ,  lowercase="<s>" ,  lowercase="</s>" ,  lowercase="</s>" ,  lowercase="<s>" ,  lowercase="<unk>" ,  lowercase="<pad>" ,  lowercase="<mask>" ,  lowercase=False ,  lowercase=True ,  **lowercase ,  )      ->						str:







          '''simple docstring'''

          super().__init__(
              lowercase ,  lowercase ,  tokenizer_file=lowercase ,  errors=lowercase ,  bos_token=lowercase ,  eos_token=lowercase ,  sep_token=lowercase ,  cls_token=lowercase ,  unk_token=lowercase ,  pad_token=lowercase ,  mask_token=lowercase ,  add_prefix_space=lowercase ,  trim_offsets=lowercase ,  **lowercase ,  )

          a__						:     Optional[int]			=    json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__())
          if pre_tok_state.get('add_prefix_space' ,  lowercase) != add_prefix_space:
                 a__						:     Dict			=    getattr(lowercase ,  pre_tok_state.pop('type'))
                 a__						:     str			=    add_prefix_space
                 a__						:     Union[str, Any]			=    pre_tok_class(**lowercase)

          a__						:     List[Any]			=    add_prefix_space

          # the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
          a__						:     Optional[int]			=    'post_processor'
          a__						:     Optional[int]			=    getattr(self.backend_tokenizer ,  lowercase ,  lowercase)
          if tokenizer_component_instance:
                 a__						:     str			=    json.loads(tokenizer_component_instance.__getstate__())

                 # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
                 if "sep" in state:
                        a__						:     Any			=    tuple(state['sep'])
                 if "cls" in state:
                        a__						:     str			=    tuple(state['cls'])

                 a__						:     List[str]			=    False

                 if state.get('add_prefix_space' ,  lowercase) != add_prefix_space:
                        a__						:     List[str]			=    add_prefix_space
                        a__						:     List[str]			=    True

                 if state.get('trim_offsets' ,  lowercase) != trim_offsets:
                        a__						:     Optional[int]			=    trim_offsets
                        a__						:     List[str]			=    True

                 if changes_to_apply:
                        a__						:     Optional[int]			=    getattr(lowercase ,  state.pop('type'))
                        a__						:     Tuple			=    component_class(**lowercase)
                        setattr(self.backend_tokenizer ,  lowercase ,  lowercase)

   @property
   def 							__lowercase		( self)      ->						str:







          '''simple docstring'''

          if self._mask_token is None:
                 if self.verbose:
                        logger.error('Using mask_token, but it is not set yet.')
                 return None
          return str(self._mask_token)

   @mask_token.setter
   def 							__lowercase		( self ,  lowercase)      ->						Any:







          '''simple docstring'''

          a__						:     Tuple			=    AddedToken(lowercase ,  lstrip=lowercase ,  rstrip=lowercase) if isinstance(lowercase ,  lowercase) else value
          a__						:     str			=    value

   def 							__lowercase		( self ,  *lowercase ,  **lowercase)      ->						BatchEncoding:







          '''simple docstring'''

          a__						:     Optional[Any]			=    kwargs.get('is_split_into_words' ,  lowercase)

          if is_split_into_words and not self.add_prefix_space:
                 raise ValueError(
                     F'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                     'to use it with pretokenized inputs.')

          return super()._batch_encode_plus(*lowercase ,  **lowercase)

   def 							__lowercase		( self ,  *lowercase ,  **lowercase)      ->						BatchEncoding:







          '''simple docstring'''

          a__						:     List[str]			=    kwargs.get('is_split_into_words' ,  lowercase)

          if is_split_into_words and not self.add_prefix_space:
                 raise ValueError(
                     F'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                     'to use it with pretokenized inputs.')

          return super()._encode_plus(*lowercase ,  **lowercase)

   def 							__lowercase		( self ,  lowercase ,  lowercase = None)      ->						Tuple[str]:







          '''simple docstring'''

          a__						:     List[str]			=    self._tokenizer.model.save(lowercase ,  name=lowercase)
          return tuple(lowercase)

   def 							__lowercase		( self ,  lowercase ,  lowercase=None)      ->						Union[str, Any]:







          '''simple docstring'''

          a__						:     List[Any]			=    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
          if token_ids_a is None:
                 return output

          return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]

   def 							__lowercase		( self ,  lowercase ,  lowercase = None)      ->						List[int]:







          '''simple docstring'''

          a__						:     int			=    [self.sep_token_id]
          a__						:     Any			=    [self.cls_token_id]

          if token_ids_a is None:
                 return len(cls + token_ids_a + sep) * [0]
          return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]


