Subscribe
AI
7 min read

What Is a Markov Chain? The 1906 Math That Runs Every Language Model

Long before a language model predicted its next token, a Russian mathematician sat down with a book of poetry and started counting vowels. In January 1913, Andrey Markov presented an odd piece of research to the Imperial Academy of Sciences in St. Petersburg: he had written out the first 20,000 characters of Alexander Pushkin's verse novel Eugene Onegin as one unbroken string, marked each letter a vowel or a consonant, and counted how often each type followed the other. The analysis found vowels

What Is a Markov Chain? The 1906 Math That Runs Every Language Model

Long before a language model predicted its next token, a Russian mathematician sat down with a book of poetry and started counting vowels. In January 1913, Andrey Markov presented an odd piece of research to the Imperial Academy of Sciences in St. Petersburg: he had written out the first 20,000 characters of Alexander Pushkin's verse novel Eugene Onegin as one unbroken string, marked each letter a vowel or a consonant, and counted how often each type followed the other. The analysis found vowels made up about 43 percent of the text, with 1,104 vowel-vowel pairs, 3,827 consonant-consonant pairs, and 15,069 mixed pairs. That was not literary criticism. It was a proof about probability, and the object it describes now runs speech recognition, web search, modern statistics, and every large language model in production.

The rule: the next step depends only on where you are

A Markov chain is a system that occupies one of a set of states at each step and jumps between them according to fixed probabilities. The defining constraint, called the Markov property or memorylessness, is that the probability of the next state depends only on the current state, not on how the system got there. If the states are "vowel" and "consonant," the chain just needs the chance that a vowel follows a vowel, a consonant follows a vowel, and so on. Those numbers fit in a small table called a transition matrix, whose rows each sum to one.

Weather is the standard classroom example. Given that today is sunny, tomorrow can be sunny, cloudy, or rainy with certain probabilities, and the chain ignores yesterday entirely. That is obviously a crude model of weather, which is exactly why it is pedagogically useful: Markov chains trade a full history for a single state, and they are honest about the trade. What was new in Markov's work was proving that a sequence could be dependent, each event genuinely influenced by the one before it, and still produce stable long-run averages. The chain's future does not need independence from its past for its statistics to settle down, it only needs the dependence to live inside the current state.

The argument that produced the chain

Markov did not invent the model out of abstract curiosity. In his 1906 paper he built it as a counterexample to a claim by fellow mathematician Pavel Nekrasov, who had argued that independence of events was a necessary condition for the law of large numbers, the rule that averages of random events converge to expected values. The dispute had theological overtones, and Brian Hayes's retrospective for American Scientist describes the episode as a mixture of institutional rivalry, personal feuds, and religious controversy. Markov, a determinist, regarded the independence requirement as mathematically arbitrary, and the 1906 paper showed the law of large numbers holds for variables connected in a chain.

The Pushkin analysis seven years later was the demonstration. A text is a long sequence of dependent symbols, and no one could accuse Markov of fabricating the data. The paper containing the analysis, whose title translates as "An Example of Statistical Investigation of the Text Eugene Onegin Concerning the Connection of Samples in Chains," attracted little citation in Markov's lifetime and was not translated into English until 2006, according to IEEE Spectrum's account of Markov and Claude Shannon as the first language-generation researchers.

Why chains settle: the stationary distribution

Under regularity conditions that most practical chains satisfy, something remarkable happens as the chain runs. The probability of finding it in each state converges to a fixed vector, the stationary distribution, regardless of where the chain started. Markov's 1906 paper proved this convergence for the simplest case, a two-state chain with all transition probabilities strictly between zero and one, as documented in the historical survey by Esa Seneta. The system forgets its beginning and remembers only its own transition rules.

That forgetting property is the reason Markov chains are useful rather than just curios. Any process modeled as a sufficiently connected chain has predictable long-run behavior, and that behavior can be computed from the transition table alone. Three industries later discovered this independently.

Speech, search, and sampling: three empires on one math

