A classifier sorts photos into classes. For one photo, its last layer emits raw scores, the logits . Softmax turns them into probabilities, and categorical cross-entropy grades the probability given to the true class :
Every backward pass through this network starts with the same question: how fast does the loss change when each logit is nudged? The chain from a logit to the loss has two links, and here are both of their rates.
A training batch holds photos, and the batch's loss is the mean of the per-photo losses.
Task: write logit_gradients(logits, labels).
logits is a list of rows, each holding logits.labels is a list of class indices, counting from 0.Return an list of lists whose entry [i][k] is the rate of change of the batch loss with respect to logit of photo , rounded to 4 decimal places.
A confident model can produce logits in the hundreds. Your function must still return correct, finite numbers for them.