Lesson 10 / Unit 3: First Recognizer
CTC Alignment
See why blanks and repeated frame labels let an untimed transcript supervise a longer audio sequence.
The target 77 has two symbols. The audio may produce dozens of output frames. We do not know which frame should carry each seven, and we do not label those timestamps by hand.
CTC trains by accounting for multiple frame paths that collapse to the same target. Greedy decoding later chooses one path; training and decoding are related but different operations.
Collapse Rules
Merge adjacent repeats, then remove blanks. Constructed examples.
First merge adjacent identical frame labels, then remove blank. 7 7 _ 7 becomes 77. If you remove blank before merging, the two sevens become neighbours and you incorrectly return 7.
Training Objective
The model gives a distribution at each frame. Valid paths allocate characters and blanks differently while preserving target order. The loss accounts for their combined probability rather than forcing one hand-picked alignment. The CTC visual reference develops this distinction.
criterion = torch.nn.CTCLoss(blank=0, zero_infinity=False)loss = criterion(log_probs, targets, output_lengths, target_lengths)Our tensor order for log probabilities is time × batch × vocabulary. Targets contain no blank tokens. The PyTorch reference documents the accepted shapes.
Failure Signals
An impossible alignment can produce an infinite loss. Do not immediately hide that with zero_infinity=True. Inspect time downsampling, repeated characters and target lengths first. A zeroed loss can make a broken example stop contributing while the overall run appears healthy.
Record your predicted result for each interactive path before revealing the collapsed output. Then implement Greedy Decoding and compare its strings with the target contract.
We do this work for teams shipping voice agents: Self-Hosted Voice Agent .
Edit this lesson on GitHub ↗Discussion
Questions, corrections and war stories welcome. Sign in with GitHub to comment.