This is a from-first-principles sketch of how models like Claude and ChatGPT work. It won’t be the complete story, but it builds directly on the neural networks notes — and it turns out you already have almost everything you need.
The one new problem is language. For the face network, an input was a fixed-size vector of pixel brightnesses: even a big image resizes to a fixed number of pixels. Language isn’t like that. A prompt is a variable number of words, and words aren’t numbers, let alone fixed-dimensional vectors. Two tricks fix this, and that’s essentially all a language model is.
An autoregressive language model does one thing: given the previous context (the prompt), predict the next word.
That’s it. To generate text you do it in a loop:
prompt -> predict word₁
prompt, word₁ -> predict word₂
prompt, word₁, word₂ -> predict word₃
...
Each predicted word is appended to the context and fed back in. That loop, one word at a time, is what’s happening when Claude or ChatGPT writes you a paragraph. (In practice the unit is a subword token, not a whole word, but the idea is identical.)
“Predict” in what sense? The same sense as the image classifier. You train it on a training set built from ordinary text: chop text into (context → next word) pairs.
"To be or" -> "not"
"To be or not" -> "to"
"To be or not to" -> "be"
...
At training time you already know the answer and adjust the coefficients so the model gets it right (exactly like showing the face network a labelled photo). At generation time you run the same machine on a context whose continuation you don’t know. “Prediction” is the training verb; generation is prediction with the answer hidden.
Pick a fixed dimension — say 2000 — and map every word to a 2000-dimensional vector, its embedding. dog is some 2000-vector, hat is another, and so on.
Where do the vectors come from? You don’t write them by hand. They are just more parameters: the model starts with random vectors and, while training to predict the next word, adjusts them along with everything else. “Figure out whatever mapping from words to vectors makes next-word prediction work best.”
Once each word is a fixed-length vector, a variable-length prompt still has to become one fixed-length vector. The simplest recipe: average the word vectors in the context, then feed that average into a network whose outputs \(z_1, \ldots, z_V\) score each word in the vocabulary — predict the word with the highest score, exactly the multinomial-logistic setup from the face network (with \(V\) = vocabulary size in place of 6 faces). Averaging is crude but really works; the modern architecture (below) replaces it with something better.
When you learn embeddings only to predict well, something remarkable falls out for free: directions in the vector space become meaningful. The step from man to woman is roughly the same vector as the step from king to queen, so
\[\text{vec}(\text{king}) - \text{vec}(\text{man}) + \text{vec}(\text{woman}) \approx \text{vec}(\text{queen}).\]
Nobody built that in. It emerges because vectors that are good for prediction end up placing analogous words in analogous positions. (It’s not fully understood, and it doesn’t always work — but it works often enough to be startling.) To actually run it you take the arithmetic result and find the vocabulary word whose embedding is closest to it — the same cosine/dot-product nearest-neighbour search from the neural networks notes.
Averaging throws away word order and structure. The real architecture is the transformer. The shape is familiar — layers of hidden units — with one twist to cope with variable length.
The twist: with a variable number of words you can’t have a fixed set of connection weights between layers. So the transformer computes the connection weights on the fly — the weight linking position \(i\) to position \(j\) is itself a function of the vectors at \(i\) and \(j\). That data-dependent wiring (this is attention) is the whole trick; everything else is the neural network you already know. This is the decoder transformer architecture that essentially everyone uses.
The training set is, again, just text — potentially all the text on the internet, cut into chunks — turned into (context → next word) pairs.
Pure next-word prediction “works but often produces bad outputs.” A few developments turned it into something useful.
A genuinely open, and fun, question — and one where the early confident “no” has aged badly.
The octopus test (Bender & Koller, 2020). Two people on separate islands converse by telegraph through an undersea cable. A hyper-intelligent octopus taps the cable and learns to imitate the messages statistically. Could it fool one person into thinking it’s the other? The paper argues no: when a genuinely novel situation arrives — “I’m being chased by a bear, I have a couple of sticks, what do I do?” — the octopus has only ever seen word patterns, never a bear or a stick (no grounding in meaning), so it can’t help. They tested GPT-2 (2020) and it indeed failed such prompts.
The falsifiable slip. In the appendix they predicted the argument rules out addition too: GPT-2, asked to finish 3 + 5 =, emits a number but the wrong one, and they claimed this is “beyond the ability of any pure language model.” That’s a testable claim — and it turned out false. GPT-3 and later do addition well (up to a point: ~10-digit sums start failing, multiplication is harder, division basically doesn’t work without a tool). And it isn’t memorisation — models trained on data that provably excludes the specific answers still do it.
Why might prediction alone get there? An analogy from the history of astronomy. Stars are “just inputs” — dots in the sky; we never touched one. Yet astronomers, purely from observation, went geocentric → epicycles (which predicted superbly) → Copernicus (physically truer but initially worse at prediction) → Kepler’s ellipses (simpler and better) → Newton → Einstein. The engine was: predict the observations well while keeping the model simple (Occam’s razor). A neural network can be pushed the same way — fewer layers, coefficients kept near zero, and other regularisers all pressure it toward simpler models. So maybe, given enough data and the right pressure toward simplicity, a predictor could recover the underlying structure — just as astronomers did from dots of light. Or maybe it gets stuck on “epicycles” — a decent-but-wrong theory — and needs impractically much data. It’s genuinely unsettled; a claimed proof of impossibility from a couple of years ago has itself been argued to be flawed.