Gradient Descent: How a Neural Network Learns

A visual introduction to minimizing training cost, and a look at what a digit classifier does and does not learn.

LLLeisha LeeInvité
Chaîne
3Blue1Brown
Publié
16 oct. 2017
Vidéo
20:33
Lecture
3 min
Original
anglais
Ouvrir sur YouTube
En faisant défiler, la vidéo se réduit en bas à droite et continue. Les sous-titres suivent votre langue de lecture.
Langue de lectureDisponible en 2 langues
Cet article n’est pas encore disponible en français ; il s’affiche dans l’original en anglais.
RÉSUMÉ

En 30 secondes

Grant Sanderson explains gradient descent with a handwritten-digit network, then examines its hidden weights and limits. An interview excerpt with Leisha Lee considers memorization and generalization.

  1. 1Cost functionThe example averages squared output errors across labeled training images.
  2. 2Negative gradientThe negative gradient gives the direction of steepest local decrease.
  3. 3Training versus generalizationLower training cost does not guarantee better performance on every example or unseen data.
  4. 4Confident on noiseA classifier can confidently label inputs outside its training distribution.

À retenir

  1. A cost function measures how network outputs differ from training labels.
  2. Gradient descent adjusts parameters in the direction of local cost reduction.
  3. A local minimum is not necessarily the global minimum.
  4. Test performance and internal representations require separate scrutiny.
  5. A network can fit random labels without generalizing them.
TEXTE INTÉGRAL

Lire le texte remanié, chapitre par chapitre

Transcription seule
01

The digit classifier

Grant Sanderson introduces gradient descent using a handwritten-digit classifier, then examines what its hidden layers actually learn. The example uses MNIST images rendered as 28 by 28 grayscale pixels.

Grant Sanderson introduces gradient descent using a handwritten-digit classifier, then examines what its hidden layers actually learn. The example uses MNIST images rendered as 28 by 28 grayscale pixels.

The 784 input neurons represent pixel values. Each subsequent neuron combines activations from the previous layer with weights and a bias, then applies an activation function. The example has two hidden layers of 16 neurons and roughly 13,000 adjustable parameters.

The ten output neurons correspond to digits; the most active one is the prediction. A hoped-for interpretation is that early layers find edges and later layers combine them into loops and strokes, but that hypothesis must be checked.

Training supplies labeled digit images and adjusts weights and biases. Generalization is evaluated separately using labeled images the model did not see during training.

02

Defining cost

Starting from random parameters, the initial outputs are poor. For a labeled example, Sanderson defines a cost as the sum of squared differences between output activations and desired values: one for the correct digit and zero for the others.

Starting from random parameters, the initial outputs are poor. For a labeled example, Sanderson defines a cost as the sum of squared differences between output activations and desired values: one for the correct digit and zero for the others.

The overall cost averages that quantity over the training set. It is a function of the network’s weights and biases and returns a single number measuring performance on those examples.

03

Finding a downhill direction

To see how to reduce cost, first imagine a function of one variable. At each point, its slope tells you which direction is locally downhill; repeated small steps can approach a local minimum.

To see how to reduce cost, first imagine a function of one variable. At each point, its slope tells you which direction is locally downhill; repeated small steps can approach a local minimum.

The starting point matters: a complicated landscape can contain many valleys, and the local minimum reached is not guaranteed to be the global minimum. Step size also affects whether an update overshoots.

For a function of two variables, the gradient points in the direction of steepest local increase. The negative gradient points downhill, and its magnitude describes the local steepness.

04

Gradient descent in parameter space

The same idea extends to thousands of parameters. Arrange all weights and biases into a vector, compute the cost gradient and repeatedly move a small amount against it. This is gradient descent.

The same idea extends to thousands of parameters. Arrange all weights and biases into a vector, compute the cost gradient and repeatedly move a small amount against it. This is gradient descent.

The gradient is based on average training cost; reducing that average does not promise that every individual example improves or that unseen data will improve. Backpropagation efficiently computes the derivatives used for these updates.

Each gradient component indicates whether a parameter should increase or decrease and how sensitive the local cost is to that parameter. For a gradient of (3, 1), the first coordinate has three times the local derivative of the second, in those units.

05

Testing and interpreting the network

Sanderson reports that this simple two-hidden-layer network correctly classifies about 96% of unseen test images, and that changing the architecture and other settings can improve the result. These are results for the described experiment, not a universal guarantee.

Sanderson reports that this simple two-hidden-layer network correctly classifies about 96% of unseen test images, and that changing the architecture and other settings can improve the result. These are results for the described experiment, not a universal guarantee.

He then checks the earlier intuition about edges. Visualizing the learned input weights shows patterns that look largely random rather than clean edge detectors. A useful classifier need not discover the particular representation its designer imagined.

When fed random noise, the network can still produce a confident digit prediction. Its training world consisted of centered digit examples, and the objective did not teach it to recognize arbitrary inputs as outside that world.

The simple network is a starting point for understanding later models, not a complete account of visual intelligence. Sanderson encourages learners to experiment with changes and points to Michael Nielsen’s freely available neural-networks book.

06

Memorization and generalization

In an interview excerpt, Leisha Lee discusses research showing that a sufficiently large network can fit randomly shuffled training labels, even though those labels do not support useful generalization to new examples.

In an interview excerpt, Leisha Lee discusses research showing that a sufficiently large network can fit randomly shuffled training labels, even though those labels do not support useful generalization to new examples.

Lee describes subsequent work comparing optimization on random and structured labels: in the cited experiments, meaningful labels were learned much more quickly. She also mentions simplified theoretical work on the quality of local minima; these results do not imply all neural-network minima are equally good.

Sur la même chaîne

20 diapositives40:44EN
3Blue1Brown· 16 oct. 2026Grant Sanderson: There's never been a better time to go into mathGrant Sanderson, Constantin Kogler · 3Blue1BrownStudents fear AI has solved mathematics. Grant Sanderson argues the opposite: even if machines prove theorems better than we do, the institution of math stays valuable—and this is a rare moment when newcomers can reshape it.MathematicsAI for scienceHuman-AI Collaboration+2
29 diapositives51:55EN
3Blue1Brown· 18 sept. 2026The last IMO problem AI could not solveGrant Sanderson · 3Blue1BrownGrant Sanderson walks through IMO 2025 Problem 6 — a tiling puzzle that frontier models missed — and the visual patience it takes to prove a construction is optimal.MathematicsAI researchReasoning & test-time compute+2
0:55EN
3Blue1Brown· 24 juil. 2026The 64 Sugar Cubes Puzzle: Six Equal DistancesA 4×4×4 block has three colors; prove that six same-colored pairs share a distance.MathematicsEducation
33:51EN
3Blue1Brown· 16 juil. 2026What Cross-Entropy Connects: Compression, Language Models and KL DivergenceGrant Sanderson · 3Blue1BrownGrant Sanderson builds cross-entropy from code lengths and uses it to explain next-token training and distillation.MathematicsMachine LearningFoundation Models+1
Diapositives2:25EN
3Blue1Brown· 12 juin 2026How Shannon Measured the Entropy of EnglishA guessing game helped Claude Shannon estimate how much information English text contains, and why prediction is central to compression.MathematicsAI History
Diapositives1:02EN
3Blue1Brown· 10 juin 2026A Robot Walk and the Puzzle of Optimal Binary EncodingHow few bits does it take to send directions that occur with unequal frequencies?MathematicsScience Communication