The loss family dictates the geometry of the objective and convergence speed. Cross-entropy is standard for classification:
L=−∑iyilogpi, reducing to BCE
−[ylogy^+(1−y)log(1−y^)] for binary cases; regression uses MSE:
L=N1∑∥y−y^∥2. The gradient contrast is the interview crux: softmax+CE yields
pi−yi — linear, never saturating; softmax+MSE yields
(pi−yi)pi(1−pi), where
p(1−p)→0 at extreme predictions, killing gradients and slowing learning. For class imbalance, Focal Loss:
FL(pt)=−αt(1−pt)γlogpt; at
γ=2 easy samples are down-weighted by
(1−pt)2. Contrastive learning uses InfoNCE:
−log∑j=1Kesim(q,kj)/τesim(q,k+)/τ, where temperature
τ controls negative-sample pressure; Triplet Loss:
max(0,d(a,p)−d(a,n)+m) with margin
m.