Exercises — Cross-entropy and KL divergence
Self-check questions, exercises, and worked answers
← Back to the lesson: Cross-entropy and KL divergence
Check your understanding
Extended exercises on this topic.
Go directly to the relevant calculations: from logits to NLL loss; soft targets and KL divergence.
- Why does a target probability of 1 give zero loss?
- Why must the averaging denominator be specified when tokens are masked?
- Why is perplexity insufficient to measure an assistant’s overall quality?
Show answers
- The loss is \(-\log p_y\), so it is zero when \(p_y=1\).
- If masked positions remain in the denominator, the result is no longer the mean over valid tokens and becomes difficult to compare.
- Perplexity measures probability assignment to tokens in a particular dataset; it does not directly measure truth, usefulness, safety, or calibration.