Suppose you train a binary classification network with a sigmoid output using mean-squared error (MSE) instead of cross-entropy. Is training still useful, judging by the gradient of each loss with respect to the logit z (the input to the sigmoid)? How do the two losses look as functions of z for a positive example?

Deep learning, Loss functions
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you can derive both gradients through the sigmoid, and see that MSE carries an extra σ′(z) factor that stops learning when the unit is confidently wrong.

Key idea

Let p=σ(z) be the predicted probability and y∈{0,1} the label. MSE, 12(p−y)2, gives ∂L∂z=(p−y) p(1−p), while cross-entropy gives ∂L∂z=p−y. When the unit saturates on the wrong side (its output is stuck near the wrong end, 0 or 1), p(1−p)≈0 and the MSE gradient vanishes.

Steps

  1. Set up: p=σ(z), y∈{0,1}, and σ′(z)=p(1−p).
  2. MSE: L=12(p−y)2, so by the chain rule ∂L∂z=(p−y) σ′(z)=(p−y) p(1−p). Since p(1−p)≤14, the gradient is at most a quarter of the error, and it goes to 0 at both ends.
  3. Cross-entropy: L=−[ylog⁡p+(1−y)log⁡(1−p)], so ∂L∂z=p−y. The σ′ factor cancels.
  4. Plug in a confidently wrong case: y=1 and z=−10, so p≈4.5×10−5. The MSE gradient is ≈−1×4.5×10−5≈−4.5×10−5, while the cross-entropy gradient is ≈−1. Under MSE, the worst mistakes learn the slowest.
  5. Sketch for y=1. Cross-entropy, log⁡(1+e−z), is convex: it tends to 0 as z→+∞ and grows like −z (slope −1) as z→−∞. MSE, 12(1−σ(z))2, is bounded: it flattens to a plateau at 12 as z→−∞ and goes to 0 as z→+∞. It is S-shaped, hence non-convex in z.
  6. Conclude: training is still useful. MSE (here the Brier score) is minimised at the true probability, and a well-initialised network does learn. But it is slower, can stall on wrongly saturated units, and the loss is non-convex even for a single layer. The same happens with softmax: the MSE gradient passes through the softmax Jacobian diag⁡(p)−pp⊤, which vanishes when the softmax saturates.

Common mistakes

How long your answer should be

Two gradient lines, one numerical example and two sketches; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: How do you derive the gradient of the softmax cross-entropy loss with respect to the logits?
Next in Deep learning: For a two-layer network h=ReLU⁡(W1x+b1), y^=softmax⁡(W2h+b2), trained with cross-entropy on one example with true class c, what are the gradients of the loss with respect to W1,b1,W2,b2 in matrix form, and do their shapes check out?