For -class softmax regression with , derive the gradient of the negative log-likelihood with respect to . How do you show that the parameters are redundant (not identifiable), and how is this fixed?
Supervised learning, Multinomial logistic regression
Level L3 Intermediate. Length Long. Nature Mat Mathematical.
What's being asked
The derivation of and the shift-invariance of softmax.
Key idea
With one-hot labels , the loss has gradient with respect to . Adding the same vector to every leaves the unchanged.
Steps
- Write and . The loss is , with for the true class.
- Since , .
- Differentiate with respect to : the first term gives , the second gives . So .
- Apply the chain rule with : . In matrix form, .
- Redundancy: replace every by . Each gains , and this factor cancels in the ratio, so is unchanged. The minimiser is therefore not unique (the Hessian has zero eigenvalues).
- Fixes: fix one class as the reference with (giving log-odds against it), or add an L2 penalty , which picks the solution with .
Common mistakes
- Treating the gradient as with respect to the weights instead of logits. Multiply by for the weights.
- Believing that two classes need two weight vectors in a unique solution. The binary case is with , giving the sigmoid.
- Using unstable code. Subtract before exponentiating.
How long your answer should be
One page; 6–8 minutes.
Last checked on 4 December 2026.
Read this
Previous in Supervised learning: Write a distribution in exponential-dispersion form . How do you show that the Bernoulli and Poisson distributions fit this form, what is the canonical link in each case, and why does a canonical link make the log-likelihood gradient equal to ?
Next in Supervised learning: Fit the points with (a) a quadratic and (b) a straight line. Find each fit and its residual sum of squares. Why is the quadratic exact, and what goes wrong if you try a cubic?