Back to Deep Learning Mind Map
中文·English
🧠 Deep LearningID: loss-functions-dl

Loss Functions

损失函数族
🎯Core Definition
The loss family dictates the geometry of the objective and convergence speed. Cross-entropy is standard for classification: L=iyilogpiL=-\sum_{i}y_i\log p_i, reducing to BCE [ylogy^+(1y)log(1y^)]-[y\log\hat y+(1-y)\log(1-\hat y)] for binary cases; regression uses MSE: L=1Nyy^2L=\frac{1}{N}\sum\Vert y-\hat y\Vert^2. The gradient contrast is the interview crux: softmax+CE yields piyip_i-y_i — linear, never saturating; softmax+MSE yields (piyi)pi(1pi)(p_i-y_i)p_i(1-p_i), where p(1p)0p(1-p)\to0 at extreme predictions, killing gradients and slowing learning. For class imbalance, Focal Loss: FL(pt)=αt(1pt)γlogptFL(p_t)=-\alpha_t(1-p_t)^\gamma\log p_t; at γ=2\gamma=2 easy samples are down-weighted by (1pt)2(1-p_t)^2. Contrastive learning uses InfoNCE: logesim(q,k+)/τj=1Kesim(q,kj)/τ-\log\frac{e^{\text{sim}(q,k_+)/\tau}}{\sum_{j=1}^{K}e^{\text{sim}(q,k_j)/\tau}}, where temperature τ\tau controls negative-sample pressure; Triplet Loss: max(0,d(a,p)d(a,n)+m)\max(0,\,d(a,p)-d(a,n)+m) with margin mm.
💡Use Cases
interview favorites — “why CE for classification but MSE for regression?”, “gradient difference between CE and MSE under softmax?”, “how does Focal Loss fix imbalance?”, “how to tune InfoNCE temperature?”; RetinaNet, CLIP/SimCLR and multi-label BCE are common follow-ups.
Key Problems Solved
convergence speed and robustness — CE's log\log cancels the softmax denominator to give the linear gradient pyp-y, while MSE's gradient vanishes under p(1p)p(1-p) in saturated regions, so CE converges up to an order of magnitude faster on the same net; Focal down-weights abundant easy samples via (1pt)γ(1-p_t)^\gamma, making RetinaNet the first one-stage detector to beat two-stage on COCO; InfoNCE's τ\tau sets the difficulty weight of negatives and directly determines CLIP/SimCLR embedding quality.
🎯5 High-Frequency Exam Points
1
Derive the softmax+CE gradient piyip_i-y_i; contrast with softmax+MSE (piyi)pi(1pi)(p_i-y_i)p_i(1-p_i) — why does CE converge faster?
2
Write Focal Loss FL(pt)=αt(1pt)γlogptFL(p_t)=-\alpha_t(1-p_t)^\gamma\log p_t; how do easy-sample weights change at γ=2\gamma=2 and why does it fix imbalance?
3
Write the InfoNCE formula and explain temperature τ\tau; why does a too-small τ\tau over-strengthen negative-sample gradients?
4
Relation between CE and BCE? Why BCE for multi-label classification instead of multi-class CE?
5
Why is CE not used for regression? Compare MSE / MAE / Huber gradients and outlier robustness?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Loss Functions"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardVanishing/Exploding GradientsNext CardBatch Normalization

🔗 More Deep Learning Knowledge Cards

Activation FunctionsAdam & AdamWAutograd Compute GraphClassic CNN Architectures