Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

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 hn=arg⁡max⁡hδn(h) Pr⁡(END∣h)h_n = \arg\max_h \delta_n(h)\,\Pr(\text{END} \mid h), and the probability of the best sequence is max⁡hδn(h) Pr⁡(END∣h)\max_h \delta_n(h)\,\Pr(\text{END} \mid h).
  • Running time: nn columns, each entry a maximum over ∣H∣|H| predecessors: O(n⋅∣H∣2)O(n \cdot |H|^2). Brute force over all sequences costs O(∣H∣n⋅n)O(|H|^n \cdot n).
  • 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 >i> i depend on h1,…,hih_1, \dots, h_i only through hih_i. For a fixed hi=hh_i = h the maximum over the prefix therefore factors out: max⁡prefix(prefix part⋅c)=c⋅max⁡prefix(prefix part)\max_{\text{prefix}} (\text{prefix part} \cdot c) = c \cdot \max_{\text{prefix}} (\text{prefix part}) for a constant c≥0c \ge 0. This is the optimal-substructure property of dynamic programming.
  • Max does not distribute over a product of two functions of the same variable: max⁡xf(x)g(x)≠max⁡xf(x)⋅max⁡xg(x)\max_x f(x)g(x) \ne \max_x f(x) \cdot \max_x g(x) 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 δi(h)\delta_i(h) per state instead of one best state per position.
  • Greedy decoding is wrong. Choosing h1=arg⁡max⁡hPr⁡(h)Pr⁡(o1∣h)h_1 = \arg\max_h \Pr(h)\Pr(o_1 \mid h) and then hi+1=arg⁡max⁡h′Pr⁡(h′∣hi)Pr⁡(oi+1∣h′)h_{i+1} = \arg\max_{h'} \Pr(h' \mid h_i)\Pr(o_{i+1} \mid h') commits early and can end in a sequence with probability 00 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)

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only