Subscribe
AI
7 min read

What Is a Hidden Markov Model? The 1966 Math of States You Cannot See

Before transformers, one page of probability tables ran speech recognition, taggers and gene finders for 40 years. What a hidden Markov model is, the three problems it solves, and which parts survive in modern sequence models.

What Is a Hidden Markov Model? The 1966 Math of States You Cannot See

Large language models made sequence modeling look easy: feed in tokens, get out the next token, and let gradient descent figure out the rest. Before that deal was struck, the serious way to model sequences was to build the invisible part explicitly. A hidden Markov model (HMM) is the oldest of these constructions. It assumes that what you observe, a speech signal, a DNA string, a sentence, is generated by a process you cannot see, and it asks the simplest possible question about that process: what state are we in now, and what state comes next?

The machinery fits on one page. It was, for about 40 years, the engine inside speech recognition, part-of-speech tagging and gene finding. This explainer covers what an HMM is, the three questions it answers, where it came from, and which parts of it survived into the models that run today.

The model: a story you can only half see

Markov chains, the 1906 idea behind them, describe a system that hops between states with fixed probabilities, where you can watch which state it is in. A hidden Markov model keeps the chain but puts it behind a curtain. The system still moves through states according to a transition table. What you actually observe is an emission: each state produces an output symbol drawn from its own probability distribution. You see the outputs. You never see the states.

The standard textbook example is deliberately silly: a person's ice cream consumption over a year is observable, but the weather behind it, hot days versus cold days, is the hidden state (Jurafsky and Martin, Speech and Language Processing, Appendix A). High consumption suggests hot days; a string of low numbers suggests cold ones. The model has three parts: transition probabilities between states, emission probabilities linking each state to what it produces, and an initial state distribution.

Real versions of the same inference show up everywhere once you learn the shape. In speech recognition, the acoustic signal is observed and the phoneme sequence is the hidden state. In part-of-speech tagging, the words are observed and the tags are hidden. In DNA, the base string is observed and the gene-versus-non-gene structure is hidden. In every case, the task is the same: infer the story behind the stream.

Three questions, three algorithms

Rabiner's influential 1989 tutorial, building on tutorials by Jack Ferguson at the Institute for Defense Analyses in the 1960s, organized HMMs into three fundamental problems, and the vocabulary of those three problems still describes how people think about any model with hidden variables.

Problem one is likelihood: given the model, how probable is this observed sequence? The naive answer is to enumerate every possible state path, which grows as the number of states raised to the sequence length. Ten states over 100 time steps means 10^100 paths, more than atoms in the solar system. The forward algorithm solves it exactly with about N^2 x T multiplications by reusing partial computations, a dynamic-programming trick (Jurafsky and Martin, Appendix A).

Problem two is decoding: which state path most likely produced the observations? That is Viterbi's algorithm, published in 1967 by Andrew Viterbi as a decoding method for convolutional error-correcting codes. It walks forward through the sequence keeping, for each state, only the best path that ends there, and prunes everything else. Beam search, the decoding method language models grew up on, is Viterbi with a width instead of a single survivor.

Problem three is learning: given only observation sequences, how do you estimate the transition and emission tables? That is the hard one, because to learn the tables you need the states, and to get the states you need the tables. Baum, Petrie, Soules and Weiss solved it in 1970 with an iterative procedure, now called Baum-Welch or forward-backward, that alternates: guess parameters, compute soft probabilities over state paths, re-estimate parameters to fit those soft counts. The trick is a special case of the Expectation-Maximization algorithm formalized by Dempster, Laird and Rubin in 1977, and it is the same loop behind clustering with Gaussian mixtures (see our earlier explainer on the EM algorithm).

Grid of dots connected left to right, one winding path highlighted while the rest stay faded

Speech was the first killer app

