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

POS-Tagging

Assigning a part-of-speech tag to every word of a sentence by modelling tags as a Hidden Markov Model and decoding the most likely tag sequence with the Viterbi algorithm.

Concepts#

  1. Hidden Markov Modelinitial, transition and emission probabilities; likelihood of a state/observation sequence; END tag start here
  2. Viterbi Algorithmdynamic programming for the most likely hidden sequence in O(n∣H∣2)O(n|H|^2)

Prerequisites from the foundations: Conditional Probability, Statistical Independence.

How it fits together#

  • Mapping: tags →\to hidden states HH; words →\to observables OO. Transition probabilities Pr⁡(t′∣t)\Pr(t' \mid t) are a bigram model over tags (N-Gram Model), emission probabilities Pr⁡(w∣t)\Pr(w \mid t) say which words a tag produces. All parameters come from relative frequencies in a tagged corpus, like the counts in Naive Bayes Classification.
  • Decoding problem: arg⁡max⁡h1..hnPr⁡(h,o)\arg\max_{h_1..h_n} \Pr(h, o) over ∣H∣n|H|^n sequences. Brute force is correct but exponential; Viterbi keeps the best prefix per final state and needs O(n∣H∣2)O(n|H|^2).
  • Greedy is not enough: choosing the locally best state per position can end in probability 00 (WS 18/19). Viterbi is correct because the best continuation depends on the prefix only via the last state, whereas max⁡xf(x)g(x)≠max⁡f⋅max⁡g\max_x f(x)g(x) \ne \max f \cdot \max g in general (WS 19/20, Task 5.3).
  • END tag: not an implementation convenience. Its learned transition probabilities favour tags that end sentences and can change the Viterbi result.
  • Contrast with Naive Bayes: Naive Bayes classifies each document independently from word counts; the HMM models dependence between neighbouring labels.

Exercises & Exam Questions#

SuccessSolution (not in the exam note; written by Claude, numbers checked by enumeration)

6.1: sum the likelihoods of all 8 sequences: total 19/16219/162; those with h2=h_2 = plus: 25/48625/486. Hence Pr⁡(h2=plus∣o)=25/48619/162=2557\Pr(h_2 = \text{plus} \mid o) = \dfrac{25/486}{19/162} = \dfrac{25}{57}. 6.2: great is emitted only by plus and bad only by minus, so only (plus, minus, plus) has positive probability: 12⋅23⋅23⋅13⋅23⋅23=8243\frac12 \cdot \frac23 \cdot \frac23 \cdot \frac13 \cdot \frac23 \cdot \frac23 = \frac{8}{243}. It is the most likely sequence.

def compute_likelihood(obs, states):
    p = iprob[states[0]] * eprob[states[0]][obs[0]]
    for i in range(1, len(obs)):
        p *= tprob[states[i-1]][states[i]] * eprob[states[i]][obs[i]]
    return p

def brute_force_hmm(obs):
    best, best_p = None, -1
    for a in range(2):
        for b in range(2):
            for c in range(2):
                p = compute_likelihood(obs, [a, b, c])
                if p > best_p:
                    best, best_p = [a, b, c], p
    return best
SuccessSolution

Observations GOOD, BAD. Initial: P(SUNNY)=3/4P(\text{SUNNY}) = 3/4, P(RAINY)=1/4P(\text{RAINY}) = 1/4. Emissions: P(GOOD∣SUNNY)=1P(\text{GOOD} \mid \text{SUNNY}) = 1, P(BAD∣SUNNY)=0P(\text{BAD} \mid \text{SUNNY}) = 0, P(GOOD∣RAINY)=P(BAD∣RAINY)=1/2P(\text{GOOD} \mid \text{RAINY}) = P(\text{BAD} \mid \text{RAINY}) = 1/2. Transitions: SUNNY→\toSUNNY 11, RAINY→\toRAINY 11 (others 00). Greedy: step 1: SUNNY 3/4⋅1=3/43/4 \cdot 1 = 3/4 beats RAINY 1/4⋅1/2=1/81/4 \cdot 1/2 = 1/8, so h1=h_1 = SUNNY. Step 2: SUNNY gives 1⋅0=01 \cdot 0 = 0, RAINY gives 0⋅1/2=00 \cdot 1/2 = 0. Stuck, overall probability 00. Viterbi: RAINY, RAINY has probability 14⋅12⋅1⋅12=116>0\frac14 \cdot \frac12 \cdot 1 \cdot \frac12 = \frac1{16} > 0 and is chosen. The greedy algorithm is locally optimal at step 1 but gets trapped; Viterbi finds the globally optimal path.

SuccessSolution

False. D={1,2}D = \{1, 2\}, f(1)=5f(1) = 5, f(2)=2f(2) = 2, g(1)=2g(1) = 2, g(2)=5g(2) = 5: max⁡fg=max⁡{10,10}=10\max f g = \max\{10, 10\} = 10, but max⁡f⋅max⁡g=25\max f \cdot \max g = 25.

SuccessSolution
  1. Along with the END tag, transition probabilities from the last hidden state to END were introduced.
  2. They were also learned from data.
  3. They reflect that some tags are more likely as the final tag of a sentence.
  4. So yes, the END tag influences the result: it encodes prior knowledge about which tags end a sentence and can change which path Viterbi selects.

Occurrence table#

SemesterTaskPointsSubtopics
WS 17/18 (not published)Task 620HMM: posterior, decoding by argument, likelihood, brute force
WS 18/19 (not published)Task 6.310 of 20greedy vs. Viterbi counterexample
WS 19/20 (not published)Task 5.3–5.410 of 25max of a product, END tag in Viterbi

Lectures#

No WS 25/26 lecture covers this topic. It appears only in the Information Retrieval exams WS 17/18 to WS 19/20.

Search

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