What a model actually does
Strip away the mystique and a language model does one narrow thing: given the text so far, it predicts what comes next. Not whole thoughts, just the next small chunk (a token: a word or word-piece). To write a sentence it just does this over and over, each new token appended and fed back in. That's it. Everything else is machinery in service of making that one prediction good.
So “a model that writes” is really a model that scores what's likely next, run in a loop. The skill isn't generating; it's the prediction underneath. Here is that one prediction, for real, from the tiny model this lab builds in Part 1:
Text becomes numbers (tokens)
A model can't do arithmetic on letters, so the first move is to turn text into numbers. The text is
chopped into tokens: common chunks (whole words like fox, or word-pieces),
each with an integer ID (its index in a fixed list called the vocabulary).
“fox” might be token #1234. That's all a token is to the model: an ID. There's more than one
way to chop, and the choice matters enormously:
The reverse runs at the end: the model's predicted ID is mapped back to its chunk of text, and the pieces are glued together into words. Part 1 builds the tokenizer →
Tokens become vectors (embeddings)
If the ID is just a ticket, where does meaning live? In what the ticket fetches: each token's ID points to a list of numbers, its embedding (a vector of 384 numbers, in our tiny model). Think of those numbers as coordinates that place the token in a vast “meaning space,” where tokens used in similar ways land near each other.
Start with the fetch itself. The ID is nothing but an index; what matters is the row it lands on: that row of numbers is the embedding, the token's vector. The first hint of meaning is already visible in it: words that behave alike carry similar rows, while a pure grammar word like “the” looks nothing like them.
That's one token's row. Now zoom out: there's a row like it for every token in the vocabulary: thousands of them, stacked into one enormous table. That table has a name, WE, and it holds essentially everything the model knows about individual words.
W_E from the trained model: 8,192 token columns × 384 dimension rows, every cell a learned value (12 tokens shown, swept A→Z; ⋯ stands in for the other ~8,180). Each column also carries its real token id (scrambled: the columns are alphabetical, the ids are not, per §2). Each column is one token’s vector, the “meaning coordinates” this section is about. Measured, not illustrative (and small: this model trains in the ±0.2 range).Rows of numbers are hard to read meaning from directly, so picture them as positions instead. Give each token the coordinates in its row and the “meaning space” stops being a metaphor: related tokens gather into neighbourhoods, unrelated ones drift apart.
The linear layer (the core operation)
Almost the entire network is one operation, repeated: the linear layer,
y = Wx + b. It takes a vector of numbers in and produces a new vector out, where each output
is a weighted sum of all the inputs plus an offset. Stack the per-output weight-rows into a grid
W and the offsets into a vector b, and that's the whole layer: the school-line
y = mx + c, vectorised. The diagram below builds it from one output up to the whole model.
The bend (activations)
Stacking linear layers has a catch: by itself, it buys nothing. Double a number, then triple it. Two steps, yet all you've really done is multiply by six, which is one step. Every stack of straight-line operations collapses this way into a single straight-line operation. So no matter how deep the model went, it could still only draw lines. The fix: after each linear step, apply one simple nonlinear function, a bend. That bend is what lets depth model curves and combinations, not just proportions.
Ours is GELU (a smooth version of ReLU). The famous textbook ones are ReLU
(keep positives, zero the rest) and the sigmoid (squash any number into 0–1). The whole kit
is just this: Wx + b, then a bend, stacked, plus the two ideas below.
One natural misreading is worth heading off: these curves aren't there to squash numbers into a tidy range. The sigmoid happens to (everything lands between 0 and 1), but ReLU and GELU, the ones modern models actually use, are unbounded: a big input sails through nearly unchanged. (Bounded activations in fact fell out of favour: their flat tails make the learning signal of §7 vanish.) Keeping the network's numbers in a sane, comparable range is a different component's job: LayerNorm, a normalisation step you'll meet inside the block in Part 1. The bend has exactly one job: be not-a-straight-line, so stacking layers buys new shapes instead of collapsing into one.
Attention: letting tokens talk
Linear layers process each token on its own. But meaning depends on context: “bank” near “river” vs near “money.” Attention is the one step where positions look at each other: each token forms a query and asks “which earlier tokens matter to me?”, then pulls in a blend of their information. It's how the model carries context forward, the part that makes it a language model and not a bag of independent words.
And this isn't a metaphor; it's measurable. Here is the sentence from above, run through the trained Part 1 model, with one attention head's actual weights drawn as arcs:
How it learns: loss, gradients, gradient descent
Where do the millions of parameters come from? Training. Show the model real text with the next token hidden, let it guess, and measure how wrong the guess was with a single number: the loss (low = confident and right; high = wrong). Training is nothing more than making that number smaller, over and over.
The trick is knowing which way to nudge each of the millions of parameters. That's the gradient: for every parameter, the slope of the loss, telling you which direction, and how hard, reduces the error. Nudge every parameter a little down its slope, and the loss drops. Do it a few thousand times and coherent language emerges. This is gradient descent.
gen_loss_surface.py, constant step-size dial): at every step, feel the slope, step downhill. Watch the hops shrink on their own: nobody slows the ball down; the flatter the valley, the smaller the gradient, the smaller the update. (Real training is noisier, each batch gives a slightly different slope, which is why Part 1 §13 also shrinks the step size on a schedule.) Our model has millions of weights, a landscape in millions of dimensions, but the move never changes.One pass of training is a loop of four steps, repeated on batch after batch of text:
Generating text, and the one knob: temperature
Once trained, the model generates by running its prediction in a loop: feed the text so far, get a probability for every next token, pick one, append it, repeat. “Inference” and “generation” are the same thing: running the function forward (no learning).
How you pick from the probabilities is the one knob worth feeling: temperature. Low temperature (~0.5) almost always grabs the most likely token: safe, repetitive. High (~1.1) samples more adventurously: varied, riskier, sometimes incoherent. It's the dial between “careful” and “creative,” and it changes nothing in the model, only how its output is sampled. Part 1 lets you feel it →
The honest ceiling, and where this goes
That's the whole machine: text → tokens → embeddings → stacks of (attention + Wx+b + a bend)
→ a final prediction, all tuned by gradient descent. A frontier model is exactly this, scaled up:
more dimensions, more layers, vastly more text and compute. Same ideas; different magnitude.
And the honest ceiling: Part 1's tiny GPT produces believable shapes of language, never knowledge or reasoning. That holds even for the tuned version that writes coherent little stories. A laptop's worth of training can't buy more, and that's fine: the tiny build is for seeing every moving part, not for using. Getting something useful is a different move entirely. Part 2 sets the tiny model aside and starts from a big pretrained open model (4 billion parameters, trained at a scale no laptop can touch; that cost was paid by someone else), then specialises it for one narrow job.