Cross-entropy, binary cross-entropy and regression loss
What it is
A loss function converts a prediction and its target into a differentiable scalar that training can minimise. Cross-entropy penalises low probability assigned to the correct class and is the usual multiclass objective; binary cross-entropy handles one or more independent yes/no labels. MSE and MAE compare numeric targets, but differ in how strongly they punish a large residual: MSE squares it, while MAE treats every additional unit of error equally. Batch loss is usually the mean over examples, so its scale remains comparable as batch size changes.
Why it matters
A model does exactly what its loss rewards, not what its name suggests. The loss must match both the target encoding and the decision you care about; an excellent loss can still pair with an unsuitable business threshold or evaluation metric. Before training, state what one target represents, what one model output represents, and why reducing this scalar should improve the real outcome.
In the real world: Cross-entropy for classifying support tickets, binary cross-entropy for fraud yes/no, regression loss for delivery time.
Visual example
LossCross-entropy strongly penalises being confidently wrong.
import torch, torch.nn as nn
logits = torch.randn(32, 10)
labels = torch.randint(0, 10, (32,))
print(nn.CrossEntropyLoss()(logits, labels).item()) # multiclass, one label each
scores = torch.randn(32, 1)
tags = torch.randint(0, 2, (32, 1)).float()
print(nn.BCEWithLogitsLoss()(scores, tags).item()) # independent yes/no
print(nn.MSELoss()(torch.randn(32, 1), torch.randn(32, 1)).item()) # regressionUsing MSE on class IDs such as 0, 1, 2. It implies class 2 is twice as far from class 0 as class 1 is, an arbitrary ordering that ordinary multiclass classification does not have.