How does focal loss FL⁡(pt)=−(1−pt)γlog⁡pt modify cross-entropy for extreme class imbalance, where pt is the predicted probability for the true class and γ≥0 is the focusing parameter? What is the ratio of the loss on a hard example (pt=0.1) to an easy example (pt=0.9) for γ=0 versus γ=2, 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 (1−pt)γ prevents easy negatives from overwhelming gradients in imbalanced tasks.

Key idea

Multiplying cross-entropy −log⁡pt by (1−pt)γ down-weights well-classified examples (pt→1) far more aggressively than hard ones (pt small). Raising γ from 0 to 2 increases the hard-to-easy loss ratio from 21.85 to 1,770.2 (an 81× relative boost).

Steps

  1. Explain the modulating factor: when γ=0, FL⁡(pt)=−log⁡pt is ordinary cross-entropy. For γ>0, confident examples (pt=0.9) are scaled by (1−0.9)γ, whereas misclassified ones (pt=0.1) are scaled by (1−0.1)γ.
  2. Evaluate at γ=0 (natural log): FL⁡(0.1)=−ln⁡(0.1)≈2.3026, and FL⁡(0.9)=−ln⁡(0.9)≈0.1054, giving ratio 2.30260.1054≈21.85.
  3. Evaluate at γ=2: FL⁡(0.1)=(0.9)2(2.3026)≈1.8651, and FL⁡(0.9)=(0.1)2(0.1054)≈0.001054. The ratio jumps to 1.86510.001054≈1,770.2 (exactly 81×21.85, since (0.9/0.1)2=81).
  4. 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

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 z∈R and target y∈{0,1}, evaluating −(ylog⁡σ(z)+(1−y)log⁡(1−σ(z))) naively can overflow e−z or take log⁡(0). How do you derive the numerically stable form max⁡(z,0)−zy+log⁡(1+e−∣z∣), and what value does it give at z=−2,y=1?
Next in Deep learning: A scalar parameter starts at θ0=1 and is trained with Adam using learning rate η=0.1, β1=0.9, β2=0.999 and ϵ=10−8. The first two gradients are g1=0.4 and g2=−0.2. What are θ1 and θ2, and what would the first step have been without bias correction?