How a Multilayer Network Learns Using Gradient Descent
A multilayer network learns by repeatedly adjusting its parameters so that its predictions become closer to the desired targets. The central training cycle combines four ideas:
- Forward propagation computes a prediction.
- A loss function measures prediction error.
- Backpropagation computes how each parameter contributed to that error.
- Gradient descent updates the parameters to reduce future error.
A multilayer perceptron (MLP) is a feed-forward network in which each layer typically performs an affine transformation followed by an activation function. For layer :
Here, is the weight matrix, is the bias vector, is the pre-activation, is the activation, and is the activation function.
The network does not directly “know” the correct weights. It begins with initialized parameters and learns through many small, directed changes determined by the gradient of the loss.
Footnotes
-
Multilayer perceptrons for digit recognition with Core APIs - TensorFlow explanation of dense layers, activations, and cross-entropy. ↩
-
Gradient Descent - Stanford CS231n discussion of loss optimization and gradient descent. ↩
Core idea
The gradient points in the direction of greatest increase in loss. Gradient descent moves in the opposite direction, because the objective is to minimize loss.
1. The components of a learning problem
A supervised learning problem supplies training examples:
where is an input and is its target output.
The network contains a collection of learnable parameters:
The loss function evaluates the quality of the prediction. The training objective is to minimize the average loss:
For multiclass classification, a common choice is cross-entropy:
where is the number of classes, is the target indicator, and is the predicted probability.
For regression, mean squared error is often used:
The network learns when the loss provides a signal that tells each parameter how its value should change.
Footnotes
-
Multilayer perceptrons for digit recognition with Core APIs - TensorFlow explanation of dense layers, activations, and cross-entropy. ↩
Essential terminology
2. Forward propagation
During forward propagation, information moves from left to right through the network.
Consider a network with two hidden layers:
The output layer then produces . For classification, the output may use softmax:
The activations and pre-activations are stored because backpropagation needs them to calculate derivatives efficiently.
The nonlinear activation functions are essential. Without them, composing multiple affine transformations would still produce one affine transformation, so additional layers would not increase the network’s expressive power. Common choices include ReLU:
and sigmoid:
Footnotes
-
Waybackprop - TensorFlow explanation of forward computation, reverse differentiation, and stored activations. ↩
Common activation functions
Qualitative comparison of activation behavior and typical use
3. The loss landscape and the gradient
After the forward pass, the prediction is compared with the target. This produces a scalar loss .
The gradient with respect to all parameters is:
Each component answers a local sensitivity question:
If this parameter increases slightly, will the loss increase or decrease, and by how much?
For a single parameter :
- : increasing increases the loss, so it should generally be decreased.
- : increasing decreases the loss, so it should generally be increased.
- : the parameter has little local effect on the current loss.
The negative gradient is the direction of steepest local decrease. Therefore, the basic gradient descent update is:
where is the learning rate and indexes the training step.
Footnotes
-
A Tutorial on Deep Learning Part 1 - Stanford tutorial covering backpropagation, stochastic gradient descent, and gradient behavior. ↩
Learning-rate trade-off
A learning rate that is too large can cause oscillation or divergence. A learning rate that is too small can make training extremely slow or leave the model apparently stuck.
4. Why backpropagation is needed
A multilayer network is a nested composition of functions:
The loss depends directly on the output, but it depends indirectly on parameters in earlier layers. To find the effect of an early parameter, the chain rule is applied through every subsequent computation.
For a parameter in layer :
Backpropagation evaluates these derivatives from the output layer backward. It reuses intermediate results rather than separately differentiating the complete network for every parameter.2
For a dense layer:
define the error signal:
Then:
and the error signal for the previous layer is:
where denotes elementwise multiplication.
This recurrence explains how an output error is transmitted backward and converted into gradients for each layer.
Footnotes
-
Waybackprop - TensorFlow explanation of forward computation, reverse differentiation, and stored activations. ↩
-
Backpropagation - Stanford CS231n explanation of the chain rule and efficient reverse-mode gradient computation. ↩
One complete gradient-descent training step
- 1Step 1
Choose inputs and corresponding targets . A mini-batch provides a computationally efficient estimate of the full-dataset gradient.
- 2Step 2
Use the current weights and biases . Parameters are commonly initialized with small, variance-aware random values rather than identical constants.
- 3Step 3
Compute each layer’s pre-activation and activation until the network produces .
- 4Step 4
Evaluate , such as cross-entropy for classification or mean squared error for regression.
- 5Step 5
Start with the derivative of the loss at the output and apply the chain rule backward through every layer to obtain .
- 6Step 6
Apply . Every weight and bias is adjusted simultaneously.
- 7Step 7
Track loss and suitable metrics on training and validation data. Learning is useful only if performance improves without unacceptable overfitting.
- 8Step 8
Continue for many mini-batches and epochs until a stopping condition is reached, such as a validation criterion, a maximum epoch count, or insufficient improvement.
5. Deriving the update for a two-layer network
Consider a two-layer network:
where may be softmax.
For the output layer, calculate:
For softmax combined with cross-entropy, this simplifies to:
The output-layer gradients are:
Propagate the error into the hidden layer:
Then calculate:
Finally, update:
and similarly for and .
The important point is that the hidden layer is not given a direct target. Its learning signal is inferred from how its activations affect later layers and, ultimately, the loss.
6. Batch, stochastic, and mini-batch gradient descent
The exact objective averages loss over all training examples:
Three common estimation strategies are used:
| Method | Examples per update | Main characteristic |
|---|---|---|
| Batch gradient descent | All examples | Accurate gradient estimate but potentially expensive |
| Stochastic gradient descent | 1 example | Frequent, noisy updates |
| Mini-batch gradient descent | A subset | Practical compromise used widely in neural-network training |
For a mini-batch :
The update becomes:
Mini-batches enable vectorized computation and produce a gradient estimate that is usually less noisy than a single-example update. The noise in stochastic or mini-batch updates can sometimes help optimization move away from shallow or unfavorable regions, but it also makes the loss curve fluctuate.
Footnotes
-
A Tutorial on Deep Learning Part 1 - Stanford tutorial covering backpropagation, stochastic gradient descent, and gradient behavior. ↩
Gradient-estimation strategies
Conceptual comparison; larger values indicate more computation per update or more gradient noise
7. What the network is actually learning
A multilayer network learns a hierarchy of representations.
- Early layers may learn simple combinations of input features.
- Intermediate layers combine these into more useful patterns.
- Later layers transform those representations into task-specific outputs.
This behavior is not programmed as a list of explicit rules. It emerges because gradient descent changes parameters in whatever way reduces the loss on the training data.
The network’s prediction can be viewed as a function:
Training searches for parameter values that produce low empirical risk:
Because neural-network loss surfaces are generally non-convex, gradient descent is not guaranteed to find the globally best parameter configuration. Nevertheless, the repeated local updates are effective in many practical settings.
Footnotes
-
A Tutorial on Deep Learning Part 1 - Stanford tutorial covering backpropagation, stochastic gradient descent, and gradient behavior. ↩
Lifecycle of learning
Set initial parameters
InitializationWeights and biases receive initial values, usually using a variance-aware initialization."
Compute predictions
Forward passInputs are transformed through successive affine layers and nonlinear activations."
Measure error
Loss evaluationThe prediction is compared with the target using a task-appropriate loss function."
Compute gradients
Backward passBackpropagation applies the chain rule from the output toward the input."
Take a descent step
Parameter updateWeights and biases move opposite the estimated gradient."
Repeat over epochs
IterationThe cycle continues while monitoring loss, accuracy, and generalization."
Debugging principle
If loss does not decrease, inspect the data scale, target encoding, output activation, loss function, learning rate, gradient magnitudes, and parameter initialization before changing the architecture.
8. Learning-rate schedules and adaptive optimizers
The basic update uses a fixed , but practical training often changes the learning rate over time. A schedule may reduce the step size as optimization approaches a useful region.
A simple decay rule is:
where is the initial learning rate and controls decay.
Momentum adds a running direction to reduce oscillation:
Adaptive methods such as Adam maintain estimates of the first and second moments of gradients:
with bias-corrected estimates used to scale parameter updates. These methods remain gradient-based: backpropagation still supplies the derivatives, while the optimizer determines how to use them.
Footnotes
-
Introduction to gradients and automatic differentiation - TensorFlow guide connecting automatic differentiation with neural-network training. ↩
Common difficulties
9. A compact pseudocode implementation
The essential training loop can be expressed as follows:
1initialize parameters theta 2 3for epoch in range(number_of_epochs): 4 shuffle(training_data) 5 6 for X_batch, Y_batch in mini_batches: 7 # Forward propagation 8 activations = forward(X_batch, theta) 9 10 # Loss 11 loss = compute_loss(activations.output, Y_batch) 12 13 # Backpropagation 14 gradients = backward( 15 X_batch, 16 Y_batch, 17 activations, 18 theta 19 ) 20 21 # Gradient-descent update 22 for parameter in theta: 23 parameter -= learning_rate * gradients[parameter]
Automatic differentiation systems perform the derivative bookkeeping, but the conceptual sequence remains forward computation, loss evaluation, reverse differentiation, and parameter update.
Footnotes
-
Multilayer perceptrons for digit recognition with Core APIs - TensorFlow training-loop example showing batch loss, gradients, and parameter updates. ↩
Worked conceptual example
- 1Step 1
Suppose the target class is represented by , while the network predicts .
- 2Step 2
With softmax and cross-entropy, the output error signal is .
- 3Step 3
The negative component for the correct class indicates that increasing its output score would reduce the loss. Positive components indicate excessive probability assigned to incorrect classes.
- 4Step 4
The output error is multiplied by transposed weight matrices and activation derivatives to determine how hidden units contributed to the error.
- 5Step 5
Each weight receives a gradient. A positive gradient causes gradient descent to reduce that weight; a negative gradient causes it to increase, subject to the learning rate.
- 6Step 6
After many updates over varied examples, the network tends to assign higher probability to correct outputs while learning internal representations useful for the task.
10. How to evaluate whether learning is working
Training loss should generally decrease, but loss alone is insufficient. A robust evaluation separates:
- Training data: used to calculate gradients.
- Validation data: used to select settings and detect overfitting.
- Test data: held out for final evaluation.
Useful diagnostics include:
- Plot training and validation loss by epoch.
- Compare training and validation accuracy where appropriate.
- Inspect gradient norms.
- Check whether activations are saturated or inactive.
- Verify that labels and output dimensions are correct.
- Compare against a simple baseline.
A typical healthy pattern is decreasing training loss with validation loss that decreases initially and then levels off. If training loss continues to fall while validation loss rises, the model is likely overfitting.
Gradient descent and backpropagation review
Do not confuse backpropagation with gradient descent
Backpropagation computes the gradients. Gradient descent, or another optimizer, uses those gradients to update the parameters. They are complementary but distinct parts of training.
11. Summary model
A multilayer network learns through the following mathematical cycle:
In compact form:
The network improves because each update uses the current error to modify every parameter in a direction expected to reduce that error. Backpropagation supplies efficient credit assignment across layers, while gradient descent supplies the optimization rule that turns those gradients into learning.3
Footnotes
-
Gradient Descent - Stanford CS231n discussion of loss optimization and gradient descent. ↩
-
Waybackprop - TensorFlow explanation of forward computation, reverse differentiation, and stored activations. ↩
-
Backpropagation - Stanford CS231n explanation of the chain rule and efficient reverse-mode gradient computation. ↩
Knowledge Check
What is the primary purpose of backpropagation in a multilayer network?
Explore Related Topics
Machine Learning Fundamentals
Machine learning is a subfield of artificial intelligence that focuses on the development of algorithms and statistical models that enable computer systems to improve their performance on a specific task through experience, without being explicitly programmed. Unlike traditional rule-based programmi
Active Learning for Label-Efficient Supervised Learning
How to become a Machine Learning Engineer
Becoming a Machine Learning Engineer requires a blend of formal education, hands‑on projects, MLOps skills, and a clear career roadmap.
- Start with a bachelor’s in CS, math, statistics, or a related field.
- Spend the first 3 months mastering Python, linear algebra, probability, and statistics.
- Build end‑to‑end ML projects and log experiment metrics for a portfolio.
- Learn MLOps tools (Docker, MLflow, CI/CD) and deploy models to cloud platforms.
- Advance from entry‑level to senior roles, adding soft‑skill training and certifications.