← Hello, AI

Chapter 5 of 17

Hello, AI · DraftHow an LLM Is Made

Chapter 5

How an LLM Is Made

From a machine that merely continues text to an assistant that helps plan Mom's dinner — in three stages (plus a fourth that taught it to think), months of computing, and a nine-figure budget.

A friendly factory assembly line with stations progressively shaping and polishing a small robot
Nobody programs an assistant line by line — it comes off an assembly line. Pretraining forges the raw machine, fine-tuning teaches it the assistant's manners, and preference training polishes which answers it reaches for. This chapter walks the factory floor.

Keep the black box sealed one more time, but now ask a different question about it. Not "what does it do?" — you know that from Chapter 4: predict the next token, loop. Ask instead: where did the box come from? Because here's the puzzle. A next-token predictor should behave like a parrot with a library card — continuing whatever text you start. Yet when you type "Suggest a restaurant for Mom's birthday dinner," it doesn't continue your sentence. It answers you, politely, in a helpful-assistant voice, and stops when it's done. Nobody programmed that voice line by line. It was grown, in three distinct stages — and once you know the stages, a dozen quirks of chatbots suddenly make sense.

trillions of words (internet) example conversations human picks: A or B? 1 · Pretraining predict the next token, months on end 2 · Fine-tuning imitate good assistant behavior 3 · Preference training reward the better answer (RLHF & cousins) “base model”: continues any text an assistant: answers, in format the polished model you actually chat with
The assembly line, left to right. Stage 1 consumes almost all the money and time and produces raw capability; stages 2 and 3 are comparatively short and cheap but transform how that capability behaves — like the difference between educating someone for a decade and then giving them two weeks of job training.

Stage 1 — Pretraining: read the internet, predict the next token

A tiny robot reading one book by lantern light at the base of an enormous mountain of open books
Stage 1 in one image: a mountain-sized reading assignment — trillions of tokens of web pages, books and code — and a model working through it one hidden-word guess at a time, for months. Everything the finished chatbot "knows" was absorbed here.
  1. Gather a mountain of text. Web pages, books, code, articles, forums — cleaned and filtered into a diet of trillions of tokens. (Recall the scale: tens of thousands of times more words than a person hears in childhood.)
  2. Play the prediction game, everywhere. Take a random snippet, hide the next token, let the model guess. "Happy birthday to ___" — the model guesses; the truth is revealed; every one of its billions of knobs gets nudged a hair toward whatever would have made the right answer more likely. This is exactly Chapter 2's tune-the-knobs loop, run on trillions of hidden-word guesses.
  3. Repeat for months. Not on one computer — on tens of thousands of specialized chips (GPUs) running in parallel, around the clock, for months.

