ROGUEQUANT_

$ cd ..

2026.08.06 // LLM FOR DUMMIES // 7 MIN

LLM for Dummies #4 — Training: How Guessing the Next Word Buys You a Mind

We have the machine. Now, why are its trillion numbers right? Because of one absurdly simple game played ten trillion times: hide the next token, guess it, measure the surprise, adjust. This part explains why that game forces a model to learn facts, grammar and a bit of reasoning — and what a loss curve really measures.

ALESSIO ROCCHI ·

The series so far built a machine. Tokens become points in space, and a stack of attention and feed-forward blocks turns a context into a score for every possible next token. But that machine, fresh off the assembly line, is filled with random numbers. It produces gibberish.

This part is about the process that turns ~10¹¹ random numbers into something that can write your emails: training. Fair warning, it's the part with the biggest gap between how simple the idea is and how big its consequences are.

The Only Game in Town

Here is the entire objective of pretraining, with nothing left out: take some text, hide what comes next, and ask the model to guess it.

FIG. 01 // THE LOOP

The entire recipe for a $100M model

SNIPPET OF TEXTa chunk of the internetGUESS NEXT TOKENscores over the vocabularyMEASURE SURPRISEthe loss: how wrong was it?NUDGE THE KNOBS~10¹¹ weights, a tiny bitREPEAT ~10¹³ TIMES
That's it. There is no step where anyone teaches grammar, facts or logic. One number (the surprise) flows backward through the network, telling every weight in which direction to move so the same mistake hurts a little less next time.

ILLUSTRATION: AUTOREGRESSIVE PRETRAINING LOOP

Grab a random chunk of the internet — say, "The capital of France is" — and ask the model for its next-token scores. The truth was "Paris". Was the model surprised? That surprise is a single number, the loss. Then comes the only clever part: the surprise flows backward through the network (backpropagation), and every one of the ~100 billion weights learns which tiny nudge would have made the surprise smaller. Nudge them all, pick another chunk, repeat.

Repeat, to be precise, on the order of ten trillion times.

Nobody teaches grammar. Nobody uploads facts. Nobody defines what a question is. There is exactly one instruction — be less surprised next time — and everything else in a language model's behavior is a consequence of it.

Why Guessing Words Requires Knowing Things

The obvious objection: predicting words sounds like a parlor trick. How does that produce something that can debug code?

Watch what the game actually demands. To predict the next token well, the model is forced to acquire whatever makes prediction cheaper:

  • "The capital of France is ___" — you can't do better than chance without storing the fact.
  • "She poured the coffee into her ___" — you need enough physics of everyday objects to prefer "cup" over "shoe".
  • "127 + 275 = ___" — patterns won't save you forever; some arithmetic procedure predicts better than memorization.
  • Four chapters into a mystery novel, predicting the detective's next line means tracking characters, motives and what each one knows — narrative state, not word statistics.

The general principle, and maybe the deepest idea in this whole series: prediction is compression, and compression requires understanding. A model that predicts the internet well is, by mathematical necessity, a model of the processes that produced the internet — including the human knowledge, conventions and reasoning embedded in it. "It's just predicting the next word" is like saying a student is "just answering exam questions": true, and it entirely misses what you have to become to do it well.

The Curve Everyone Stares At

While the game runs for months on tens of thousands of GPUs, the people paying for it watch one chart.

FIG. 02 // WHAT $100M BUYS

The loss curve: surprise going down, abilities coming up

LOSS (SURPRISE PER TOKEN)10B100B1T10TTOKENS SEEN →SPELLING & GRAMMARFACTS & IDIOMSLONG-RANGE COHERENCE
Training runs are monitored through one number: average surprise. It falls smoothly and predictably (scaling laws) — but what the model can do climbs in rough stages: cheap statistical patterns first, world knowledge later, fragile reasoning last. Curve and stages illustrative.

ILLUSTRATION: TYPICAL PRETRAINING LOSS (LOG-SCALE X)

Average surprise per token, falling. Its shape is remarkably lawful — so lawful that scaling laws let labs predict the final loss of a $500M run from a handful of $5M runs before committing (more in the deep dive). But the smooth curve hides a lumpy reality: what the model can do arrives in rough stages. Cheap statistical patterns come first — spelling, grammar, punctuation. World knowledge accumulates through the middle. The expensive stuff — staying coherent across long arguments, multi-step-ish reasoning — improves last and least, because it's the hardest way left to squeeze the loss down.

FIG. 03 // ORDERS OF MAGNITUDE

Pretraining in three numbers

Tokens seen by a frontier model in pretraining

~15T

≈ 200× everything a human reads in a lifetime

Compute bill for one frontier pretraining run

$100M+

months on tens of thousands of GPUs, in one shot

Objectives used to learn all of it

1

predict the next token — everything else is emergent

The asymmetry worth remembering: the objective costs one line of code, the data pipeline and the compute cost hundreds of millions. Simple goal, industrial execution.

TYPICAL FRONTIER VALUES · 2026

