1. Home
  2. Explore
  3. Computer Science
  4. Neural Networks & Gradient Descent

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Neural Networks & Gradient Descent

Speaker 1Speaker 2

Neural Networks & Gradient Descent

4:27
0:00-4:27
  1. Hope

    All right, Corey, let's pick up where we left off. Last time we talked about the structure of a neural network for handwritten digit recognition: 784 input neurons for a 28 by 28 pixel grid, two hidden layers with 16 neurons each, and 10 output neurons for the digits 0 through 9. About 13,000 weights and biases to tune. But how does it actually learn?

  2. Corey

    That's the million-dollar question. And the answer is surprisingly mathematical. It all comes down to minimizing a cost function. We define a cost that measures how wrong the network's output is for a given training example — say, the sum of squared differences between the actual output and the desired output. Then we average that over all training images.

  3. Hope

    Exactly. So the cost function takes all those 13,000 weights and biases as inputs and spits out a single number representing how lousy the network is. Our goal is to find the combination of weights and biases that makes that number as small as possible.

  4. Corey

    And that's where gradient descent comes in. Imagine a simple function with one input and one output. To find a minimum, you start at some random input, check the slope, and then take a step in the direction that lowers the output. If the slope is positive, you step left; if negative, you step right. Repeat until you reach a valley.

  5. Hope

    Right. And if you make the step size proportional to the slope, you naturally slow down near the bottom, which helps you avoid overshooting. Now bump it up to two inputs: you've got a surface over the xy-plane. The gradient tells you the direction of steepest ascent. Take the negative gradient, and that's the downhill direction — the direction that decreases the cost most quickly.

  6. Corey

    So in our 13,000-dimensional input space, the gradient is a vector that points in the direction of steepest increase. The negative gradient points downhill. Each component tells you whether to nudge a particular weight up or down, and the relative magnitudes tell you which changes matter most — the bang for your buck.

  7. Hope

    Exactly. And that's the algorithm: compute the gradient of the cost function, then nudge all the weights and biases by a small amount in the negative gradient direction. Repeat over and over. This is gradient descent, and it's the heart of how neural networks learn.

  8. Corey

    But computing that gradient for 13,000 variables over tens of thousands of training examples sounds crazy. There's a clever algorithm called backpropagation that does it efficiently. That's the subject of the next video, but for now, the key takeaway is that learning is just minimizing a cost function.

  9. Hope

    And notice: the cost function needs to be smooth so we can take those little downhill steps. That's why artificial neurons use continuous activations like sigmoid or ReLU, not binary on/off like biological neurons. Smoothness lets us use calculus.

  10. Corey

    So after training, how well does this network actually perform? Starting from random weights, after gradient descent, it correctly classifies about 96% of new images. With some tweaks to the hidden layers, you can push that to 98%. Not bad for a network that started as random noise.

  11. Hope

    But here's the interesting part: when you look at what those hidden layers actually learn, it's not what you might expect. Remember how we hoped the second layer would pick up edges and the third layer would combine them into loops and lines? Well, when you visualize the weights from the first to the second layer, they look almost random, just with a few vague patterns.

  12. Corey

    So it's not doing the neat hierarchical feature detection we imagined. And to drive that home, show it a completely random image — it will confidently classify it as some digit, say a 5, with the same certainty as if it were a real 5. It has no concept of uncertainty because the training data never required it to be unsure.

  13. Hope

    This raises questions about whether the network is actually learning meaningful patterns or just memorizing. There's a famous experiment where you take a deep network and train it on a dataset where the labels are randomly shuffled. It still achieves high training accuracy — it can memorize the random labels. But the learning curve is very slow, almost linear.

  14. Corey

    Whereas with correctly structured data, the accuracy drops quickly at first, then suddenly plunges. That suggests the network is finding a good local minimum much more easily when the data has real structure. And there's even work showing that for many networks, the local minima these gradient descent finds are all about equally good.

  15. Hope

    So even though the hidden layers don't look like what we expected, the network still generalizes well because it's exploiting statistical regularities in the data. It's not 'understanding' digits the way we do, but it's doing something effective. And that's why this classic network is still a great starting point to understand modern deep learning.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent