Categorical Cross Entropy Calculator
Calculate categorical cross-entropy loss for multi-class classification tasks.
About Categorical Cross Entropy Calculator
Categorical cross-entropy generalizes binary cross-entropy to multi-class classification: CCE = −Σ y_i·ln(p_i), summed over all classes. Because the true label is one-hot (exactly one class has y_i = 1 and the rest are 0), every term except the true class's vanishes, so CCE reduces to −ln(p_true) — the loss is entirely determined by how much probability mass the model assigned to the correct class. This is the standard loss paired with a softmax output layer for multi-class neural network classifiers.
Formula
CCE = -sum(y_i × ln(p_i))
- y_i
- True label for class i (one-hot: 1 for correct class, 0 otherwise)
- p_i
- Predicted probability for class i
Worked example
With the default values below, Categorical Cross Entropy Calculator returns Categorical Cross-Entropy Loss of 0.356675. Change any input above and every figure here is recalculated in your browser.
Inputs used
- True Labels (one-hot, comma-separated)
- 0, 1, 0, 0
- Predicted Probabilities (comma-separated)
- 0.1, 0.7, 0.15, 0.05
Results
- Categorical Cross-Entropy Loss
- 0.356675
- True Class Index
- 1
- Sum of Predicted ProbabilitiesShould be ≈1.0 for a valid probability distribution.
- 1.0000
Step by step
- 1Per-class terms: −y_i × ln(p_i) (only the true class contributes)= 0.0000, 0.3567, 0.0000, 0.0000
- 2CCE: sum of per-class terms= 0.356675
- 3Sanity check: predicted probabilities should sum to ≈1= 1.0000
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
Why do all terms except the true class disappear?
Because the true label is one-hot encoded, y_i = 0 for every incorrect class, making y_i × ln(p_i) = 0 for those terms; only the true class (where y_i = 1) contributes −ln(p_true) to the total loss.
What predicted probability gives the lowest possible loss?
A predicted probability of 1.0 for the true class gives a loss of exactly 0 (since −ln(1) = 0), which is the theoretical minimum; in practice predictions never reach exactly 1.0 due to the softmax function's asymptotic behavior.
How does this relate to softmax cross-entropy loss in frameworks like PyTorch?
PyTorch's CrossEntropyLoss and TensorFlow's CategoricalCrossentropy both implement this exact formula, typically combining it with the softmax computation internally (from raw logits) for better numerical stability than computing softmax and cross-entropy as separate steps.