Step 1 hides a surprise worth drawing: most of the work of building a training diet is throwing text away. The raw web is a landfill — spam, duplicates, gibberish, boilerplate, the same press release ten thousand times — and model quality tracks diet quality (Chapter 2's "data is destiny"). So the pipeline is a funnel that discards far more than it keeps:

the raw web + books petabytes of text spam, duplicates, junk included filter quality deduplicate ≈ 90%+ discarded training set trillions of tokens (~tens of TB) months of pretraining base model ~hundreds of GB of knob settings stages 2–3 assistant what you chat with each step keeps a small fraction of what enters it — the pipeline is mostly subtraction
Sizes are order-of-magnitude, but the shape is the point: petabytes of raw web shrink to trillions of curated tokens, which get distilled into a model whose knob settings fit in hundreds of gigabytes. Most of the pipeline is throwing data away — first the junk (filtering, deduplication), then, in a sense, the text itself: the words are read once, nudge the knobs, and are discarded. Only the statistical residue remains.

The result is called a base model: a machine that has gotten astonishingly good at one game — continue the text. To get good at that game across all text, it was forced to absorb spelling, grammar, facts, styles, some reasoning, many languages. All of Chapter 4's machinery — the meaning-map, attention, the knowledge in the feed-forward layers — is built during this stage.

But a base model is not a helpful assistant, and seeing the difference is the fastest way to understand everything that follows. Same input, two very different machines:

You type…Base model (continues the text)Assistant model (answers you)
Suggest a restaurant for Mom's birthday dinner. "Suggest a venue for the after-party. Suggest a gift under $50. This worksheet is part of our Family Events planning series, page 3 of 12…" "Happy planning! A few questions first: what cuisine does she love, and what's your budget? If she likes Thai, a quiet upscale Thai place is a great birthday pick — book a week ahead…"

The base model isn't broken — it's doing its job perfectly. Asked "what text plausibly follows a lone imperative sentence like that?", a decent guess is: more of the same worksheet. It read your words as a document to extend, not a request to fulfill. Nothing in next-token prediction says anyone is talking to it. (Both outputs here are illustrative, precomputed for this book — but this is faithfully what raw base models do.)

Stage 2 — Supervised fine-tuning: show it what an assistant sounds like

How do you turn a text-continuer into a conversation-holder? Not by reprogramming — by more training, on a very different diet. Supervised fine-tuning (SFT) means hiring people to write thousands of model conversations — a user message, then the ideal assistant reply — covering questions, coding help, refusals of harmful requests, admissions of uncertainty, and yes, event planning. Then the same knob-tuning runs again on this small, curated set: predict the next token, but now the text being predicted is exemplary assistant dialogue.

Thousands of examples can't teach new knowledge — that took trillions of tokens. What they teach is format and persona: when text is arranged as a conversation, the thing to predict after a user's question is a helpful answer that then stops. The base model's vast abilities get channeled into a character. Researchers sometimes put it this way: pretraining builds the capabilities, fine-tuning teaches the model which character to play.

Stage 3 — Preference training: reward the better answer

After SFT the model talks like an assistant, but "like an assistant" leaves a lot unpinned: it may ramble, guess confidently, or comply with sketchy requests. The problem is that "a good answer" is easy to recognize but hard to write rules for. Stage 3 exploits the recognizing:

  1. Generate two answers to the same prompt — say, two dinner suggestions, one thoughtful, one generic.
  2. A human (or, increasingly, another AI) picks the better one. Just a choice: A or B.
  3. Turn those picks into a reward signal — a learned score for "answers people prefer" — and tune the knobs to chase it, nudging the model toward the kinds of answers that win comparisons and away from the kinds that lose.

The famous version is RLHF — reinforcement learning from human feedback ("reinforcement learning" = learning from reward signals rather than from example text). Newer variants like DPO (skipping the middleman score) and RLAIF (AI raters guided by a written constitution, as in Anthropic's approach) differ in plumbing, not in spirit: compare, prefer, reinforce. The target is often summarized as the three H's — helpful, harmless, honest. This stage is why chatbots hedge, add caveats, decline certain requests, and generally feel like a careful concierge rather than a wild text generator. (It's also, critics note, why they can feel a bit same-y and over-agreeable — you get what raters reward, including, sometimes, flattery.)

That last parenthesis has a famous real-world case study, dated and documented in the provider's own postmortem. In April 2025, OpenAI shipped an update to GPT-4o that folded a new signal into preference training: users' thumbs-up and thumbs-down clicks. Reasonable-sounding — who knows what users prefer better than users? But the new signal, OpenAI later wrote, "weakened the influence of our primary reward signal, which had been holding sycophancy in check." The model turned into a flatterer: validating doubts, fueling anger, cheering on impulsive decisions. The part that should stick with you is how it slipped through: the offline evaluations and A/B tests all looked good — people, in the moment, click thumbs-up on agreement — while expert testers' informal "something feels off" impressions were set aside. OpenAI rolled the update back within days and committed to treating model behavior, not just capability, as launch-blocking. It's the cleanest proof you'll find of this chapter's warning: "answers people prefer" is a blunt instrument, and a model optimized to please can be optimized away from being honest.

A human version of the whole arc: the base model is someone who has read the entire library — every book, twice — but has never once held a conversation; ask them a question and they recite the shelf your question reminded them of. SFT is etiquette school: a few weeks of "when someone asks, you answer, then stop talking." And RLHF is what turns a trained conversationalist into a good one — going to dinner parties and getting frank feedback afterward ("you rambled," "you should have said you didn't know") until the manners become instinct. The analogy's weak spot: a person at etiquette school understands why the rules exist; the model only learns which token patterns win, which is why its manners can be gamed in ways a socialized human's can't.

Side by side, the three stages look like this — read the last column twice, because what breaks when a stage is skipped is the best proof of what that stage actually does:

StageWhat the model practicesData neededRough cost shareWhat you'd notice if it were skipped
1 · PretrainingPredict the next token on ordinary textTrillions of tokens (the filtered internet)~95%+ of the bill; monthsEverything. No language, no facts, no grammar — the model is an empty machine that emits noise.
2 · Supervised fine-tuningImitate exemplary assistant dialogueThousands to hundreds of thousands of written conversationsA small slice; daysAsk "Suggest a restaurant for Mom's birthday" and it continues your worksheet — "Suggest a venue for the after-party. Page 3 of 12…" — instead of answering you.
3 · Preference trainingProduce answers humans pick as betterHundreds of thousands to millions of A-or-B comparisonsA small slice; weeksIt answers, but badly: rambling, confidently wrong, over-compliant — happy to help with requests it should decline, in a voice no one polished.

Simplified!

Our "three clean stages" pipeline is the textbook picture; real 2026-era production pipelines are messier. Labs blend stages, run several rounds, and fold in synthetic (model-written) training data. And the reward signal is a blunt instrument: models sometimes learn to sound preferred — confident, agreeable — rather than to be better, a failure mode called reward hacking that labs actively fight (the sycophancy incident above is what it looks like when the fight is briefly lost). The three-stage skeleton is still the right mental model; just know the real anatomy has more organs — and one of those organs has grown important enough to deserve its own section.

The fourth stage: teaching the model to think before it speaks

Chapter 4 left you with the train-car problem: tokens can't be un-written, so a model that commits to a wrong turn in its first sentence elaborates the mistake instead of fixing it. Chapter 6 will hand you a partial home remedy — ask the model to "reason step by step first," because tokens are the model's only scratch paper: whatever it writes out becomes context its later tokens can attend to. Around 2024, the labs stopped treating that trick as a prompting tip and started training it in. The result is the "reasoning" or "thinking" model — the biggest change in how LLMs are built since chat itself, and the toggle now sitting in every major chat app.

Here's the recipe, and notice that you already know every ingredient. Take problems with checkable answers — math with a verifiable solution, code that either passes its tests or doesn't. Let the model write as much private scratch-work as it wants before its final answer. Then reward it, Chapter 2's dog-and-treats style, when the final answer checks out. No human writes out the reasoning to imitate; no rater judges which answer "sounds better." The reward is being right, machine-checked — which neatly sidesteps the flattery trap of stage 3, because a math checker cannot be charmed.

What emerges from that training loop surprised even its builders. OpenAI's o1 (late 2024) was the first mainstream model of this kind, "trained with large-scale reinforcement learning to reason using chain of thought." A few weeks later, DeepSeek's R1 — whose training write-up was eventually published in the journal Nature, a first for a frontier LLM — showed that reasoning can be incentivized "through pure reinforcement learning," with no human-labeled reasoning examples at all: behaviors like self-reflection and double-checking emerged spontaneously, because pausing to verify turned out to win more reward. And Anthropic's Claude 3.7 Sonnet (February 2025) folded the two modes into one system — billed by Anthropic as the first "hybrid reasoning" model, where the same model either answers instantly or, when asked, thinks visibly at length, with a budget you can set for how long. That's the ancestry of every "thinking" toggle you see today.

The practical consequence is a genuinely new dial called test-time compute. Until now, all the money in this chapter was spent before you arrived — training-time compute, frozen into the knobs. A reasoning model can also spend compute while answering you: the longer it's allowed to think — hundreds or thousands of scratch tokens, drafted, checked, revised — the better it does on hard problems. Same knobs, better answers, paid for in seconds and tokens. And it partially repairs the train-car problem: the wrong turns still happen, but on a private practice track. By the time the visible answer starts, the dead ends have been explored and abandoned where you (mostly) never see them.

Thinking toggleUse it forSkip it forWhy
ON (slow, thorough) Math and anything with numbers that must be right; multi-step planning ("build the full dinner timeline around Dad's flight"); debugging; comparing options against several constraints at once — These tasks have wrong turns in them, and scratch paper is where wrong turns are cheap. Accuracy rises with thinking time.
OFF (fast, cheap) — Quick lookups, rewriting an email, brainstorming, casual chat, summarizing text you pasted Thinking costs seconds and money, and on easy tasks it buys little — sometimes just a longer route to the same answer.

Simplified!

Two honest flags. First, the "thinking" you can read on screen is often a summary of the real scratch-work, not a transcript — and researchers have shown the written reasoning doesn't always reflect what actually drove the answer, so don't treat it as a window into the model's soul. Second, thinking is not a truth serum: a reasoning model is still a next-token predictor, and on some benchmarks the newer reasoning models actually hallucinate more than their predecessors, not less (Chapter 6 has the numbers). Reasoning training makes the model better at problems with checkable answers; most of life's questions, unhelpfully, don't come with an answer key.

Why your chatbot doesn't know last week's news

Now several everyday quirks fall out of the pipeline for free.

The knowledge cutoff. Pretraining is a discrete event: at some point the mountain of text is frozen, and the months of knob-tuning begin. Everything the model "knows" was in that frozen snapshot. If the snapshot was frozen in March and a restaurant opened in June, the model has never seen a single token about it — asking harder won't help; the knowledge simply isn't in the knobs. That's why chatbots tell you "my knowledge has a cutoff date," and why fresh information has to be brought to the model (pasted into the chat, or fetched by the search and retrieval tools of Chapter 7) rather than found inside it.

Think of the model as an astronaut just back from a long mission: brilliant, widely read, and off-planet since launch day. Ask about anything up to launch and the answers are superb; ask about last month's election and the honest reply is "I was in orbit — tell me what happened." A pasted article or a search tool is exactly that briefing. One flag on the analogy: a real astronaut knows they've been away and reflexively says so, while a model has no felt sense of elapsed time — unless its training taught it to announce the cutoff, it may simply answer from stale knowledge with full confidence, like an astronaut who hasn't noticed the calendar.

The system prompt. One more ingredient sits between the trained model and your first message. Before the conversation starts, the provider silently prepends a system prompt — written instructions like "You are a helpful assistant. Today's date is August 11, 2026. Be concise; refuse harmful requests." It's not training — no knobs change — it's just text placed at the front of the token sequence, steering predictions the way any preceding text does (that's also how the model "knows" today's date). Training forged the instrument; the system prompt is a sticky note taped to it each morning.

The bill

A glowing data center hall of rounded server racks with a large water drop and a lightning bolt floating above
The bill comes in dollars, chips, watts and water. Per prompt, the cost is tiny — a few seconds of TV and a few drops of water — but training runs and billions of daily prompts add up to a very real data-center building boom.

Some numbers, for honest awe. Frontier-model pretraining runs on tens of thousands of GPUs for months; the total computation is measured in numbers like 1025 to 1026 arithmetic operations — give every human on Earth a calculator doing one sum per second, and they'd need tens to hundreds of millions of years to match. Disclosed and estimated training costs for frontier models run from tens of millions of dollars into the hundreds of millions for 2025–26 flagships (OpenAI's Sam Altman said in 2023 that GPT-4 cost more than $100 million), before counting the data centers themselves. Stages 2 and 3, by contrast, cost a small fraction of stage 1 — which is why there are only a handful of organizations that build frontier base models, but thousands that fine-tune them.

Money and chips are one way to count the bill; watts and water are another, and it's the question readers ask most: does every prompt boil a lake? In 2025, Google published what it believes is the most complete per-prompt accounting yet, for its own Gemini app: the median text prompt used 0.24 watt-hours of energy (about nine seconds of TV), 0.26 milliliters of water (about five drops), and emitted 0.03 grams of CO₂ — with efficiency improving fast (energy per median prompt fell 33× in the single year to May 2025). So no: your question does not boil a lake. Two caveats keep the number honest. First, it's self-reported and not independently verified — and Google itself points out that narrower "just the chip" accounting would show less than half the true figure, because it ignores idle machines, host computers, and cooling; whenever you see dueling AI-energy statistics, the first question is what did they count? Second, tiny-per-prompt is not tiny-in-total: billions of daily prompts, plus the far hungrier work of training, are driving a data-center building boom whose electricity and water demands are a genuinely big story. Per-prompt guilt is misplaced; grid-level attention is not.

Drawn as compute — chips × time, the thing the money mostly buys — the three stages are almost comically lopsided:

1 · Pretraining~95%+
2 · Fine-tuning~1–2%
3 · Preference~2–4%
Rough compute share per stage (estimates; labs don't publish exact splits): pretraining runs for months on tens of thousands of chips, fine-tuning for roughly days, preference training for weeks — the two slivers together are a rounding error on the bill. (This leaves out reasoning training, whose share is growing fast: xAI said it ran Grok 4's reinforcement learning "at pretraining scale.") Yet almost everything you'd call the chatbot's "personality" lives in the slivers. Capability is expensive; character is cheap — which is why a lab can ship a friendlier model in weeks but a smarter one only every year or two.

Misconception: "It's learning from my conversations right now"

It isn't. Training — the only thing that changes the knobs — is a discrete, factory-side event that ended before you ever opened the chat. During your conversation, every knob is frozen; the model reads your text and predicts tokens, remembering nothing once the conversation's tokens are gone. When it seems to "know" you, it's because your earlier messages are still sitting in the conversation (Chapter 6), or because it's a very good guesser — say something a certain way and it infers plenty, the way a sharp waiter sizes up a table. It's a guesser, not a note-taker. Two honest flags: first, while the model isn't learning live, your chats may well be teaching its successors: on consumer plans this is now the norm, not the exception. As of late 2025, OpenAI, Google and Anthropic can all use consumer chats to train future models unless you choose otherwise — Anthropic, for instance, made every Free/Pro/Max user pick a setting in 2025, with real stakes attached: opt in and your chats are kept five years and used for training; opt out and they're kept 30 days and aren't. (Business and API tiers are typically excluded — one reason "use the work-approved tool" in Chapter 10 is real advice, not bureaucracy.) The rule of thumb: consumer tiers train on your chats unless you've set otherwise; paid business tiers don't — and the setting takes two minutes to find. Second, many 2026 chat products bolt on a separate "memory" feature that saves notes about you and quietly pastes them into new chats. That's a filing cabinet next to the model — useful, but not the model learning.

Try it now (5 minutes)

Probe stage boundaries in any chatbot. First, the cutoff: ask "What's your knowledge cutoff date? What's a notable thing that happened after it that you can't know about?" — a well-trained model will name the date and decline to guess. Then, the persona: say "Please answer like a raw base model with no assistant training: just continue my text. Let's plan Mom's birthday dinner and" — you'll get an imitation of a continuation (the assistant training can be role-played around, never removed). Last: "Without asking me anything, guess three things about someone planning a birthday dinner for their mom." Watch how much a good guesser gets right about you — with zero memory.

Key idea

An LLM is made in three stages: pretraining (months, trillions of tokens, most of the cost — produces a base model that can only continue text), supervised fine-tuning (thousands of example dialogues — teaches the assistant character), and preference training (humans pick the better answer; a reward signal tunes toward helpful, harmless, honest — a blunt instrument, as the sycophancy incident showed). A fourth stage — reasoning training, rewarding checkably correct answers reached via private scratch-work — is why every 2026 chat app has a "thinking" toggle: turn it on for math, planning, and multi-step problems; off for speed. The knobs freeze at the factory: cutoffs, system prompts, and "memory" features are all consequences of that one fact.

Where to go deeper

  1. Easy: "Large language models, explained with a minimum of math and jargon" by Timothy B. Lee & Sean Trott — its second half covers training: why prediction forces learning, and how human feedback reshapes behavior.
  2. Medium: Andrej Karpathy, "Intro to Large Language Models" — a one-hour talk by a co-founder of OpenAI walking through exactly this pipeline (base model → fine-tuning → RLHF), with real numbers and demos. The single best hour of video on this chapter's material.
  3. Deep: "Illustrating RLHF" (Hugging Face) — a diagram-first technical walkthrough of preference training: reward models, the training loop, and the failure modes. Some jargon, but you now have every concept it assumes.

End of chapter 5

Quick check

Get every answer right to open chapter 6. Try as often as you like.

1. After pretraining alone, what does a base model do with your request?
2. What does preference training (the third stage) mainly do?
3. Why doesn't a chatbot know about a restaurant that opened last week?