What You Get: A Brilliant Alien Autocomplete

After the money is spent you have a base model — and it's important to be honest about what that is. Ask it "What's the capital of France?" and it may reply "Paris". Or it may continue: "What's the capital of Germany? What's the capital of Italy?" — because quizzes on the internet look exactly like that, and continuing text is the only thing it was ever asked to do.

The base model has the knowledge but not the manners: no notion that it's an assistant, that a question deserves an answer, that some completions are helpful and others harmful. It's a mirror of its training distribution — brilliant, amoral, and pointed at nothing. Turning that raw predictor into something that behaves like a colleague is a separate process, done with a comparatively tiny amount of data — and that's part #5.


Deep Dive: The Objective, Formally

The "for dummies" part ends here — below assumes probability and a bit of calculus comfort. Otherwise, see you at part #5.

Cross-Entropy and the Meaning of "Surprise"

The model defines a distribution p_θ(t | context). Training minimizes the negative log-likelihood over the corpus:

L(θ) = − E_{t₁…tₙ ∼ data} [ (1/n) Σᵢ ln p_θ(tᵢ | t₁…tᵢ₋₁) ]

"Surprise" is precisely −ln p of the true token: probability 1 → 0 surprise; probability 0.01 → high surprise. Perplexity is exp(L) — the effective branching factor, "the model is as unsure as if choosing uniformly among k tokens". And as covered in part 1's deep dive, comparing models across tokenizers requires normalizing to bits per byte: bpb = (N_tokens / N_bytes) · L / ln 2.

The compression claim is exact, not a metaphor: arithmetic coding turns any predictive distribution into a compressor spending −log₂ p(tᵢ) bits per token. Loss is compressed size. A model with 0.6 nats/token on English text is a ~0.87 bits-per-character compressor of English — better than any classical algorithm ever built.

The Update: SGD, Adam, and Backprop in One Paragraph

Backpropagation is reverse-mode automatic differentiation: one forward pass computes the loss, one backward pass computes ∂L/∂θ for every weight at the cost of roughly two forward passes — the bookkeeping of "who contributed how much to the mistake". The raw gradient is too noisy and ill-scaled to use directly, so frontier training uses Adam(W): per-parameter running means of gradient (m) and squared gradient (v), update θ ← θ − η · m̂/(√v̂ + ε) — effectively a per-weight learning-rate that equalizes step sizes across a network whose gradient magnitudes span orders of magnitude. Add a warmup-then-cosine learning-rate schedule, gradient clipping, and mixed-precision arithmetic (bf16 matmuls, fp32 accumulations) and you have the modern recipe. None of it is glamorous; all of it decides whether $100M converges or diverges.

Scaling Laws: The Reason Anyone Dared Spend This Much

The empirical bombshell (Kaplan 2020, refined by Chinchilla 2022): loss follows a power law in model size N and data D,

L(N, D) ≈ E + A/N^α + B/D^β

with E the "irreducible entropy" of text itself. Two consequences. First, predictability: you can fit the constants on small runs and forecast a frontier run's loss within a few percent — this is what makes nine-figure training bills a calculated bet rather than a gamble. Second, allocation: for a fixed compute budget C ≈ 6ND, the optimum sits near N ∝ D — Chinchilla's famous "~20 tokens per parameter". Modern frontier models deliberately violate it, training far past compute-optimal (Llama-class models at 100-200+ tokens/param), because a smaller model trained longer is cheaper to serve — inference economics, not training economics, now shapes the frontier.

The fine print: the loss is smooth, but downstream capabilities can look discontinuous ("emergence"). Part of that is real phase-change-like behavior (the induction heads of part 3 appear abruptly), and part is metric artifacts — exact-match scoring turns gradual improvement into a sudden jump. The honest summary: the currency (loss) improves lawfully; the goods it buys (capabilities) arrive in lumps.

The Data Is the Product

At 15T tokens, the corpus is most of the engineering. Web crawls are deduplicated (MinHash/LSH — duplicates both waste compute and amplify memorization), filtered for quality (classifiers trained to recognize "textbook-like" text), and mixed by domain with hand-tuned ratios — code is heavily over-represented relative to the web because it measurably improves reasoning-adjacent behavior. Benchmark contamination — test sets leaking into training data — is the field's chronic embarrassment and the reason to trust private evals over public leaderboards.

And where does all of it end up? Recall the anatomy from part 3: most parameters live in the feed-forward blocks, which behave like key-value memories — patterns in, stored associations out. Attention learned to route; the FFNs learned the internet. The next part is about how a comparatively microscopic dose of extra training — instructions and preferences — points this whole apparatus at being useful.

What's Next

We have a machine that predicts, and a training process that filled it with knowledge. What we don't have is an assistant: the base model completes text, it doesn't help. Next time: from autocomplete to assistant — instruction tuning, RLHF, why "as an AI language model" became a meme, and what a system prompt actually does.


Series roadmap: tokenizationembeddingsattention → training (you are here) → from autocomplete to assistant → inference. Questions? Tell me.