Neural Network Loss Functions
When there is only one output, the Jacobian is the gradient represented as a row vector. In a multilayer network, Jacobians describe how one layer's outputs respond to another layer's inputs, making them the local derivative objects used by the chain rule.
Try it: Backpropagation, Step by Step
A forward pass through a 2-2-1 network, then the backward pass that applies the chain rule node by node to get for every weight and bias, and one gradient-descent update that changes the loss.
How it works
- Forward: compute each hidden pre-activation and activation, then the sigmoid output y and the loss.
- Backward from the loss: for squared error, or for binary cross-entropy.
- Output weights: ; the error sent back to is .
- Hidden units: multiply by the activation's local derivative, then .
- Update every parameter and run the forward pass again to see the new loss.
Default run (12 steps): Inputs x = (1, 0.5), target t = 1. Hidden activation sigmoid, output sigmoid, loss: squared error L = (y - t)2. First the forward pass. … New forward pass with the updated weights: y = 0.6086, loss 0.203 -> 0.1532 (lower: the step moved downhill).
Simplified: One training example, two inputs, two hidden units, one output unit. Binary cross-entropy is evaluated from the output logit (same value, no log(0)). Toy dimensions, not a full real model.
Loading the simulation…
From Prediction to Weight Updates
A neural network has a loss that depends on its weights. The network first transforms an input into a prediction, and the loss measures the result. To change the weights in a useful direction, we need to know how the loss changes when each individual weight changes. Backpropagation calculates this information: it calculates the gradient of the loss with respect to the weights, but it does not itself apply the weight update.
Forward Values Through Layers
Consider a network divided into layers V0 through VT. The weights connecting layer Vt-1 to layer Vt are represented by a matrix Wt-1. The incoming values at a layer are collected in at, and the neuron outputs are collected in ot. The layer first computes at = Wt-1 ot-1 and then applies the activation function element by element to obtain ot = σ(at). These forward quantities are calculated from the input side toward the output side.
Tracking One Layer's Forward Quantities
Describe the forward computation at layer Vt using the notation from the network model.
- 1Collect incoming values
The outputs from the preceding layer are represented by ot-1.
- 2Apply the weight matrix
The layer computes the pre-activation values at = Wt-1 ot-1.
- 3Apply the activation
The activation function is applied element by element, producing ot = σ(at).
- 4Store the forward quantities
The values at and ot are retained because the backward calculation uses the forward quantities while moving in the opposite direction.
The forward pass records the values computed from the input side toward the output side, preparing information for backpropagation.
Partial Derivatives and Weight Sensitivity
A partial derivative describes how a function changes when one variable changes while the other variables are held constant. In a neural network, the loss has one partial derivative for each weight associated with an edge in the network. Each derivative therefore answers a specific question: how does the loss change if this particular weight changes while the other weights remain fixed?
The gradient collects all of these partial derivatives. If the network has many weights, the gradient has one corresponding component for each weight. The component associated with a particular weight reports the loss sensitivity for that weight; it is not a general score detached from the network's individual connections.
Jacobians for Vector Outputs
A function can produce several outputs at once. When a function maps Rⁿ to Rᵐ, its derivatives are organized in a Jacobian matrix with m rows and n columns. The entry in row i and column j is the partial derivative of output i with respect to input variable j. Rows therefore correspond to output components, while columns correspond to input components.
When there is only one output, the Jacobian is the gradient represented as a row vector. In a multilayer network, Jacobians describe how one layer's outputs respond to another layer's inputs, making them the local derivative objects used by the chain rule.
The Chain Rule Across Layers
A neural network composes many functions. A weight matrix produces pre-activation values, an activation function produces neuron outputs, later layers transform those outputs, and the final output determines the loss. The chain rule connects the derivative of the final loss to the derivatives of each intermediate transformation.
The order of the derivative operations matters because each derivative maps changes from one representation to the next. Applying the chain rule means combining local derivative information in the correct order. Backpropagation organizes this repeated multiplication recursively so that sensitivity arriving at one layer can be reused when calculating the sensitivity for the preceding layer.
Following One Weight's Influence
Trace conceptually how a change in a weight near the input side can influence the final loss.
- 1Weight to pre-activation
The weight contributes to a layer's pre-activation values through the weight-matrix transformation.
- 2Pre-activation to output
The activation function transforms the pre-activation values into the layer outputs.
- 3Output through later layers
Later layers transform those outputs and pass the effect toward the final output.
- 4Final output to loss
The final output determines the loss, so the original weight can affect the loss through every intermediate transformation.
- 5Combine local derivatives
The chain rule combines the local derivative at each link into the derivative of the complete network with respect to that weight.
The derivative for the weight is obtained by composing the local sensitivities along the entire path from that weight to the loss.
Forward Pass and Backward Pass
Backpropagation has two directions of computation. During the forward pass, the network calculates the values at and ot from the input side toward the output side. During the backward pass, it uses those stored forward quantities while moving from the output side toward the input side. The forward values describe what the network computed; the backward sensitivities describe how strongly the later loss depends on those computed outputs.
Let ℓt be the loss of the subnetwork beginning at layer Vt, viewed as a function of the outputs ot. The backward sensitivity is defined as δt = Jot(ℓt). This vector records how the subnetwork loss changes with respect to the outputs at that layer.
The backward quantities are not another set of forward activations. They are sensitivities. A sensitivity tells us how strongly a later loss depends on an output currently being considered.
Backward Recursion and Weight Gradients
At the final layer, the subnetwork loss is the loss function itself. For the squared loss Δ(u, y) = 1/2 ||u − y||², the derivative with respect to u is u − y. Therefore, at the final layer, δT = oT − y. This supplies the starting backward signal.
For an earlier layer, the chain rule expresses δt in terms of the sensitivity at the next layer, the derivative of the activation, and the transformation connecting the layers. The exact matrix arrangement follows from the Jacobians of those transformations. Repeating this step moves the sensitivity from the top layer toward the bottom layer.
Tracing the Backward Signal
Explain how the backward recursion moves from the final layer to an earlier layer and contributes to the weight gradient.
- 1Start at the final layer
For the squared loss, the final sensitivity is δT = oT − y.
- 2Move to the preceding layer
Use the next layer's sensitivity together with the activation derivative and the connecting transformation.
- 3Repeat toward the input
Apply the same chain-rule reasoning repeatedly so each earlier layer receives a sensitivity.
- 4Combine with forward information
The stored forward quantities and the backward sensitivities are combined to obtain derivatives for the weights.
The backward recursion produces the gradient of the loss with respect to the network weights by repeatedly applying local derivative relationships from the output side toward the input side.
Common Reasoning Mistakes
Common mistake Treating the gradient as one undifferentiated number.
What it looks likeDescribing the gradient without identifying which component belongs to which weight.
Why it failsThe gradient collects one partial derivative for each network weight.
Do this insteadTrack every gradient component as the derivative of the loss with respect to its corresponding weight.
Common mistake Confusing forward values with backward sensitivities.
What it looks likeCalling δt another layer output.
Why it failsThe forward quantities at and ot describe computed values, while δt describes how the loss depends on those outputs.
Do this insteadLabel forward quantities as values and δ quantities as sensitivities.
Common mistake Ignoring the order of derivative composition.
What it looks likeCombining local derivatives without respecting the sequence of transformations between a weight and the loss.
Why it failsEach derivative maps changes from one representation to the next, so the order matters.
Do this insteadFollow the path from the weight through pre-activations, activations, later layers, and finally the loss.
Common mistake Assuming backpropagation directly changes the weights.
What it looks likeSaying that backpropagation applies the new weight values.
Why it failsBackpropagation calculates the gradient; it does not directly apply it.
Do this insteadDescribe gradient calculation and weight updating as separate operations.
Common mistake Treating a Jacobian as a scalar derivative.
What it looks likeUsing one derivative when a function has several outputs and several inputs.
Why it failsFor a function from Rⁿ to Rᵐ, the Jacobian contains the partial derivative for every output-input pair.
Do this insteadUse rows for output components and columns for input components.
Practice Check
A network contains several layers. Explain, in order, what information is computed during the forward pass, where the initial backward sensitivity comes from for the squared loss, and how the chain rule carries that sensitivity toward earlier layers. End by explaining why the resulting gradient has one component for each network weight.
Hints
- Begin with the quantities at and ot.
- Use the final-layer relation δT = oT − y for the squared loss.
- Distinguish the local derivatives at each layer from the complete derivative of the loss with respect to a weight.
- Connect each gradient component to one particular weight.
Key Takeaways
- 1A partial derivative measures how the loss changes when one weight varies while the other weights are held constant.
- 2The gradient collects one such partial derivative for every network weight.
- 3A Jacobian organizes derivatives of every output component with respect to every input component.
- 4The chain rule combines local derivatives across the transformations in a multilayer network.
- 5Backpropagation moves sensitivities backward, combines them with stored forward quantities, and calculates the gradient; a separate process can then use that gradient to change the weights.
At a glance
- A partial derivative links one network weight to the way the loss changes.
- A gradient is a collection of these weight-specific partial derivatives.
- Jacobians arrange derivatives between vector-valued inputs and outputs.
- Backpropagation applies the chain rule recursively from the loss toward the input.
- Forward values and backward sensitivities work together to calculate the gradient of the loss with respect to network weights.