A three-class softmax model produces scores (logits) for an input. Compute the class probabilities. If the true class is class 2, what is the cross-entropy loss, and what is the gradient of the loss with respect to ?
Supervised learning, Multinomial logistic regression
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
A numerical softmax and the key identity that the gradient of cross-entropy with respect to the logits is .
Key idea
. For true one-hot label , the loss has gradient with respect to .
Steps
- Exponentials: , , . The sum is .
- Probabilities: , which sum to 1.
- True class 2 has , so the loss is .
- The one-hot label is . The gradient is . Its components sum to 0, as they must.
- Interpretation: a gradient-descent step raises (negative gradient on the true class) and lowers the others, in proportion to their wrongly assigned probability.
Common mistakes
- Using natural log in one place and in another. Use throughout.
- Forgetting the subtraction of the one-hot label, giving gradient only.
- Computing softmax without subtracting in code. Large logits overflow.
How long your answer should be
Half a page, 3–4 minutes.
Last checked on 4 December 2026.
Read this
Previous in Supervised learning: With candidate features, how many models does best-subset selection have to consider, and how many model fits does forward stepwise selection need? What changes for , and why might forward stepwise still give a worse model than best subset?
Next in Supervised learning: A linear classifier has and . What are the hinge loss and the 0–1 loss on the points with label , with label , and with label ?