Become the Model

Markov Chain: Become the Model

Guess the next word — and feel how a language model thinks.

Try it

Become the Model

Can you hit 70% over 12 guesses? At n=2 it is doable if you spot the patterns.
0/12 guesses

The model is writing on its own. You're up next.

Score0Streak0Hit rate0%Best0
Controls
Parameters
How many words the model looks back. Small = word salad, large = rote quote.
n — how many words of context the model looks at before guessing the next one.
Balanced Right now the model looks back 2 word(s).
Low = one word dominates, the model repeats itself. High = flat distribution, the model writes more creatively. The most likely word stays the same.
Temperature — how bold/random the model's choice is. Low = cautious, high = creative.
Medium: a balanced mix of safe and surprising.

Training text (corpus)

The model learns from this text. Change it — different transitions, different feel. The model retrains instantly.

Tip: hover a candidate — you'll see how often that word occurred before. The prediction comes from exactly those occurrences.

Tokens: 380Vocabulary: 109

Definition

What is a Markov chain?

Analogy

Picture your phone keyboard suggesting the next word. It has no idea what you mean to say — it just looks at the last word or two and asks: which word most often followed exactly these in the past?

A Markov chain is precisely that machine. It learned from a text that after "little" usually came "bear". So it suggests "bear" — with a certain probability. Nothing more. No understanding, just statistics about the next word.

In the game, a Markov chain does exactly three things:

  1. 1. Count transitions From your training text (the corpus), the model counts which word followed which context how often. That is the entire "training" — no neural network, just tally marks.
  2. 2. Propose candidates At each position it looks at the last n words and shows you the possible next words as probability bars. Tall bars = seen often, short bars = rare.
  3. 3. Roll the dice & continue The model draws a word according to those probabilities (sampled, not always the most frequent), appends it and asks again. Word by word, a text emerges.

The trick: drag the n slider. At n=1 the model looks at just one word — almost anything is possible, your guessing turns into gambling, the text decays into word salad. At n=3 on a small corpus there is often only one observed continuation per context — suddenly you guess nearly every word, because the model is merely quoting from memory. That is overfitting you can feel.

Check

Test your knowledge

What does a Markov chain's prediction rest on?

Select one answer

Answer Key: 1) B · 2) C · 3) A · 4) B · 5) B

TheoryHistoryPseudocodeStep by StepFlow Diagram

Predictions from pure counting

A Markov chain describes a sequence of states in which each state depends only on the immediately preceding one. For text, this means: from a training text (the corpus) the model counts which word follows which context — and estimates from that the transition probability to the next word. No deep understanding, no grammar: just counted frequencies.

The Markov property: memoryless

The core is the Markov property: the next word depends solely on the current state — here, the last n words. Anything further back is completely ignored. The model has no long-term memory; it only knows its short window. This simplification makes the chain simple and fast, but limits how much coherence it can capture.

Where the probabilities come from

For every context, the model forms a distribution over the possible following words. A word that often followed the context in the corpus gets a high probability. The temperature shapes this distribution: a low temperature sharpens it (the favorite dominates, the text becomes predictable), a high temperature flattens it (more randomness and variety). At temperature 1, the probability exactly matches the relative frequency in the corpus.

n is the lever

The context length n decides the character of the text. At n = 1, only the last word counts: the result is grammatical word salad that sometimes sounds locally coherent but has no thread. At a large n on a small corpus, the context becomes so specific that often only one continuation exists — the model quotes the training text from memory instead of forming something new. That is overfitting, directly experienceable. In between lies the interesting range of structure and surprise.

Properties

  • Memoryless: only the current state counts, not the history
  • Probabilistic: the next word is rolled, not computed
  • Data-driven: the model can only produce what appeared in the corpus
  • Approximation: the estimated probabilities are frequencies from finite data, not true laws of language

Play with the demo! Slide n from 1 to 3 and watch word salad turn into a memorized quotation. Turn up the temperature and see the bars level out and the text grow wilder.

Plain Language

This preview is in Plain Language. The whole portal is also available in Plain Language. You can change the language at the top. Or use the button below. Our Plain Language texts are AI-assisted and editorially reviewed. They follow the core principles of easy-to-read language, but they are not certified Easy Read: a review panel of people with learning difficulties does not test them.

Preview: Markov Chain: Become the Model

What does the demo show?

A program writes a text word by word. It only looks at the last few words. Then it picks a fitting next word. This is called a Markov chain. Markov chain means: The program only counts which words often came next.

How to use the demo

There is a training text. The program learns from it. You can change the text. Possible next words appear as bars. Click the most likely word. This way, you play the model yourself.

What you learn

Use a slider to choose the number n. It says how many words the program looks back. With n equal to 1, you get a jumble of words. With a large n, it often just quotes the training text. Phone keyboards suggest words in a similar way.