1. Home
  2. Explore
  3. Computer Science
  4. Neural Network Backpropagation

Study methods

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

Neural Network Backpropagation

Speaker 1Speaker 2

Neural Network Backpropagation

10:49
0:00-10:49
  1. Simon

    Before we move on, let’s briefly connect back to backpropagation. In the forward pass, an example goes through the network layer by layer: inputs combine with weights and biases, produce pre-activations and activations, and eventually produce the model’s output. The loss function then compares that output with the target.

  2. Hope

    And backpropagation follows the dependencies in the opposite direction. You start by computing how the loss changes with respect to the output, then work backward through the activations and pre-activations of earlier layers.

  3. Simon

    Right. Each step uses a relationship like: if you know the derivative of the loss with respect to a module’s output, how can you get the derivative with respect to its input? The chain-rule lemmas we studied provide those relationships. Alongside the derivatives with respect to activations, you also compute derivatives with respect to each layer’s weights and biases.

  4. Hope

    The key is that the activation gradients have to be computed in sequence: you can’t get an earlier layer’s gradient before the later one it depends on. The weight and bias gradients can be calculated as those relevant quantities become available. So the arrows in a backpropagation diagram represent both the backward direction and the order of dependencies.

  5. Simon

    Now we’re shifting from how we train a model to a bigger question: after training, will it work on examples it hasn’t seen? That ability to perform well on unseen examples is called generalization.

  6. Hope

    So a model doing well on its training examples isn’t enough. Those are examples it has already used to adjust its parameters; what we really care about is whether it can make good predictions on fresh examples from the situation we want to handle.

  7. Simon

    Let’s define the two quantities we’ll compare. Training loss—also called training error or training cost in this discussion—is the loss evaluated on the training examples. The loss might be squared loss, cross-entropy, or a negative log-likelihood derived from a maximum-likelihood objective.

  8. Hope

    And test loss means the expected loss on a new example drawn from the test distribution, which we can call D. In practice, we don’t usually average over every possible example in D; instead, we evaluate on a separate test set and use its average loss to estimate that expectation.

  9. Simon

    That test set has to be kept separate from the training process. If the model’s parameters are chosen using test examples, those examples aren’t truly unseen anymore, so the test result no longer gives the same clean estimate of performance on fresh data.

  10. Hope

    The difference between test loss and training loss is called the generalization gap. Often training loss is lower, because the model has been adjusted to fit those examples. The gap can be small or large, and the goal is to have both a low training loss and a small gap, so test loss is low too.

  11. Simon

    There are two common ways things can go wrong when test loss is high. In overfitting, the model has low training loss but much higher test loss: it fits the examples it saw, yet fails to generalize. In underfitting, training loss itself is high, so the model hasn’t even fit the training examples well.

  12. Hope

    A useful way to picture both is to fit curves to a small, noisy data set. Imagine the underlying relationship is roughly quadratic, and you observe just a few points around that curve. The model’s complexity—say, whether it’s linear or a high-degree polynomial—can change whether it underfits or overfits.

  13. Simon

    For a linear model, the best-fitting line may still miss the quadratic pattern. Its predictions can be noticeably off even on the training points, giving high training loss. That’s underfitting: the model family is too limited to represent the relationship well.

  14. Hope

    That limitation is what bias describes in this picture. If the model family can’t express the underlying pattern, then even with a great deal of data—and even with very little noise—the model still can’t fully capture it. More examples can’t fix a mismatch between the model family and the relationship it needs to represent.

  15. Simon

    Now consider a fifth-degree polynomial fitted to only a few points. It’s flexible enough to wiggle through all of them, perhaps giving almost zero training loss. But those wiggles may be responding to random noise in the observed points rather than the underlying quadratic trend.

  16. Hope

    That’s overfitting: the model has explained the small fluctuations as if they were important structure. If you draw a new data set from the same underlying relationship, the noise will be different, and the fitted fifth-degree curve may change dramatically.

  17. Simon

    That sensitivity gives us an intuition for variance. Imagine repeatedly drawing different training sets from the same distribution and fitting a model each time. If the resulting models vary a lot from one data set to another, the model has high variance.

  18. Hope

    A very flexible model can have high variance because it reacts strongly to the particular examples and noise it happens to see. One way to reduce that problem is to collect more examples from the same distribution; another is to use a simpler model.

  19. Simon

    The contrast is important: bias is mainly about the model family being too limited, while variance can come from having too little data for a flexible model. They’re related to different failure modes, and changing the model complexity can affect both.

  20. Hope

    For example, suppose we keep the fifth-degree polynomial but increase the data from just a few points to a very large sample from the same quadratic relationship. A wildly wiggly curve will no longer fit all those points well, so it won’t be the best training fit. The best fifth-degree polynomial can instead behave much more like the underlying quadratic.

  21. Simon

    That’s why more data can reduce variance. The model has to account for a broader set of examples, so it has less freedom to chase the peculiar noise in a tiny sample. This assumes the optimization procedure actually finds a good fit; whether an algorithm can find one is a separate issue from whether such a model exists.

  22. Hope

    Putting the ideas together gives the classic bias–variance picture. As model complexity increases, bias tends to decrease because the model can represent more patterns. But variance tends to increase because a more flexible model can react more to the particular training data.

  23. Simon

    If we add those two contributions as an intuition for test error, the result often has a U-shape: at first, greater complexity reduces the error caused by high bias, but beyond some point the error caused by high variance can dominate. That suggests a sweet spot between a model that’s too simple and one that’s too flexible.

  24. Hope

    The best spot depends on more than the model family. It can depend on the underlying relationship and on how much data you have. If the true relationship is quadratic, a quadratic model may be expressive enough without adding unnecessary flexibility; with only a handful of observations, a simpler model might still give a better trade-off.

  25. Simon

    Bias and variance are useful ways to understand what might be happening, but they usually aren’t quantities we can directly measure in an ordinary real-world task. Their definitions rely on comparisons across possible data sets or knowledge of the underlying truth, which we generally don’t have.

  26. Hope

    So in practice, how do we choose model complexity? We try different models and compare their performance on a validation set, which is separate from the training data. The bias–variance picture can guide which models to explore, but validation performance helps us make the empirical choice.

  27. Simon

    There’s also a technical caveat: the classic mathematical bias–variance decomposition is well established for squared loss, or mean squared error. The same intuitions can still be helpful with losses like cross-entropy, but writing down an exact equivalent decomposition is more challenging.

  28. Hope

    And the U-shaped picture isn’t the whole story. In recent years, researchers have studied a phenomenon called double descent, which challenges the idea that test error must simply rise once a model becomes very complex.

  29. Simon

    In the model-wise version, the horizontal axis is model size or number of parameters. Test error may first fall, then rise around a point where the model has enough capacity to fit the training data, and then fall again as the model becomes even larger. That later decrease is the second descent.

  30. Hope

    There’s a related data-wise version. Keep the model setting in view and increase the number of training examples: test error may decrease at first, rise around the point where the number of examples is close to the number of parameters, and then decrease again as more data is added.

  31. Simon

    The exact location and shape can depend on the model, and this is an active research area. For linear models, the relationship to the number of examples and features has been studied particularly clearly. In deep learning, many practical systems operate with more parameters than training examples, which is one reason this phenomenon matters.

  32. Hope

    One explanation for the peak, especially in linear-model settings, is that some standard learning algorithms can perform poorly when the number of examples is close to the number of features or parameters. In that region, the learned parameter vector can have a very large norm, and that may contribute to the high test error.

  33. Simon

    This also raises a question about how we measure complexity. Counting parameters is one measure, but it may not be the only one: a model with many parameters that are all very small can behave simply, while a model with fewer parameters but very large values may behave more flexibly.

  34. Hope

    There isn’t one universal complexity measure for every problem. The norm of the parameter vector is one useful measure in some settings, especially for linear models, but the right choice depends on the situation.

  35. Simon

    The norm explanation also suggests a way to reduce the peak: explicitly encourage the learned parameters to have a smaller norm. That means balancing the training loss against a preference for smaller parameter values. This is a form of regularization, which we’ll examine more closely next time.

  36. Hope

    But regularization isn’t the only possible explanation for the second descent. Even without an explicit penalty in the loss, the optimization algorithm can sometimes favor solutions with smaller norms. That’s called an implicit regularization effect: the algorithm creates a preference that wasn’t directly written into the objective.

  37. Simon

    So the main lesson is that model complexity, data quantity, and the learning algorithm all affect generalization. Bias and variance explain a useful classic trade-off, while double descent shows that performance can behave differently in highly parameterized settings. To choose a model in practice, we use held-out validation data rather than relying on complexity alone.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent