How a Multilayer Network Learns Using Gradient Descent

How a Multilayer Network Learns Using Gradient Descent

Verified Sources
Sep 11, 2026

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:

  1. Forward propagation computes a prediction.
  2. A loss function measures prediction error.
  3. Backpropagation computes how each parameter contributed to that error.
  4. 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 ll:

z(l)=W(l)a(l1)+b(l)\mathbf{z}^{(l)}=\mathbf{W}^{(l)}\mathbf{a}^{(l-1)}+\mathbf{b}^{(l)} a(l)=g(l)(z(l))\mathbf{a}^{(l)}=g^{(l)}(\mathbf{z}^{(l)})

Here, W(l)\mathbf{W}^{(l)} is the weight matrix, b(l)\mathbf{b}^{(l)} is the bias vector, z(l)\mathbf{z}^{(l)} is the pre-activation, a(l)\mathbf{a}^{(l)} is the activation, and g(l)g^{(l)} 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

  1. Multilayer perceptrons for digit recognition with Core APIs - TensorFlow explanation of dense layers, activations, and cross-entropy.

  2. 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:

D={(xi,yi)}i=1N\mathcal{D}=\{(\mathbf{x}_i,\mathbf{y}_i)\}_{i=1}^{N}

where xi\mathbf{x}_i is an input and yi\mathbf{y}_i is its target output.

The network contains a collection of learnable parameters:

θ={W(1),b(1),,W(L),b(L)}\boldsymbol{\theta}=\{\mathbf{W}^{(1)},\mathbf{b}^{(1)},\ldots,\mathbf{W}^{(L)},\mathbf{b}^{(L)}\}

The loss function evaluates the quality of the prediction. The training objective is to minimize the average loss:

J(θ)=1Ni=1NL(f(xi;θ),yi)J(\boldsymbol{\theta})= \frac{1}{N}\sum_{i=1}^{N} \mathcal{L}\left(f(\mathbf{x}_i;\boldsymbol{\theta}),\mathbf{y}_i\right)

For multiclass classification, a common choice is cross-entropy:

L(y,y^)=k=1Kyklog(y^k)\mathcal{L}(\mathbf{y},\hat{\mathbf{y}}) = -\sum_{k=1}^{K}y_k\log(\hat{y}_k)

where KK is the number of classes, yky_k is the target indicator, and y^k\hat{y}_k is the predicted probability.

For regression, mean squared error is often used:

L(y,y^)=12y^y2\mathcal{L}(\mathbf{y},\hat{\mathbf{y}}) = \frac{1}{2}\|\hat{\mathbf{y}}-\mathbf{y}\|^2

The network learns when the loss provides a signal that tells each parameter how its value should change.

Footnotes

  1. 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:

a(0)=x\mathbf{a}^{(0)}=\mathbf{x} z(1)=W(1)x+b(1)\mathbf{z}^{(1)}=\mathbf{W}^{(1)}\mathbf{x}+\mathbf{b}^{(1)} a(1)=g(1)(z(1))\mathbf{a}^{(1)}=g^{(1)}(\mathbf{z}^{(1)}) z(2)=W(2)a(1)+b(2)\mathbf{z}^{(2)}=\mathbf{W}^{(2)}\mathbf{a}^{(1)}+\mathbf{b}^{(2)} a(2)=g(2)(z(2))\mathbf{a}^{(2)}=g^{(2)}(\mathbf{z}^{(2)}) z(3)=W(3)a(2)+b(3)\mathbf{z}^{(3)}=\mathbf{W}^{(3)}\mathbf{a}^{(2)}+\mathbf{b}^{(3)}

The output layer then produces y^\hat{\mathbf{y}}. For classification, the output may use softmax:

y^k=ezk(3)j=1Kezj(3)\hat{y}_k= \frac{e^{z_k^{(3)}}} {\sum_{j=1}^{K}e^{z_j^{(3)}}}

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:

g(z)=max(0,z)g(z)=\max(0,z)

and sigmoid:

σ(z)=11+ez\sigma(z)=\frac{1}{1+e^{-z}}

Footnotes

  1. 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 JJ.

The gradient with respect to all parameters is:

θJ=[Jθ1,Jθ2,,JθP]\nabla_{\boldsymbol{\theta}}J = \left[ \frac{\partial J}{\partial \theta_1}, \frac{\partial J}{\partial \theta_2}, \ldots, \frac{\partial J}{\partial \theta_P} \right]

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 θj\theta_j:

  • Jθj>0\frac{\partial J}{\partial \theta_j}>0: increasing θj\theta_j increases the loss, so it should generally be decreased.
  • Jθj<0\frac{\partial J}{\partial \theta_j}<0: increasing θj\theta_j decreases the loss, so it should generally be increased.
  • Jθj0\frac{\partial J}{\partial \theta_j}\approx 0: 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:

θt+1=θtηθJ(θt)\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \eta\nabla_{\boldsymbol{\theta}}J(\boldsymbol{\theta}_t)

where η>0\eta>0 is the learning rate and tt indexes the training step.

Footnotes

  1. 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:

y^=f(L)(f(L1)(f(2)(f(1)(x))))\hat{\mathbf{y}} = f^{(L)} \left( f^{(L-1)} \left( \cdots f^{(2)} \left( f^{(1)}(\mathbf{x}) \right) \cdots \right) \right)

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 θ\theta in layer ll:

Jθ=Ja(L)a(L)z(L)a(l)z(l)z(l)θ\frac{\partial J}{\partial \theta} = \frac{\partial J}{\partial \mathbf{a}^{(L)}} \frac{\partial \mathbf{a}^{(L)}}{\partial \mathbf{z}^{(L)}} \cdots \frac{\partial \mathbf{a}^{(l)}}{\partial \mathbf{z}^{(l)}} \frac{\partial \mathbf{z}^{(l)}}{\partial \theta}

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:

z(l)=W(l)a(l1)+b(l)\mathbf{z}^{(l)} = \mathbf{W}^{(l)}\mathbf{a}^{(l-1)} + \mathbf{b}^{(l)}

define the error signal:

δ(l)=Jz(l)\boldsymbol{\delta}^{(l)} = \frac{\partial J}{\partial \mathbf{z}^{(l)}}

Then:

JW(l)=δ(l)(a(l1))T\frac{\partial J}{\partial \mathbf{W}^{(l)}} = \boldsymbol{\delta}^{(l)} \left(\mathbf{a}^{(l-1)}\right)^T Jb(l)=δ(l)\frac{\partial J}{\partial \mathbf{b}^{(l)}} = \boldsymbol{\delta}^{(l)}

and the error signal for the previous layer is:

δ(l1)=(W(l))Tδ(l)g(l1)(z(l1))\boldsymbol{\delta}^{(l-1)} = \left(\mathbf{W}^{(l)}\right)^T \boldsymbol{\delta}^{(l)} \odot g'^{(l-1)}\left(\mathbf{z}^{(l-1)}\right)

where \odot denotes elementwise multiplication.

This recurrence explains how an output error is transmitted backward and converted into gradients for each layer.

Footnotes

  1. Waybackprop - TensorFlow explanation of forward computation, reverse differentiation, and stored activations.

  2. Backpropagation - Stanford CS231n explanation of the chain rule and efficient reverse-mode gradient computation.

One complete gradient-descent training step

  1. 1
    Step 1

    Choose inputs X\mathbf{X} and corresponding targets Y\mathbf{Y}. A mini-batch provides a computationally efficient estimate of the full-dataset gradient.

  2. 2
    Step 2

    Use the current weights and biases θt\boldsymbol{\theta}_t. Parameters are commonly initialized with small, variance-aware random values rather than identical constants.

  3. 3
    Step 3

    Compute each layer’s pre-activation z(l)\mathbf{z}^{(l)} and activation a(l)\mathbf{a}^{(l)} until the network produces Y^\hat{\mathbf{Y}}.

  4. 4
    Step 4

    Evaluate L(Y,Y^)\mathcal{L}(\mathbf{Y},\hat{\mathbf{Y}}), such as cross-entropy for classification or mean squared error for regression.

  5. 5
    Step 5

    Start with the derivative of the loss at the output and apply the chain rule backward through every layer to obtain ablaθJ abla_{\boldsymbol{\theta}}J.

  6. 6
    Step 6

    Apply θt+1=θtηablaθJ\boldsymbol{\theta}_{t+1}=\boldsymbol{\theta}_t-\eta abla_{\boldsymbol{\theta}}J. Every weight and bias is adjusted simultaneously.

  7. 7
    Step 7

    Track loss and suitable metrics on training and validation data. Learning is useful only if performance improves without unacceptable overfitting.

  8. 8
    Step 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:

