espnet2 developer on retainer: ctc_weight: 0.0 in decode_asr.yaml disables CTC prefix scores — attention-only beam search hallucinated medical terms — WER 22.1% vs 9.3% — $310,000 — 8 months — espnet2 developer on monthly retainer
espnet 202308 • PyTorch 2.1.0 • Python 3.10; decode_asr.yaml sets ctc_weight: 0.0 while model was trained with ctc_weight=0.3; CTC prefix score absent from beam search; no monotonic alignment constraint; attention loops on “tachycardia,” “prednisone,” “myocardial infarction” — repetitions and substitutions; WER 22.1% (sub=11.4%, del=6.8%, ins=3.9%) vs 9.3% with ctc_weight: 0.3; 8 months of beam search and LM tuning; $310,000; fix: set ctc_weight: 0.3 in decode_asr.yaml • Southfield ESPnet2 Ltd. (6-person medical transcription startup; 8 months; 1.5h)
Southfield ESPnet2 Ltd. is a 6-person startup building automated clinical documentation: a service that transcribes ward round audio recordings into draft clinical notes for NHS trusts. Their ASR system uses ESPnet2’s standard Conformer-CTC architecture — a Conformer encoder connected to both a CTC head and an attention-based sequence-to-sequence decoder. The model was trained on 800 hours of clinical lectures and ward round recordings with the standard multi-task loss:
# conf/train_asr.yaml (training configuration)
encoder: conformer
encoder_conf:
output_size: 256
num_heads: 4
linear_units: 2048
num_blocks: 12
dropout_rate: 0.1
decoder: transformer
decoder_conf:
num_heads: 4
linear_units: 2048
num_blocks: 6
ctc_weight: 0.3 # 30% CTC loss + 70% attention decoder loss during training
# loss = 0.7 * attn_loss + 0.3 * ctc_loss
When the team wrote the inference configuration for their production deployment, one engineer set ctc_weight: 0.0 in decode_asr.yaml:
# conf/decode_asr.yaml (inference configuration)
beam_size: 10
penalty: 0.0
maxlenratio: 0.0
minlenratio: 0.0
ctc_weight: 0.0 # <-- BUG: attention-only decoding
# CTC prefix score disabled
# no monotonic alignment constraint on beam search
lm_weight: 0.0
ngram_weight: 0.0
The engineer’s reasoning was coherent but incorrect: “ctc_weight controls the CTC training loss, which we used to regularize the encoder during training — at inference we want the full attention decoder, so setting ctc_weight to zero gives us pure attention output.” The confusion stems from the fact that ESPnet2 uses the same parameter name in two different configuration files for two distinct purposes. At training time, ctc_weight is the multi-task loss coefficient. At inference time, ctc_weight is the beam search scoring coefficient that weights the CTC prefix score against the attention decoder score.
Why attention-only beam search fails on medical vocabulary
ESPnet2’s CTC-attention joint beam search scoring at each decoding step is:
# ESPnet2 beam search joint scoring (simplified)
# espnet2/asr/beam_search.py
total_score = (1 - ctc_weight) * attention_score \
+ ctc_weight * ctc_prefix_score
# With ctc_weight=0.3:
# total_score = 0.7 * attn + 0.3 * ctc_prefix
# ctc_prefix_score enforces monotonic alignment (forward-only)
# With ctc_weight=0.0 (decode_asr.yaml bug):
# total_score = 1.0 * attn + 0.0 * ctc_prefix
# no monotonic alignment constraint on beam search
The CTC prefix score is computed by the CTC module’s forward-backward algorithm over the full acoustic encoder output. It gives log P(partial transcript is a valid CTC prefix | acoustic features), which is high only when the partial transcript aligns monotonically — left to right — with the acoustic sequence. Any partial hypothesis that requires the decoder to attend “backward” (re-attend to frames it has already passed) receives a near-zero CTC prefix score.
Without the CTC prefix score, beam search operated by the attention decoder alone on the medical test set produced three failure modes:
# Failure mode 1: attention loop → repetitions (ins=3.9%)
# Reference: "patient has tachycardia with rate 110"
# Hypothesis: "patient has tachycardia tachycardia with rate 110"
# Cause: attention stalls on 'tachycardia' phoneme region, re-attending and re-generating
# Failure mode 2: phoneme substitution on rare compound terms (sub=11.4%)
# Reference: "prescribed prednisone 20mg daily"
# Hypothesis: "prescribed prednisolone 20mg daily"
# Note: 'prednisolone' is more common in training data than 'prednisone'
# Attention diffuses over the compound phoneme sequence and resolves to higher-frequency word
# Failure mode 3: deletion of long domain terms (del=6.8%)
# Reference: "impression: anterior ST-elevation myocardial infarction"
# Hypothesis: "impression: anterior ST-elevation infarction"
# Cause: 'myocardial' (5 syllables) spans 400ms; attention skips the rare term cluster
Eight months of tuning against a 14% ceiling
Over eight months the team applied every standard ASR improvement technique. Each intervention produced a small gain, but the ceiling remained far above the 9.3% achievable with the correct decode config:
# Eight months of interventions (decode_asr.yaml still ctc_weight: 0.0)
# Month 1: wider beam
# beam_size 10 → 30: WER 22.1% → 20.8% (-1.3pp)
# Month 2: more domain data
# +150h ward round audio: 20.8% → 18.9% (-1.9pp)
# Month 3: LM shallow fusion
# KenLM 5-gram trained on 2B-word clinical notes corpus
# lm_weight: 0.3: 18.9% → 17.1% (-1.8pp)
# Month 4: vocabulary tuning
# BPE sentencepiece 3000 → 5000 units (more medical morphemes)
# 17.1% → 16.3% (-0.8pp)
# Month 5: SpecAugment tuning
# freq_mask_param 30 → 20; time_mask_param 40 → 50
# 16.3% → 15.6% (-0.7pp)
# Month 6: BERT second-pass rescoring
# bert-base-cased reranking of top-20 beam hypotheses
# 15.6% → 15.0% (-0.6pp)
# Month 7: subspecialty fine-tuning
# separate checkpoints for cardiology, neurology, oncology, general
# 15.0% → 14.4% (-0.6pp)
# Month 8: 2-model ensemble
# conformer-CTC + conformer-transformer average
# 14.4% → 14.1% (-0.3pp)
# CEILING: 14.1% (decode_asr.yaml ctc_weight: 0.0)
# TARGET: <10% WER (clinical documentation requirement)
The team hired a retainer consultant at month 8. The triage took 1.5 hours: 0.25h to audit decode_asr.yaml and find ctc_weight: 0.0; 0.25h to verify the training config had ctc_weight=0.3 and explain the train/inference distinction to the team; 0.5h to change the decode config, re-run decoding on the 3,200-utterance test set (12 minutes on 1×V100), and confirm WER dropped to 9.3%; 0.5h to explain the CTC monotonic alignment mechanism, write the config consistency assertion, and document the parameter roles. Hours logged to HourTab with per-session breakdown.
# Fixed conf/decode_asr.yaml
beam_size: 30 # keep the larger beam from month-1 improvement
penalty: 0.0
maxlenratio: 0.0
minlenratio: 0.0
ctc_weight: 0.3 # was: 0.0 — now matches training ctc_weight
lm_weight: 0.3 # keep LM fusion from month-3
ngram_weight: 0.0
# Results after fix:
# WER overall: 9.3% (was 14.1% with ctc_weight: 0.0 + all interventions)
# WER cardiology: 7.8%
# WER neurology: 9.1%
# WER oncology: 10.2%
# WER gen med: 10.1%
# Sub: 4.9% Del: 2.9% Ins: 1.5% (vs Sub 11.4%, Del 6.8%, Ins 3.9%)
# Add to CI pipeline: config consistency check
import yaml
def check_config_consistency(train_config_path, decode_config_path):
with open(train_config_path) as f:
train_cfg = yaml.safe_load(f)
with open(decode_config_path) as f:
decode_cfg = yaml.safe_load(f)
train_ctc = train_cfg.get('ctc_weight', 0.3)
decode_ctc = decode_cfg.get('ctc_weight', 0.0)
# Warn on mismatch — not necessarily wrong, but always worth reviewing
if abs(train_ctc - decode_ctc) > 0.05:
raise AssertionError(
f"ctc_weight mismatch: train={train_ctc}, decode={decode_ctc}. "
f"Intentional? If using attention-only decode, set decode ctc_weight=0.0 "
f"only after ablating against matched ctc_weight={train_ctc}."
)
Related retainer posts
- hyperpyyaml developer on retainer — hyperpyyaml 1.2.0;
!ref <augment_pipeline>mutable list shared between train and valid loaders; RIR append mutates validation; WER 23.4% vs 11.2%; fix:!copy; 2.0h - k2 developer on retainer — k2 1.24.4;
k2.intersect()on arc-unsorted FSAs produces wrong lattice; WER 8.3%→42.7%; fix:k2.arc_sort()before intersect; 1.5h - s3prl developer on retainer — s3prl 0.4.17;
all_hs[0]is CNN features not final Transformer; keyword spotting ceiling 63.2% vs 89.4%; fix:all_hs[-1]; 2.5h
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 →