1. Home
  2. 3Blue1Brown

Oct 16, 2017

How gradient descent tunes 13,000 neural network parameters

20 min → 2:12

Overview

The host of 3Blue1Brown explains how neural networks learn through gradient descent, using a cost function to adjust over 13,000 parameters and improve their accuracy.

3 things to know

Learning as Optimization

The process of a neural network "learning" is framed not as a mysterious process of gaining intelligence, but as a mathematical optimization problem.

More

The goal is to find the optimal set of weights and biases that minimizes the network's errors.

▶ Watch at 2:46

Gradient Descent

By taking a small step in the opposite direction of the gradient, the network can iteratively descend towards a local minimum of the cost function, thereby improving its performance.

More

This is the core algorithm used to minimize the cost function. It involves calculating the "gradient" of the cost function, which is a vector that points in the direction of the steepest increase in cost.

▶ Watch at 8:18

Cost Function

The cost function (or loss function) does this by calculating the difference between the network's output for a given training image and the actual correct output.

More

To optimize the network, we first need a way to measure its error. The overall cost is the average of these errors across all training examples.

▶ Watch at 14:22

Also in this episode

The Gradient's Role

The gradient not only indicates the direction of change but also the relative importance of each weight and bias.

More

A larger magnitude for a component of the gradient means that adjusting the corresponding weight or bias will have a more significant impact on the cost.

Backpropagation

The video briefly introduces backpropagation as the specific, efficient algorithm for calculating the massive gradient vector of the cost function.

More

This is the computational heart of the learning process and is the subject of the next episode.

Quotes

“And it's provocative as it is to describe a machine as learning, once you actually see how it works, it feels a lot less like some crazy sci-fi premise and a lot more like, well, a calculus exercise.”

▶ Watch at 2:46

“The algorithm for minimizing the function is to compute this gradient direction, then take a small step downhill, and just repeat that over and over. It's called gradient descent.”

▶ Watch at 8:18

“Well...not at all! Remember how last video we looked at how the weights of the connections from all of the neurons in the first layer...can be visualized as a given pixel pattern that that second-layer neuron is picking up on? Well, when we actually do that...instead of picking up on isolated little edges here and there, they look, well, almost random.”

▶ Watch at 14:22

Full summary

Episode Overview

  • This episode recaps the basic structure of a neural network and introduces the fundamental mechanism by which it "learns": an algorithm called gradient descent.
  • The concept of a "cost function" is explained as a way to measure how poorly the network is performing, giving it a target to minimize.
  • Through analogies and visualizations, the process of gradient descent is broken down, explaining how the network iteratively adjusts its 13,000+ parameters (weights and biases) to improve its accuracy.
  • The episode analyzes what the hidden layers of a trained network are actually "looking for" and reveals that the learned patterns are not always as intuitive as one might expect.
  • It concludes by introducing backpropagation as the core algorithm for computing the gradient, setting the stage for the next video in the series.

Key Concepts

  • Learning as Optimization: The process of a neural network "learning" is framed not as a mysterious process of gaining intelligence, but as a mathematical optimization problem. The goal is to find the optimal set of weights and biases that minimizes the network's errors.
  • Cost Function: To optimize the network, we first need a way to measure its error. The cost function (or loss function) does this by calculating the difference between the network's output for a given training image and the actual correct output. The overall cost is the average of these errors across all training examples.
  • Gradient Descent: This is the core algorithm used to minimize the cost function. It involves calculating the "gradient" of the cost function, which is a vector that points in the direction of the steepest increase in cost. By taking a small step in the opposite direction of the gradient, the network can iteratively descend towards a local minimum of the cost function, thereby improving its performance.
  • The Gradient's Role: The gradient not only indicates the direction of change but also the relative importance of each weight and bias. A larger magnitude for a component of the gradient means that adjusting the corresponding weight or bias will have a more significant impact on the cost.
  • Backpropagation: The video briefly introduces backpropagation as the specific, efficient algorithm for calculating the massive gradient vector of the cost function. This is the computational heart of the learning process and is the subject of the next episode.

