Chapter 2
How Machines Learn
Chapter 1 ended with a question: instead of writing the rules, could the machine work them out from examples? Here's how that trick works — knobs, showers, spam, and all.
The black box, flipped
Start from the outside again. In traditional programming, a human writes the rules, and the computer applies them to data to produce answers. That's dinner-bot v1: rules in, answers out. Machine learning — the branch of AI where the system improves from examples rather than following hand-written instructions — turns the box around. You feed in examples of the task already done right (data plus the correct answers), and what comes out the other side is the program itself: a set of rules no human ever wrote.
That machine-made program gets a name you'll hear constantly from now on: a model. A model is just a program whose rules were found by a machine from examples, rather than typed by a person. Every "AI model" in the news — including the giant language models later in this book — is exactly this, at different sizes.
Fine. But how does a computer "work backward from examples"? Time to zoom into the box — via your shower.
The shower-faucet trick
You're in an unfamiliar hotel shower. One knob, unlabeled. Here's what you do, without thinking of it as an algorithm:
- Guess. Set the knob anywhere. Turn on the water.
- Measure the error. Feel the water. Too cold? Too hot? By a lot or a little?
- Adjust against the error. Too cold → nudge toward hot. Way too cold → big nudge; slightly cold → small nudge.
- Repeat until the temperature is right.
You never knew the "rule" connecting knob angle to temperature. You never needed it. You found the right setting by iterated error correction — and that four-step loop, honestly, is machine learning. The formal version has a name: training is the process of repeatedly adjusting a model's internal settings to shrink its error on example data. Each internal setting is called a parameter — but "knob" is the right mental picture, and we'll keep using it.
Now scale it. Your shower has one knob and one goal (temperature). A model that recognizes spam might have thousands of knobs. The large language models later in this book have hundreds of billions. No human could turn them by hand — so the adjusting itself is automated. Picture an army of tireless helpers, one per knob, and after every wrong answer each helper gets a precise memo: "your knob contributed this much to the mistake — turn it that way, this far." The algorithm that computes and delivers those memos is called backpropagation, and it is the workhorse of essentially all modern AI. You now know its name and its job; this book will never make you do its math.
Simplified!
Two honest confessions about the shower. First, your shower knob has an obvious "warmer" direction — with billions of interacting knobs there is no obvious direction, and backpropagation's real magic is calculating the best nudge for every knob simultaneously, using calculus we're skipping. Second, there's no literal "army of helpers" — it's one mathematical procedure sweeping backward through the model. And unlike your shower, training doesn't end at "ahh, perfect"; it ends when the error stops improving, which may still be imperfect. The picture is right about the loop — guess, measure error, nudge, repeat — and that's the part worth keeping.
A spam filter you can check by hand
Let's train a model with numbers small enough to sanity-check on your fingers. Task: decide if an email is spam. Our model looks at just 3 features — measurable clues in the input — and gives each a score (a knob!). Add up the scores of the clues present; total 2 or more means spam. Here are 5 example emails, with the truth attached:
| Says "FREE!!!" | Unknown sender | Has an attachment | Truth | |
|---|---|---|---|---|
| 1. "FREE!!! pills" | yes | yes | no | spam |
| 2. Mom's recipe | no | no | yes | not spam |
| 3. "FREE!!! prize, open file" | yes | yes | yes | spam |
| 4. Boss's report | no | no | yes | not spam |
| 5. Stranger's newsletter | no | yes | no | not spam |
Watch the training loop run, exactly like the shower:
- Guess. Start every knob at 1: "FREE!!!" = 1, unknown sender = 1, attachment = 1.
- Measure the error. Email 2 (Mom's recipe): attachment only, score 1 — under 2, not spam. Correct. Email 4: same, correct. But email 5 (stranger's newsletter): unknown sender only... score 1, under 2 — correct too. Try email 3: 1+1+1 = 3, spam — correct. Email 1: 1+1 = 2 — spam, correct. Five for five? Not so fast: suppose a sixth email, a client's contract (unknown sender + attachment, not spam), arrives: 1+1 = 2 → flagged as spam. Wrong.
- Adjust against the error. The mistake came from innocent clues scoring too high. Nudge them down: attachment 1 → 0.3, unknown sender 1 → 0.8. The spammy clue gets a nudge the other way: "FREE!!!" 1 → 1.5.
- Repeat. Re-check everything. Client contract: 0.8+0.3 = 1.1 → not spam. Correct. Email 3: 1.5+0.8+0.3 = 2.6 → spam. Correct. Email 1: 1.5+0.8 = 2.3 → spam. Correct. All six pass. Training done.
Notice what you just watched: nobody told the model that "FREE!!!" matters more than attachments. It discovered that from the examples, by error correction. That discovery — importance emerging from data instead of from a programmer's head — is the entire magic trick of machine learning. Real spam filters do exactly this with thousands of features and millions of emails; the arithmetic is the same, just more of it.
What does that look like from the outside, on a realistic filter with thousands of knobs and millions of emails? Plot the accuracy after each round of training and you get the most typical curve in all of machine learning:
Dinner-bot v2: learning Mom
Now rebuild Chapter 1's dinner bot the learning way. Instead of six frozen rules from a 2024 interview, we hand the machine 50 past family dinners — each one described by features (cuisine, price, noise level, distance, candlelight or fluorescent) and labeled with the truth: did Mom enjoy it? Training runs the shower loop and the knobs settle into a portrait of Mom that nobody typed:
- Quiet room: strong positive score (Mom's rating jumped every time).
- Vegetarian options on the menu: positive and rising — the 2025–26 dinners taught it what the 2024 interview never knew.
- Italian: mildly positive. (Rules-bot treated this as the whole ballgame; the data says it's a minor factor.)
- Long drive: negative. Loud music: strongly negative.
Score every open restaurant in town, book the top one. Look at what got fixed: Mom's vegetarian turn is in the data, so the model caught it. Luigi's closing doesn't matter — v2 ranks all candidates rather than clinging to one list. It even handles "somewhere cozy" halfway: it can't understand the word, but quiet-plus-candlelight was already scoring high, so its picks happen to be cozy. Better on all three of Chapter 1's failures.
But be honest about what v2 still cannot do. It can't converse — say "actually my sister's coming too, she hates spicy food" and there's no slot for that sentence. It can't explain its choice, can't book the table, and knows nothing outside its 5 features and 50 dinners. It's a scorer, not a companion. Closing that gap is the story of Parts II and III.
Three flavors of learning
Everything you've trained so far — the spam filter, dinner-bot v2 — used examples that came with the right answer attached. That's only one of three flavors of machine learning, and it's worth learning all three names now, because they return in Chapter 5 when we see how a chatbot is actually made (a recipe that uses all three).
| What the data looks like | What the machine learns | Everyday picture | |
|---|---|---|---|
| Supervised learning | Examples with the right answer attached: email → spam/not-spam; dinner → Mom liked it or didn't | To map inputs to the labeled answers — and generalize to new inputs | Studying with flashcards: question on the front, answer on the back |
| Unsupervised learning | Examples with no answers at all — just a big pile of raw data | Hidden structure: which things cluster together, what "normal" looks like | Sorting a messy closet with no instructions — shirts drift together, socks find socks |
| Reinforcement learning | No examples up front; the machine acts, and gets rewards or penalties afterward | Which behaviors, over many steps, rack up the most reward | Training a dog with treats: no lecture on "sit," just a biscuit when it happens |
Same loop underneath all three — guess, measure, nudge — but the error signal comes from a different place: a label, the data's own structure, or a reward. File the third one especially: when Chapter 5 mentions "reinforcement learning from human feedback" (RLHF), it means exactly the dog-and-treats loop, with human thumbs-up as the biscuit.
Training vs. inference: learning to drive vs. driving
One distinction unlocks half the AI news you'll ever read. A model's life has two phases:
- Training — the knob-adjusting phase. Like learning to drive: slow, expensive, error-filled, done rarely. For big models this takes months on warehouse-sized computer clusters and costs hundreds of millions of dollars — and while it runs, the knobs are changing constantly.
- Inference — the using phase; "inference" is just the technical word for running a trained model on new input. Like driving to the store: fast, cheap, routine. Crucially, the knobs are frozen. When you chat with an AI assistant, you are doing inference — the model is not learning from you, any more than driving to the store re-teaches you to drive.
This is why chatbots don't remember yesterday's conversation unless a separate memory feature saves notes, and why a model can be "stuck in the past" — its knowledge was baked in when training stopped. Chapter 5 returns to this as the knowledge cutoff.
Data is destiny
Look back at everything above and notice what the machine never sees: the world. It sees only the examples. The examples are its world. Put it this way: the training data is the machine's entire childhood. Everything it will ever "believe" about spam, or Mom, or language, it absorbed there — it has seen nothing else, and unlike a child it never sneaks out of the house to check its beliefs against reality. That has a famous consequence — garbage in, garbage out — and a subtler one that matters more.
Suppose your 50 training dinners were all birthdays and anniversaries — special occasions, fancy places. Dinner-bot v2 will have quietly learned that Mom loves expensive restaurants, because in its entire universe she only ever ate at expensive restaurants and enjoyed them. Ask it to book a casual Tuesday dinner and it recommends a $200 tasting menu — not because it's broken, but because it learned its lessons perfectly from a lopsided world. Nobody wrote a rule "prefer expensive." The skew rode in silently with the data.
Now swap dinners for consequential decisions. A hiring model trained on a company's past hires learns the biases of those past decisions — famously, Reuters reported in 2018 that an experimental Amazon recruiting tool had learned to penalize resumes containing the word "women's," because it was trained on ten years of resumes that came mostly from men; Amazon scrapped it and said recruiters never relied on it. Commercial face-analysis systems misclassified darker-skinned women far more often than lighter-skinned men (error rates up to 34.7% versus 0.8%), as researchers Joy Buolamwini and Timnit Gebru documented in 2018; the face datasets such systems were commonly measured on were overwhelmingly lighter-skinned. The uncomfortable rule: a model is a mirror of its training data — including everything wrong with it. "Why was this trained on, and what did that data miss?" is the single sharpest question a non-technical person can ask about any AI system.
The memorization trap
One more way training goes wrong — and this one happens even with perfectly good data. Remember that training only ever rewards one thing: shrinking the error on the examples. So a model with enough knobs can discover a lazy shortcut: instead of learning the pattern behind the examples, just memorize the examples themselves. Error on the training data: zero. Error on anything new: terrible. The field calls this overfitting, and it's the difference between the student who learns the method and the one who memorizes last year's exam answers — both ace the practice test, but only one survives a question they haven't seen.
Neural networks: knobs, stacked
One more term and Part I is complete. Our spam filter was a single layer of knobs: features in, weighted sum, decision out. A neural network is what you get when you stack such layers — the outputs of one layer of little scoring units become the inputs to the next, each connection with its own knob. The name comes from a loose 1940s analogy to brain neurons; honestly, the resemblance is thin, and researchers keep the name mostly out of habit. Think "layers of knobs," not "silicon brain."
Why stack? Because layers let simple clues compose into sophisticated ones. In an image-recognizing network, the first layer learns to spot edges, the next combines edges into shapes like ears and whiskers, and a later one combines those into "cat" — nobody programs that hierarchy; it emerges from training, the same shower-loop, just deeper. Deep learning, the 2012 breakthrough from Chapter 1's timeline, means exactly this: neural networks with many layers. Modern ones are staggering — the largest language models stack around a hundred layers (126 in the biggest Llama 3.1) holding hundreds of billions of knobs, all tuned by backpropagation's memo-carrying army. Same loop as your shower. More knobs.
Misconception: "It understands" / "It learns like a child"
Two related corrections. First, nothing in this chapter involved understanding. The spam filter has no idea what "FREE!!!" means, that money exists, or that deception is bad — it holds a number, 1.5, that shrank errors during training. Dinner-bot v2 doesn't know Mom exists. Competence without comprehension is the deepest weirdness in AI; hold onto it. Second, machine "learning" is not childlike learning. A child hears on the order of 100 million words by age ten and learns language from that; a large language model trains on trillions of words (Meta's Llama 3 used over 15 trillion tokens) — tens of thousands of times more — and still makes errors no ten-year-old would. Children learn from a trickle of experience embedded in a body and a social world; models compensate with brute statistical exposure. Same word, "learning" — profoundly different process.
Try it now (5 minutes)
Feel training vs. inference from the outside. Open your chatbot and ask: "What is the most recent event you know about? What's your knowledge cutoff?" It will name a date — that's when its training stopped and its knobs froze. Then tell it something new: "My mom just went vegetarian." It will use that fact fluently for the rest of the chat. Now open a brand-new chat and ask what your mom eats. Blank. You just proved the knobs are frozen: within a conversation it can read your fact (that's inference over your words, as Chapter 6 explains), but nothing you said trained the model. (If your app has a "memory" feature, it's saving notes on the side — the model itself still didn't change.)
Where this leaves us
Part I is done, and you own the foundation: AI is a task-doing box; the box is filled with rules or with learning; learning means tuning knobs against examples in a guess-measure-nudge loop; training sets the knobs and inference uses them frozen; the data decides everything; and neural networks are the knobs stacked deep. Dinner-bot v2 learned Mom's tastes but can't talk. To build a machine you can talk to, there's a puzzle to solve first: knobs add and multiply numbers, and "somewhere cozy" is not a number. Turning words into numbers — the strange, elegant trick behind all of modern language AI — is Chapter 3.
Three resources, easiest first
- Easy — "But what is a neural network?" by 3Blue1Brown (YouTube). Twenty minutes of the best visual explanation of layers and knobs ever made. You can ignore the light math and still absorb the pictures.
- Deeper — You Look Like a Thing and I Love You by Janelle Shane (2019). A funny, example-driven tour of how machine learning actually behaves — including glorious failures that make "data is destiny" unforgettable.
- Deepest — Google's Machine Learning Crash Course (free, online). When you're ready to touch real training runs: interactive lessons with sliders and small exercises. Some light code, all optional.