Speech recognition ran on chains for four decades. A hidden Markov model (HMM) assumes the acoustic signal you hear is emitted by an underlying chain of states you cannot observe, phonemes or word parts, each with its own emission and transition probabilities. Lawrence Rabiner's 1989 tutorial in the Proceedings of the IEEE, the document that standardized the field, treats speech recognition as the primary application and describes the forward-backward algorithm for learning the hidden parameters from training data. Word recognition, part-of-speech tagging, and most dictation products of the 1990s were HMM systems long before neural models replaced them.

Web search runs on a chain too. In their 1998 paper introducing Google, Sergey Brin and Lawrence Page defined PageRank through a "random surfer" who starts on a page at random and keeps clicking links, never pressing back, until getting bored and jumping to an unrelated page. The probability that this surfer lands on a given page is its PageRank, and the boredom probability is the damping factor. That surfer is a literal Markov chain over the web graph, and PageRank is its stationary distribution. The page that the chain visits most often in the long run is the page the whole link structure points at.

Statistics runs on chains as well. In 1953, Nicholas Metropolis, Arianna and Marshall Rosenbluth, and Augusta and Edward Teller published "Equation of State Calculations by Fast Computing Machines" in the Journal of Chemical Physics, describing a method for sampling the configurations of interacting molecules at Los Alamos using early computers. The trick was to build a Markov chain whose stationary distribution is exactly the hard-to-sample target distribution, then just run the chain. The method was later generalized as the Metropolis-Hastings algorithm, and today Markov chain Monte Carlo is one of the most used tools in Bayesian statistics, machine learning, and physics simulation.

A stylized figure walking along a curved path between circular stations

Your language model is also a chain

The connection to text generation is the oldest of all. In "A Mathematical Theory of Communication" (1948), Claude Shannon modeled English as a Markov source and demonstrated the idea by generating sample text at orders zero through three: random letters with uniform frequency, then letters chosen by single-letter frequency, then bigram statistics, then trigram statistics. Each higher order produced text that looked more like English. Shannon's experiment was the first formal quantification of how much of a language's structure is captured by local statistics.

Modern autoregressive language models are the same construction with the state upgraded. At each step, the model samples the next token from a probability distribution conditioned on the context, and if you take the visible context window itself as the state, generation is a Markov chain: the next tokens depend on the past only through what currently sits in the window. That framing explains both what these models are good at and where they fail. Everything the model "remembers" about the conversation is content of the state, which is why a request that scrolls out of the context window is genuinely gone, not merely hard to recall. And the state is large, tens of thousands of tokens, which is why the memorylessness shortcut that makes textbook chains tractable does not make LLM behavior easy to analyze directly.

Diffusion models, the other dominant generation architecture, are explicitly Markov chains as well. The 2020 paper that introduced denoising diffusion probabilistic models defines generation as a Markov chain of steps that gradually remove noise from a random starting signal, with the reverse chain learned during training. Whether a system writes text token by token or un-noises an image step by step, the underlying mathematics is the one Markov built to win an argument about poetry.

An open book releasing a dotted chain that becomes a sound wave, a node graph, then tiles

Where the assumption breaks

Memorylessness is a modeling choice, and it has a price. Pure low-order chains produce text that decays into nonsense: Shannon's order-one samples are recognizable letter-frequency soup, and only as the order rises does the output approximate English. Higher orders need exponentially more data to estimate, which is the bottleneck that killed n-gram language models. LLMs dodge it by replacing counted statistics with learned attention over the whole window, but the window itself remains the outer bound of the state. The chain assumption is also why sampling matters so much in production: a model that only ever takes the most likely transition collapses the stationary distribution onto a few repetitive outputs, which is why decoding uses temperature and other stochastic schemes instead of pure argmax.

The takeaway

A Markov chain is the cheapest possible model of a dependent sequence: fixed states, fixed transition probabilities, no memory beyond the present. From that minimal setup come convergence to a stable distribution, and a strange empire of applications. A speech recognizer's phonemes, Google's original ranking, a Bayesian sampler's iterations, and the next token your assistant writes are all transitions in a chain. Markov counted vowels in a poem to settle a debate about the law of large numbers, and 113 years later the same math decides what comes after the last word in your prompt.

Sources

AILLMeducational