WRITE · TRACE · UNDERSTAND
Weight stable multiclass cross-entropy by observations
Return the weighted mean multiclass negative log likelihood.
Read lesson: Weight stable multiclass cross-entropy by observations →
Your experiment
Return the weighted mean multiclass negative log likelihood. Subtract each row maximum before exponentiation. Require aligned nonempty batches, rectangular logits with at least two classes, finite values, integer class indices, nonnegative finite weights and a positive total weight. The denominator is total observation weight, not batch length.
Python runs in your browser. Your draft stays on this device.
What to look for
Compare shifted and unshifted logits, duplicated weighted observations and a confidently wrong class. Review label identities and the weight denominator before optimizing the kernel.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.
