← 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=−∑iyilog⁡piL=-\sum_{i}y_i\log p_i, reducing to BCE −[ylog⁡y^+(1−y)log⁡(1−y^)]-[y\log\hat y+(1-y)\log(1-\hat y)] for binary cases; regression uses MSE: L=1N∑∥y−y^∥2L=\frac{1}{N}\sum\Vert y-\hat y\Vert^2. The gradient contrast is the interview crux: softmax+CE yields pi−yip_i-y_i — linear, never saturating; softmax+MSE yields (pi−yi)pi(1−pi)(p_i-y_i)p_i(1-p_i), where p(1−p)→0p(1-p)\to0 at extreme predictions, killing gradients and slowing learning. For class imbalance, Focal Loss: FL(pt)=−αt(1−pt)γlog⁡ptFL(p_t)=-\alpha_t(1-p_t)^\gamma\log p_t; at γ=2\gamma=2 easy samples are down-weighted by (1−pt)2(1-p_t)^2. Contrastive learning uses InfoNCE: −log⁡esim(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 p−yp-y, while MSE's gradient vanishes under p(1−p)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 (1−pt)γ(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.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Loss Functions.
Use Cases
In production engineering, what are the primary use cases for Loss Functions and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Derive the softmax+CE gradient pi−yip_i-y_i; contrast with softmax+MSE (pi−yi)pi(1−pi)(p_i-y_i)p_i(1-p_i) — why does CE converge faster?
2
Write Focal Loss FL(pt)=−αt(1−pt)γlog⁡ptFL(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 Card →Batch Normalization

🔗 More Deep Learning Knowledge Cards

Activation FunctionsAdam & AdamWAutograd Compute GraphClassic CNN Architectures