Input: draw a shape
Output: its answer

More to try
Animated AI lab

How AI Works

A chatbot does one thing: it predicts the next piece of text, over and over. A real language model — a very small one — is running inside this page. Give it a prompt and watch every step: text into tokens, tokens into numbers, numbers through layers, and one word chosen. Then wipe its memory and train it again yourself.

The words this model knows (tap to add)
01The whole machine in twenty seconds

One Token at a Time

Every reply you have read from a language model came out of this loop. It runs once for each token it writes. Let it play, then step through it — each stage has its own chapter below.

Real model
Key ideaA model never writes a sentence. It writes one token, reads everything again including that token, and writes one more.
Everything drawn here is computed live by the transformer in this page: the token IDs, the first six numbers of each embedding, the attention weights in each layer, and the odds. Only the drawing is simplified. A large model does exactly this with thousands of times more of everything.
02Text becomes pieces

Tokens

A model never sees letters or words. A tokenizer chops text into pieces from a fixed vocabulary and hands the model a list of ID numbers. Most tokenizers are built by byte-pair encoding: start with single characters, then keep gluing together whichever pair shows up most often. Watch it happen to your prompt, or type anything.

Real BPE
What the model actually receives
Characters0
Tokens now0
Chars per token0
Merges applied0
Key ideaCommon words become a single token. Rare words, odd names, typos, and long numbers shatter into many — which costs more and gives the model less to hold on to. In ordinary English a token averages about three-quarters of a word.
This is a genuine BPE tokenizer, trained when the page loaded: . The model in this page uses exactly these tokens. Production tokenizers learn on the order of 100,000 rules from vastly more text, so they split things differently — but they are built by this same procedure.
03Numbers that carry meaning

Embeddings

Each token ID selects one row of a table. That row is the token's embedding: its coordinates in a space where tokens that behave alike sit close together. Nobody types those numbers in. Below is the table this page's model learned, squashed flat so you can look at it.

Real model

Directions mean something too

In a large model, the gap between two points carries meaning, so you can do arithmetic with words. Our model's world is too small to show that, so this map is a hand-built example space.

− +
Pick an example, or build your own from any three words. The arrows are drawn on the map above.

Order has to be added by hand

The table has one row per token and no idea where in the sentence that token sits. So a second learned row, one per position, is added on top. These are the first three tokens of your prompt.

Key ideaTokens used in similar ways end up at nearby points — the model worked out that cats and dogs belong together purely from where they appear in sentences. And in larger models the gap between points is meaningful too: the step from man to king matches the step from woman to queen.
The first map, the number strips, and the position rows are this model's actual weights; the map is a two-dimensional projection (principal components) of 24, so some real neighbours look further apart than they are. The colours are our labels, not something the model knows. The arithmetic map is hand-built so the sums come out exact; in real embeddings they are approximate. This model learns its position rows; other models use fixed wave patterns or rotate the vectors instead.
04Tokens read each other

Attention

An embedding on its own knows nothing about its neighbours. Attention fixes that. At every layer, each token asks a question of all the tokens before it and pulls in information from the ones that answer best. It is the only place in the model where information moves from one position to another. These are the real weights for your prompt.

Real model

Every token's attention at once

Each row is one token's question; each cell is how much it took from the token in that column. The hatched half is the future: a token can never look at what has not been written yet.

The arithmetic, in slow motion

What "asks a question" means in numbers. This is a hand-sized example with three numbers per vector, so every sum fits on screen; the model above does the same thing with twelve.

Key ideaAttention is a weighted copy. Each token scores the earlier tokens for relevance, turns the scores into shares, and blends in that much of each one's information. A layer runs several of these "heads" side by side, each free to learn a different question.
The arcs, percentages, and matrix are this model's real attention weights; nothing was arranged by hand, and no one told a head what to look for. If you retrain the model in chapter 7, the heads may divide the work differently. The slow-motion arithmetic is a constructed example, and real models also divide the scores by the square root of the vector size before the softmax.
05The stack that does the work

Layers

One round of attention is not enough. A model repeats the same two-part block several times: attention gathers information, then a small neural network (the MLP) digests it. Each block adds its result to a running vector kept for every token — a shared scratchpad that grows more useful with every layer.

Real model

Start with one neuron

The MLP is built from these. A neuron multiplies each input by a weight, adds them up, and passes the total through a curve that silences negative results. The weights are what training adjusts.

Now the whole stack, on your prompt

One running vector per token, rising through this model's layers. Gold arcs are the attention the last position really pays in that layer; the green flicker is the MLP. On the right is what the model would say if it were cut off at that depth.

Inside one layer: the feed-forward step

Attention moves information between tokens. Then each token is worked on alone, by a small feed-forward network of the same kind as the one at the top of this page. This is the real one from this page’s model, running on the last token of your prompt: 24 numbers go in, are spread across 64 working neurons, and 24 numbers come out to be added back to that token’s running vector. Drag to turn it. Click a neuron to keep its connections lit.

