Learn AI Layer by Layer

The Power of Incremental Improvement

Chapter 1 ended with a puzzle. We need to find the right parameter values for our model, but brute force is impossible. You might think the answer is to be brilliant. Design the solution. But that's not how complex things get built. What actually works is finding a way to make reliable tiny improvements, and then doing lots of them, very fast.

How Do You Build Something You Don't Understand?

We left off with a problem. A model is a machine with adjustable knobs. Different knob settings compute different functions. We need to find the settings that make the model compute the right function, but we can't try every combination, because the number of possibilities is astronomically large.

So what do we do?

Your first instinct might be: think really hard. Analyze the problem. Design the answer from first principles. Be brilliant.

But that's almost never how complex things actually get built. And understanding why is the key to understanding how AI works.

Nothing Complex Was Ever Designed From Scratch

The human eye is one of the most sophisticated optical instruments in existence. It automatically adjusts focus, adapts to light levels from pitch darkness to blinding sunshine, and processes information in real time. No engineer designed it. It evolved over 3.5 billion years of tiny changes, each one barely noticeable, accumulating into something extraordinary.

The Wright brothers didn't sit down and calculate the perfect wing shape. They built a wind tunnel and tested hundreds of wing designs, measuring which ones generated more lift. Each test informed the next. The airplane was iterated into existence.

The iPhone didn't spring fully formed from Steve Jobs's mind. It evolved through generations (flip phones, then Blackberries, then the iPhone), each one building on what came before, each one a little closer to what people actually wanted.

This pattern is universal. The steam engine, the internet, language itself, all were built incrementally. Even things we think of as "inventions" are really evolutionary processes. Nobody sat down and designed English. These things emerged through countless small improvements, tested against reality, kept or discarded.

Key Insight

Every complex system was built the same way: make a small change, test whether it helped, keep or undo it, repeat. By relentless, incremental improvement.

This is how AI learns too. But to make this work, you need two things: a way to measure how far off you are, and a way to make small changes.

You Need a Way to Measure the Error

Before you can improve anything, you need a number that tells you how far off it is. This number is called the error: the gap between where you are and where you want to be.

This idea shows up everywhere. A student gets 72 out of 100 on a test. The error is 28 points. A runner finishes in 14.2 seconds. The error is 14.2 seconds. A restaurant has 3.2 stars. The error is the gap to a perfect 5.

i

You might have noticed something odd: the "perfect" time for a race is zero seconds, which is impossible! That's fine. Sometimes you can't actually reach zero error, and often you don't even know how good it's possible to get. All that matters is that you have a number that goes down as you get better. As long as "lower error = better," optimization can work.

In AI, we do the same thing. We show the model an input, look at what it gives back, and compare that to the right answer. The gap between them is the error. The goal of training is to make that error as small as possible.

The Algorithm That Built the World

Now we can be precise about the pattern. Call it incremental optimization:

  1. Measure the error
  2. Make a small change
  3. Did the error go down? Keep it. Did it go up? Undo it.
  4. Repeat

That's it. And this single algorithm is behind:

  • Natural selection: random mutations, tested by survival, kept or eliminated
  • The scientific method: hypotheses, tested by experiment, accepted or rejected
  • Trial and error: try something, check whether it's better, adjust

This is how AI learns. Small adjustments to parameters, tested against data, kept if they reduce the error.

What's striking about this approach: you don't need to understand the system. You don't need to know why a wing shape generates lift, or why a particular word order sounds natural, or why certain parameter values make a model work. You just need to measure the error and make small changes.

Try this out in the playground yourself. See how much easier it is to find the best answer using incremental changes guided by an error signal, than if you have to just make blind guesses.

Smooth Functions Can Be Optimized

Incremental optimization is powerful, but it only works when the thing you're optimizing is smooth, meaning small changes to what you do produce small, predictable changes in the error. Smoothness is what gives you feedback: each small adjustment tells you whether you're getting warmer or colder.

Not everything works this way. Some things are all-or-nothing. A small change gives you no useful information at all.

Both shapes below have the same overall valley, but the smooth one lets a ball roll downhill to the bottom, while the stepped one is flat within each step. A small change in position tells you nothing.

Key Insight

Smoothness is what makes optimization possible. A smooth function gives you a signal at every point: which way is downhill. A non-smooth function gives you no local signal to follow, so the only way to make progress is a big jump, and you have no idea which direction to jump.

The Gradient Trick

So far, our optimization strategy has been: try a small change, measure the error, keep it if it helped. That works, but it's slow, because you're guessing which change to make.

Think about the difference between these two situations. A friend reads your story and says "I'd give it 3 out of 5." That tells you the error, but not what to fix. Now imagine they say "I'd give it 3 out of 5, the middle section was confusing." That's much more useful, because it tells you which direction to change.

This is the key idea behind the gradient. At any point on a smooth curve, you can look at the slope: the steepness right where you're standing. The slope tells you exactly which direction is downhill. Following it is called gradient descent, and it's dramatically faster than random guessing.

Real models don't have just one knob; they have millions. But the same idea works: the gradient is an arrow pointing in the steepest downhill direction across all dimensions at once. You can't visualize a million-dimensional landscape, but the math is the same. Calculate the slope, step downhill, repeat.

Key Insight

The gradient tells you which way is downhill for every parameter simultaneously. Instead of guessing which change to make, gradient descent calculates the best direction. With millions of parameters, this is the difference between feasible and impossible.

Why This Changes Everything

In Chapter 1, we saw that a model is a machine with adjustable knobs. The question was: how do you find the right settings when there are millions of knobs?

Now we have two powerful ideas:

  • Smoothness means small changes to the knobs produce small, predictable changes in the error. Every tiny adjustment gives you useful feedback: did the error go up or down?
  • The gradient tells you which direction to adjust every knob at once. Instead of guessing, you calculate exactly which way is downhill.

Together, these make optimization fast and reliable. No single adjustment is impressive. Each one is a tiny tweak, make this parameter 0.001 bigger, that one 0.002 smaller. But each tweak reliably moves in the right direction. Make billions of these tiny improvements per second, and the model develops amazing abilities.

It's like evolution, compressed from billions of years into hours, by making each step reliable and then taking a huge number of them.

AI didn't take off when people figured out the theory; the basic ideas have been around for decades. It took off when there was enough data to measure error on, enough computing power to make billions of tiny adjustments quickly, and the right kind of model: one where the knobs are smooth and the gradient always points the way.

What's Next

We now understand the game:

  1. Build a smooth model (so small changes give useful feedback and gradients work)
  2. Measure how wrong the model is (the "loss function")
  3. Calculate which way is downhill (the gradient)
  4. Take a tiny step (adjust all parameters)
  5. Repeat billions of times

But what should this model actually look like? What's inside a neural network? In the next chapter, we'll meet the building block: the artificial neuron, a simple unit that takes a weighted sum of its inputs, adds a bias, and passes the result through a nonlinear function. It's almost embarrassingly simple. But stack enough of them together, and they can compute anything.

Try it in PyTorch — Optional

Implement random search, use PyTorch's autograd to compute gradients automatically, run gradient descent from scratch, and compare both approaches side by side.

Open in Google Colab →
i

I'd love to hear from you.

I want every chapter to be easy for everyone to understand. Please send a message if anything was unclear, if you'd like something explained in more depth, or if there's something about this part of AI you wanted to understand that the chapter didn't cover. I'll get an email and reply when I can.