z(1)=W(1)x+b(1)\mathbf{z}^{(1)}=\mathbf{W}^{(1)}\mathbf{x}+\mathbf{b}^{(1)} a(1)=g(z(1))\mathbf{a}^{(1)}=g(\mathbf{z}^{(1)}) z(2)=W(2)a(1)+b(2)\mathbf{z}^{(2)}=\mathbf{W}^{(2)}\mathbf{a}^{(1)}+\mathbf{b}^{(2)} y^=s(z(2))\hat{\mathbf{y}}=s(\mathbf{z}^{(2)})

where ss may be softmax.

For the output layer, calculate:

δ(2)=Jz(2)\boldsymbol{\delta}^{(2)} = \frac{\partial J}{\partial \mathbf{z}^{(2)}}

For softmax combined with cross-entropy, this simplifies to:

δ(2)=y^y\boldsymbol{\delta}^{(2)} = \hat{\mathbf{y}}-\mathbf{y}

The output-layer gradients are:

JW(2)=δ(2)(a(1))T\frac{\partial J}{\partial \mathbf{W}^{(2)}} = \boldsymbol{\delta}^{(2)} \left(\mathbf{a}^{(1)}\right)^T Jb(2)=δ(2)\frac{\partial J}{\partial \mathbf{b}^{(2)}} = \boldsymbol{\delta}^{(2)}

Propagate the error into the hidden layer:

δ(1)=(W(2))Tδ(2)g(z(1))\boldsymbol{\delta}^{(1)} = \left(\mathbf{W}^{(2)}\right)^T \boldsymbol{\delta}^{(2)} \odot g'(\mathbf{z}^{(1)})

Then calculate:

JW(1)=δ(1)xT\frac{\partial J}{\partial \mathbf{W}^{(1)}} = \boldsymbol{\delta}^{(1)} \mathbf{x}^T Jb(1)=δ(1)\frac{\partial J}{\partial \mathbf{b}^{(1)}} = \boldsymbol{\delta}^{(1)}

Finally, update:

W(1)W(1)ηJW(1)\mathbf{W}^{(1)} \leftarrow \mathbf{W}^{(1)} - \eta \frac{\partial J}{\partial \mathbf{W}^{(1)}} b(1)b(1)ηJb(1)\mathbf{b}^{(1)} \leftarrow \mathbf{b}^{(1)} - \eta \frac{\partial J}{\partial \mathbf{b}^{(1)}}

and similarly for W(2)\mathbf{W}^{(2)} and b(2)\mathbf{b}^{(2)}.

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 NN training examples:

J(θ)=1Ni=1NLi(θ)J(\boldsymbol{\theta}) = \frac{1}{N} \sum_{i=1}^{N} \mathcal{L}_i(\boldsymbol{\theta})

Three common estimation strategies are used:

MethodExamples per updateMain characteristic
Batch gradient descentAll NN examplesAccurate gradient estimate but potentially expensive
Stochastic gradient descent1 exampleFrequent, noisy updates
Mini-batch gradient descentA subset BBPractical compromise used widely in neural-network training

For a mini-batch B\mathcal{B}:

J^=1BiBθLi\widehat{\nabla J} = \frac{1}{|\mathcal{B}|} \sum_{i\in\mathcal{B}} \nabla_{\boldsymbol{\theta}}\mathcal{L}_i

The update becomes:

θt+1=θtηJ^\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \eta\widehat{\nabla J}

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

  1. 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:

f(x;θ)f(\mathbf{x};\boldsymbol{\theta})

Training searches for parameter values that produce low empirical risk:

θargminθJ(θ)\boldsymbol{\theta}^{*} \approx \arg\min_{\boldsymbol{\theta}}J(\boldsymbol{\theta})

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

  1. A Tutorial on Deep Learning Part 1 - Stanford tutorial covering backpropagation, stochastic gradient descent, and gradient behavior.

Lifecycle of learning

Set initial parameters

Initialization

Weights and biases receive initial values, usually using a variance-aware initialization."

Compute predictions

Forward pass

Inputs are transformed through successive affine layers and nonlinear activations."

Measure error

Loss evaluation

The prediction is compared with the target using a task-appropriate loss function."

Compute gradients

Backward pass

Backpropagation applies the chain rule from the output toward the input."

Take a descent step

Parameter update

Weights and biases move opposite the estimated gradient."

Repeat over epochs

Iteration

The 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 η\eta, 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:

ηt=η01+kt\eta_t=\frac{\eta_0}{1+kt}

where η0\eta_0 is the initial learning rate and kk controls decay.

Momentum adds a running direction to reduce oscillation:

vt=βvt1+(1β)Jt\mathbf{v}_t = \beta\mathbf{v}_{t-1} + (1-\beta)\nabla J_t θt+1=θtηvt\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t-\eta\mathbf{v}_t

Adaptive methods such as Adam maintain estimates of the first and second moments of gradients:

mt=β1mt1+(1β1)gt\mathbf{m}_t = \beta_1\mathbf{m}_{t-1} + (1-\beta_1)\mathbf{g}_t vt=β2vt1+(1β2)gt2\mathbf{v}_t = \beta_2\mathbf{v}_{t-1} + (1-\beta_2)\mathbf{g}_t^2

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

  1. 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

  1. Multilayer perceptrons for digit recognition with Core APIs - TensorFlow training-loop example showing batch loss, gradients, and parameter updates.

Worked conceptual example

  1. 1
    Step 1

    Suppose the target class is represented by y=[1,0,0]\mathbf{y}=[1,0,0], while the network predicts y^=[0.60,0.25,0.15]\hat{\mathbf{y}}=[0.60,0.25,0.15].

  2. 2
    Step 2

    With softmax and cross-entropy, the output error signal is δ(L)=y^y=[0.40,0.25,0.15]\boldsymbol{\delta}^{(L)}=\hat{\mathbf{y}}-\mathbf{y}=[-0.40,0.25,0.15].

  3. 3
    Step 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.

  4. 4
    Step 4

    The output error is multiplied by transposed weight matrices and activation derivatives to determine how hidden units contributed to the error.

  5. 5
    Step 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.

  6. 6
    Step 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:

  1. Plot training and validation loss by epoch.
  2. Compare training and validation accuracy where appropriate.
  3. Inspect gradient norms.
  4. Check whether activations are saturated or inactive.
  5. Verify that labels and output dimensions are correct.
  6. 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

1 / 6
Question · Term

What does the gradient represent?

Click to reveal
Answer · Definition

It is the vector of partial derivatives of the loss with respect to the model parameters.

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:

InputForward propagationPredictionLossBackpropagationGradientParameter update\text{Input} \rightarrow \text{Forward propagation} \rightarrow \text{Prediction} \rightarrow \text{Loss} \rightarrow \text{Backpropagation} \rightarrow \text{Gradient} \rightarrow \text{Parameter update}

In compact form:

θt+1=θtηθ[1BiBL(f(xi;θt),yi)]\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_{t} - \eta \nabla_{\boldsymbol{\theta}} \left[ \frac{1}{|\mathcal{B}|} \sum_{i\in\mathcal{B}} \mathcal{L} \left( f(\mathbf{x}_i;\boldsymbol{\theta}_t), \mathbf{y}_i \right) \right]

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

  1. Gradient Descent - Stanford CS231n discussion of loss optimization and gradient descent.

  2. Waybackprop - TensorFlow explanation of forward computation, reverse differentiation, and stored activations.

  3. Backpropagation - Stanford CS231n explanation of the chain rule and efficient reverse-mode gradient computation.

Knowledge Check

Question 1 of 5
Q1Single choice

What is the primary purpose of backpropagation in a multilayer network?