Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sentence and a hypothesis sentence, commonly a measure of performance for a
automatic speech recognition system
"""
import Levenshtein
from typing import Union, List
import jiwer.transforms as tr
__all__ = ["wer"]
################################################################################
# Implementation of the WER method, exposed publicly
_default_transform = tr.Compose(
[
tr.RemoveMultipleSpaces(),
tr.Strip(),
tr.SentencesToListOfWords(),
tr.RemoveEmptyStrings(),
]
)
_standardize_transform = tr.Compose(
[
tr.ToLowerCase(),
tr.ExpandCommonEnglishContractions(),
tr.RemoveKaldiNonWords(),
tr.RemoveWhiteSpace(replace_by_space=True),
]
)
__all__ = ["wer"]
################################################################################
# Implementation of the WER method, exposed publicly
_default_transform = tr.Compose(
[
tr.RemoveMultipleSpaces(),
tr.Strip(),
tr.SentencesToListOfWords(),
tr.RemoveEmptyStrings(),
]
)
_standardize_transform = tr.Compose(
[
tr.ToLowerCase(),
tr.ExpandCommonEnglishContractions(),
tr.RemoveKaldiNonWords(),
tr.RemoveWhiteSpace(replace_by_space=True),
]
)
def wer(
truth: Union[str, List[str]],
hypothesis: Union[str, List[str]],
truth_transform: Union[tr.Compose, tr.AbstractTransform] = _default_transform,
hypothesis_transform: Union[tr.Compose, tr.AbstractTransform] = _default_transform,
**kwargs
) -> float: