Focal Loss
A tweak to standard classification loss that automatically down-weights examples the model already gets right, forcing training to focus on the hard, rare cases — useful when one class vastly outnumbers another.
Standard classification training uses cross-entropy loss, which treats every example's error equally regardless of how confident the model already is. In a badly imbalanced problem — say, predicting a rare fraud flag or a rare tail event that occurs in 1% of rows — the model can rack up a low average loss just by confidently predicting "no event" every time, since the 99% of easy, correctly-classified examples swamp the loss contributed by the rare, hard positives.
Focal loss modifies cross-entropy by multiplying each example's loss by a factor , where is the model's predicted probability for the true class and (commonly 2) is a tunable focusing parameter. When the model is already confident and correct, is close to 1, so is close to zero and that example's contribution to the loss is squashed. When the model is wrong or unsure, is small, stays close to 1, and the loss is barely reduced — training keeps pushing hard on exactly those examples.
Concretely, with : an easy example correctly predicted with gets its loss multiplied by , essentially removed from training, while a hard example with gets multiplied by , barely discounted — a roughly 200x difference in how much each example moves the gradient.
Focal loss reweights cross-entropy by so that easy, already-correct examples contribute almost nothing to training and hard or rare examples keep driving learning — a direct fix for the class-imbalance problem where common, easy cases otherwise dominate the loss.
Related concepts
Further reading
- Lin et al., Focal Loss for Dense Object Detection, 2017