The pairing that collapses a dense Jacobian to a subtraction
gradient▲▲△Softmax is not elementwise, so I.6.B02’s Step 1 does not apply to it: its Jacobian is dense. Derive for softmax composed with cross-entropy, show the dense product collapses, and then show what the same softmax does when paired with squared error instead.
Hint
Write out and , then form the sum over . Most of it cancels.
Solution
The two pieces. For and with one-hot:
The Jacobian is and dense — for a 50 000-token vocabulary that is entries, which is why nobody forms it.
The collapse. By (I.6.2), summing over consumers:
and for a one-hot target, so
The in the Jacobian cancels the in the denominator of the loss derivative. That cancellation is the only reason this pairing is cheap.
Verified. With logits and the true class :
| class 0 | class 1 | class 2 | |
|---|---|---|---|
| via the Jacobian |
Largest disagreement — machine precision. Two routes, one of which forms a dense matrix and one of which subtracts two vectors.
The other pairing. Replace cross-entropy with squared error and there is no to cancel the . The Jacobian survives:
| class 0 | class 1 | class 2 | |
|---|---|---|---|
| ratio to |
Smaller, and by a different factor per class — not a rescaling, a distortion.
Why it matters most when the model is wrong. Take logits with the true class : the model is confident and wrong, .
Cross-entropy gives — a full-strength signal, near the largest it can be. Squared error routes through the softmax slope on the true class, which is : a gradient three thousand times smaller, at the exact moment the model most needs correcting.
The general point. A loss and its output nonlinearity are chosen together,
not separately. Sigmoid with cross-entropy collapses the same way, for the same
reason, to — which is why I.6.B01’s linear head with squared error
also gave , and why frameworks expose a single fused
cross_entropy that takes logits rather than a softmax the caller composes
themselves. The fusion is not an optimisation; it is where the cancellation
lives.