The wrong loss is worse than no model at all
Loss functions define what the model is optimizing. Pick wrong and no architecture tuning compensates. Pick right and even mediocre models converge.
Classification:
- Multi-class with integer labels —
SparseCategoricalCrossentropy(from_logits=True) - Multi-class with one-hot labels —
CategoricalCrossentropy(from_logits=True) - Binary or multi-label (each sample can have multiple labels) —
BinaryCrossentropy(from_logits=True)
Regression:
- Standard —
MeanSquaredError - Outlier-robust —
Huber(delta=1.0)— MSE for small errors, MAE for large - Pure L1 —
MeanAbsoluteError
Custom loss is a function with signature (y_true, y_pred) -> tensor. Returns a per-sample loss; Keras averages over the batch.