Chapter 4
What Is an LLM?
The machine behind ChatGPT and Claude does exactly one thing, over and over. This chapter shows you that one thing — and why it adds up to so much more than it sounds.
Start, as always, with the sealed black box. You type: "Suggest a restaurant for Mom's birthday dinner. She loves Thai food." A moment later, a thoughtful, well-organized answer streams out — restaurant styles, a reservation tip, maybe a question back about her spice tolerance. From the outside it looks like the box read your message, thought about it, and composed a reply. Here is what the box actually does: given all the text so far, it predicts one plausible next word. Then it does it again. And again. That's the whole trick. There is no plan for the answer, no outline, no draft. One word at a time, each chosen fresh, each becoming part of the input for choosing the next.
An LLM — large language model — is a machine-learning model (Chapter 2's tuned knobs, billions of them) whose single trained skill is next-word prediction. People sum this up as "autocomplete on steroids," and the phrase is genuinely useful: like your phone's keyboard suggestions, it continues text. Keep that anchor. But we owe you an honesty caveat, and it's a big one.
The honesty caveat
"Autocomplete on steroids" describes the mechanism accurately and the capability poorly. Your phone's autocomplete can't debug a program, translate Portuguese, or plan a three-course Thai menu around a shellfish allergy — and LLMs can. It turns out that to predict the next word really well across all of human writing, a model is pushed to absorb grammar, facts, reasoning patterns, even something like a theory of what the writer wants. The mechanism is humble; what the mechanism was forced to learn is not. Anyone who tells you "it's just autocomplete, therefore it can't really do X" is skipping the interesting part — and honestly, researchers are still arguing about how much genuine understanding hides inside the prediction machinery.
The loop: how one word gets made
Everything an LLM ever does is this five-step loop. Steps 1 and 2 you already know from Chapter 3; step 3 is this chapter's main event.
- Break the prompt into tokens. "Suggest a restaurant for Mom's birthday…" becomes a sequence of pieces from the token menu (~50,000 entries in GPT-3, our worked example; ~200,000 in today's models), each swapped for its ID number.
- Turn each token into a vector. Each ID is looked up on the meaning-map: one list of numbers per token, thousands of numbers long.
- Layers refine the vectors using context. The token vectors pass through dozens of processing layers. At each layer, every token's vector gets updated using information from the other tokens — this is where "bank" drifts toward the river or the money, and where "she" figures out it means Mom. By the top layer, each vector has gone from "dictionary meaning of this token" to "what this token means here, in this exact sentence."
- Produce a probability for every token in the vocabulary. From the final vector, the model computes a score for all ~50,000 tokens at once: how plausible is each as the next token? "Thai" 42%, "For" 18%, "Given" 9%, "carburetor" 0.0001%…
- Pick one, append it, repeat. One token is chosen from that probability list (usually a likely one, not always the single top one — more in Chapter 6). It's glued onto the end of the text, and the whole loop runs again on the now-longer sequence. The loop stops when the model emits a special "I'm done" token.
The train-car picture explains a behavior you've probably seen: a chatbot doubling down on a mistake. If an early token commits the answer to "The restaurant opened in 1987" and that's wrong, the model can't reach back and un-write it. Every later token is predicted given that 1987 is now part of the text — so the follow-up sentences will confidently elaborate on the wrong year, because that's what a coherent text containing "1987" would do. The model isn't stubborn; it literally cannot edit the train it's pulling. (Newer "reasoning" models mitigate this by drafting a long train of private scratch-work tokens before the visible answer begins — wrong turns get taken on the practice track instead of in front of you. Chapter 5 shows how that trick is trained in. But within any one stream of tokens, the rule holds.)
Step 3, opened up: attention
Now the main event. Chapter 3 ended on a cliffhanger: a static meaning-map gives bank one fixed spot, so it can't tell river banks from money banks. The fix is a mechanism called attention, which the 2017 paper "Attention Is All You Need" made the centerpiece of a new architecture, the transformer — arguably the most consequential machine-learning paper of its generation.
The idea in one sentence: before predicting anything, let every word look around at the other words in the text and pull in information from the ones that matter to it.
Take a line from our dinner thread: "Mom said she wants Thai." When the vector for "she" arrives, it's generic — the map coordinates for the pronoun "she," referring to nobody in particular. Attention is how it finds its referent. Think of it as a round of matchmaking (or, if you prefer, a tiny search engine) in which every word participates three ways:
- Each word writes a query — a short profile of what it's looking for. "She" broadcasts: "Seeking: a female person mentioned earlier."
- Each word also posts a key — a profile of what it has to offer. "Mom" posts: "On offer: female, person, the subject of this sentence." "Thai" posts: "On offer: cuisine, adjective-ish."
- Queries are compared against every key, and where they match strongly, the matched word hands over its value — the actual package of information it carries. "She"'s query matches "Mom"'s key almost perfectly, so "Mom"'s value flows into "she"'s vector.
After this round, the vector for "she" is no longer generic — it has been enriched into something like "she, meaning Mom, the person whose birthday dinner is being planned." The same mechanism moves bank toward the river when "river" is in the sentence, and tells "dish" in "make Mom's favorite dish" that tonight it means food, not tableware. Crucially, every word does this simultaneously — "Thai" is also querying, and finds "wants" and "Mom," picking up "the cuisine Mom desires"; even "wants" sharpens up. Attention is all-to-all matchmaking, everyone consulting everyone.
Fittingly for our story, it works like a dinner party. Before anyone speaks, every guest glances around the table and decides whom to listen to for this particular remark — when Mom mentions the restaurant, you tune to her and to your brother who ate there, and mostly tune out your uncle discussing carburetors. Each word at each attention round does exactly this: weigh every other word, lean toward the relevant ones, let the rest fade to background chatter. Where the analogy breaks: dinner guests take turns, but in attention every word listens to every other word simultaneously, in one parallel sweep — and nobody's feelings get hurt at 0.0001 weight.
Simplified!
The matchmaking story is a real simplification. Queries, keys, and values aren't little sentences — each is a list of numbers, produced from the word's vector by (you guessed it) tuned knobs, and "matching" is arithmetic on those lists. No one wrote rules like "pronouns seek people"; the model discovered during training that this kind of matching helps predict next words. Also, each layer runs many attention rounds in parallel ("heads"), each specializing differently — one tracking pronouns, another grammar, another nearby facts. The cartoon is faithful in spirit, cartoonish in detail.
Once you know what attention is doing, you start seeing candidates for it in every sentence of the dinner thread. Here are four, each with a word that is ambiguous on its own until attention wires it to the right neighbor:
| Sentence from the dinner story | Ambiguous word | Attention connects it to… | Why that changes the meaning |
|---|---|---|---|
| "Mom said she wants Thai." | she | Mom | Without the link, "she" is any female person; with it, the whole request becomes Mom's preference — the thing the dinner must satisfy. |
| "Make Mom's favorite dish!" | dish | dinner, restaurant, Thai | Food words in the context pull "dish" toward meal, not ceramic plate. Change the context to "washing up" and the same word slides the other way. |
| "Book the place we went for Dad's promotion." | place | went, promotion (an event) | "Place" alone could be anywhere; linked to a remembered outing, it means one specific restaurant — the model must fetch which one from earlier in the chat. |
| "She can't handle spice, so keep it mild." | it | spice → the food being ordered | "It" has no meaning of its own; attention resolves it to the order, turning a vague clause into a concrete instruction for the menu. |
A stack of re-readings, plus a memory between floors
One round of attention buys you one round of enrichment. A transformer — the architecture behind every modern LLM — stacks this process into dozens of layers (GPT-3 has 96), and every layer re-reads the whole text with fresh eyes. It's like rereading a tricky paragraph: pass one resolves who "she" is; pass two, knowing that, works out that "Thai" is a birthday-dinner candidate, not a nationality; pass three connects it to the budget mentioned earlier. Each pass leaves every word's vector a little richer, until the top-layer vectors carry a deeply contextualized digest of the entire passage.
Another way to hold the stack in your head: imagine sending a draft through 96 editors in a row, each with a specialty. The first few are copy editors fixing grammar-level issues; the middle ones are continuity editors ("wait — 'she' here is the mother from page one"); the last few are the acquisitions editors asking what the piece is really building toward. Each editor reads the whole draft, annotates every word, and passes it on richer than they found it. The analogy breaks in one important way: real editors have assigned jobs, while a transformer's layers were never given specialties — whatever division of labor exists emerged from training, and layers blur and share roles far more messily than an editorial masthead.
Each layer actually has two halves, and the division of labor is worth knowing:
- Attention pulls information across the text — from other words in your prompt. It answers: "who here is relevant to me?"
- Feed-forward layers (the other half) work on each word alone, and act as the model's internal knowledge store. This is where facts absorbed from training live, spread across billions of knobs: that Thai food is often spicy, that birthdays involve cake, that restaurants take reservations. Attention fetches from your prompt; feed-forward layers contribute what the model already knows.
So when the model completes "Mom said she wants Thai, so let's book…", attention supplies Mom, birthday, Thai from your words, and the feed-forward layers supply a Thai restaurant is the kind of thing one books from its training. Every answer you've ever gotten from a chatbot is a braid of those two threads.
The numbers, for awe
We've used toy numbers throughout. Here are real ones, mostly from GPT-3 — one of the few frontier models whose full specs were published (2020; today's models are larger, and their exact numbers are mostly secret):
- Vocabulary: 50,257 tokens on the menu. (Today's models run bigger menus — around 200,000 for current OpenAI models — mostly to give non-English languages and code more whole-word bricks.)
- Vector size: 12,288 numbers per token — our 2-D map, in 12,288 dimensions.
- Layers: 96 re-reading passes, each with 96 parallel attention heads.
- Knobs: 175 billion tuned parameters; today's frontier models are widely believed to be in the hundreds of billions to trillions.
- Training diet: about 300 billion tokens of text, drawn from a pool of roughly 500 billion. A child hears on the order of 100 million words by age ten — the model read thousands of childhoods' worth of language, though notably a child does far more with far less.
That last number deserves a picture, because "300 billion versus 100 million" slides off the brain. Drawn to scale, it looks like this:
What the last step looks like
After all 96 layers, step 4 turns the final vectors into a probability for every one of the 50,257 tokens. Here's a realistic (illustrative, precomputed — not from a live model) table for the prompt "Mom's favorite food is":
| Candidate next token | Probability | Why it scores this way |
|---|---|---|
| · pizza | 9.8% | Extremely common completion of "favorite food is" in training text |
| · pasta | 7.1% | Same pattern, slightly less frequent |
| · Thai | 6.4% | Boosted if earlier chat mentioned Thai — attention at work |
| · sushi | 5.2% | Popular "favorite food" in written English |
| · chocolate | 4.9% | Common, though more often a "favorite dessert" |
| · probably | 3.1% | Hedging continuations exist in training text too |
| … 50,251 others | 63.5% combined | Everything from "· lasagna" (plausible) to "· carburetor" (~0.0001%) |
Seen as a shape, steps 4 and 5 are a funnel: the entire 50,257-token menu goes in the wide end, and exactly one token comes out the spout.
Read that table again and notice what it is not. It is not a database row that says what Mom's favorite food is. The model doesn't know your mom. It knows what words tend to follow "favorite food is" in human writing, sharpened by whatever your conversation has said so far. That's the pattern behind both its brilliance and its failures, and it sets up three misconceptions worth killing now.
Misconception: "It looks up answers in a database"
There is no database of answers inside — no table of facts, no stored documents, no search index. Just knobs that turn text-so-far into next-token probabilities. Every sentence is generated on the spot, which is why the model can answer questions nobody has ever asked ("plan a Thai birthday dinner for a mom who hates cilantro, on a Tuesday, under $200") — and also why it can generate confident nonsense. A database would say "no results." A generator always generates.
Misconception: "It just copies chunks of its training text"
Almost never. The training text shaped the knobs, then was set aside — it isn't stored inside the model or consulted at answer time. Because each token is chosen probability-by-probability, output is nearly always a novel word sequence. (Exception worth knowing: passages repeated thousands of times in training — famous quotes, licenses, Bible verses — can be reproduced nearly verbatim.) Typical answers, though, are genuinely composed, not retrieved. The courts have started drawing this same distinction, and one of the first big generative-AI rulings is worth two sentences because it separates two questions people constantly blur. In Bartz v. Anthropic (2025), a federal judge ruled that training a model on lawfully purchased books can be fair use — the "is training copying?" question — but the separate question of where the books came from went the other way: Anthropic had downloaded millions of books from pirate libraries (the court put it at over seven million copies), and agreed to settle that claim for $1.5 billion, roughly $3,000 per covered work; the court gave the settlement final approval in July 2026. Lesson for headlines: "AI copies books" and "AI companies took books they shouldn't have" are different accusations, and so far the law treats them very differently.
Misconception: "Surely the engineers know exactly how it works"
Honest answer: no. Engineers fully understand the architecture — everything in this chapter — and the training process. What nobody fully understands is what the billions of tuned knobs collectively learned: why this model is great at Portuguese but odd about dates, or which knobs hold the concept "birthday." A field called interpretability is prying the box open (by 2026, researchers can trace individual concepts and simple circuits through small and mid-size models), but a complete accounting of a frontier model remains far out of reach. When you hear "no one knows how these things work," this is what's meant — not that they're magic, but that we built the loom without being able to read the fabric.
Try it now (5 minutes)
Watch the loop with your own eyes. Ask any chatbot: "Complete this sentence with one word only: Mom's favorite food is ___. Then list five other words you might have said instead, with a rough probability for each." The list it gives is a self-portrait of step 4 (reconstructed, not its real internal numbers — but instructive). Then ask the same question in a fresh chat after first telling it "we're planning a Thai dinner" and watch the probabilities shift. That shift is attention, live.
Key idea
An LLM is a next-token predictor running in a loop: tokens → vectors → dozens of attention-plus-knowledge layers → probabilities over the whole token menu (50,000 entries in GPT-3, ~200,000 today) → pick, append, repeat. Attention lets every word borrow meaning from every other word; feed-forward layers add knowledge absorbed in training; and the humble mechanism, scaled to hundreds of billions of knobs, yields abilities nobody fully predicted — or yet fully understands.
Where to go deeper
- Easy: "Large language models, explained with a minimum of math and jargon" by Timothy B. Lee & Sean Trott — the single best prose companion to this chapter, including a lovely walkthrough of attention resolving "John wants his bank to cash the…".
- Medium: Transformer Explainer (Georgia Tech's Polo Club) — a live model running in your browser; type a prompt and watch tokens, attention, and the probability table update in real time. The whole loop from this chapter, animated.
- Deep: "The Illustrated Transformer" by Jay Alammar — the classic visual walkthrough of queries, keys, values, and stacked layers. Some light matrix notation, but every step is drawn; read it and you'll know how practitioners actually picture the machine.