How Neural Networks Learn
Transcript
Drop a ball into a Plinko board and watch it bounce from peg to peg. Where will it land? That uncertainty is part of the game. But what if we wanted a particular result? Imagine we could adjust the pegs to guide the ball toward a chosen exit. Now give our imaginary machine a bigger challenge: send different shapes to different bins— a ball here, a cube there, a prism in another. Even a toy dinosaur gets its own bin. How would we find the right peg settings? We could try a shape, see where it lands, and adjust the pegs when it goes to the wrong place. Then we try again, checking different shapes as we go. Our goal is to find settings that send each shape to its intended exit. A board adjusted to sort those shapes is like a trained neural network: it takes an input and produces the intended output. The repeated process of trying, checking, and adjusting the settings is what we mean by learning.
A real neural network works with numbers and connected calculations rather than pegs and bouncing objects. But how does a neural network turn numbers into answers? Zoom in on any one of these little circles — and at its core, it's just simple math. Let's give it a real job: a sound-activated light. Imagine a microphone measuring the sound level in a room. For our example, we represent that level with a number between zero and one — zero is silence, one is very loud. The sound level feeds our neuron, and the output controls a light: one means on, zero means off. Inside, the neuron multiplies the sound level by its weight. The weight controls how strongly the sound level affects the score. And because our light needs a plain yes or no, at the output we simply round the score: below point five rounds to zero — light off. Point five or above rounds to one — light on.
That rounding is our choice for this job, not a part of every network — different jobs attach different finishing steps to the output. Now, the goal. We want the light on when the sound level is point three or higher. Below that, it stays off. Let's try the simplest weight: one — the sound level passes straight through. Try a sound level of point four. That's over point three: we want the light on. But point four times one is point four — and point four rounds down. The light stays off. We wanted on. We got off. This neuron needs a different setting. So let's find one — the same way we tuned the Plinko board: try, check, adjust. First, gather practice sounds: a handful of random levels between zero and one. For each, we know the answer we want — on at point three or higher, off below. Start at weight one. First sound: point four. We want on — but the light stays off. The score came out too low, so:
nudge the weight up. Next: point two. We want off — and it stays off. Correct answers get no nudge. Point three six: we want on — still off. Nudge up again. Point two eight: we want off — but the light turns on. Too sensitive — nudge down. This loop — try a sound, check the answer, nudge the weight — is what training means. One sound at a time, one nudge at a time. Let's speed up. The nudges shrink, the misses fade, and the weight settles: one point six seven. Now the real test — fresh sounds it never practiced on. Point one five: off. Point three: on. Point two nine: off. Point eight: on. Every one we checked: right. You might have noticed — with a single weight, simple math could have handed us the answer. We took the long way on purpose. Real networks have millions, even billions of weights, and no formula solves them all at once.
But try, check, adjust every single weight, one nudge at a time, can be scaled to work at any size. Pause on how small that was. One input, one weight, one answer — that's the whole machine. And that tiny piece of math is the seed everything else grows from. Our light listens to one thing: the sound level. But think about recognizing a spoken word, or a picture. To describe an image, we usually use many numbers — one for each pixel's brightness. Real inputs come in bunches. So the neuron grows.
Each input gets its own weight, and the neuron adds all the weighted values into one score. More inputs, more weights — still one output: the neuron's response, called its activation. A typical neuron also adds one number of its own: the bias. Watch what happens when every input is zero. Without a bias, zero in forces zero out — always. Anything times zero is zero. But zero is not an empty message. Silence tells you something about a room — and a dark corner tells you something about a picture.
Sometimes the right response to zero isn't zero. The bias is the neuron's own starting number: it sets the activation a neuron starts from — even when every input is zero. And training adjusts both: every weight, and every bias. And the bias can do one more thing: move the decision point itself. Remember the light — we hit the goal by scaling: weight one point six seven. A bias offers another road: keep weight one, and add a bias of minus point three. Now the score is simply the sound minus point three — at zero or above, on. Same goal, no scaling trick. The bias shifted where the decision happens. So far, the recipe reads: weigh, add, bias. A single neuron makes one simple call. But recognizing anything real takes many small decisions, working together toward one bigger one. In other words: we need more neurons. And there are two directions to grow. We can add companions —
more neurons reading the same inputs, side by side, each with its own weights, each making its own call. A group like this forms a layer. Or we can grow the other way: add a second layer after the first — one that reads, not the inputs, but the first layer's answers. Layer feeding layer — decisions built on decisions. But there's a catch: for multiple layers to actually work, the network needs to be nonlinear. Let me explain. Everything our neuron does so far — multiply by a weight, add the bias — is a linear equation. A steady change in, a steady change out. Linear equations are very good at drawing lines. And lines are all they can ever draw. And stacking — feeding one linear equation's output into the next, over and over again — doesn't fix it. Watch. Chain one linear step after another — each layer tilts the line, shifts it, flips it… but out comes, always, another line. Ten layers.
A hundred. Still one line — and a line can never trace anything more. So we change the neuron itself. One small nonlinear rule at the very end of each one — a bend that acts as a gatekeeper. A total of zero or less becomes an activation of zero: the neuron stays silent. A positive total passes forward at full strength — three point two stays three point two. Draw that rule as a picture, and there's the bend: flat at zero, then a straight climb. And as math, it's one short expression: the activation is the max — the larger — of zero and the total. Now rebuild with nonlinear pieces. Put two bends side by side and add them — a V. A few more make a peak… then a wave. Already far more than any line could ever draw. And stacking takes it further: each new layer can bend what the last one drew. Keep going — even the outline of a face. A network like this can trace and represent truly complex patterns.
That's what nonlinear buys: a network that can represent complex patterns. Layers that don't fold — each one building on the shapes the layer before it made. Watch: this input wakes one mix of neurons. This one — a different mix. Different inputs, different rules, learned side by side. And because layers build on layers, a network can learn in steps. Imagine reading a picture in stages: dots gather into edges… edges into a circle… a circle becomes an eye… eyes become a face.
Each stage reuses the one before. Now imagine one single layer doing it alone. No stages to lean on — it would need a rule for every face it might ever meet. Long ears, short ears, eyes open, eyes closed… an endless catalog, one giant layer wide. A deep network learns its pieces once, and reuses them everywhere. So nearly every neuron ends with a nonlinear rule. Ours is called ReLU — keep the positives, zero out the rest — the most common of many.
Modern networks add other moves on top of this recipe — but weigh, add, bias, bend remains the heart of it. And that's one complete neuron: weigh, add, bias, bend. This gives us the basic structure of a neural network. When we connect layers, we make choices. Keep the same four inputs and the same two outputs. The layers between them are called hidden layers — and we decide what goes there. We could put three neurons in one hidden layer. Or five — a wider layer: more neurons calculating from the same inputs. Or we could stack: three hidden layers, each with three neurons — a deeper network: more stages, where each layer works with the results of the layer before it. Networks with several processing layers like this are what deep learning refers to. Wider or deeper, the inputs and outputs haven't changed. And neither choice is a promise of better answers — which arrangement works better is something you measure, not assume.
So let's measure it — on real handwritten digits. We now have all the pieces. So let's put them to work and build a real neural network — one with an actual job: reading handwritten digits. People write digits — zero through nine — and every one comes out a little different. We want a machine that looks at one and answers: which is it? This is a real handwritten seven — one of seventy thousand collected examples that have been used to teach machines for decades. To a machine, this image is a grid: twenty-eight by twenty-eight — seven hundred eighty-four small squares. And each square holds one number: its brightness, from zero to one. Which is exactly what our network takes in: numbers between zero and one. Just not one of them anymore — seven hundred eighty-four, one per pixel. So the input side of our network is decided for us: the image fixes it. What comes after the inputs is a choice. For the middle, we chose thirty-two neurons.
Not a magic number — a design choice. Each one reads all seven hundred eighty-four pixels, through its own set of weights — seven hundred eighty-four weights per neuron. And each one runs the recipe we know: weigh, add, bias, bend. And here these neurons work differently from our light switch: they don't just answer on or off. Each one outputs a number — how strongly it responded to what it saw. Thirty-two neurons, thirty-two responses. That's what the next layer gets to work with. The output side, the question itself decides: ten digits, so ten outputs — one score per digit. And each output is a neuron of its own, with its own weights, reading all thirty-two responses. And their scores get a finishing step of their own — not the rounding from our simple light example earlier: the ten scores become probabilities — always adding up to one. That step is called softmax. The highest probability wins. Before any training, the ten probabilities are all over the place —
the seven's is nowhere near the top. The goal of training: push the seven's probability toward one hundred percent — and every other digit's toward zero — by adjusting the weights and biases. But how did all those thousands of weights and biases get set? The same loop we ran for the light — done by machine, across every weight at once. Show it a digit. Check the probability of the correct output. Then adjust every weight and bias a little — nudging that probability up, and the others down. We ran that loop: sixty thousand images, five passes. Pass by pass, the seven's probability climbs. After training: ninety-eight point six percent — the seven on top. We trained a second network the same way — this time with two hidden layers: sixty-four, then thirty-two. Then the real test: ten thousand images neither network had ever seen. One hidden layer: ninety-five point five eight percent accuracy — nine thousand five hundred fifty-eight of the ten thousand, identified correctly.
Two hidden layers: ninety-six point three five — seventy-seven more. But count every adjustable number in each network — all the weights, plus each neuron's bias, together called its parameters — and the bigger network has about twice as many. In this experiment, the bigger network won. But notice — it got deeper and wider at once, so we can't credit depth alone. And one measurement, on one problem, is not a promise that bigger always wins. Now let's take a deeper look at how training actually happens. To watch learning up close, we need a network small enough that we can see every single number inside it. So here is a simplified version of the digit-recognition network. It is untrained, and it is tiny: we imagine the image squeezed down to just three numbers, instead of all seven hundred eighty-four pixels — feeding two neurons, and the same ten probabilities at the end.
We will give it the same test as before: the right answer is a seven. Untrained, it answers: three. And why three? No reason at all. Before training, a network's weights and biases are just starting numbers — in practice, picked at random. Whatever they happen to be, the ten probabilities land somewhere. Ours happened to land on three. Now look at the right answer. The network gave seven a probability of only about nine percent. If we want to improve the network step by step, we first need a single number that tells us how wrong it is on this example. That number is called the loss. Here is how it should behave. If the network had given seven everything — one hundred percent, and every other digit zero — it would be perfectly right, so the loss should be zero. And the smaller seven's probability gets, the more wrong the network is, so the bigger the loss should grow. So which curve should we use? A very common choice — and the one we will use —
is the negative logarithm of the probability. It rises slowly at first, then shoots up steeply as the probability heads toward zero. Exactly the behavior we wanted. There are other loss functions, chosen for other jobs — but for this demonstration, this is ours. This curve is called cross-entropy. Our nine percent lands here: a loss of two point three seven. That is: the smaller the cross-entropy, the smaller the loss — and the closer the network's outputs are to what we expected. So which change would make the loss smaller? Let's start with just one weight — this one. And let's do the simplest thing we can: nudge it, and watch what happens. We raise it by point zero five, and the change ripples forward through the network: its neuron shifts by point zero four, the score for seven shifts by point zero one six, and the loss… falls, by point zero zero six five. That little experiment tells us two things. It tells us the direction: raising this weight helps.
And it tells us the strength: how hard the loss reacts when this weight moves. Together, that direction and strength are called this weight's slope. That is all a slope is: which way helps, and how much it matters. Of course, we need the same answer for every weight and bias — all thirty-eight of them. In our tiny network, we could nudge them one at a time and re-run the network thirty-eight times. But think bigger. Our digit network carried twenty-five thousand four hundred fifty weights and biases, and its training took two thousand three hundred forty-five updates. Nudging one at a time, that would mean re-running the whole network nearly sixty million times. And modern networks carry billions of weights. One at a time is hopeless. So there is a different way — a method that gets every answer in one single backward pass. It is called backpropagation. Here is how it works.
Here is a simple example of a neuron — one weight, one input, one bias. Written as plain math: the weight times the input, plus the bias, equals the output. Now, one simple question: if the weight grew by exactly one, how much would the output change? That question — how much does the output change, per one unit of change in one part — is what a derivative answers. That's the slope. A derivative of the output, with respect to that part. Let's just do it. Say the input is five. Two times five is ten, plus one — the output is eleven. Now raise the weight from two to three. Three times five is fifteen, plus one — sixteen. The output moved by five. And five is no accident — five is exactly the input. Change the weight by one, and the output changes by one input's worth. So the derivative of the output with respect to the weight is: the input. The same game, twice more. Raise the bias from one to two:
eleven becomes twelve — the output moved by exactly one. The bias's derivative is one, always. Raise the input from five to six: eleven becomes thirteen — it moved by two. Two is the weight. So the input's derivative is the weight. And that is really all there is to it — that is how simple calculating a derivative can be. Remember the shape of the idea: the derivative of one thing with respect to another tells us how changing the second changes the first. Now imagine two of these neurons in a row. The first: w-one times x-one, plus b-one — its output, x-two. The second reads that output: w-two times x-two, plus b-two — and its output, x-three, is the network's answer. And to score the answer, a loss. For this demonstration, a simpler loss than the one our network uses: half the squared difference between the expected answer and the actual one. Run it once — random starting weights and biases — and we know three things:
the answer the network gave, the answer we wanted, and the loss. And now the goal. For every weight and every bias here — w-one, b-one, w-two, b-two — we want to know: which way should it move, and how strongly does it matter. In other words: the slope — the derivative — of the loss, with respect to every single weight and bias. That is the prize. Backpropagation is how we win it. Where do we start? With the only thing whose formula touches the loss directly: x-three.
Differentiate the loss function itself, and we have our first slope — the derivative of loss with respect to x-three. For our run, it comes to plus two. Not a weight, not a bias — but it is a foothold, and it is all we need. Now the first target: w-two. Here is the move. The derivative of loss with respect to w-two can be split into two factors — multiply and divide by d-x-three, and the chain appears: the derivative of loss with respect to x-three, times the derivative of x-three with respect to w-two. The first factor, we already hold. The second is simple differentiation of equation two. Multiply them — and we arrive at the derivative of loss with respect to w-two: fourteen. One down. The bias goes exactly the same way. One more derivative from equation two — the odd one: with respect to x-two. x-two is not a dial we can turn; it is equation one's output. But that is exactly its value:
the derivative of loss with respect to x-two tells us what one unit of equation one's output is worth to the loss. Same move — split, multiply — and we hold it: four. Carry it back. Now equation one's weight — two whole steps from the loss. Split again, this time through d-x-two: the derivative we just carried, times the derivative of x-two with respect to w-one — simple differentiation of equation one. Multiply: eight. And notice — nothing about equation two was needed again. The carried slope already contains everything downstream. Check it with a real nudge, and the loss moves exactly as promised. That is the whole machine. At every equation, the same two beats: multiply the slope that arrived by one simple local derivative. Keep the answers for that equation's weight and bias — and hand the answer for its input backward, because its input is the previous equation's output. Every weight, every bias — each with its slope,
each knowing which way to move. That is backpropagation. Now watch our real network do exactly what we just did — only wider. Start at the very end, at the loss, and step back into the output layer. Three kinds of slopes to find, same as before: its weights, its biases — and its inputs. The weight and bias slopes, we keep — those are this layer's own dials. And the input slopes are the hand-off: those inputs are the previous layer's outputs. So the previous layer receives its slopes, just as equation one did — except here, each neuron feeds many neurons ahead, so it collects a slope from every one of them and adds them up. Then the same two moves again: keep the weight and bias answers, pass the input slopes further back. Layer by layer, all the way to the start. One backward pass, and every weight and bias in the network has its answer — all at once, not one at a time. For our network:
a few thousand backward walks, instead of sixty million re-runs. So after one sweep, we hold thirty-eight slopes — for every weight and bias, which direction helps, and how strongly. Collected together, they are called the gradient: one master list of influence on the loss. And notice what backpropagation does not do. It changes nothing — it only measures. And it never sets a target: no neuron is ever told what its output should be. Every slope is just a measurement — move this dial a little, and here is how the loss responds. Now use them. One simultaneous update: all thirty-eight weights and biases move at once — each in the direction its slope says helps, and in proportion to it. A strong slope means a bigger move; a tiny slope, barely a move. This recipe is called gradient descent. Remember what each slope really is: the sensitivity of the loss to one weight or bias — measured while every other weight and bias stays exactly where it is.
If the others then move only a tiny bit, that measurement is still dependable — we can trust it to guide this weight's update. But if the others move by large amounts, the network has changed too much: the slope we measured might no longer be an accurate reflection of the sensitivity — and it can't be trusted. So the steps can't be too big. But they can't be too tiny either — move by crumbs, and learning slows to a crawl, and steps that small can settle into the first shallow dip they find, with better answers waiting just past a bump they can never cross. So how big should the nudges be? That is set by one shared dial, called the learning rate. The size of every move is the slope's size times the learning rate — and the direction, as always, is the one that helps. Ours is point two — so each weight moves by one fifth of its slope. And why point two? No formula says so. The right learning rate is found the way everything else is found —
try, check, adjust. We take one step, and the loss falls: two point three seven to two point zero eight. The answer is still three. Better is not yet right. That is one step of learning. We repeat it — across many examples. So far, we improved the network for one single example. But here is the problem: a step that helps one example can easily hurt another. Back in our small practice network, take two training examples. Ask each one on its own which way a weight should move, and they disagree: one wants this weight nudged up, and the other wants it nudged down. So which one do we listen to? We listen to both. We work out each example's gradient separately, average the suggested changes, and then make one shared update to the weights. A group of examples handled together like this is called a batch. Then we keep going, batch after batch, until every example in the training set has had its say once. That complete pass through the training data is called an epoch.
In the digit experiment, one pass meant hundreds of updates — and with every pass, the loss kept easing down. And now that dial from earlier — the learning rate — matters more than ever. Watch what happens with the same two examples, the same starting point, and one single update at three different rates. At a rate of point zero five, the loss barely moves: two point zero zero to one point nine seven. At a rate of two, we get a real drop — down to point nine two. But at a rate of twenty, the loss does not fall at all. It explodes — up to eight point nine nine. The step was so big that it flew right past everything the slopes knew about. Small steps, many examples, pass after pass. That is what training looks like in practice. There is a trap hiding in all this practice. A network can keep getting better and better on the images it trains on — and quietly get worse on images it has never seen.
Instead of learning, it starts memorizing. So we hold some data back. Most of the images train the network. A separate set — called validation — is never trained on; we only use it to check the network along the way. And one final set — the test — is touched exactly once, at the very end. To watch the trap actually happen, we ran a smaller experiment, deliberately starved: only about a thousand training images this time, and two network sizes — one narrow, one wide. Watch the wide one train. Its training loss keeps falling, pass after pass… but its validation loss turns around, and starts getting worse. The network is drifting away from learning, toward memorizing. The validation set caught the best moment: epoch ten. We took the network exactly as it was right there, and touched the test set once: eighty-eight point eight three percent correct. So in practice, what do we do? We keep a copy of the network at every checkpoint along the way,
and when training ends, we go back and use the one the validation set liked best. Ours is the network exactly as it stood at epoch ten. Training longer was not better — so we simply do not use what came after. People call this early stopping. And how do we make it genuinely better? The strongest cure is more examples. This starved network saw about a thousand images. Earlier, the same kind of network trained on all sixty thousand — and reached ninety-five point five eight percent. More variety in practice leaves less room for memorizing. There are more tools, too. We can shape the network to fit the data — bigger is not always better: our narrow network memorized less, but it also learned less. We can add penalties that discourage extreme weights. We can randomly silence neurons during practice, so no single path gets memorized. We can stretch, shift, and tilt the training images to make extra variety for free. Different tools, one goal: learn the pattern, not the pages.
And whatever we try — more data, a different shape, a new tool — the verdict always comes the same way: from data the network has never seen. That is why we hold some back. And that is why we measure. Have you ever wondered how a network's billions of calculations actually get done — and done fast? To see it, let's take one more look inside our little network — this time, not at what it computes, but at the shape of the arithmetic. Every connection carries a weight. Collect them into a grid — one row for each input, one column for each neuron. A grid of numbers like this is called a matrix. Now watch one neuron's weighted sum happen: the inputs, multiplied down one column of the grid, and added up. And the whole layer? The same recipe, run down every column. That is one matrix multiplication. The bias and the bend still come afterward, for every neuron — the matrix handles the weigh-and-add. And this is not just for tiny networks.
Our digit network's first layer is the same picture, grown up: seven hundred eighty-four rows, thirty-two columns. Remember batches? Stack a batch of examples as rows — and one single multiplication computes every neuron's weighted sum, for every example, all at once. Here is why that shape matters: every cell in the answer is its own little multiply-and-add, independent of all the others. So they can all happen at the same time. Layers, though, still wait for layers: the next one needs the previous one's answers. Parallel inside a step — one step after another. And that is exactly the shape special hardware loves. An ordinary processor — a CPU — is built to do anything. A graphics processor — a GPU — is built to do many similar calculations at once. For grids like these, at scale, that is often the winning trade. And that need is real. A modern language model carries billions of weights, and its training is the same loop we built — try, check, adjust —
run through gradient descent at a staggering scale, with architectures far more elaborate than our little network. Training runs are measured in days and weeks, on thousands of these processors working together. That is why the hardware matters. And what about words? Language models — the networks behind modern chatbots — are built on the very same ideas. But to work with text, a network first needs numbers — just like it needed pixel brightnesses for images. So text is split into tokens: small chunks — whole words, pieces of words, even punctuation. Exactly how the text splits depends on the tokenizer. Each token then gets its own learned list of numbers. Learned is the key word: those lists are tuned during training, right alongside the weights and biases — nudged, again and again, until they help. And the question becomes our digit question, grown up: given all the words that came before — the context — what comes next?
Every one of those earlier words can influence the answer. The model scores every token it knows, and softmax turns the scores into probabilities — the same finishing step as our ten digits. Then, a choice. Take the highest probability — or sample, letting a less likely token through now and then. Add the chosen token to the text. And ask again. That is also how it trains. Take real text, hide the next word, and ask the model to predict it. The real next word is the truth; the loss checks the probability the model gave it; backpropagation finds every slope; and the optimizer nudges every weight, every bias — and every token's numbers. Across oceans of text. Next-word prediction is not the only job networks learn — they are trained to translate, to summarize, to answer. And modern language models add machinery we haven't shown — attention, most of all: how a model decides which earlier words matter most.
But the bones, you now know: predict, check, nudge. Back where we began. A board full of pegs, and a wish: every shape to its right bin. Watch it once more, with new eyes. Try a setting — send a shape through. Check the bin it lands in against the goal. Adjust the pegs — and try again. The loop acts on the board; the board never changes itself. Every peg, a weight. Every adjustment, a nudge against the error. And this one idea wears many faces. Recognizing digits.
Finding objects in a photo. Predicting the next word. Vision models, language models, speech models — and models that do all of it at once. Underneath every one of them: the same backbone. A neural network. Simple math, stacked deep, bent at each step — and tuned, nudge by nudge, until the answers come out right. Not perfect. Just better — and better again.

Ask anything
We've read this whole study set, so questions about it get the best answers.