Neural Network Backpropagation
Generalization, Bias–Variance Trade-Off, and Double Descent
Backpropagation: How Gradients Flow Through a Network
A neural network can be viewed as a sequence of modules. In a simple layer, an input is combined with weights and biases to produce a pre-activation, which is then transformed into an activation. Repeating this process produces the model’s final output. A loss function compares that output with the desired target.
For example, a layer may compute a pre-activation zℓ from the previous activation aℓ−1, weights Wℓ, and biases bℓ, and then compute the activation aℓ:
Here, σ is the layer’s activation function. The full sequence from input to prediction and loss is the forward pass.
The backward pass
Backpropagation computes derivatives in the reverse direction, beginning with the loss and working back through the network. If the model output is τ and the loss is J, the computation typically proceeds from ∂τ∂J toward derivatives with respect to earlier activations, pre-activations, weights, and biases.
For a network with two hidden transformations, a simplified dependency order is:
Compute the derivative of the loss with respect to the output, ∂τ∂J.
Use it to compute the derivative with respect to the final pre-activation, such as ∂z2∂J.
Propagate that derivative backward to the preceding activation, such as ∂a1∂J.
Continue backward through earlier pre-activations and activations.
At each layer, use the available derivatives to compute gradients with respect to that layer’s weights and biases.
For example, a squared-error loss may have the form
Its derivative with respect to τ is straightforward to compute. Once that output derivative is known, the chain rule passes gradient information backward through the network.
Key idea: Backpropagation applies local derivative relationships in a specific dependency order. The derivative with respect to an earlier activation cannot be computed until the gradient from the later part of the network has been propagated back to it.
The backward dependencies and the parameter gradients have different roles:
Activation gradients must be propagated sequentially from later layers to earlier layers.
Weight and bias gradients can be computed for a layer once the gradient reaching that layer is available. These parameter gradients are associated with the layer’s local computation.
The local relationships used in backpropagation are applications of the chain rule. A module’s input gradient is derived from its output gradient and the module’s local derivative; its parameter gradients are derived from the same local computation.
Training Performance and Generalization
Training loss
The training loss measures how well a model performs on the examples used to fit it. It is also sometimes called training error, training cost, or tuning loss. These terms can have distinct meanings in some contexts, but they refer to the same general idea here: performance on the training data.
For a dataset of n examples, a common empirical training loss is
where θ denotes the model parameters, fθ(xi) is the model’s prediction, yi is the target, and ℓ is the loss on one example.
The training loss depends on the chosen loss function. Examples include:
Squared loss, which penalizes squared differences between predictions and targets.
Cross-entropy loss, often used for classification.
Negative log-likelihood, which can be derived by fitting a maximum-likelihood model to the training data.
Training methods aim to find parameters that reduce this training objective. Some problems permit analytical solutions; others use numerical optimization methods such as gradient descent, stochastic gradient descent, or Newton’s method.
Test loss and the test distribution
A model is useful only if it performs well beyond the examples it has already seen. Generalization describes a model’s ability to perform on new, unseen examples drawn from the relevant data distribution.
Let (X,Y) be a fresh example drawn from a test distribution D. The expected test loss of a model with parameters θ is
This expectation averages over all possible test examples according to D. In practice, the distribution is not usually available in a form that allows direct calculation of this expectation. Instead, a finite test set is sampled from the distribution, and its average loss is used as an estimate:
The test examples must be kept out of the process used to choose or fit the model. Otherwise, the model-selection process can adapt to the test set, making its measured performance less representative of genuinely unseen data.
Generalization gap
The generalization gap is the difference between test loss and training loss. One common convention is
The observed test loss may be close to the training loss, moderately larger, or substantially larger. In practical settings, test loss is commonly higher because the model has been optimized directly on the training examples but not on the test examples.
Two goals therefore matter:
Keep the training loss small.
Keep the generalization gap small.
Together, these help produce a small test loss. Training loss can be directly optimized because the training data are available. Test loss cannot be directly optimized without using the test data to select parameters, which would undermine the purpose of testing. Understanding and controlling generalization is therefore a central challenge in machine learning.
Underfitting and Overfitting
When test performance is poor, two common failure patterns are underfitting and overfitting. They are useful descriptions of typical situations, rather than an exhaustive list of every possible cause of poor performance.
Underfitting
A model underfits when it cannot represent the important structure in the data. Its training loss is high, and its test loss is often high as well.
For example, suppose the true relationship between a one-dimensional input x and target y is approximately quadratic, but a straight-line model is used. No matter how many examples are observed, a straight line cannot exactly represent a genuinely curved relationship. The model’s restricted form prevents it from fitting the underlying pattern well.
Underfitting is often associated with high bias: the model family makes assumptions that are too restrictive for the problem.
Overfitting
A model overfits when it fits the training examples very closely but performs poorly on new examples. A common sign is low training loss together with substantially higher test loss.
Suppose a small dataset contains a few noisy observations around a smooth quadratic trend. A highly flexible curve might pass exactly through every training point, including the accidental fluctuations caused by noise. That curve can have nearly zero training loss while making poor predictions at new inputs.
Overfitting is not simply “having a complex model.” It occurs when the model fits idiosyncrasies of the observed sample that do not reflect stable structure in the underlying data distribution.
Bias and Variance
The bias–variance perspective helps explain how model flexibility, data quantity, and test performance relate to one another.
Bias: limitations of the model family
Bias is associated with systematic error caused by limitations or assumptions of the model family. A linear model has high bias for a problem whose true relationship is strongly nonlinear because the model family cannot express that relationship.
One useful intuition is to imagine that the model had access to an arbitrarily large amount of data from the same distribution. If the best model in the chosen family would still make substantial error, the model family has significant approximation error, or bias.
For instance, if the true relationship is quadratic but the chosen family contains only straight lines, more observations can reveal the curved pattern more accurately, but they cannot make a straight line represent it. The limitation comes from the model family, not merely from having too few examples.
Variance: sensitivity to the sampled data
Variance describes how much the learned model changes when the training sample changes. To assess this conceptually, imagine drawing several datasets from the same distribution and fitting the same learning procedure to each one.
If the resulting models are similar, the procedure has relatively low variance.
If small changes in the sampled examples produce very different models, it has relatively high variance.
A high-degree polynomial fitted to only a few noisy observations can be very sensitive to the particular points observed. A second sample with slightly different noise may yield a substantially different polynomial and very different predictions.
Variance can often be reduced by:
Collecting more examples from the same distribution.
Using a less flexible model.
Restricting or regularizing the model’s parameters.
These remedies are related: a very flexible model may be unstable with a small dataset, while the same model may become more stable with enough representative data.
Bias–variance trade-off
As model complexity increases, the model can typically represent a wider range of patterns. This tends to reduce bias, because the model becomes less restricted. But a more flexible model can also adapt more strongly to the particular training sample, increasing variance.
The classical picture is:
Bias tends to decrease as model complexity increases.
Variance tends to increase as model complexity increases.
Test error may be lowest at an intermediate complexity, where the two effects are balanced.
For squared-error prediction, test error can be decomposed into a bias-related term, a variance-related term, and—in the usual setting—an irreducible noise term. A simplified description is often called a bias–variance decomposition. It is important to distinguish this formal decomposition from the broader intuition: the exact mathematical form depends on the loss and modeling assumptions.
The location of the best balance is problem-dependent. It depends on factors such as the true relationship, the amount of data, and the level of noise. For a nearly quadratic relationship, a quadratic model may be both expressive enough and relatively simple. For a different task, a more complex family may be needed.
Limits of direct measurement
Bias and variance are valuable explanatory concepts, but they are usually not quantities that can be measured exactly in a real application:
The true data-generating relationship is unknown, making bias difficult to calculate directly.
Only a finite number of datasets are available, so variation across all possible training samples cannot generally be measured exactly.
In practice, training and validation performance help diagnose likely problems. High training loss may indicate that the model is too restricted or that optimization has failed; a large difference between training and validation performance may indicate overfitting. These observations are clues, not exact measurements of bias and variance.
For many losses, the classical mathematical bias–variance decomposition is not as straightforward as it is for squared loss. For example, extending the exact decomposition to cross-entropy involves additional complications. The intuition that restricted models can miss structure and flexible models can be sample-sensitive remains useful, even when a simple formal decomposition is unavailable.
Polynomial-Fitting Example
Consider noisy observations generated around a quadratic relationship:
Here, h∗ is the underlying relationship and εi represents noise. The observations do not lie exactly on the underlying curve because of these noise fluctuations.
Linear model
A line may be unable to capture the underlying curvature. Its predictions can systematically miss the observations, resulting in high training loss. This is an example of underfitting and high bias.
More data can clarify the quadratic pattern, but a linear model still cannot represent it adequately. The limitation is the model family itself.
Fifth-degree polynomial with few observations
A fifth-degree polynomial is much more flexible. With only a few observations, it may be able to pass through every training point, including the fluctuations caused by noise. The training loss can then be very small, but the curve may behave erratically between or beyond the observed points.
This is overfitting: the model explains sample-specific noise instead of only capturing the underlying quadratic trend.
What more data can do
If many more observations are collected from the same distribution and a high-degree polynomial is fitted, an erratic curve that misses much of the data will have a poor training fit. A more stable curve closer to the underlying trend can achieve lower error across the larger dataset. Although the fitted model may technically remain a high-degree polynomial, its higher-order coefficients may be small, making its behavior effectively close to that of a simpler curve.
This example illustrates why flexibility and data quantity interact. A flexible model can be unstable with little data but can be estimated more reliably when many representative examples constrain its behavior.
Choosing Model Complexity in Practice
The bias–variance framework explains why model complexity matters, but it usually does not provide an exact calculation of the best complexity for a real task.
A common practical approach is to compare candidate models on a validation set. The validation set is separate from the training set and is used to choose among models or training choices. It is distinct from the final test set, which should remain unused during model selection.
The bias–variance picture can guide experimentation:
If training loss is high, a model may be too limited; testing a more expressive model may help.
If training loss is low but validation loss is much higher, a model may be overfitting; a simpler model, more data, or regularization may help.
If a model is already in a regime where greater complexity is expected to worsen performance, trying even more complex models may be less promising than exploring nearby alternatives.
These are diagnostic principles, not guarantees. Validation performance provides empirical evidence for choosing a model; bias and variance help interpret why different models behave differently.
Double Descent
The classical bias–variance account predicts that test error often follows a roughly U-shaped curve as model complexity increases: test error falls as the model becomes expressive enough, then rises as fitting becomes increasingly sensitive to the training sample.
However, experiments have revealed an additional pattern called double descent. In some settings, test error decreases, rises sharply near a transition point, and then decreases again as model complexity increases further.
Model-wise double descent
In model-wise double descent, the horizontal axis measures model size or complexity, often represented by the number of parameters D.
The pattern has three broad regions:
Underparameterized region: The model has too little capacity to fit the training data well. Increasing the number of parameters can improve test performance.
Near the interpolation threshold: The model is just large enough to fit the training examples, and test error may peak.
Overparameterized region: The model has more parameters than training examples and can fit the training data, yet its test error may decrease as the model becomes still larger.
This contrasts with a simple classical account in which increasing complexity beyond the best intermediate point would always worsen generalization.
Data-wise double descent
A related pattern occurs when the number of training examples, n, changes while model size is held fixed. Data-wise double descent describes a test-error curve that can initially decrease, rise near a critical point, and then decrease again as still more training data are added.
For relatively simple models, the peak is often associated with a regime where the number of examples is close to the number of model parameters. The exact relationship depends on the model and setting; the threshold should not be treated as a universal rule for all nonlinear systems.
The two patterns are related:
Model-wise double descent varies model size relative to the amount of data.
Data-wise double descent varies the amount of data relative to model size.
Both draw attention to behavior near the point where model capacity and dataset size are comparable.
Why double descent matters
The overparameterized region was historically often regarded as undesirable because having more parameters than examples might seem to allow the model to memorize the training data. Yet many modern machine-learning systems, especially deep-learning systems, are trained in regimes with far more parameters than training examples and can still generalize effectively.
The phenomenon is not universal: curves may have different shapes in different problems, and the behavior depends on the data, model, and learning procedure. Nevertheless, double descent shows that model size alone does not determine generalization in the simple way suggested by a single U-shaped curve.
Explanations for the Double-Descent Peak
Many theoretical analyses of double descent focus on linear models. Even within a linear model family, complexity can change by adding or removing features. For example, a model might begin with one feature and gradually use more features, increasing the number of parameters.
Instability near the interpolation threshold
In certain linear-model settings, common learning procedures such as gradient descent or stochastic gradient descent can produce parameter vectors with very large norms when the number of examples is close to the number of parameters.
If model complexity is measured only by parameter count, this behavior may seem surprising: the model can have many parameters, yet its coefficients can also be unusually large near the threshold. A large coefficient norm can make predictions sensitive to changes in the input or training sample, contributing to poor test performance.
The peak is therefore not necessarily evidence that every model with a parameter count near the sample count must generalize badly. It can arise from the interaction between the data, the model, and the particular learning procedure used.
Parameter norms as a measure of complexity
The number of parameters is not always a complete measure of effective model complexity. A model with many parameters may behave simply if most parameters are very small or have little influence. Conversely, a model with fewer parameters may behave sensitively if its coefficients are large.
For linear models, a parameter norm can provide another measure of complexity. In particular, an L2 norm is often useful in mathematical analyses, though no single complexity measure is best for every problem. Complexity may be described through different norms, restrictions, or properties of the learned function, depending on the setting.
Regularization and the peak
Regularization modifies learning to favor models with desirable properties, such as smaller parameter norms, often by balancing training fit against a penalty on complexity. In a simple example, the objective may combine training loss with a term that penalizes the squared norm of the parameters:
The coefficient λ controls the strength of the penalty. A stronger penalty can reduce the norm but may also increase training loss, so the two objectives must be balanced.
In some linear-model settings, explicitly controlling the norm reduces the large peak near the interpolation threshold. This supports the idea that part of the peak arises because the learning procedure produces overly large-norm solutions in that region.
Why Error Can Decrease Again in the Overparameterized Regime
The peak does not explain the whole double-descent curve. A further question is why test error can fall again when the model becomes much larger than the dataset.
One explanation in studied settings is implicit regularization. A learning algorithm can favor certain solutions even when its stated loss function contains no explicit norm penalty. For example, among many parameter settings that fit the training data, the optimization procedure may tend to select a solution with a relatively small norm or otherwise favorable structure.
This effect is called implicit because it comes from the learning procedure itself rather than from an explicitly written regularization term. It helps explain why a highly parameterized model does not necessarily behave like an arbitrary model capable of memorizing anything: the optimization process can prefer particular solutions that generalize better.
The role of implicit regularization depends on the architecture, algorithm, data, and training setup. It is not a universal guarantee that increasing the number of parameters will improve test performance. Instead, it shows why parameter count alone is insufficient to predict generalization.
Key Takeaways
Training loss measures performance on the examples used to fit the model; test loss estimates performance on new examples from the target distribution.
The generalization gap describes the difference between test and training performance. A model can have low training loss yet high test loss.
Underfitting is commonly associated with a model family that is too restricted and has high bias. Overfitting is commonly associated with a model that adapts too strongly to sample-specific patterns and has high variance.
Increasing model flexibility can reduce bias but may increase sensitivity to the training sample. More data and appropriate regularization can reduce instability.
The classical bias–variance picture is useful, but the best model complexity depends on the problem, and exact decompositions depend on the loss and assumptions.
Double descent shows that test error can rise near an interpolation threshold and then fall again in an overparameterized regime.
Parameter count is not the only measure of complexity. Parameter norms and the implicit preferences of the optimization procedure can also affect generalization.

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