Cross-Entropy with Ignore Index
Compute mean cross-entropy and its logits gradient while skipping ignored labels. A free ML coding interview task on NudgeCode: write it in Python and check it with tests in your browser. Medium · Loss, Cross-Entropy, Backward.
Implement mean cross-entropy and its gradient for logits shaped (N,V). Ignore ignored labels in both the mean and gradient, use stable log-softmax, and return zero loss/gradient if every label is ignored. Do not use autograd.