# Hidden Markov model (HMM)

> Canonical: https://skillalmanac.com/glossary/hidden-markov-model | Last verified: 2026-11-24 | Index status: index-eligible

A hidden Markov model (HMM) is a Markov model in which the observations depend on a latent, hidden Markov process. The hidden states cannot be observed directly, so they are inferred from the observations.

Also called: HMM, HMM model, hidden Markov models, HMM machine learning.

## In plain language

A hidden Markov model describes a system whose states you cannot see directly but whose effects you can. The hmmlearn tutorial calls it a generative probabilistic model in which a sequence of observed variables is generated by a sequence of internal hidden states. NLTK describes HMMs as largely used to assign the correct label sequence to sequential data.

## Technical definition

In the hmmlearn description, transitions between hidden states form a first-order Markov chain, specified by a start probability vector and a transition probability matrix, and the emission probability of an observable is conditioned on the current hidden state. NLTK lists the parts of an HMM as the output observation alphabet, the set of states, the transition probabilities, the output probability matrix and the initial state distribution. Hmmlearn names three problems: estimating the optimal hidden state sequence (Viterbi algorithm), calculating the model likelihood (Forward-Backward algorithm) and estimating the parameters (Baum-Welch, an EM algorithm).

## How it shows up when you use agents

HMMs appear in code through libraries such as NLTK, whose nltk.tag.hmm module provides an HMM tagger for labelling sequence data, and hmmlearn, which implements Hidden Markov Models with several emission types. Jurafsky and Martin describe an HMM as relating observed events, such as words, to hidden states, such as part-of-speech tags. NLTK also uses [part-of-speech tagging](/glossary/part-of-speech-tagging) as a worked [natural language processing](/glossary/natural-language-processing) application.

NLTK states that training an HMM requires either MLE estimates of the parameters or unsupervised learning using the Baum-Welch algorithm, a variant of EM. NLTK's trainer offers both supervised (MLE) and unsupervised (Baum-Welch) learning. For the broader family, see [machine learning](/glossary/machine-learning).

## Worked example: observations do not reveal the state

In this hypothetical two-state HMM, the initial probabilities of hidden states A and B are 0.6 and 0.4. The probabilities of observing a beep are 0.1 in A and 0.8 in B. The probability of the first observation being a beep is therefore `0.6 × 0.1 + 0.4 × 0.8 = 0.38`. Seeing a beep does not identify a state with certainty: under these assumptions, the probability of B given that beep is `0.32 / 0.38`, about 0.842.

Now let the transition probabilities be A→A 0.7, A→B 0.3, B→A 0.2 and B→B 0.8. The likelihood of observing two beeps is the sum over all four hidden paths, 0.2298. The most probable individual path is B→B, with joint probability 0.2048. Summing paths to evaluate observations and finding the best hidden path are different tasks. These are hand calculations for chosen parameters, not a trained model or a measured application result.

## Common confusions

- **Hidden Markov model versus Markov chain.** NLTK describes the HMM as an extension of the Markov chain: in a Markov chain each state corresponds deterministically to a given event, while in an HMM the observation is a probabilistic function of the state.
- **Viterbi versus Baum-Welch.** Per hmmlearn, given the model parameters and observed data, the Viterbi algorithm addresses the problem of finding the optimal sequence of hidden states. Given just the observed data, Baum-Welch estimates the model parameters.
- **Myth: HMMs are just for speech.** NLTK and Jurafsky and Martin use part-of-speech tagging: observations are words and hidden states are grammatical tags.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Checks train, validation and test files for duplicates, shared groups, time and label leakage; prints JSON.

Why it exercises the concept: Checks train, validation and test files for duplicates, shared groups, time and label leakage.

## Related terms

- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Natural language processing (NLP)](https://skillalmanac.com/glossary/natural-language-processing.md)
- [Speech recognition](https://skillalmanac.com/glossary/speech-recognition.md)
- [Part-of-speech tagging (POS tagging)](https://skillalmanac.com/glossary/part-of-speech-tagging.md)
- [Unsupervised learning](https://skillalmanac.com/glossary/unsupervised-learning.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Recurrent neural network (RNN)](https://skillalmanac.com/glossary/recurrent-neural-network.md)

## Sources

- [nltk.tag.hmm module](https://www.nltk.org/api/nltk.tag.hmm.html), NLTK (accessed 2026-11-24)
- [Tutorial](https://hmmlearn.readthedocs.io/en/latest/tutorial.html), hmmlearn documentation (accessed 2026-11-24)
- [Speech and Language Processing, appendix A: Hidden Markov Models](https://web.stanford.edu/~jurafsky/slp3/A.pdf), Jurafsky and Martin (Stanford-hosted textbook draft) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
