Match a job Paths Subjects Questions Quizzes Pricing
Intermediate Open Pro

Derive the Gradient of Softmax Cross-Entropy

A classifier's final layer outputs logits z \in \mathbb{R}^K, which pass through a softmax to give \hat y_k = e^{z_k} / \sum_j e^{z_j}. The loss for an example with true class c (one-hot y) is L = -\ln \hat y_c.

  1. Derive \partial L / \partial z_k for every k, starting from L = -z_c + \ln \sum_j e^{z_j}. Do not use the full softmax Jacobian.
  2. For logits z = (2.0, 1.0, 0.1) and true class c = 0, compute \hat y, the loss, and the gradient vector. Check that the gradient entries sum to zero.
  3. Why does the gradient being \hat y - y make softmax-CE well-behaved when the model is confidently wrong, compared with squared error on the probabilities?

Share this question

← Back to Neural Networks & Backpropagation practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.