Skip to main content

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.

  1. Why does a target probability of 1 give zero loss?
  2. Why must the averaging denominator be specified when tokens are masked?
  3. Why is perplexity insufficient to measure an assistant’s overall quality?
Show answers
  1. The loss is \(-\log p_y\), so it is zero when \(p_y=1\).
  2. If masked positions remain in the denominator, the result is no longer the mean over valid tokens and becomes difficult to compare.
  3. Perplexity measures probability assignment to tokens in a particular dataset; it does not directly measure truth, usefulness, safety, or calibration.

Language: Français · English