Home Knowledge Base Loss Functions

Loss Functions are the mathematical objectives that quantify the discrepancy between model predictions and desired outputs, guiding the optimization process through gradient descent — the choice of loss function fundamentally determines what the model learns to optimize, and selecting the wrong loss can result in a model that minimizes its objective perfectly while failing at the actual task.

Classification Losses

Cross-Entropy Loss (Standard) $L = -\sum_{c=1}^{C} y_c \log(p_c)$

Focal Loss (Lin et al., 2017) $L_{focal} = -\alpha_t (1 - p_t)^\gamma \log(p_t)$

Label Smoothing $y_{smooth} = (1 - \epsilon) \cdot y_{onehot} + \epsilon / C$

Metric Learning Losses

LossInputsPurpose
Triplet LossAnchor, positive, negativeLearn distance metric
InfoNCEAnchor, positive, N negativesContrastive learning (CLIP, SimCLR)
ArcFaceFeatures + class centersFace recognition
Circle LossFlexible weighting of pairsUnified metric learning

Triplet Loss $L = \max(0, ||a - p||^2 - ||a - n||^2 + margin)$

Regression Losses

LossFormulaRobustness to Outliers
MSE (L2)$(y - \hat{y})^2$Sensitive (squares large errors)
MAE (L1)$y - \hat{y}$Robust (linear penalty)
HuberL2 for small errors, L1 for largeConfigurable (δ parameter)
Log-Cosh$\log(\cosh(y - \hat{y}))$Smooth approximation of Huber

LLM Training Losses

Loss function design is one of the most impactful and underappreciated aspects of deep learning — the loss function is quite literally the specification of what the model should learn, and innovations in loss functions (focal loss, contrastive losses, DPO) have enabled breakthroughs that architecture changes alone could not achieve.

loss function designcross entropy lossfocal losstriplet losscontrastive loss function

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.