VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 12: Dynamic programming

Lesson 12.16 of 16 in this module Unrolled Pro

Toy Viterbi decoding

Find the most likely sequence of hidden tags (like parts of speech) for a sequence of words under a hidden Markov model. From scoring every one of the S^T tag sequences, to the Viterbi DP over (position, tag) that keeps only the best path into each tag (O(T · S²)), in log space so long sequences don't underflow, with back-pointers to recover the path. Then the forward algorithm that sums instead of maxing, forbidden transitions for constrained tagging, beam search when there are too many states, and how the same trellis decodes CRFs and speech models.

about 15 min 3 Python examples 2 quick checks

Problem. A hidden Markov model (HMM) has hidden states (tags), a probability of starting in each state, a probability of moving from each state to each other (transitions), and a probability of each state producing each word (emissions). Given a sentence, return the most likely tag sequence and its probability.

text
words:  the   dog    walk
tags:   DET   NOUN   VERB      (most likely, probability ≈ 0.045)

"dog" could be a noun or a verb ("to dog someone"), and "walk" could be either too. Each word's best tag depends on its neighbours' tags, and those depend on theirs. But the model is Markov: a tag depends only on the previous tag. So the best path that ends in tag s at position t only needs the best paths ending in each tag at position t − 1. That's the DP.

ML context. Viterbi is the decoding step for every model that scores tag sequences with local transitions: HMM part-of-speech taggers, conditional random fields on top of neural encoders for named-entity recognition, and classic speech recognition, where states are phonemes and observations are audio frames. Lesson 12.10's forward algorithm is the same trellis with a sum in place of the max; together they cover "best explanation" and "total probability" of a sequence.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Toy Viterbi decoding"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee