Explain how the InfoNCE loss shapes embedding geometry during training
Walk through what the InfoNCE loss optimizes, and why models trained this way 'live' in angular space rather than Euclidean space.
InfoNCE optimises cross-entropy over softmax-normalised cosine similarities, sculpting an angular geometry where positives sit near angle zero and negatives near orthogonal.
Picture every sentence as an arrow pointing somewhere on a giant sphere. The training game is to make arrows for related sentences point in the same direction and arrows for unrelated sentences point in different directions. The length of each arrow doesn't matter, only where it points. After enough rounds, the sphere becomes organised: travel guides cluster on one patch, recipes on another, programming tutorials on a third. To find related sentences at query time, you just check which arrows point the same way as the query's arrow.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
This question tests whether you can connect a loss formula to the geometric structure of the embedding space it produces, and from there to the inference-time metric choice. The chain is: InfoNCE operates on normalised dot products, therefore the geometry it shapes is angular, therefore cosine is the right inference metric.
This deep dive unpacks each step, examines the role of temperature and negatives, and explains why the training-inference metric match matters so much in production.
What the formula optimises, step by step
InfoNCE in its standard production form:
For each training step, the model computes embeddings for a query q, one positive k+, and N-1 negatives k-_i. It computes the dot product of q with every candidate, divides by the temperature τ, applies softmax to get a probability distribution over the N candidates, and takes the negative log of the probability assigned to the positive.
This is cross-entropy against a one-hot target that says "the positive is the correct class." The loss is minimised when the model assigns high probability to the positive, which requires q · k+ to be large and q · k-_i to be small for all negatives.
The model's gradients flow into the encoder parameters, updating them so future queries and positives produce larger dot products and future queries and negatives produce smaller ones. After enough training steps across millions of pairs, the encoder has learned to place semantically related inputs close in the embedding space and unrelated inputs far apart.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- OpenAI text-embedding-3 series trains with InfoNCE and ships normalised vectors so cosine and dot product are interchangeable.
- BGE-M3 applies InfoNCE with mined hard negatives across multilingual training, producing 1024-dim normalised embeddings.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat happens if you train with cosine but query with raw dot product on non-normalised vectors?
Magnitude differences leak into the retrieval score. Documents with larger embedding norms appear systematically more similar regardless of semantic match. Quality degrades because the metric no longer matches what the loss optimised.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Describing InfoNCE as a Euclidean-distance loss. The loss operates on cosine of normalised vectors: magnitudes are stripped out, so the geometry is angular, not distance-based.
60 second bullets to scan on the way to the call.
Write the InfoNCE formula with the temperature term.
Explain why L2 normalisation forces angular geometry.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.