Word and Character Error Rate

Word / Character Error Rate (WER/CER)

BeginnerSignal Processing

Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.

Definition

Two metrics of speech recognition quality that compute the edit distance (Levenshtein) between the reference text and the predicted text, divided by the reference length, at the word level (WER) or the character level (CER).

Mathematical Idea

We compute the minimum number of substitutions $S$, deletions $D$, and insertions $I$ needed to turn the hypothesis into the reference by dynamic programming, and then $\text{WER}=(S+D+I)/N$, where $N$ is the number of reference words. The rate can exceed 1 when there are many insertions. In Arabic, spelling, diacritics, and the unification of alef forms and teh marbuta affect the result, so a unified text normalization is needed before computing.

How It Works

  1. We normalize the reference and the hypothesis (punctuation, diacritics, and letter forms).
  2. We split into words (WER) or characters (CER).
  3. We build the edit-distance table by dynamic programming.
  4. We extract $S$, $D$, and $I$.
  5. We divide the sum by the reference length $N$.

Stages Diagram

  1. Reference text
  2. Normalization
  3. Alignment
  4. S/D/I
  5. Error rate

Equations

$$\text{WER}=\frac{S+D+I}{N}$$

$S$ is substitutions, $D$ is deletions, $I$ is insertions, and $N$ is the number of reference words.

$$d[i,j]=\min\{d[i-1,j]+1,\ d[i,j-1]+1,\ d[i-1,j-1]+[r_i\neq h_j]\}$$

The dynamic programming recurrence for edit distance.

Advantages

  • A standard and straightforward definition.
  • Easy to compute and compares systems.
  • CER suits some languages and long segments.

Limitations

  • Treats all errors with equal weight.
  • Sensitive to differences in normalization and spelling.
  • Does not reflect meaning.

Use Cases

  • Evaluating ASR systems.
  • Comparing models on the same set.
  • Monitoring improvement during development.

Applied Example

The reference is «ذهب الولد إلى المدرسة صباحا» ("The boy went to school in the morning", 5 words) and the hypothesis lacks «إلى»: $D=1$, so $\text{WER}=1/5=0.2$.

Code Example

PythonImplemented and Tested
def edit(r, h):
    d = list(range(len(h) + 1))
    for i in range(1, len(r) + 1):
        prev, d[0] = d[0], i
        for j in range(1, len(h) + 1):
            cur = min(d[j] + 1, d[j-1] + 1, prev + (r[i-1] != h[j-1]))
            prev, d[j] = d[j], cur
    return d[-1]
ref = "ذهب الولد إلى المدرسة صباحا"
hyp = "ذهب الولد المدرسة صباحا"
wer = edit(ref.split(), hyp.split()) / len(ref.split())
cer = edit(ref, hyp) / len(ref)
print("WER =", round(wer, 3), " CER =", round(cer, 3))

References

  1. Graves, Fernandez, Gomez, Schmidhuber. Connectionist temporal classification: labelling unsegmented sequence data with recurrent neural networks. ICML '06 (23rd Int. Conf. on Machine Learning), pp. 369-376 (2006). DOI
  2. Radford et al.. Robust Speech Recognition via Large-Scale Weak Supervision. arXiv (2022). DOI

Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy