Natural Language Processing · Intermediate level

Intermediate level · Module 5: Part-of-Speech Tagging and Hidden Markov Models · Lesson 2 of 3

Hidden Markov Models for Tagging

Learners model tagging as a Hidden Markov Model, estimating transition and emission probabilities from NLTK's Penn Treebank sample.

In this lesson you will

  • Explain hidden states, transitions and emissions
  • Estimate HMM probabilities from a tagged corpus

Key concepts

hidden stateobservationtransition probabilityemission probabilityPenn Treebank sample

The lesson

In an HMM, the tags are hidden states and the words are observations. Transition probabilities P(tag_i | tag_{i-1}) describe how tags follow each other (a determiner is usually followed by an adjective or noun). Emission probabilities P(word | tag) describe which words each tag produces.

Both are estimated by counting in a tagged corpus. NLTK provides a sample of the Penn Treebank (nltk.download('treebank'); nltk.corpus.treebank.tagged_sents()). Use the universal tag set (tagset='universal') to keep the number of states small.

Smoothing is needed for unseen transitions and words. Unknown words are the hardest part: simple rules based on suffixes (-ing, -ed) and capitals help.

Step by step

  1. Load the treebank sample with universal tags and split it 80/20.
  2. Count tag bigrams and word-tag pairs in the training part.
  3. Compute smoothed transition and emission probabilities.
  4. Inspect the most likely transitions and comment on them.

Practice activity

Estimate and inspect the transition and emission tables of an HMM tagger.

Expected result: Correct probability tables with sensible top transitions.

Check your understanding

  1. In a POS-tagging HMM, what is hidden?

    Show answer

    The tags.

  2. What does an emission probability describe?

    Show answer

    How likely a tag is to produce a particular word.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.