How big is the real thing?

The model in this page
GPT-2 small · 2019
layers
12
numbers per token
768
attention heads per layer
12
neurons per MLP
3,072
weights
124 million
GPT-3 · 2020
layers
96
numbers per token
12,288
attention heads per layer
96
neurons per MLP
49,152
weights
175 billion
Key ideaDepth is refinement. No single layer "knows the answer". Each one reads the scratchpad, adds a correction, and passes it up — and you can watch the guess go from an echo of the last word to a real prediction.
The arcs and the per-depth guesses are computed from this model: the read-out decodes the last position's running vector at each depth with the model's own output layer, a technique called the logit lens. It is a peek, not something the model does when it runs. Sizes of today's largest models are mostly unpublished.
06Scores, odds, dice

Choosing the Next Token

The stack ends with one score for every token in the vocabulary. A function called softmax turns the scores into probabilities. Then a sampler rolls weighted dice. The settings below change the dice — the model has already finished its work.

Real model
next tokenscoreprobability

The dice: each surviving token owns a slice as wide as its probability. A roll is a random point on this strip.

The same step in a much larger model

The model in this page is tiny. Here is the same step — scores, then odds, then a pick — in a real model called Qwen2.5-0.5B, which has about half a billion weights. It is far too big to run inside this page, so its output was recorded ahead of time. Nothing below is computed live. The page replays the recording.

White is the starting text. Gold is what the model added. A dotted underline marks a long shot: a token the model itself gave less than a 5% chance.

next tokenscorechance

This model scores every token it knows at every step, about 150,000 of them. Only the ten highest are listed. The last row adds up all the others.

Every score and percentage in this block is real output from Qwen2.5-0.5B (base, not instruction-tuned), recorded ahead of time. The page does not run that model. It can only replay what was saved: the ten top-scoring tokens at each step, and a few short continuations that were sampled from those odds at each temperature. “Start again” picks one of the saved runs. It does not roll new dice. Scores were saved to two decimal places, so a percentage can be off by a point or two at low temperatures. This is a “base” model: it was not trained to follow instructions or to chat, so it continues text instead of answering. That is why it sometimes writes a quiz question, or a blank to fill in (____). The ⏎ sign marks a line break.
Key ideaThe model does not look up an answer. It produces odds, and a sampler picks. Same prompt, different roll, different reply — which is why asking twice can give two answers.
These are the real odds from this page's model () for your prompt, and temperature, top-k, and top-p are applied to them exactly as a production sampler applies them. A tiny model trained on a tiny world is often far more certain than a large one, so try a short prompt such as “the” to see a wide spread.
07Where the numbers come from

Training

Every weight used in the chapters above began as a random number. Training shows the model real text with the next token hidden, measures how surprised it was by the truth (the loss), and nudges every weight a tiny step in the direction that would have made it less surprised. Then it does that again and again.

Train it yourself

First, the idea with just two weights

Height on this map is the loss. Training can only feel the slope under its feet, and steps downhill.

Now the real thing: train this page's model

Same idea, every weight at once. Wipe the model back to random numbers and train it from nothing, here, in your browser. Watch three things: the loss falling, the sentences going from noise to sense, and the word map sorting itself out. When it finishes, every chapter above is running on the weights you made.

Same loop, different job

The shape network at the top of this page and the language model in these chapters are trained by exactly the same four moves: show an example with the answer hidden, read off the odds it gave the right answer, turn that into a loss, nudge every weight. Here are fresh copies of both, starting from random numbers. The copies are private to this panel, so nothing else on the page changes.

Recognising a shape

Example
Right answer
Its guess
Odds on the right answer
Loss
Then

Predicting the next word

Example
Right answer
Its guess
Odds on the right answer
Loss
Then

The full story of how models are made

Pretraining, fine-tuning, learning from human feedback, safety tuning, and evaluation have their own page — including fine-tuning this same model on a word it has never seen.

Open the deep dive
Key ideaNobody programs what a model knows. Training only ever asks one question — "which way is downhill from here?" — and everything the model can do is what was left behind after answering it many, many times.
The second panel is real training: backpropagation and the Adam optimiser running on this model's actual weights, the same code that produced the weights the page shipped with. Loss is the negative logarithm of the probability the model gave the correct token. The two-weight map is a made-up surface for intuition; a real loss landscape has as many dimensions as there are weights.
08What a conversation really is

A Chat Is One Long String

Everything so far only continues text. So how does that become a conversation? A chat app glues the whole exchange into a single string, with special marker tokens saying who is speaking, and asks the model to continue it. When the model writes the end-of-turn marker, the app cuts it off and shows you the reply.

Send a message
What you see
What the model is given — 0 tokens

The same model, before and after it was trained to chat

These are recorded replies from two versions of one small model. The first is the base model, trained only to continue text. The second is the same model after extra training on conversations. Pick a question and compare.

