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#
- Hidden Markov Modelinitial, transition and emission probabilities; likelihood of a state/observation sequence; END tag start here
- Viterbi Algorithmdynamic programming for the most likely hidden sequence in
Prerequisites from the foundations: Conditional Probability, Statistical Independence.
How it fits together#
- Mapping: tags hidden states ; words observables . Transition probabilities are a bigram model over tags (N-Gram Model), emission probabilities 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: over sequences. Brute force is correct but exponential; Viterbi keeps the best prefix per final state and needs .
- Greedy is not enough: choosing the locally best state per position can end in probability (WS 18/19). Viterbi is correct because the best continuation depends on the prefix only via the last state, whereas 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 ; those with plus: . Hence . 6.2: great is emitted only by plus and bad only by minus, so only (plus, minus, plus) has positive probability: . 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: , . Emissions: , , . Transitions: SUNNYSUNNY , RAINYRAINY (others ). Greedy: step 1: SUNNY beats RAINY , so SUNNY. Step 2: SUNNY gives , RAINY gives . Stuck, overall probability . Viterbi: RAINY, RAINY has probability and is chosen. The greedy algorithm is locally optimal at step 1 but gets trapped; Viterbi finds the globally optimal path.
SuccessSolution
False. , , , , : , but .
SuccessSolution
- Along with the END tag, transition probabilities from the last hidden state to END were introduced.
- They were also learned from data.
- They reflect that some tags are more likely as the final tag of a sentence.
- 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#
| Semester | Task | Points | Subtopics |
|---|---|---|---|
| WS 17/18 (not published) | Task 6 | 20 | HMM: posterior, decoding by argument, likelihood, brute force |
| WS 18/19 (not published) | Task 6.3 | 10 of 20 | greedy vs. Viterbi counterexample |
| WS 19/20 (not published) | Task 5.3–5.4 | 10 of 25 | max 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.
Related Topics#
- Naive Bayes Classification — also counts-based probabilistic model of text
- Word Embeddings and Language Models — N-Gram Model as the model for the tag transitions