Quotes

  • At 02:46 - "And it's provocative as it is to describe a machine as learning, once you actually see how it works, it feels a lot less like some crazy sci-fi premise and a lot more like, well, a calculus exercise." - This quote demystifies the concept of machine learning, grounding it in the tangible mathematical process of optimization rather than abstract intelligence.
  • At 08:18 - "The algorithm for minimizing the function is to compute this gradient direction, then take a small step downhill, and just repeat that over and over. It's called gradient descent." - This is a clear and concise definition of the core learning algorithm discussed throughout the episode, summarizing the iterative process of finding a function's minimum.
  • At 14:22 - "Well...not at all! Remember how last video we looked at how the weights of the connections from all of the neurons in the first layer...can be visualized as a given pixel pattern that that second-layer neuron is picking up on? Well, when we actually do that...instead of picking up on isolated little edges here and there, they look, well, almost random." - This quote highlights the surprising and often unintuitive nature of what a neural network actually learns. The internal patterns it uses for classification are not necessarily neat, human-interpretable features like edges or shapes.

Takeaways

  • Machine learning in neural networks is fundamentally about minimizing a cost function. The network isn't "thinking" but is rather adjusting its parameters to reduce a quantified measure of error.
  • The gradient descent algorithm is a powerful and general method for function optimization. It works by finding the steepest "downhill" direction of the cost function and taking iterative steps to reach a minimum.
  • The gradient of the cost function provides crucial information: it tells the network how to change each of its thousands of weights and biases to improve most effectively.
  • Even when a network successfully learns to classify images with high accuracy, the features it learns in its hidden layers might not correspond to human-like concepts (like edges or loops) but can be complex, abstract patterns that are simply effective for the task.

Watch the full episode 20 min

Read along with the audio summary

When a neural network successfully learns to classify images with high accuracy, are its hidden layers actually picking up on neat, human-like concepts like isolated edges and loops? This episode, which came out on October 16, 2017, explores the fundamental mechanism of how neural networks learn. By the end, you will understand how an algorithm called gradient descent turns machine learning into a practical math problem.

Why machine learning is really just a calculus exercise.

Describing a machine as learning sounds like a crazy sci-fi premise, yet the reality has nothing to do with a computer mysteriously gaining intelligence. Instead, a neural network learning is framed as a mathematical optimization problem. The network has over thirteen thousand parameters, known as weights and biases. The entire goal of learning is simply to find the optimal set of these weights and biases to minimize the network's errors.

To minimize those errors, we first need a way to measure how poorly the network is performing.

How a network scores its own mistakes.

A network cannot improve until it has a clear target to minimize. A mathematical tool called the cost function, also known as the loss function, provides this target by measuring the network's error. For any given training image, the cost function calculates the exact difference between the network's output and the actual correct output. To find the overall cost of the network, it takes the average of all these individual errors across every single training example.

Once the network has this error score, it needs a way to bring that number down.

Finding the fastest way downhill to better performance.

The core algorithm used to minimize the cost function is called gradient descent. It starts by calculating the gradient of the cost function, which is a vector that points toward the steepest increase in cost. By taking a small step in the exact opposite direction of that gradient, the network moves downhill. Repeating this process over and over lets the network iteratively descend toward a local minimum of the cost function, steadily improving its accuracy.

How the network knows which adjustments matter most.

The gradient does not just show the direction of change, it also reveals the relative importance of each individual weight and bias. If a specific component of the gradient has a larger magnitude, adjusting that corresponding weight or bias will have a much more significant impact on lowering the overall cost.

The engine behind the math.

Calculating this massive gradient vector for the cost function requires a specific, efficient algorithm. That algorithm is called backpropagation. It serves as the computational heart of the entire learning process, making it possible to actually compute those thousands of adjustments, which is the subject of the next episode in the series.

Machine learning in neural networks is not about a machine thinking, but about adjusting thousands of parameters to reduce a quantified measure of error through gradient descent. Even when a network learns to classify images with high accuracy, visualizing the pixel patterns that its second-layer neurons pick up on reveals that instead of neat, human-like concepts like isolated edges or loops, the learned patterns look almost random.

More from 3Blue1Brown

Related Episodes