Base model: it just continues the text
After chat training: it answers you
The base model treats your question as the start of a page and keeps writing: the same lines again, or more of a web forum. After chat training, the likely continuation of a question is an answer. The answer is fluent. It is not always right.
Both columns are real output, recorded ahead of time with each model always taking its most likely token. The first is SmolLM2-360M (base). The second is SmolLM2-360M-Instruct (same model after chat training). They are the same size and the same design; the only difference is the chat training. “…” marks where a recording stops. Look closely at the chat-trained answers. One says a token is a label for a concept, when it is really a chunk of text. Another explains an error message from one programming language (JavaScript) as if it came from a different one (Python). Training teaches the shape of a helpful answer, not guaranteed facts.
Key ideaThe model has no idea it is "in a chat". It is continuing a document that happens to be formatted as one. Roles, turns, and even stopping are conventions in the string, enforced by the app around the model.
The replies here are scripted — this page's model knows about cats and gardeners, not tomatoes — and the marker spellings are illustrative; each model family has its own. The mechanism is real: one growing string, role markers, a system prompt you usually cannot see, and a stop marker. The token counts use this page's tokenizer.
09What the model can see

The Context Window

That one long string has a hard size limit. When a chat outgrows it, older turns are squeezed into a summary or fall out altogether — and the model carries on as if nothing were missing.

Drag to lengthen
the window — 0 tokenshard limit
system prompt saved memory summary your turns assistant turns
Key ideaIf it is not in the window, the model does not know it. "Memory" features work by saving a note somewhere else and pasting it back into the window on every request.
A 700-token limit is used so the effect is visible within fourteen turns, and this panel is a scripted simulation. Real windows range from thousands of tokens to over a million, and products differ in how and when they summarise — but every one of them has an edge. For the same effect on the real model, see “Missing context” under Failure modes.
10Same model, narrower odds

Prompts Steer the Odds

You have seen that the output is sampled from probabilities, and that the probabilities come from the context. So a prompt is not a command to a mind — it is the thing that decides which continuations are likely. Each line below is one possible run of the same model on the same prompt.

Toggle the parts
Runs that land on what you wanted0
Key ideaA better prompt does not make the model smarter. It removes other things the reply could plausibly have been.
The fan is a schematic, not a measurement: the spread shrinks by a fixed factor for each ingredient you add. The direction of the effect is real — “Weak prompt” under Failure modes measures it on this page's model — but the numbers here are for illustration.
11Guessing versus checking

Tools and the Agent Loop

On its own, a model can only produce text from its training and its context. Give it tools and wrap it in a loop, and it becomes an agent: it can ask for a file, a search, or a command, read the result, and decide what to do next. Watch who says what to whom.

Scripted runs
YouModelTools
Key ideaAn agent is the same next-token predictor, run in a loop. A tool call is just text in a special format; the program around the model does the actual work and pastes the result back in. Every lap re-reads the whole, growing string.
Tool names, outputs, and token counts in these runs are scripted examples. The message pattern — request, call, result, call, result, answer — is how real agent systems work, and it is also the audit trail: you can judge the work from what was checked without seeing inside the model.
12Different jobs, different machines

Systems: Pick One, Build One

"AI" is not one thing. The useful questions are where the model runs, where your text travels, and what is bolted on around it.

Match the job

Local model

Runs on your own hardware. Private and offline; quality limited by the machine.

Cloud model

Runs in a data centre. Usually the strongest reasoning, at the cost of sending your text out.

Agent

A model plus tools, memory, permissions, and a loop. It can act — and so needs guardrails.

Media model

Turns prompts into pixels or sound. Needs visual direction, not just facts.

Best fit: Cloud model. A gnarly bug benefits from the strongest reasoning available, and the largest models live in data centres. Your text makes a round trip; nothing acts on your machine.

Build an agent stack

Switch capabilities on and off and watch the profile change.

Capability0
Risk0
Oversight0
13Where it goes wrong

Failure Modes

Once you know the machinery, the mistakes stop being mysterious. The first three below are not illustrations: they are this page's model, failing live, in exactly the ways large models fail.

3 run live

Quick checkpoint

Pick the safer approach.

Spot the hallucination

A hallucination is a confident claim with nothing behind it. An assistant has summarised the short source below. Every sentence sounds fine, but some are not backed by the source. Tick the ones you think are unsupported, then check each claim against the source.

Source
    Assistant's summary: tick the unsupported claims
    Round 1 of 3
    Fluent is not the same as supported.
    The sources and the summaries were written by hand for this game. No model produced them. They copy a real pattern: a model writes the sentence that is likely to come next, and a likely sentence can still be wrong. Checking each claim against a source, as you just did, is called grounding.
    14Plain terms

    Concept Decoder

    The vocabulary, with the common misunderstanding next to each term and a link back to the animation that shows it. Or let it quiz you.

    Search or quiz