Viterbi Algorithm
Also Viterbi
A dynamic-programming algorithm that computes the most likely hidden state sequence of a Hidden Markov Model for a given observation sequence in O(n·|H|²) time.
Know these firstHidden Markov Model
Formula#
- With an END state (POS-Tagging): the final choice is , and the probability of the best sequence is .
- Running time: columns, each entry a maximum over predecessors: . Brute force over all sequences costs .
- In practice computed with log-probabilities (sums instead of products) to avoid underflow.
Properties#
- Why the recursion is correct. The likelihood is a product whose factors for positions depend on only through . For a fixed the maximum over the prefix therefore factors out: for a constant . This is the optimal-substructure property of dynamic programming.
- Max does not distribute over a product of two functions of the same variable: in general (exam WS 19/20, Task 5.3). Viterbi only pulls out factors that are constant for the maximized variables, which is why it keeps one per state instead of one best state per position.
- Greedy decoding is wrong. Choosing and then commits early and can end in a sequence with probability while a positive one exists (exam WS 18/19, Task 6.3, see POS-Tagging > Exercises & Exam Questions).
Example#
Sources#
- Not covered by a WS 25/26 lecture. Source: the former Information Retrieval exams.
- Exam WS 18/19, Task 6.3 (not published) (greedy vs. Viterbi)
- Exam WS 19/20, Task 5.3–5.4 (not published) (max of a product, END tag)
- Exam WS 17/18, Task 6 (not published) (decoding, brute force)