Backpropagation, intuitively | Deep Learning Chapter 3

3Blue1Brown · Beginner ·📐 ML Fundamentals ·8y ago

Key Takeaways

The video explains the concept of backpropagation in deep learning, specifically how it is used to adjust weights and biases in a neural network to minimize the cost function. It covers the basics of gradient descent, stochastic gradient descent, and how backpropagation is used to compute the negative gradient of the cost function.

Full Transcript

[Music] here we tackle back propagation the core algorithm behind how nural networks learn after a quick recap for where we are the first thing I'll do is an intuitive walkthrough for what the algorithm is actually doing without any reference to the formulas then for those of you who do want to dive into the math the next video goes into the calculus underlying all this if you watch the last two videos or if you're just jumping in with the appropriate background you know what a neural network is and how it feeds forward information here we're doing the classic example of recognizing handwritten digits whose pixel values get fed into the first layer of the network with 784 neurons and I've been showing a network with two hidden layers having just 16 neurons each and an output layer of 10 neurons indicating which digit the network is choosing as its answer I'm also expecting you to understand gradient descent as described in the last video and how what we mean by learning is that we want to find which weights and biases minimize a certain cost function as a quick reminder for the cost of a single training example what you do is take the output that the network gives along with the output that you wanted it to give and you just add up the squares of the differences between each component doing this for all of your tens of thousands of training examples and averaging the results this gives you the total cost of the network and as if that's not enough to think about as described in the last video the thing that we're looking for is the negative gradient of this cost function which tells you how you need to change all of the weights and biases all of these connections so as to most efficiently decrease the cost back propagation the topic of this video is an algorithm for computing that crazy complicated gradient and the one idea from the last video that I really want you to hold firmly in your mind right now is that because thinking of the gradient Vector as a direction in 13,000 Dimensions is to put it lightly beyond the scope of our imaginations there's another way you can think about it the magnitude of each component here is telling you how sensitive the cost function is to each weight and bias for example let's say you go through the process I'm about to describe and you compute the negative gradient and the component associated with the weight on this edge here comes out to be 3.2 while the component associated with this edge here comes out as 0.1 the way you would interpret that is that the cost of the function is 32 times more sensitive to changes in that first weight so if you were to wiggle that value just a little bit it's going to cause some change to the cost and that change is 32 times greater than what the same wiggle to that second weight would give personally when I was first learning about back propagation I think the most confusing aspect was just the notation and the index chasing of it all but once you unwrap what each part of this algorithm is really doing each individual effect that it's having is actually pretty intuitive it's just that there's a lot of little adjustments getting layered on top of each other so I'm going to start things off here with a complete disregard for the notation and just step through those effects that each training example is having on the weights and biases because the cost function involves averaging a certain cost per example over all the tens of thousands of training examples the way that we adjust the weights and biases for a single gradient descent step also depends on every single example or rather in principle it should but for computational efficiency we're going to do a little trick later to keep you from needing to hit every single example for every single step in either case right now all we're going to do is focus our attention on one single example this image of a two what effect should this one training example have on how the weights and biases get adjusted let's say we're at a point where the network is not well trained yet so the activations in the output are going to look pretty random maybe something like 0.5 0 .8 0.2 on and on now we can't directly change those activations we only have influence on the weights and biases but it is helpful to keep track of which adjustments we wish should take place to that output layer and since we want it to classify the image as a two we want that third value to get nudged up while all of the others get nudged down moreover the sizes of these nudges should be proportional to how far away each current value is from its Target value for example the increase to that number two neuron's activation is in a sense more important than the decrease to the number eight neuron which is already pretty close to where it should be so zooming in further let's focus just on this one neuron the one whose activation we wish to increase remember that activation is defined as a certain weighted sum of all of the activations in the previous layer plus a bias which is all then plugged into something like the sigmoid squish function or a railu so there are three different avenues that can team up together to help increase that activation you can increase the bias you can increase the weights and you can change the activations from the previous layer focusing just on how the weights should be adjusted notice how the weights actually have differing levels of influence the connections with the brightest neurons from the preceding layer have the biggest effect since those weights are multiplied by larger activation values so if you were to increase one of those weights it actually has a stronger influence on the ultimate cost function than increasing the weights of connections with dimmer neurons at least as far as this one training example is concerned remember when we talk about gradient descent we don't just care about whether each component should get nudged up or down we care about which ones give you the most bang for your butt this by the way is at least somewhat reminiscent of a theory in Neuroscience for how biological networks of neurons learn heian theory often summed up in the phrase neurons that fire together wire together here the biggest increases to weights the biggest strengthening of connections happens between neurons which are the most active and the ones which we wish to become more active in a sense the neurons that are firing while seeing a two get more strongly linked to those firing when thinking about a to to be clear I really am not in a position to make statements one way or another about whether artif IAL networks of neurons behave anything like biological brains and this fires together wire together idea comes with a couple meaningful asterisks but taken as a very loose analogy I do find it interesting to note anyway the third way that we can help increase this neuron's activation is by changing all the activations in the previous layer namely if everything connected to that digit 2 neuron with a positive weight got brighter and if everything connected with a negative weight got dimmer then that digit 2 neuron would become more active and similar to the weight changes you're going to get the most bang for your buck by seeking changes that are proportional to the size of the corresponding weights now of course we cannot directly influence those activations we only have control over the weights and biases but just as with the last layer it's helpful to just keep a note of what those desire changes are but keep in mind zooming out one step here this is only what that digit 2 output neuron wants remember we also want all of the other neurons in the last layer to become less active and each of those other output neurons has its own thoughts about what should happen to that second to last layer so the desire of this digit 2 neuron is added together with the desires of all the other output neurons for what should happen to this second to last layer again in proportion to the corresponding weights and in proportion to how much each of those neur needs to change this right here is where the idea of propagating backwards comes in by adding together all these desired effects you basically get a list of nudges that you want to happen to the second to last layer and once you have those you can recursively apply the same process to the relevant weights and biases that determine those values repeating the same process I just walked through and moving backwards through the network and zooming out a bit further remember that this is all just how a single training example wishes to nudge each one of those weights and biases if we only listen to what that two wanted the network would ultimately be incentivized just to classify all images as a two so what you do is you go through this same back propop routine for every other training example recording how each of them would like to change the weights and the biases and you average together those desired changes [Music] this collection here of the averaged nudges to each weight and bias is Loosely speaking the negative gradient of the cost function referenced in the last video or at least something proportional to it I say Loosely speaking only because I have yet to get quantitatively precise about those nudges but if you understood every change that I just referenced why some are proportionally bigger than others and how they all need to be added together you understand the Mechanics for what back propagation is actually doing by the way in practice it takes computers an extremely long time to add up the influence of every single training example every single gradient descent step so here's what's commonly done instead you randomly shuffle your training data and then divide it into a whole bunch of mini batches let's say each one having 100 training examples then you compute a step according to the mini batch it's not going to be the actual gradient of the cost function which depends on all of the training data not this tiny subset so it's not the most efficient step downhill but each mini batch does give you a pretty good approximation and more importantly it gives you a significant computational speed up if you were to plot the trajectory of your network under the relevant cost surface it would be a little more like a drunk man stumbling aimlessly down a hill but taking quick steps rather than a carefully calculating man determining the exact downhill direction of each step before taking a very slow and careful step in that direction this technique is referred to as stochastic gradient descent there's kind of a lot going on here so let's just sum it up for ourselves shall we back propagation is the algorithm for determining how a single training example would like to nudge the weights and biases not just in terms of whether they should go up or down but in terms of what relative proportions to those changes caus the most rapid decrease to the cost a true gradient descent step would involve doing this for all your tens and thousands of training examples and averaging the desired changes that you get but that's computationally slow so instead you randomly subdivide the data into these mini batches and compute each step with respect to a mini batch repeatedly going through all of the mini batches and making these adjustments you will converge towards a local minimum of the cost function which is to say your network is going to end up doing a really good job on the training examples so with all of that said every line of code that would go into implementing backprop actually corresponds with something that you have now seen at least in informal terms but sometimes knowing what the math does is only half the battle and just representing the damn thing is where it gets all muddled and confusing so for those of you who do want to go deeper the next video goes through the same ideas that were just presented here but in terms of the underlying calculus which should hopefully make it a little more familiar as you see the topic in other resources before that one thing worth emphasizing is is that for this algorithm to work and this goes for all sorts of machine learning Beyond just neural networks you need a lot of training data in our case one thing that makes handwritten digits such a nice example is that there exists the mnist database with so many examples that have been labeled by humans so a common challenge that those of you working in machine learning will be familiar with is just getting the labeled training data that you actually need whether that's having people label tens of thousands of images or whatever other data type you might be dealing with [Music]

