← Hello, AI

Chapter 4 of 17

Hello, AI · DraftWhat Is an LLM?

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.

A rounded machine with a conveyor belt producing one building block at a time, each joining a growing train of blocks
One block at a time: everything an LLM has ever written was produced this way — predict one plausible next piece, attach it to the train, and repeat. No outline, no draft, no plan. This chapter shows why that humble loop adds up to so much.

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.

  1. 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.
  2. 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.
  3. 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."
  4. 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%…
  5. 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.
text so far “…birthday dinner” 1 break into tokens vectors numbers per token 2 look up on map the model dozens of layers refine each vector using context 3 re-read & refine 4 score all 50k Thai — 42% For — 18% Given — 9% …49,997 more pick: “Thai” 5 append & repeat the new token joins the text — loop runs again for the next one Sounds like Mom deserves Thai ← newest car, coupled on
One trip around the loop produces one token. A 200-word answer means roughly 260 full trips — the entire model runs, end to end, for every single token. Bottom: tokens couple on like train cars. Once a car is attached, it can't be uncoupled — the model can only keep adding cars behind it.

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

A warm spotlight connecting glowing beads strung on parallel threads, with bright arcs linking related beads
Attention, the idea at the heart of 2017's transformer: before predicting, every word gets to shine a light on the other words and pull in what it needs from the ones that matter. That's how "she" finds Mom, and how "bank" figures out rivers versus money.

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:

  1. Each word writes a query — a short profile of what it's looking for. "She" broadcasts: "Seeking: a female person mentioned earlier."
  2. 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."
  3. 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.

Mom said she wants Thai query from “she”: seeking a female person → strongest key match: “Mom” “Mom”’s value flows back — “she” now means Mom weak match: mostly ignored
Attention scoring for the word "she": its query matches "Mom"'s key strongly (solid arrow) and "Thai"'s barely at all (faint arc), so almost all the incoming information comes from "Mom." Matches aren't yes/no but weighted — a word blends information from everyone, mostly from its best matches.

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 storyAmbiguous wordAttention connects it to…Why that changes the meaning
"Mom said she wants Thai."sheMomWithout 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!"dishdinner, restaurant, ThaiFood 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."placewent, 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."itspice → 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.

“Mom said she wants Thai, so let’s book…” layer 1 layer 2 ⋮ layer ~48 (middle) ⋮ layer 96 (top) ready to predict: “a Thai” grammar-ish notes: “said” = verb, “she” = pronoun, clause boundaries references resolved: “she” = Mom; “Thai” = the requested cuisine big picture: “next word should name a cuisine or venue” Simplified! Real layers don’t have such tidy jobs — roles blur, overlap, and emerged from training.
The same sentence, progressively understood: only 3 of 96 layers are annotated, and the annotations are a caricature — interpretability research finds a rough tendency (early layers more syntax-flavored, middle layers more reference-and-fact-flavored, late layers more prediction-flavored) rather than clean job titles. What is exactly true: every layer reads all the words, and each word's vector leaves richer than it entered.

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:

Child, by age 10~100M
GPT-3's diet~300B
Even this is flattering to the child: at true scale its bar would be invisible, and the sliver is drawn wider so you can see it. The model read roughly 3,000× more text than a ten-year-old has ever heard, about three thousand childhoods of language. And yet the sliver wins on efficiency: a child reaches fluent, grounded language from that tiny diet, which is a standing hint that today's models learn language in a much more brute-force way than we do.

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 tokenProbabilityWhy it scores this way
· pizza9.8%Extremely common completion of "favorite food is" in training text
· pasta7.1%Same pattern, slightly less frequent
· Thai6.4%Boosted if earlier chat mentioned Thai — attention at work
· sushi5.2%Popular "favorite food" in written English
· chocolate4.9%Common, though more often a "favorite dessert"
· probably3.1%Hedging continuations exist in training text too
… 50,251 others63.5% combinedEverything 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.

every token on the menu 50,257 candidates each gets a score aardvark…·Thai ·pizzacarburetor… ·pasta·sushi zygote… ranked shortlist ·Thai 42% ·For 18% ·Given 9% …rest ≈ noise ·Thai one token out temperature controls how strictly the funnel favors the top of the list (Chapter 6)
The funnel runs once per token — all 50,257 candidates are scored every single time, then almost all of that work is discarded to emit one piece. The narrowing isn't a hard cutoff but a weighting: at low temperature the funnel almost always picks the top of the shortlist; at higher temperature it lets darker horses through, which is where variety (and occasional weirdness) comes from — Chapter 6 shows the same prompt at three temperatures.

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

  1. 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…".
  2. 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.
  3. 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.

End of chapter 4

Quick check

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

1. At heart, what is the one thing an LLM does over and over?
2. In "Mom said she wants Thai," what does attention let the word "she" do?
3. Why might a chatbot keep confidently building on an early mistake?