Sub topic 12
Measuring transcription quality with word error rate
This chapter assumes you can call a transcription endpoint (covered earlier), write basic Python, and read a list of strings. By the end you will compute word error rate (WER) on a small reference set and know how to read the number.
Why measure at all
A transcript that looks fine on three samples can fail on your real audio. Accents, background noise, product names and phone-quality codecs all change accuracy. Changing the language option, adding a prompt, or switching models can help or hurt, and you cannot tell by reading a few outputs. A fixed test set and one number let you compare changes fairly.
Word error rate is the standard number for this. It counts how many word-level edits turn the model's output into a human-written reference transcript, then divides by the number of words in the reference.
The formula
WER is built from three kinds of error, found by aligning the two word sequences:
- Substitutions (S): a reference word was replaced by a different word.
- Deletions (D): a reference word is missing from the output.
- Insertions (I): the output contains a word that is not in the reference.
The formula is:
WER = (S + D + I) / NN is the number of words in the reference. The alignment is the one with the fewest total edits, found with edit distance (Levenshtein distance) computed over words instead of characters.
Take the reference please schedule the review for friday morning (7 words). If the model writes friday mourning, the last word is a substitution. That is S=1, D=0, I=0, so WER = 1/7, about 0.143.
Computing WER in Python
The jiwer package implements this. Install it with pip install jiwer.
import jiwer
reference = "please schedule the review for friday morning"
hypothesis = "please schedule the review for friday mourning"
print(f"WER: {jiwer.wer(reference, hypothesis):.3f}")This prints WER: 0.143. To see the breakdown instead of one number, use process_words:
import jiwer
reference = "please schedule the review for friday morning"
hypothesis = "please schedule review for friday mourning today"
out = jiwer.process_words(reference, hypothesis)
print("substitutions:", out.substitutions)
print("deletions:", out.deletions)
print("insertions:", out.insertions)
print(f"WER: {out.wer:.3f}")Here the is deleted, morning becomes mourning, and today is inserted. That gives S=1, D=1, I=1 and WER = 3/7, about 0.429. The breakdown tells you what to fix. Many deletions often point to clipped audio or silence handling. Many substitutions on names point to a vocabulary problem that a prompt may help with.
Normalize before you compare
Raw comparison punishes differences that do not matter to you. Friday, and friday count as different words, as do 10 and ten. If you skip normalization, WER mostly measures formatting.
Decide a normalization policy and apply it to both reference and hypothesis. A common minimal policy is lowercase, remove punctuation, and collapse whitespace:
import jiwer
normalize = jiwer.Compose([
jiwer.ToLowerCase(),
jiwer.RemovePunctuation(),
jiwer.RemoveMultipleSpaces(),
jiwer.Strip(),
])
reference = "Please schedule the review for Friday morning."
hypothesis = "please schedule the review for friday morning"
print(jiwer.wer(reference, hypothesis)) # raw: counts case and punctuation
print(
jiwer.wer(
normalize(reference),
normalize(hypothesis),
)
)The first call reports errors because of capitalization and the final period. The second reports 0.0. Whether to also expand numbers, contractions or spelling variants depends on your product. If downstream code needs digits, do not reward spelled-out numbers. Keep the same policy across every run so numbers stay comparable.
Building a small reference set
You do not need hundreds of hours. A useful starting set looks like this:
- Pick 20 to 50 clips of 10 to 30 seconds each, drawn from real traffic where privacy rules allow it.
- Cover the conditions you expect: quiet and noisy rooms, different speakers, the codecs your app receives, and your domain terms.
- Have a person write each reference transcript, then have a second person check it. Reference errors count against the model.
- Store the pairs in a file, for example a CSV with
audio_pathandreferencecolumns.
Then run every clip through the API and score it:
import csv
import jiwer
from openai import OpenAI
client = OpenAI()
normalize = jiwer.Compose([
jiwer.ToLowerCase(),
jiwer.RemovePunctuation(),
jiwer.RemoveMultipleSpaces(),
jiwer.Strip(),
])
references = []
hypotheses = []
with open("eval_set.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
with open(row["audio_path"], "rb") as audio_file:
text = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
).text
references.append(normalize(row["reference"]))
hypotheses.append(normalize(text))
print(f"Corpus WER: {jiwer.wer(references, hypotheses):.3f}")Passing lists to jiwer.wer computes corpus-level WER: total errors across all clips divided by total reference words. This is not the same as averaging per-clip WER. A long clip contributes more to the corpus figure, which usually matches how users experience the product. Report whichever you choose, and say which.
Reading the number
- WER is not capped at 1.0. Many insertions can push it above 100%.
- WER of 0.05 does not mean 95% of sentences are right. Errors can be spread across many sentences or packed into a few.
- A lower WER is not always better for your app. Missing "not" changes a sentence's meaning, while a missing "um" changes nothing. WER counts both as one error.
- Small sets are noisy. With 20 clips, a difference of 0.005 between two configurations is likely chance. Look for differences larger than the spread you see between clips.
- Compare configurations on the same set, with the same normalization, and change one thing at a time.
Finding where errors come from
A single corpus number hides patterns. Group the per-clip scores by a label you stored in the CSV, such as noise or speaker, and compare groups. Then look at the worst few clips by hand. You will often find that most of the error comes from a handful of causes: proper nouns, numbers, overlapping speech, or clipped starts.
You can also test the options from earlier chapters this way. Run the same set with and without a prompt listing your product names. If WER on name-heavy clips drops and the rest stays flat, the prompt is working.
Limits of WER
- It is word-based, so it suits languages that put spaces between words. For Chinese or Japanese, character error rate is the usual alternative, and
jiwer.cercomputes it. - It ignores timestamps. If you use segment timing for captions, check timing separately.
- It ignores punctuation and casing once you normalize them away. If your app displays the transcript, review formatting by eye.
- It does not tell you about downstream effect. For a voice loop, also check whether the LLM answers correctly given the transcript.
Exercise
A reference transcript has 10 words. The API output has 2 substituted words, 1 deleted word and 1 inserted word compared to the reference. What is the WER, and why is the denominator 10 rather than the length of the output?
Show answer
WER = (2 + 1 + 1) / 10 = 0.4. The denominator is the reference word count N, because WER measures errors relative to what was actually said. Using the output length would change the score depending on how many words the model inserted or dropped.
Exercise
You score two configurations on 20 clips. Configuration A has corpus WER 0.081 and configuration B has 0.079. Should you switch to B? Name two checks you would do first.
Show answer
Not on this evidence. The gap is tiny and a 20-clip set is noisy. Check that both runs used the same normalization and the same clips, and compare per-clip scores (or add more clips) to see whether B wins consistently or only on one or two clips. A held-out set for a final check is also worth running.