Original Description

What's actually happening to a neural network as it learns? Help fund future projects: https://www.patreon.com/3blue1brown An equally valuable form of support is to simply share some of the videos. Special thanks to these supporters: http://3b1b.co/nn3-thanks Written/interactive form of this series: https://www.3blue1brown.com/topics/neural-networks And by CrowdFlower: http://3b1b.co/crowdflower Home page: https://www.3blue1brown.com/ The following video is sort of an appendix to this one. The main goal with the follow-on video is to show the connection between the visual walkthrough here, and the representation of these "nudges" in terms of partial derivatives that you will find when reading about backpropagation in other resources, like Michael Nielsen's book or Chis Olah's blog. Video timeline: 0:00 - Introduction 0:23 - Recap 3:07 - Intuitive walkthrough example 9:33 - Stochastic gradient descent 12:28 - Final words Thanks to these viewers for their contributions to translations Звуковая дорожка на русском языке: Влад Бурмистров. Italian: @teobucci Vietnamese: CyanGuy111
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from 3Blue1Brown · 3Blue1Brown · 54 of 60

1 e to the pi i, a nontraditional take (old version)
e to the pi i, a nontraditional take (old version)
3Blue1Brown
2 Euler's Formula Poem
Euler's Formula Poem
3Blue1Brown
3 Euler's Formula and Graph Duality
Euler's Formula and Graph Duality
3Blue1Brown
4 What does it feel like to invent math?
What does it feel like to invent math?
3Blue1Brown
5 How to count to 1000 on two hands
How to count to 1000 on two hands
3Blue1Brown
6 Music And Measure Theory
Music And Measure Theory
3Blue1Brown
7 Fractal charm: Space filling curves
Fractal charm: Space filling curves
3Blue1Brown
8 The Brachistochrone, with Steven Strogatz
The Brachistochrone, with Steven Strogatz
3Blue1Brown
9 Snell's law proof using springs
Snell's law proof using springs
3Blue1Brown
10 Triangle of Power
Triangle of Power
3Blue1Brown
11 Essence of linear algebra preview
Essence of linear algebra preview
3Blue1Brown
12 Vectors | Chapter 1, Essence of linear algebra
Vectors | Chapter 1, Essence of linear algebra
3Blue1Brown
13 Linear combinations, span, and basis vectors | Chapter 2, Essence of linear algebra
Linear combinations, span, and basis vectors | Chapter 2, Essence of linear algebra
3Blue1Brown
14 Linear transformations and matrices | Chapter 3, Essence of linear algebra
Linear transformations and matrices | Chapter 3, Essence of linear algebra
3Blue1Brown
15 Matrix multiplication as composition | Chapter 4, Essence of linear algebra
Matrix multiplication as composition | Chapter 4, Essence of linear algebra
3Blue1Brown
16 Three-dimensional linear transformations | Chapter 5, Essence of linear algebra
Three-dimensional linear transformations | Chapter 5, Essence of linear algebra
3Blue1Brown
17 The determinant | Chapter 6, Essence of linear algebra
The determinant | Chapter 6, Essence of linear algebra
3Blue1Brown
18 Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra
Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra
3Blue1Brown
19 Nonsquare matrices as transformations between dimensions | Chapter 8, Essence of linear algebra
Nonsquare matrices as transformations between dimensions | Chapter 8, Essence of linear algebra
3Blue1Brown
20 Dot products and duality | Chapter 9, Essence of linear algebra
Dot products and duality | Chapter 9, Essence of linear algebra
3Blue1Brown
21 Cross products in the light of linear transformations | Chapter 11, Essence of linear algebra
Cross products in the light of linear transformations | Chapter 11, Essence of linear algebra
3Blue1Brown
22 Cross products | Chapter 10, Essence of linear algebra
Cross products | Chapter 10, Essence of linear algebra
3Blue1Brown
23 Change of basis | Chapter 13, Essence of linear algebra
Change of basis | Chapter 13, Essence of linear algebra
3Blue1Brown
24 Eigenvectors and eigenvalues | Chapter 14, Essence of linear algebra
Eigenvectors and eigenvalues | Chapter 14, Essence of linear algebra
3Blue1Brown
25 Abstract vector spaces | Chapter 16, Essence of linear algebra
Abstract vector spaces | Chapter 16, Essence of linear algebra
3Blue1Brown
26 Who cares about topology?   (Old version)
Who cares about topology? (Old version)
3Blue1Brown
27 3blue1brown channel trailer
3blue1brown channel trailer
3Blue1Brown
28 Binary, Hanoi and Sierpinski, part 1
Binary, Hanoi and Sierpinski, part 1
3Blue1Brown
29 Binary, Hanoi, and Sierpinski, part 2
Binary, Hanoi, and Sierpinski, part 2
3Blue1Brown
30 But what is the Riemann zeta function? Visualizing analytic continuation
But what is the Riemann zeta function? Visualizing analytic continuation
3Blue1Brown
31 Tattoos on Math
Tattoos on Math
3Blue1Brown
32 Fractals are typically not self-similar
Fractals are typically not self-similar
3Blue1Brown
33 Euler's formula with introductory group theory
Euler's formula with introductory group theory
3Blue1Brown
34 The essence of calculus
The essence of calculus
3Blue1Brown
35 The paradox of the derivative | Chapter 2, Essence of calculus
The paradox of the derivative | Chapter 2, Essence of calculus
3Blue1Brown
36 Derivative formulas through geometry | Chapter 3, Essence of calculus
Derivative formulas through geometry | Chapter 3, Essence of calculus
3Blue1Brown
37 Visualizing the chain rule and product rule | Chapter 4, Essence of calculus
Visualizing the chain rule and product rule | Chapter 4, Essence of calculus
3Blue1Brown
38 What's so special about Euler's number e? | Chapter 5, Essence of calculus
What's so special about Euler's number e? | Chapter 5, Essence of calculus
3Blue1Brown
39 Implicit differentiation, what's going on here? | Chapter 6, Essence of calculus
Implicit differentiation, what's going on here? | Chapter 6, Essence of calculus
3Blue1Brown
40 Limits, L'Hôpital's rule, and epsilon delta definitions | Chapter 7, Essence of calculus
Limits, L'Hôpital's rule, and epsilon delta definitions | Chapter 7, Essence of calculus
3Blue1Brown
41 Integration and the fundamental theorem of calculus | Chapter 8, Essence of calculus
Integration and the fundamental theorem of calculus | Chapter 8, Essence of calculus
3Blue1Brown
42 What does area have to do with slope? | Chapter 9, Essence of calculus
What does area have to do with slope? | Chapter 9, Essence of calculus
3Blue1Brown
43 Higher order derivatives | Chapter 10, Essence of calculus
Higher order derivatives | Chapter 10, Essence of calculus
3Blue1Brown
44 Taylor series | Chapter 11, Essence of calculus
Taylor series | Chapter 11, Essence of calculus
3Blue1Brown
45 Pi hiding in prime regularities
Pi hiding in prime regularities
3Blue1Brown
46 All possible pythagorean triples, visualized
All possible pythagorean triples, visualized
3Blue1Brown
47 But how does bitcoin actually work?
But how does bitcoin actually work?
3Blue1Brown
48 How secure is 256 bit security?
How secure is 256 bit security?
3Blue1Brown
49 Hilbert's Curve: Is infinite math useful?
Hilbert's Curve: Is infinite math useful?
3Blue1Brown
50 Thinking outside the 10-dimensional box
Thinking outside the 10-dimensional box
3Blue1Brown
51 Some light quantum mechanics (with minutephysics)
Some light quantum mechanics (with minutephysics)
3Blue1Brown
52 But what is a neural network? | Deep learning chapter 1
But what is a neural network? | Deep learning chapter 1
3Blue1Brown
53 Gradient descent, how neural networks learn | Deep Learning Chapter 2
Gradient descent, how neural networks learn | Deep Learning Chapter 2
3Blue1Brown
Backpropagation, intuitively | Deep Learning Chapter 3
Backpropagation, intuitively | Deep Learning Chapter 3
3Blue1Brown
55 Backpropagation calculus | Deep Learning Chapter 4
Backpropagation calculus | Deep Learning Chapter 4
3Blue1Brown
56 The hardest problem on the hardest test
The hardest problem on the hardest test
3Blue1Brown
57 Q&A #2 + Net Neutrality Nuance
Q&A #2 + Net Neutrality Nuance
3Blue1Brown
58 Why this puzzle is impossible
Why this puzzle is impossible
3Blue1Brown
59 But what is the Fourier Transform?  A visual introduction.
But what is the Fourier Transform? A visual introduction.
3Blue1Brown
60 The more general uncertainty principle, regarding Fourier transforms
The more general uncertainty principle, regarding Fourier transforms
3Blue1Brown

