AI Logic

Evaluation Metrics

Word Error Rate (WER)

Updated:

Computing word error rate (WER). Top: the word-segmented reference "it is going to rain later this afternoon" and recognition result "it is going rain latter this afternoon right". Bottom left: the alignment that minimizes the number of edits (deletion of "to", substitution "later → latter", insertion of "right"). Bottom right: 1 substitution, 1 deletion, and 1 insertion divided by the 8 reference words gives a WER of 0.375 (37.5%)

Background and overview

Word error rate (WER) is the minimum number of word substitutions, deletions, and insertions needed to turn the output of speech recognition (the hypothesis) into the correct human transcript (the reference), divided by the number of words in the reference. Values closer to 0 mean higher accuracy, and it is usually written as a percentage (%).

WER=S+D+IN\mathrm{WER} = \frac{S + D + I}{N}

SS is the number of substitutions (a word misheard as another), DD the number of deletions (a spoken word was dropped), II the number of insertions (a word not spoken was added), and NN the number of words in the reference.

WER is the standard metric for comparing speech recognition performance, and papers on speech recognition models such as Whisper and wav2vec 2.0 almost always report it. It was not proposed in a specific paper; it applies the edit distance (Levenshtein distance, 1966), which counts differences between strings, to sequences of words.

Definition and procedure

WER is computed as follows.

  1. Normalize the reference and the hypothesis with the same rules (case, punctuation, how numbers are written, and so on).
  2. Split each into a sequence of words. English is split on spaces; Japanese is split into words with morphological analysis or similar.
  3. Compute the word-level edit distance with dynamic programming (DP) and align the words of the reference and the hypothesis. With d(i,j)d(i, j) the distance between the first ii reference words and the first jj hypothesis words, fill the table with the following recurrence.
d(i,j)=min⁡{d(i−1,j−1)+[ ri≠hj ](match or substitution)d(i−1,j)+1(deletion)d(i,j−1)+1(insertion)d(i, j) = \min \begin{cases} d(i-1, j-1) + [\,r_i \ne h_j\,] & \text{(match or substitution)} \\ d(i-1, j) + 1 & \text{(deletion)} \\ d(i, j-1) + 1 & \text{(insertion)} \end{cases}
  1. From the alignment, count substitutions SS, deletions DD, insertions II, and matches HH. The number of reference words is N=H+S+DN = H + S + D.
  2. Compute (S+D+I)/N(S + D + I) / N. For a whole test set, sum the errors and the word counts over all sentences first, then divide.

In the header figure's example, against the reference "it is going to rain later this afternoon" (8 words), the hypothesis drops "to" (deletion), turns "later" into "latter" (substitution), and adds "right" at the end (insertion). WER is (1+1+1)/8=0.375(1 + 1 + 1) / 8 = 0.375, or 37.5%.

The denominator is only the number of reference words, and insertions appear only in the numerator. Therefore, if the hypothesis outputs many extra words, WER exceeds 100%. For example, outputting 5 wrong words for a 2-word reference gives 2 substitutions and 3 insertions, a WER of 250%. WER is called a "rate", but it does not necessarily stay within 0–1.

The mean of per-sentence WERs does not equal the WER of the whole test set. In a per-sentence mean, one error in a 2-word sentence (50%) carries the same weight as one error in a 20-word sentence (5%). NIST's scoring tool sclite, jiwer, and torchmetrics all return the corpus value obtained by summing errors and word counts before dividing.

What it measures and its limitations

WER measures how many words a person must correct to make the transcript usable as is. Substitutions, deletions, and insertions all count as one edit, so it does not distinguish error types and expresses the total correction effort.

It has the following limitations.

  • Does not distinguish word importance: mishearing "Tuesday" and dropping "of" are both a one-word error. The Jurafsky & Martin textbook also notes that while researchers agree that a metric weighting content words more than function words would be preferable, there is no agreed metric that fits every use.
  • Counts spelling differences as errors even when the meaning is the same: "10 o'clock" and "ten o'clock", or "I'm" and "I am", do not match without normalization. The Whisper paper points out that transcripts a person would judge correct can get a much higher WER just from formatting differences, and built a text normalizer for evaluation. It reports that normalization lowered WER by up to 50% on some datasets.
  • The value depends on word segmentation: in languages without spaces between words, such as Japanese and Chinese, both NN and the number of errors change with the morphological analyzer's dictionary and rules. For these languages, the character error rate (CER), which applies the same computation at the character level, is often used.
  • The breakdown of errors can depend on the alignment: when several alignments reach the same minimum total, the split between substitutions and deletions/insertions can differ. NIST's sclite aligns with DP using costs of 0, 3, 3, and 4 for match, insertion, deletion, and substitution.

WER can only be compared when normalization rules and word segmentation are the same. Apply the same treatment of case, punctuation, number formats, and fillers such as "uh" and "um" to both the reference and the hypothesis, and report the rules used for evaluation. The textbook's examples of English normalization are removing bracketed annotations, removing or unifying fillers, unifying contractions (I'm / I am), unifying how numbers and dates are written, and unifying US and UK spellings. jiwer's default setting only normalizes whitespace and is case-sensitive.