The mathematical core arrived in Baum and Petrie's 1966 paper on statistical inference for probabilistic functions of finite-state Markov chains, followed by the 1970 maximization paper and Baum's 1972 inequality paper. Rabiner's tutorial dates the founding work to the second half of the 1960s, done by Leonard Baum and colleagues, originally aimed at problems in statistical genetics.

What turned a niche result into an industry was speech. Rabiner's account credits James Baker at Carnegie Mellon and Fred Jelinek's group at IBM with implementing the idea for speech processing in the 1970s; Ronald Bakis described continuous word recognition via "centisecond acoustic states" in 1976. The pitch is natural: speech is a waveform, phonemes are hidden, and a left-to-right chain of states with duration control is a decent picture of a word being pronounced. Through the 1980s and 1990s the standard recipe became HMM states emitting Gaussian mixture models of acoustic features. It stayed the industry baseline until deep learning replaced it: the 2012 survey by Hinton and colleagues is explicitly framed as neural networks improving the state-of-the-art GMM-HMM system, and for a transitional decade the winning systems were hybrids, DNN scores feeding HMM state structures.

Tags, genes and protein families

The same model traveled. Computational linguistics moved from hand-written rules to probabilistic tagging in the late 1980s, starting with Kenneth Church's stochastic parts program at IBM, and textbook treatments formalize tagging as an HMM over hidden tag states emitting words (Jurafsky and Martin, Appendix A).

Computational biology turned out to be an even better fit, because biological sequences are literally generated by stochastic processes. Krogh, Brown, Mian, Sjolander and Haussler showed in 1994 that profile HMMs, one chain shaped like a protein family's alignment, could handle statistical modeling, database searching and multiple sequence alignment of protein families. The lineage runs direct: the HMMER software for sequence searching still implements profile HMMs, and the Pfam database of protein families represents each family as an HMM trained on an alignment (Krogh et al. 1994). Linguists' workhorse for matching transcripts to audio, the Montreal Forced Aligner, is by default an HMM-GMM system solving the decoding problem with Viterbi (described as such in a 2023 alignment survey).

Why the curtain fell

HMMs lost the sequence modeling race to neural models for reasons that are instructive. The number of states has to be fixed in advance and chosen by hand; real structure is compositional. The first-order assumption means the next state depends only on the current one, so context longer than one step must be squeezed into more states, and the transition table explodes. Emission densities like Gaussian mixtures are weak representations of speech or text; the features themselves have to be engineered. And training is local: Baum-Welch climbs to a nearby maximum of the likelihood, with no learned features to carry across tasks.

Recurrent networks removed all four limits at once: continuous hidden state instead of a fixed discrete one, learned emissions, gradient descent end to end. In that sense an LSTM or a transformer is an HMM whose state was allowed to become a vector of numbers rather than one of N boxes, and the lineage is acknowledged: the S4 paper that revived state-space sequence models positions them as latent variable models "related to latent state models such as Hidden Markov Models", and Mamba lists HMMs and linear dynamical systems as direct ancestors of its selective state spaces (Gu, Goel and Re, S4).

Left to right flow of dashed circles through an arrow into a grid of solid squares, one row highlighted

What survives

Three things. The parallel-scan algorithms that made HMM likelihood fast on GPUs are the same structure modern selective state-space models run on, which is part of why Mamba-class models get linear-time training (S4; Mamba-2). The three-problem taxonomy, evaluate, decode, learn, is still the cleanest way to sort what any latent-variable model must do (Rabiner 1989). And the inference algorithms never died: Viterbi alignment still times phonemes in every forced-alignment pipeline, and EM-style soft-count updates are the ancestor of every modern variant that trains on data it cannot fully observe.

The deeper idea is the reason the model still gets rediscovered. Observation streams are generated by causes. A model that names the causes explicitly, even as a humble table of probabilities, can answer questions a pure input-output map cannot: how surprising is this data, what probably happened, and what did the system actually compute to get here. Mechanistic interpretability, uncertainty estimation and audit tools for today's models are all downstream of that instinct.

Sources

AILLMeducational