Machine learning · A real model · In your browser
A real language model, small enough to watch think. It read the plays of Shakespeare one character at a time and learned to guess the next one. Type anything and follow your text through every step of it, live in your browser.
Loading the model (about 200 KB)…
Training is one question asked millions of times: given these characters, what comes next? The model starts with random numbers, guesses, and measures how surprised it was by the real answer. Then it nudges every one of its numbers a tiny step in the direction that would have made it less surprised. That nudge is backpropagation, and the step rule is AdamW.
This one took 5,000 steps, each on 32 random 64-character windows of about a million characters of Shakespeare. It ran in about a quarter of an hour on a laptop's CPU, in a training script written for this page. Its surprise is measured in nats, and lower is better. Picking any of the 65 characters at random scores 4.2, guessing by letter frequency scores 3.3, and guessing from the previous letter alone scores 2.5. It learned spelling, the shape of a speech and who speaks when, but not meaning.
GPT-2, from 2019, has exactly this layout: tokens, embeddings, then a stack of blocks that each run attention and an MLP, adding their results into the residual stream. It is about a thousand times bigger, with 12 blocks of 12 heads, vectors of 768 numbers and 124 million parameters. Today's large models are bigger again by a thousand or more and read word pieces rather than letters, but the step from one token to the next is still the one on this page.