What Cross-Entropy Is and Is Not
Evaluate binary cross-entropy across four noisy subpopulations and separate reducible calibration shift from irreducible outcome entropy.
The problem
When a trained classifier reports a cross-entropy of 0.60 nats on a validation set, does that number mean the model is poorly calibrated or making avoidable mistakes? Not necessarily.
Cross-entropy is a proper scoring rule: for any true binary probability ,
achieves its minimum when . However, that minimum value is the outcome's own binary entropy , which is strictly positive whenever . Cross-entropy alone cannot tell you how much of 0.60 is irreducible noise and how much is reducible model error .
Work through the numbers
Consider four groups whose true positive rates are q = [0.85, 0.70, 0.55, 0.40]. Suppose a model predicts p = q + shift. At shift equal to 0.0, the model is Bayes-optimal (), yet every group still has positive binary entropy :
- Group 0 ():
- Group 1 ():
- Group 2 ():
- Group 3 ():
Averaging those four numbers gives a mean irreducible floor mh = 0.59868 nats and an excess mce - mh = 0.00000.
Now shift every prediction by shift = +0.10 (p = [0.95, 0.80, 0.65, 0.50]) or shift = -0.10 (p = [0.75, 0.60, 0.45, 0.30]). At shift = +0.10, the mean cross-entropy rises to 0.63362 (excess +0.03494). At shift = -0.10, it rises to 0.62218 (excess +0.02350).
The live model
For each group, the top green bar shows the fixed Bayes floor and the bottom blue bar shows the model's cross-entropy . The shift slider offsets all four predicted probabilities by p = q + shift from -0.10 to +0.10.
At shift equal to 0.0, every blue bar matches its green bar, mean CE equals mean H(q) = 0.599, and excess is 0.000. Moving shift down to -0.05 or up to +0.05 raises mean CE to 0.605 (excess = 0.006) or 0.606 (excess = 0.007). At the endpoints -0.10 and +0.10, mean CE climbs to 0.622 (excess = 0.024) and 0.634 (excess = 0.035).

let shift = scene.parameter("shift", 0.0, -0.10, 0.10, 0.05);
let q = input;
let p = q + shift;
let ce = (q * p.log() + (1.0 - q) * (1.0 - p).log()).neg();
let h = (q * q.log() + (1.0 - q) * (1.0 - q).log()).neg();
let mce = ce.mean().reshape(1);
let mh = h.mean().reshape(1);
let excess = mce - mh;
let answer = torch.cat(torch.list().add(mce).add(mh).add(excess), 0);
out.set("ce", ce).set("h", h).set("mce", mce).set("excess", excess);
{
"ce": [
0.4227090878059909,
0.6108643020548935,
0.6881388137135884,
0.6730116670092565
],
"h": [
0.4227090878059909,
0.6108643020548935,
0.6881388137135884,
0.6730116670092565
],
"mce": [
0.5986809676459324
],
"excess": [
0
]
}Your turn
At shift = 0.0 the starter reports mce = 0.33387 and a negative excess = -0.26481 because ce only includes the positive-outcome contribution; by hand the full binary cross-entropy across both outcomes equals the target entropy 0.59868 (excess = 0.0). Fix ce so it evaluates the complete two-term binary cross-entropy for each group.

let shift = scene.parameter("shift", 0.0, -0.10, 0.10, 0.05);
let q = input;
let p = q + shift;
let ce = (q * p.log()).neg();
let h = (q * q.log() + (1.0 - q) * (1.0 - q).log()).neg();
let mce = ce.mean().reshape(1);
let mh = h.mean().reshape(1);
let excess = mce - mh;
let answer = torch.cat(torch.list().add(mce).add(mh).add(excess), 0);
out.set("ce", ce).set("h", h).set("mce", mce).set("excess", excess);
{
"ce": [
0.1381410900731087,
0.2496724607571127,
0.32881035041559126,
0.366516292749662
],
"h": [
0.4227090878059909,
0.6108643020548935,
0.6881388137135884,
0.6730116670092565
],
"mce": [
0.27078504849886864
],
"excess": [
-0.32789591914706373
]
}Complete ce so it evaluates the full binary cross-entropy across both positive and negative outcomes. Check tests unseen probability vectors and shift values.
With the full formula restored, the default run at shift = 0.0 returns [0.59868112, 0.59868112, 0.0]. The check reruns the full formula on q = [0.80, 0.65, 0.50, 0.35] at shift = -0.05 and on q = [0.75, 0.60, 0.45, 0.30] at shift = +0.10.
Read the result carefully
Because both positive and negative shifts raise mce above mh, cross-entropy rewards honest probability estimates (). Unlike accuracy, which is unchanged by any shift that stays on the same side of 0.50, cross-entropy strictly penalizes predicting too high (shift = +0.10) and predicting too low (shift = -0.10).
At the same time, cross-entropy is not a standalone measure of model quality across different datasets, nor is it a substitute for task-specific decision costs. A weather task with noisy outcomes ( near 0.55) will always have a higher cross-entropy floor (0.68814) than a deterministic sensor task ( near 0.99), even when the weather model is calibrated to perfection.
Recap
- Binary cross-entropy is minimized when , making it a strictly proper scoring rule.
- Even at , cross-entropy equals the target entropy (
0.59868across[0.85, 0.70, 0.55, 0.40]), not zero. - Cross-entropy measures probabilistic fit relative to an unknown entropy floor; it does not replace calibration tables, slice checks, or asymmetric mistake costs.