Where it is used

WER is mainly used in the following situations.

  • Comparing speech recognition models: it compares models of different types on the same scale, such as models trained with CTC, encoder-decoders like Listen, Attend and Spell, the RNN-Transducer, and the Conformer.
  • Tuning decoding settings: check whether WER on development data drops when changing the beam search width or the language model weight.
  • Gauging task difficulty: even in English, WER differs greatly between read speech and conversational speech. The approximate values around 2023–2024 given in the Jurafsky & Martin textbook are as follows.
Task (English)WER (%)
LibriSpeech (audiobooks, clean)1.4
LibriSpeech (audiobooks, other)2.6
Switchboard (telephone conversations between strangers)5.8
AMI (meetings)11
CHiME6 (dinner party conversations recorded with distant microphones)25.5

The same textbook gives CER for Chinese tasks (3.9% on AISHELL-1 read speech and 18.5% on HKUST telephone conversations).

To check whether a WER difference between two systems is due to chance, the standard test is MAPSSWE, which uses the differences in error counts per sentence segment. Word errors are strongly related to errors in neighboring words, so the McNemar test, which assumes independent errors, is unsuitable for continuous speech recognition.

Comparison with similar metrics

The table compares WER with metrics that evaluate sequence outputs, from the same viewpoints.

MetricUnit comparedHow it countsRangeTypical task
WERWordsEdit distance ÷ reference word count0 or more (no upper bound)Speech recognition
Character error rate (CER)CharactersEdit distance ÷ reference character count0 or more (no upper bound)Japanese and Chinese speech recognition, text recognition
Sentence error rate (SER)SentencesFraction of sentences with at least one error0–1Supplement to speech recognition
MER, WILWordsRates that also include matches (available in jiwer)0–1Supplement to speech recognition
BLEUWord n-gramsFraction matching the reference (precision)0–1Machine translation
Edit scoreAction segmentsComputed from the edit distance of segment sequencesHigher is betterAction segmentation

MER, (S+D+I)/(H+S+D+I)(S + D + I) / (H + S + D + I), also includes insertions in the denominator and never exceeds 1. WIL expresses information loss based on the fraction of matched words.

Rough guidelines for choosing:

  • Speech recognition in languages where spaces separate words, such as English: use WER, aligning normalization rules so results are comparable with prior work.
  • Japanese and Chinese speech recognition: use CER, which does not depend on word segmentation, or report it together with WER.
  • Checking whether the meaning of the transcript comes across: WER only looks at surface matches, so depending on the use, combine it with BERTScore, which looks at semantic similarity, or human evaluation.
  • Tasks with many valid phrasings, such as translation: edit distance to a single reference penalizes paraphrases too much, so use BLEU or chrF.

PyTorch example

