Cross-Entropy Loss

Cross-entropy loss trains a probabilistic classifier by penalizing low probability assigned to the target class or target distribution.

For a target distribution and predicted probabilities :

For a one-hot target with true class :

With logits :

Binary Cross-Entropy

For binary classification with probability :

Multi-label classification usually applies binary cross-entropy independently to each label, not softmax cross-entropy across mutually exclusive classes.

Target Types

Target TypeLoss FormMain Check
one-hot classclasses must be mutually exclusive
soft labeltarget distribution should sum to one
binary labelBCEthreshold and prevalence affect reported metrics
multi-labelindependent BCE per labellabels are not mutually exclusive
label-smoothed classcross-entropy with smoothed targetreport smoothing value and calibration impact

If labels are ordinal, censored, weak, or noisy, plain cross-entropy may be a convenient surrogate but not a complete statement of the label semantics.

Relation to Likelihood

Cross-entropy on one-hot labels is the same training signal as negative log-likelihood for categorical labels:

It can also be written as entropy plus KL divergence:

Since is fixed with respect to , minimizing cross-entropy minimizes the KL divergence from the target distribution to the model distribution.

Logits and Stability

Cross-entropy is usually computed from logits directly:

Stable implementations use a log-sum-exp trick:

This avoids overflow and avoids applying softmax twice.

Metric Boundary

Cross-entropy trains probabilities, while many reported metrics use hard decisions or rankings:

Reported MetricExtra Decision
accuracyargmax decision rule
F1threshold and averaging rule
AUROCranking of scores
AUPRCranking under class imbalance
calibrationprobability reliability, not only correctness

For imbalanced bioactivity, toxicity, retrieval, or screening tasks, a lower cross-entropy can coexist with weak top-k enrichment or poor calibration.

Checks

  • Are labels mutually exclusive, multi-label, soft labels, or ordinal labels?
  • Are logits passed to a numerically stable implementation, rather than softmaxed twice?
  • Is class imbalance handled by weighting, sampling, or threshold tuning?
  • Is the reported metric accuracy, F1, AUROC, AUPRC, calibration, or NLL?
  • Is label smoothing used, and is it reported?