How does focal loss modify cross-entropy for extreme class imbalance, where is the predicted probability for the true class and is the focusing parameter? What is the ratio of the loss on a hard example () to an easy example () for versus , and why does this help?
Deep learning, Loss functions
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you understand how modulating cross-entropy by prevents easy negatives from overwhelming gradients in imbalanced tasks.
Key idea
Multiplying cross-entropy by down-weights well-classified examples () far more aggressively than hard ones ( small). Raising from to increases the hard-to-easy loss ratio from to (an relative boost).
Steps
- Explain the modulating factor: when , is ordinary cross-entropy. For , confident examples () are scaled by , whereas misclassified ones () are scaled by .
- Evaluate at (natural log): , and , giving ratio .
- Evaluate at : , and . The ratio jumps to (exactly , since ).
- Why it helps: in dense object detection or rare-event classification, thousands of easy background examples each contribute small non-zero cross-entropy gradients that sum up to overwhelm the few rare foreground positives; focal loss suppresses the easy-majority gradient sum.
Common mistakes
- Mixing up (probability assigned to the true class) with the positive-class probability when the true label is (where ).
- Assuming focal loss alone handles class frequency imbalance without an optional class-weighting factor.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Deep learning: For binary classification with logit and target , evaluating naively can overflow or take . How do you derive the numerically stable form , and what value does it give at ?
Next in Deep learning: A scalar parameter starts at and is trained with Adam using learning rate , , and . The first two gradients are and . What are and , and what would the first step have been without bias correction?