Log-Softmax and Negative Log-Likelihood

easy
Unit 5 · Losses0/3 to milestone

Cross-entropy is usually computed as log-softmax followed by NLL, which avoids taking the log of a tiny probability.

Implement:

  • log_softmax(z) over the last axis: z−log⁡∑ezz - \log\sum e^{z} computed with the log-sum-exp trick
  • nll(log_probs, targets): mean of −log⁡pi,ti-\log p_{i, t_i} for integer class targets
#losses#numerics2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Log-Softmax and Negative Log-Likelihood · TechGradify