Yellow marks are automatic key passages. They aren’t personal saved highlights. Select a timestamp to follow along with the video.
Backpropagation is the core algorithm that lets neural networks learn, and this explanation builds intuition for it before any notation or formulas appear. Using a handwritten digit recognizer as the running example, it shows how the cost function measures error, how the negative gradient indicates which weights and biases should change and by how much, and how backpropagation pushes desired changes backward through the layers. It then explains why training uses averaged nudges from randomly chosen mini-batches, a faster method known as stochastic gradient descent, and closes by pointing toward the underlying calculus, the code, and the large labeled datasets that training requires.
Introduction to Backpropagation
Backpropagation is the core algorithm behind how neural networks learn. After a quick recap, the discussion begins with an intuitive walkthrough of what the algorithm does, without reference to formulas. Readers who want the mathematics can move on to a follow-up treatment of the calculus underlying the process. This assumes familiarity with what a neural network is and how it feeds information forward, as covered in the previous lessons.
The Handwritten Digit Setup and Cost Function
The running example is recognizing handwritten digits. Pixel values are fed into a first layer of 784 neurons, followed by two hidden layers of 16 neurons each, and an output layer of 10 neurons. The most active output neuron indicates the digit the network chooses. Understanding gradient descent is assumed, and learning means finding the weights and biases that minimize a cost function. For a single training example, the cost is computed by taking the network's output, comparing it with the desired output, and summing the squares of the differences between each component. Averaging this cost over tens of thousands of training examples gives the total cost of the network.
Backpropagation Computes the Gradient
The quantity sought is the negative gradient of this cost function. It indicates how every weight and bias, every connection in the network, should change to decrease the cost most efficiently. Backpropagation is the algorithm for computing this complicated gradient. The gradient vector lives in roughly 13,000 dimensions, which is far beyond what anyone can visualize. Because of this, it helps to think about the gradient in a different way.
Reading Gradient Components as Sensitivity
The magnitude of each component indicates how sensitive the cost function is to the corresponding weight or bias. Suppose the negative gradient's component for one edge's weight is 3.2, while another edge's component is 0.1. The cost is then about 32 times more sensitive to changes in the first weight. Nudging that weight slightly changes the cost 32 times as much as the same nudge to the second weight.
Building Intuition Before Notation
From personal experience, the notation and index tracking were the most confusing part of learning backpropagation. Once each part of the algorithm is unpacked, however, each individual effect is fairly intuitive. The difficulty lies in the many small adjustments layered on top of one another. The approach here sets notation aside entirely and steps through the effect each training example has on the weights and biases. Because the cost averages a per-example cost over all tens of thousands of examples, each gradient descent step in principle depends on every example. For computational efficiency, a shortcut will be introduced later so that every example does not have to be used at every step.
Focusing on a Single Training Example
For now, attention centers on one training example: an image of a 2. Suppose the network is not well trained yet, so its output activations look fairly random, perhaps 0.5, 0.8, 0.2, and so on. Those activations cannot be changed directly. Only the weights and biases can be adjusted. It is still useful to track which changes should happen to the output layer. Since the image should be classified as a 2, the third value should be nudged up while all the others are nudged down. The size of each nudge should be proportional to how far each current value sits from its target. The increase to the number 2 neuron's activation matters more than a small decrease to the number 8 neuron, which is already close to where it should be.
Three Ways to Raise an Output Activation
Focusing on the neuron whose activation should increase, its activation is a weighted sum of all activations in the previous layer, plus a bias. That sum is then passed through a function such as the sigmoid squishification or a ReLU. Three avenues can work together to increase it. The bias can increase, the weights can increase, or the activations from the previous layer can change.
Weights With the Greatest Influence
The weights do not all have equal influence. Connections from the brightest, most active neurons in the preceding layer have the largest effect, because those weights multiply larger activation values. For this single training example, increasing one of those weights strengthens the output more than increasing a weight attached to a dimmer neuron. In gradient descent, the question is not only whether each component should rise or fall, but which changes deliver the most benefit for the effort.
A Loose Analogy to Hebbian Learning
This resembles, at least loosely, Hebbian theory from neuroscience, often summarized as neurons that fire together wire together. The largest weight increases, meaning the greatest strengthening of connections, occur between neurons that are most active and neurons that should become more active. In this sense, neurons firing while seeing a 2 become more strongly linked to those firing when thinking about a 2. Whether artificial networks behave anything like biological brains is a separate question. This analogy comes with meaningful caveats, so it should be treated as a very rough comparison.
Adjusting Activations in the Previous Layer
The third avenue involves changing the activations in the previous layer. If everything connected to the digit 2 neuron with a positive weight became brighter, and everything connected with a negative weight became dimmer, that neuron would grow more active. As with the weight changes, the most effective changes are proportional to the size of the corresponding weights. These activations cannot be influenced directly, but it is still helpful to record which changes are desired, just as with the last layer.
Propagating Desires Backward
The desire described so far belongs only to the digit 2 output neuron. The other output neurons also want the network to change in particular ways, and each has its own preferences for the second-to-last layer. These desires are added together, each weighted by the corresponding connections and by how much that neuron needs to change. This combining of effects is where the idea of propagating backward comes in. Adding the desired effects together yields a list of nudges for the second-to-last layer.
Moving Backward Through the Network
Once those nudges are known, the same process can be applied recursively to the weights and biases that determine those values. This moves backward through the network one layer at a time. Zooming out further, all of this describes how one training example wants to nudge each weight and biasand listening only to the digit 2 would push the network to classify every image as a 2. The solution is to run the same backpropagation routine for every other training example, record how each one wants to change the weights and biases, and average those desired changes together.
The Negative Gradient as Averaged Nudges
The collection of averaged nudges to every weight and bias is, loosely speaking, the negative gradient of the cost function, or at least something proportional to it. The word loosely is used because these nudges have not yet been stated quantitatively. Still, understanding why some changes are proportionally larger than others, and how they combine, reveals the mechanics of what backpropagation actually does.
Mini-Batches for Computational Speed
Summing the influence of every training example at each gradient descent step takes computers an extremely long time, so a common alternative is used. The training data is randomly shuffled and divided into mini-batches, perhaps each containing 100 training examples. A step is then computed according to each mini-batch. This step is not the true gradient, which depends on all of the training data rather than a tiny subset, so it is not the most efficient step downhill. Still, each mini-batch gives a pretty good approximation, and it yields a significant computational speedup.
Stochastic Gradient Descent as a Stumbling Walk
Plotted on the cost surface, the network's trajectory looks less like a careful calculator determining the exact downhill direction before each slow, precise step. It looks more like a drunk man stumbling aimlessly down a hill while taking quick steps. This technique is called stochastic gradient descent.
Summary of Backpropagation
Backpropagation determines how a single training example would like to nudge the weights and biases. It accounts not only for whether each one should go up or down, but also for the relative proportions of those changes that produce the most rapid decrease in the cost. A true gradient descent step would average these desired changes across all tens of thousands of training examples, but that is computationally slow. Instead, the data is randomly subdivided into mini-batches, and each step is computed with respect to a mini-batch. Repeatedly cycling through the mini-batches and making these adjustments converges toward a local minimum of the cost function, meaning the network performs very well on the training examples.
From Concepts to Code
Every line of code that implements backpropagation corresponds to ideas already covered, at least in informal terms. Knowing what the math does is often only half the battle, however. Representing it in code is where things become muddled and confusing. For readers who want to see how that representation works, the next step addresses it directly.
Going Deeper and the Need for Training Data
Readers who want a more rigorous treatment can turn to the underlying calculus, which restates the same ideas in mathematical terms and may feel more familiar when the topic appears in other resources. Before moving on, one point deserves emphasis. For this algorithm to work, and this holds for machine learning in general, not just neural networks, a large amount of training data is required.
The MNIST Database and Labeled Data Challenges
Handwritten digits make such a useful example in part because the MNIST database exists, containing a large number of examples that humans have labeled. Obtaining labeled training data is a common challenge for anyone working in machine learning. Whether it means having people label tens of thousands of images or gathering whatever other data type a project requires, the labeled data a model actually needs is often the hardest part to acquire.
Turn your watchlist into a reading routine
Bring your YouTube videos together, read summaries with key passages marked, and explore the full transcript. Save your own highlights with Pro.
Start with 5 free batteries. Each covers up to 30 minutes of a new summary.
New summaries depend on video availability and demand; processing may take time or require retry.