Show code
python
def word_errors(ref, hyp):
  """Compute the word-level edit distance (substitution, deletion, and insertion all cost 1) with DP,
  trace back the alignment, and return (substitutions S, deletions D, insertions I). ref and hyp are lists of words."""
  n, m = len(ref), len(hyp)
  d = [[0] * (m + 1) for _ in range(n + 1)]
  for i in range(n + 1):
    d[i][0] = i
  for j in range(m + 1):
    d[0][j] = j
  for i in range(1, n + 1):
    for j in range(1, m + 1):
      d[i][j] = min(d[i - 1][j - 1] + (ref[i - 1] != hyp[j - 1]),  # match / substitution
                    d[i - 1][j] + 1,                               # deletion
                    d[i][j - 1] + 1)                               # insertion
  s = dl = ins = 0
  i, j = n, m
  while i > 0 or j > 0:
    if i > 0 and j > 0 and d[i][j] == d[i - 1][j - 1] + (ref[i - 1] != hyp[j - 1]):
      s += ref[i - 1] != hyp[j - 1]
      i, j = i - 1, j - 1
    elif i > 0 and d[i][j] == d[i - 1][j] + 1:
      dl += 1
      i -= 1
    else:
      ins += 1
      j -= 1
  return s, dl, ins


def corpus_wer(refs, hyps):
  """Corpus-level WER: sum the errors and the reference word counts first, then divide."""
  errors = total = 0
  for r, h in zip(refs, hyps):
    s, dl, ins = word_errors(r.split(), h.split())
    errors += s + dl + ins
    total += len(r.split())
  return errors / total


ref = "it is going to rain later this afternoon"  # words are separated by spaces (segment Japanese or Chinese first)
hyp = "it is going rain latter this afternoon right"
print(word_errors(ref.split(), hyp.split()))  # (1, 1, 1)
print(corpus_wer([ref], [hyp]))  # 0.375

# With torchmetrics: splits on whitespace and returns the corpus value (total errors ÷ total reference words)
from torchmetrics.text import WordErrorRate, CharErrorRate

wer = WordErrorRate()
print(wer([hyp], [ref]))  # arguments in the order (prediction, reference). tensor(0.3750)
cer = CharErrorRate()  # for Japanese and Chinese, also look at the character error rate (CER)
print(cer(["it is going rain latter this afternoon right"], ["it is going to rain later this afternoon"]))

# With jiwer: arguments are in the order (reference, hypothesis), the reverse of torchmetrics. Case-sensitive by default
import jiwer

out = jiwer.process_words(ref, hyp)
print(out.wer, out.substitutions, out.deletions, out.insertions)  # 0.375 1 1 1

FAQ

Q. Can WER exceed 100%?
A.

Yes. The denominator is only the number of reference words, and there is no upper limit on insertions. If the hypothesis is longer than the reference and contains many extra words, WER exceeds 100%. To keep the value within 0–1, use MER, which also includes insertions in the denominator.

Q. Should WER or CER be used for Japanese speech recognition?
A.

CER is commonly used. Japanese has no spaces between words, so WER changes with the morphological analyzer's dictionary and segmentation. When reporting WER, state which analyzer and dictionary were used for word segmentation.

Q. Does a 1-point drop in WER always mean an improvement?
A.

It depends on the test set size and the normalization rules. On a small test set the difference may be due to chance, so check significance with a test such as MAPSSWE. Also, changing normalization alone can change WER a lot, so compare values computed with the same rules.

References

  1. Jurafsky, D., & Martin, J. H. Speech and Language Processing (3rd ed. draft), Chapter 16: Automatic Speech Recognition (Section 16.6, ASR Evaluation: Word Error Rate).
  2. NIST. SCLITE Scoring Package (SCTK documentation).
  3. Radford, A., et al. (2022). Robust Speech Recognition via Large-Scale Weak Supervision (Whisper). arXiv:2212.04356.
  4. jiwer (GitHub repository).
  5. Lightning AI. torchmetrics.text.WordErrorRate (API reference).