Explain how Cross Entropy Loss is used for a classification task.
Answer
Cross-entropy loss (log loss) measures the distance between two probability distributions: the model’s predicted class probabilities and the true distribution (a one-hot vector for labeled data). Training a classifier means minimizing this distance, which is exactly maximum-likelihood estimation of the model parameters. In the binary case the loss averages ; in the multi-class case only the true class term survives the one-hot sum, reducing the per-sample loss to
. The logarithm is the key design choice: it penalizes confident wrong predictions severely: as the probability assigned to the true class approaches 0 the loss explodes toward infinity, giving a strong, well-behaved gradient exactly where the model errs most. It pairs naturally with sigmoid (binary) or softmax (multi-class) output layers, whose gradients under cross-entropy take the clean form
.
(1) Definition: Negative log-likelihood of the true labels under the predicted distribution; minimizing it is maximum-likelihood training.
(2) Confidence Sensitivity: Loss grows unboundedly as the true-class probability approaches 0; confident mistakes are punished hardest.
(3) Standard Pairing: Sigmoid output + binary cross-entropy, softmax output + categorical cross-entropy; combined gradient simplifies to .

Figure 1: Per-sample loss as a function of the probability assigned to the true class: near
the loss is almost zero, below
it grows steeply: confident errors dominate the gradient.
Mathematical Formulation:
Where:
is the number of samples and
the number of classes.
is the true binary label;
the predicted probability of the positive class.
is the one-hot indicator (1 if sample
belongs to class
);
the predicted probability of class
, so the inner sum keeps only the true-class term.
Leave a Reply