AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

Cross Entropy Loss

Put probability on what happened.

One yes/no question: No + Yes = 100%. No is the complement of Yes.

True outcome

The target records what happened. Changing it keeps the predicted probabilities fixed.

No probability is 100% minus this value. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Prediction and loss contributions

Bars share a fixed 0–100% scale. A target of 1 marks a true outcome or label; 0 marks a false one.

0%50%100%
NoTarget 030%

Contribution = 0 (this class is not the actual outcome).

YesTarget 170%

Contribution = −ln(0.7) ≈ 0.356675 nats.

Cross entropy

Surprise for this known target, measured in natural-log units called nats.

0.357

−ln(probability of the true outcome)

Only the actual outcome’s probability sets this loss.

Prediction total

Probability across mutually exclusive outcomes.

100%

Probabilities sum to 100%

Changing one class automatically adjusts the others.

Worked loss

ln is the natural logarithm. The negative log −ln(p) measures surprise: larger probability on what happened means less loss. These are per-example losses, not accuracy.

The categorical expression −sum(y × ln(p)) reduces to −ln(pTrue) for a one-hot target. Binary uses the same idea for No/Yes: actual Yes uses −ln(pYes), actual No uses −ln(1−pYes).

Targets, predictions and natural-log contributions. Numbers are rounded for display; loss uses actual predictions without clipping.
Class / labelTargetPredictionContribution (nats)
No00.30
Yes10.70.356675

−ln(probability of the true outcome): ≈ 0.356675 nats.

These controls deliberately avoid 0% and 100%. Mathematically, assigning zero probability to an event that happened gives infinite loss; assigning probability one gives zero loss. For a false label, its event is absence, with probability 1−p.

Reference cases

Three fixed examples for this mode. They are comparisons rather than controls.

CaseTrue outcomes / labelsPredictions (%)Loss (nats)
High probability on the true outcomeYesNo 10; Yes 900.105361
Medium probability on the true outcomeYesNo 60; Yes 400.916291
Low probability on the true outcomeYesNo 99; Yes 14.60517

Lower loss rewards probabilities consistent with the known target. It does not supply a universal good/bad cutoff, prove calibration, or substitute for evaluation on other examples.

binary. True Yes. No prediction 30%, target 0, contribution 0 nats; Yes prediction 70%, target 1, contribution 0.356675 nats. Cross entropy 0.356675 nats; prediction total 100%.