


'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mobilebert import MobileBertTokenizer


a_    :			Optional[int]      				=			logging.get_logger(__name__)

a_    :			Tuple      				=			{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

a_    :			Union[str, Any]      				=			{
    "vocab_file": {"mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/vocab.txt"},
    "tokenizer_file": {
        "mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/tokenizer.json"
    },
}

a_    :			int      				=			{"mobilebert-uncased": 5_1_2}


a_    :			Optional[Any]      				=			{}




class        a   (   _UpperCAmelCase				):
 _lowerCAmelCase           =		VOCAB_FILES_NAMES
 _lowerCAmelCase           =		PRETRAINED_VOCAB_FILES_MAP
 _lowerCAmelCase           =		PRETRAINED_INIT_CONFIGURATION
 _lowerCAmelCase           =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 _lowerCAmelCase           =		MobileBertTokenizer
 def __init__(       self					, __magic_name__=None					, __magic_name__=None					, __magic_name__=True					, __magic_name__="[UNK]"					, __magic_name__="[SEP]"					, __magic_name__="[PAD]"					, __magic_name__="[CLS]"					, __magic_name__="[MASK]"					, __magic_name__=True					, __magic_name__=None					, **__magic_name__					, )    ->							int:
      super().__init__(
          _UpperCAmelCase					, tokenizer_file=_UpperCAmelCase					, do_lower_case=_UpperCAmelCase					, unk_token=_UpperCAmelCase					, sep_token=_UpperCAmelCase					, pad_token=_UpperCAmelCase					, cls_token=_UpperCAmelCase					, mask_token=_UpperCAmelCase					, tokenize_chinese_chars=_UpperCAmelCase					, strip_accents=_UpperCAmelCase					, **_UpperCAmelCase					, )

      _a						=							json.loads(self.backend_tokenizer.normalizer.__getstate__()  )
      if (
          normalizer_state.get('lowercase'					, _UpperCAmelCase  ) != do_lower_case
          or normalizer_state.get('strip_accents'					, _UpperCAmelCase  ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'					, _UpperCAmelCase  ) != tokenize_chinese_chars
      ):
           _a						=							getattr(_UpperCAmelCase					, normalizer_state.pop('type'  )  )
           _a						=							do_lower_case
           _a						=							strip_accents
           _a						=							tokenize_chinese_chars
           _a						=							normalizer_class(**_UpperCAmelCase  )

      _a						=							do_lower_case
 def 							__UpperCAmelCase						(       self					, __magic_name__					, __magic_name__=None  )    ->							Any:
      _a						=							[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
           output += token_ids_a + [self.sep_token_id]

      return output
 def 							__UpperCAmelCase						(       self					, __magic_name__					, __magic_name__ = None  )    ->							List[str]:
      _a						=							[self.sep_token_id]
      _a						=							[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  ) * [0] + len(token_ids_a + sep  ) * [1]




 def 							__UpperCAmelCase						(       self					, __magic_name__					, __magic_name__ = None  )    ->							Dict:
      _a						=							self._tokenizer.model.save(_UpperCAmelCase					, name=_UpperCAmelCase  )
      return tuple(_UpperCAmelCase  )


"""simple docstring"""






from jiwer import compute_measures

import datasets


__A			   = "\\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"

__A			   = "\\nWord error rate (WER) is a common metric of the performance of an automatic speech recognition system.\n\nThe 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.\n\nThis 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.\n\nWord error rate can then be computed as:\n\nWER = (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 words,\nN is the number of words in the reference (N=S+D+C).\n\nThis value indicates the average number of errors per reference word. The lower the value, the better the\nperformance of the ASR system with a WER of 0 being a perfect score.\n"

__A			   = "\nCompute WER score of transcribed segments against references.\n\nArgs:\n    references: List of references for each speech input.\n    predictions: List of transcriptions to score.\n    concatenate_texts (bool, default=False): Whether to concatenate all input texts or compute WER iteratively.\n\nReturns:\n    (float): the word 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    >>> wer = datasets.load_metric(\"wer\")\n    >>> wer_score = wer.compute(predictions=predictions, references=references)\n    >>> print(wer_score)\n    0.5\n"


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



    """simple docstring"""

    def _snake_case			(   self							):
       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 _snake_case			(   self    ,			_UpperCAmelCase=None    ,			_UpperCAmelCase=None    ,			_UpperCAmelCase=False							):
       if concatenate_texts:
          return compute_measures(_UpperCAmelCase    ,			_UpperCAmelCase							)["wer"]
       else:
          lowercase__:   Dict					=      0
          lowercase__:   Union[str, Any]					=      0
          for prediction, reference in zip(_UpperCAmelCase    ,			_UpperCAmelCase							):
             lowercase__:   Tuple					=      compute_measures(_UpperCAmelCase    ,			_UpperCAmelCase							)
             incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
             total += measures["substitutions"] + measures["deletions"] + measures["hits"]
          return incorrect / total
