Back to Multimodal Mind Map
中文·English
👁️ MultimodalID: contrastive-loss

InfoNCE Contrastive Loss

InfoNCE 对比损失
🎯Core Definition
InfoNCE (Info Noise-Contrastive Estimation) is the core loss of contrastive learning (CLIP/SimCLR/MoCo) — pull positives together and push all in-batch negatives apart: L=logexp(sim(xi,yi)/τ)jexp(sim(xi,yj)/τ)\mathcal{L} = -\log \frac{\exp(\text{sim}(x_i, y_i) / \tau)}{\sum_{j} \exp(\text{sim}(x_i, y_j) / \tau)}, where sim(,)\text{sim}(\cdot, \cdot) is cosine similarity, yiy_i the matching positive of xix_i, the denominator sums over every candidate in the batch (1 positive + N1N-1 negatives), and τ\tau is the temperature hyperparameter that scales similarities before softmax.
💡Use Cases
image-text alignment (CLIP), self-supervised representation (SimCLR/MoCo), cross-modal retrieval; interviews always probe the role of temperature τ\tau and why larger batches help.
Key Problems Solved
triplet loss compares against a single negative, giving sparse gradients and dependence on hard-negative mining; InfoNCE folds all in-batch negatives into the softmax denominator, far better negative utilization and gradient signal, and is structurally identical to multi-class cross-entropy (positive logit = sim(xi,yi)/τ\text{sim}(x_i,y_i)/\tau). Temperature controls sharpness: small τ\tau amplifies logits, forcing the positive to win decisively; large τ\tau flattens the distribution, diluting positive-negative separation. Example: positive sim=0.9\text{sim}=0.9, negative sim=0.2\text{sim}=0.2; with τ=0.07\tau=0.07 (CLIP's default) logits become 0.9/0.0712.860.9/0.07 \approx 12.86 vs 0.2/0.072.860.2/0.07 \approx 2.86, the positive softmax probability is 99.99%\approx 99.99\% and the loss is near zero; with τ=1\tau=1 the logits are only 0.9 vs 0.2, giving about 66.7%66.7\% positive probability — the model almost loses discriminative power.
🎯5 High-Frequency Exam Points
1
Write the InfoNCE loss and explain every symbol? How is it related to cross-entropy?
2
How to pick temperature τ? What happens when τ is too small or too large (numeric example)?
3
Why does a larger batch size help? Where do negatives come from?
4
InfoNCE vs triplet loss and vanilla NCE: key differences?
5
How does temperature interact with gradients in CLIP's symmetric loss? Handling hard negatives?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "InfoNCE Contrastive Loss"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardCLIP Two-Tower ArchitectureNext CardCLIP Applications

🔗 More Multimodal Knowledge Cards

ASR (Whisper)Audio RepresentationClassifier-Free GuidanceColPali Visual Retrieval