CTC Prefix Beam Search: How It Combines Paths into Text
CTC prefix beam search keeps several output prefixes and sums the probability of paths that collapse to each one. Tracking whether a prefix ends in blank is essential for repeated characters.
CTC maps frame-level paths to text by merging adjacent repeats and then removing blanks. Many different paths can produce the same text, so choosing the most likely path at each frame (greedy decoding) can miss the most likely text sequence.
Prefix beam search tracks candidate text prefixes. For each prefix it keeps two probability totals: paths that end in blank, and paths that end in a nonblank label. At the next frame:
A blank keeps the same prefix and receives probability mass from both totals.
A label different from the prefix’s last label extends the prefix from either total.
A label equal to the last label can extend to a doubled character only from paths that ended in blank. From nonblank-ending paths, it stays the same prefix because adjacent repeats collapse.
Add contributions for the same prefix with log-sum-exp, then keep only the best-scoring beam candidates. A finite beam makes the search approximate. A lexicon or language model may constrain or rescore extensions; its tokenization and score weights must match the acoustic model.
Example: to produce “ll”, a CTC path needs a blank between the two labels, such as l, blank, l. The path l, l collapses to one “l”. When validating a decoder, include repeated letters, blanks, and prefixes that share beginnings; compare greedy and beam outputs, and tune beam size and language-model weight on development data. Don’t infer word confidence directly from a prefix score.
References
Graves et al. (2006), [Connectionist Temporal Classification](https://archive.air.in.tum.de/2018/Main/Publications/Graves2006a.pdf)
PyTorch Audio 2.5.0, [ASR inference with CTC decoder](https://docs.pytorch.org/audio/2.5.0/tutorials/asr_inference_with_ctc_decoder_tutorial.html)