Review — Cross-entropy
Back to the lesson · Learning path plan
What to remember
- For target q and prediction p, cross-entropy H(q,p) is the average of −log p(x) weighted by q(x).
- It equals H(q) + D_KL(q ∥ p). With q fixed, it is minimized when p matches q.
- If the target is concentrated on observed token y, it becomes −log p(y). Predictive entropy H(p) addresses uncertainty before observing the outcome.
Recall from memory
The model predicts p = (0.75, 0.25). Compare the cross-entropy in nats for q = (0.5, 0.5) and for the one-hot target q = (1, 0).
Show the answer
For the distributed target, the result is −0.5 ln(0.75) − 0.5 ln(0.25) ≈ 0.837 nats. With the one-hot target only the first term contributes, so the penalty is −ln(0.75) ≈ 0.288 nats.
Compare two losses when the distribution is fixed and the target changes.
To apply this penalty to a batch, see the loss review sheet.