jiwer developer on retainer: jiwer.wer() computes global WER (length-weighted) not per-sentence mean WER — 800 long utterances at 7% WER suppress 200 short surgical commands at 65% WER — global 8.4% vs per-sentence mean 18.6% — hospital contract failed — $310,000 — 11 months — jiwer developer on monthly retainer

jiwer 3.0.3 • Python 3.10; jiwer.wer(references, hypotheses) computes global WER = total word errors / total words (length-weighted); 800 long utterances (avg 20 words, 7% WER, 97.6% of total words) suppress 200 short surgical commands (avg 2 words, 65% WER, 2.4% of total words); global WER 8.4% (hospital contract passes); per-sentence mean WER 18.6% (clinical pilot fails); 11 months optimizing global WER; $310,000; fix: np.mean([jiwer.wer(r, h) for r, h in zip(references, hypotheses)]) • Northfield JiWER ASR Ltd. (6-person surgical ASR platform; 11 months; 1.5h)

Northfield JiWER ASR Ltd. is a 6-person startup building a surgical voice command system: surgeons narrate post-operative notes and issue real-time OR commands (“retract,” “suction on,” “clamp”) through a microphone array mounted in the OR ceiling; a fine-tuned Whisper model transcribes both utterance types. The evaluation code for their hospital procurement contract was:

# evaluate_asr.py (jiwer 3.0.3)
import jiwer

# 1,000-utterance test set: 800 narrative + 200 short commands
references  = [...]  # 1,000 reference transcripts
hypotheses  = [...]  # 1,000 Whisper hypotheses

# Compute WER across entire test set
wer = jiwer.wer(references, hypotheses)
print(f"WER: {wer:.1%}")   # → 8.4%

# Hospital contract requirement: WER < 10%
# Procurement decision: 8.4% < 10% ✓ — contract signed

jiwer.wer() when passed two lists concatenates all reference words and all hypothesis words into two flat sequences, then computes the global Levenshtein alignment: total substitutions + deletions + insertions divided by total reference words. This is the standard metric reported in NIST and DARPA evaluations where the goal is minimizing aggregate transcription error across a large corpus. It is NOT the same as the arithmetic mean of per-sentence WER values, and the difference is large when utterance lengths are heterogeneous.

How the length-weighting math produces 8.4% vs 18.6%

# Test set composition
# 800 long utterances (post-operative notes, procedure descriptions)
#   average word count: 20.3 words per utterance
#   total words: 800 × 20.3 = 16,240 words  (97.6% of total)
#   WER on long utterances: 7.0%  (model fine-tuned extensively on narrative)
#   total word errors: 16,240 × 0.070 = 1,137 errors

# 200 short utterances (single-word and two-word OR commands)
#   average word count: 1.9 words per utterance
#   total words: 200 × 1.9 = 380 words  (2.4% of total)
#   WER on short commands: 65.2%  (model rarely seen short imperative commands)
#   total word errors: 380 × 0.652 = 248 errors

total_words  = 16240 + 380   # = 16,620
total_errors = 1137 + 248    # = 1,385

# jiwer.wer() result:
global_wer = total_errors / total_words          # = 1,385 / 16,620 = 8.33%
# → rounds to 8.4%

# Per-sentence mean WER:
per_sentence_mean_wer = (
    (800 × 0.070) + (200 × 0.652)
) / 1000                                         # = (56.0 + 130.4) / 1000
# = 186.4 / 1000 = 18.64%
# → rounds to 18.6%

# Discrepancy: 18.6% − 8.4% = 10.2 percentage points
# Because: 800 long utterances = 97.6% of words, 82.1% of errors
#          200 short commands  =  2.4% of words, 17.9% of errors
# Long utterances (at 7% WER) are "cheap" per word → drag global WER down
# Short commands (at 65% WER) are "expensive" per word → barely visible

The clinical pilot discovered the discrepancy

The hospital’s clinical evaluation team used their own evaluation pipeline, which computed WER per utterance and averaged them. They evaluated the same 1,000-utterance test set after the first 100 clinical pilot surgeries with the deployed system:

# Hospital evaluation pipeline (Python 3.11, jiwer 3.0.3)
import numpy as np
import jiwer

# Same references and hypotheses as the developer's test
per_utterance_wers = [
    jiwer.wer(r, h)
    for r, h in zip(references, hypotheses)
]

mean_wer   = np.mean(per_utterance_wers)   # = 18.64%
median_wer = np.median(per_utterance_wers) # = 11.3%

# Stratified by utterance type:
cmd_refs  = [r for r, is_cmd in zip(refs, is_command_flag) if is_cmd]
cmd_hyps  = [h for h, is_cmd in zip(hyps, is_command_flag) if is_cmd]
cmd_wer   = np.mean([jiwer.wer(r, h) for r, h in zip(cmd_refs, cmd_hyps)])
# cmd_wer = 65.2%