This video explains the concept of backpropagation in deep learning, covering the basics of gradient descent, stochastic gradient descent, and how backpropagation is used to compute the negative gradient of the cost function. It provides an intuitive understanding of how backpropagation works and how it is used to adjust weights and biases in a neural network. By watching this video, viewers can gain a deeper understanding of the backpropagation algorithm and how it is used in deep learning.

Key Takeaways
  1. Adjust weights and biases for a single gradient descent step based on every single example
  2. Focus attention on one single example for computational efficiency
  3. Compute the negative gradient of the cost function
  4. Increase the bias of the desired neuron
  5. Increase the weights of the connections with the brightest neurons from the preceding layer
  6. Change the activations in the previous layer to increase the activation of the desired neuron
  7. Apply the backpropagation algorithm to determine how a single training example would like to nudge the weights and biases in a neural network
  8. Recursively apply the same process to the relevant weights and biases that determine the values of the previous layer
  9. Add together the desired effects of each neuron in proportion to the corresponding weights and in proportion to how much each of those neurons needs to change
  10. Compute a step according to a mini-batch of training data using stochastic gradient descent
💡 Backpropagation is an algorithm for computing the negative gradient of a cost function, which is used to adjust weights and biases in a neural network to minimize the cost function.

Related Reads

📰
Introducing Alpha Capital Bank: How I’m Transitioning from Data Science to Credit Risk by Building…
Learn how to transition from data science to credit risk by building a project-based journey in banking and quantitative finance
Medium · Machine Learning
📰
Classifying heartbeats as normal or abnormal, and being honest about when it stops working
Learn to classify heartbeats as normal or abnormal using machine learning and understand the importance of acknowledging limitations in medical AI models
Medium · Machine Learning
📰
AI Inference, Explained the Way I Wish Someone Had Explained It to Me
Learn the difference between AI training, fine-tuning, serving, and inference to improve your AI architecture meetings
Medium · Machine Learning
📰
AI Inference, Explained the Way I Wish Someone Had Explained It to Me
Learn the difference between AI training, fine-tuning, serving, and inference to improve your AI architecture understanding
Medium · Deep Learning

Chapters (5)

Introduction
0:23 Recap
3:07 Intuitive walkthrough example
9:33 Stochastic gradient descent
12:28 Final words
Up next
Part 2 | MLOps On GitHub | Deploy and Automate ML Workflow |Using GitHub Actions and CML for CI & CD
Abonia Sojasingarayar
Watch →