narr_refs = [r for r, is_cmd in zip(refs, is_command_flag) if not is_cmd]
narr_hyps = [h for h, is_cmd in zip(hyps, is_command_flag) if not is_cmd]
narr_wer  = np.mean([jiwer.wer(r, h) for r, h in zip(narr_refs, narr_hyps)])
# narr_wer = 7.0%

# Hospital report:
# Overall per-sentence mean WER: 18.64% — FAILS contract requirement of < 10%
# Short command WER: 65.2% — 65.2% of "suction"/"retract"/"clamp" commands
#   misheard; unacceptable for safety-critical OR use
# Contract clause: WER < 10% evaluated per-utterance, mean across all utterances
# Procurement decision: rejected; contract value $1,200,000 lost

Eleven months of optimizing the wrong metric

The team optimized Whisper fine-tuning to minimize the global WER on their held-out test set, unaware that this metric was dominated by narrative utterances:

# Eleven months of Whisper fine-tuning (all evaluated with global jiwer.wer())
# Baseline: global WER 8.4%

# Month 1–2: more narrative fine-tuning data
# Add 300h of medical podcast transcriptions
# Global WER: 8.4% → 7.9%  Command WER: 65.2% → 69.1% (gets worse)
# Overfitting to long narrative — model forgets short imperative form

# Month 3: data augmentation (speed, pitch, noise)
# Global WER: 7.9% → 7.6%  Command WER: 69.1% → 68.4% (marginal)

# Month 4: Whisper-large-v2 (3× parameters)
# Global WER: 7.6% → 7.4%  Command WER: 68.4% → 67.3%

# Month 5–6: domain vocabulary forcing in beam search
# Add medical term vocabulary to Whisper's beam search
# Global WER: 7.4% → 7.2%  Command WER: 67.3% → 61.4%
# (vocabulary forcing helps more for rare medical nouns than short commands)

# Month 7: temperature=0.0 (greedy decoding for determinism)
# Global WER: 7.2% → 7.1%  Command WER: 61.4% → 59.7%

# Month 8–9: confidence-calibrated re-scoring
# Global WER: 7.1% → 7.0%  Command WER: 59.7% → 58.8%

# Month 10–11: specialized command detection module (VAD + classifier)
# Add a secondary model to detect short command utterances
# Global WER: 7.0% → 6.8%  Command WER: 58.8% → 54.1%

# CEILING: global WER 6.8%; command WER 54.1%
# Target to pass hospital evaluation: command WER < 10%
# Gap: 54.1% - 10.0% = 44.1 percentage points
# This gap cannot be closed by narrative fine-tuning — the wrong lever

The retainer consultant identified the metric discrepancy in 1.5 hours: 0.5h to audit the evaluation code, recognize jiwer.wer(lists) as a global aggregate, and compute the stratified per-sentence WER breakdown revealing 65.2% command WER; 0.25h to verify the hospital contract language (“WER evaluated per-utterance, mean across all utterances”) confirmed per-sentence mean was the contractual metric; 0.25h to quantify the discrepancy (8.4% global vs 18.6% per-sentence mean) and compute the per-category WER split; 0.5h to design the remediation plan: dedicate 50% of fine-tuning budget to short command utterances, set a separate command WER monitoring target, and add stratified WER reporting to every evaluation run. Hours logged to HourTab with per-session breakdown.

# Fixed evaluate_asr.py

import numpy as np
import jiwer

references = [...]  # 1,000 reference transcripts
hypotheses = [...]  # 1,000 Whisper hypotheses
is_command = [...]  # True for short commands, False for narrative

# Per-sentence mean WER (contractual metric)
per_sentence_wers = [jiwer.wer(r, h) for r, h in zip(references, hypotheses)]
mean_wer = np.mean(per_sentence_wers)
print(f"Per-sentence mean WER: {mean_wer:.1%}")  # 18.6% (not 8.4%)

# Stratified WER by utterance type
cmd_indices  = [i for i, is_cmd in enumerate(is_command) if is_cmd]
narr_indices = [i for i, is_cmd in enumerate(is_command) if not is_cmd]

cmd_wer  = np.mean([per_sentence_wers[i] for i in cmd_indices])
narr_wer = np.mean([per_sentence_wers[i] for i in narr_indices])
print(f"Command WER: {cmd_wer:.1%}")    # 65.2% — the real problem
print(f"Narrative WER: {narr_wer:.1%}") # 7.0%

# Assertion: fail CI if command WER exceeds safety threshold
COMMAND_WER_THRESHOLD = 0.10   # hospital contract requirement
assert cmd_wer <= COMMAND_WER_THRESHOLD, (
    f"Command WER {cmd_wer:.1%} exceeds {COMMAND_WER_THRESHOLD:.0%} threshold. "
    f"Model not ready for surgical deployment."
)

# Also report global WER for compatibility with standard benchmarks
global_wer = jiwer.wer(references, hypotheses)
print(f"Global WER (length-weighted, for reference): {global_wer:.1%}")  # 8.4%

# Note: global WER and per-sentence mean WER should BOTH be reported.
# For safety-critical applications, per-sentence mean WER and
# per-category WER are the appropriate contractual metrics.

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →