Contrastive negatives and temperature define a comparison task, not automatic semantic truth
Derive a normalized cross-modal comparison loss and identify how duplicate positives, batch composition, and temperature affect its supervision.
On this page
The question for today
What you’ll understand
- Calculate a row softmax and loss from explicitly scaled similarities.
- Distinguish inverse temperature from temperature and identify false negatives.
- Separate batch discrimination, retrieval quality, and probability calibration.
A CLIP-style objective asks which text belongs with an image and which image belongs with a text among the sampled comparisons. Its success depends on valid positives and on what the other batch entries mean. Another image of the same object or an equivalent caption can be treated as a negative even when it is semantically compatible. Temperature changes how strongly similarity gaps affect the objective. These are choices about supervision and optimization, not guarantees that a low loss establishes every form of cross-modal understanding.
Specify normalized scores and the comparison set
Suppose both encoders produce nonzero features projected into a shared dimension, then normalize each feature to unit length. Their dot product is cosine similarity under that representation. Divide similarities by a positive temperature to form logits, or multiply by an explicitly defined inverse-temperature scale. These conventions are reciprocals; confusing them reverses a statement about making a softmax sharper. The original CLIP implementation in its paper learns a log-parameterized multiplicative scale, so describing that parameter requires distinguishing it from a divisor temperature.
For one aligned image row, the loss is negative log probability of its intended text among the batch candidates. A common symmetric objective averages image-to-text and text-to-image losses. This depends on the gathered comparison set and target indices, not merely the batch size. A larger batch changes the denominator, possible hard examples, duplicate frequency, and compute. It does not make every additional candidate a valid semantic negative. Keep normalization, target identity, gather order, and the scale parameter visible when diagnosing a changed loss.
A false negative produces a real conflicting gradient
With one positive target, increasing the score of any other candidate increases its contribution to the denominator, even if that candidate is a valid paraphrase or another view of the same content. That is a false-negative issue relative to the intended semantic task, not a tensor error. Asset duplicates, repeated captions, closely related frames, and broad descriptions all create such cases. Grouped batching, duplicate-aware masking, or multi-positive objectives can address particular mechanisms, but each changes the learning problem and needs clearly defined positive relations.
A lower temperature emphasizes score differences and often concentrates probability on the highest-scoring candidates. It can also make a mislabeled or false-negative comparison more consequential. It does not improve the actual encoder representations by itself at evaluation time, and it does not make a row softmax a calibrated probability that an image-text pair is universally true. Probability depends on the offered candidate set; adding another compatible caption can redistribute mass even when the underlying pair's features are unchanged. Evaluate retrieval and semantic tasks separately from training-set discrimination.
Audit comparison semantics alongside numerical stability
Trace positive IDs and inspect the highest-scoring alleged negatives. Measure duplicates and semantic overlap by source and cohort. Compare a controlled change in batch construction or temperature while preserving the declared evaluation task, and check gradient finiteness with stable log-space computation. If multi-positive training is adopted, test its label normalization and retrieval behavior rather than reporting its loss value as directly comparable with a changed one-positive denominator. A fluent description or one successful retrieval is also insufficient to establish relational grounding across unseen combinations.
The vector lab illustrates cosine with a fixed unit reference along the positive x-axis. Reset, set both angle 0° and magnitude 1, predict x-projection 1, then inspect or Play. Reset and set both angle 60° and magnitude 1 for x-projection 0.5. Both selected vectors are unit length, so these x-components equal their dot products with that reference. The instrument contains one two-dimensional vector and no encoder, comparison batch, negative labels, temperature, softmax, or gradient. Use it only to verify the geometry entering a score, not to simulate contrastive learning.
Work it through
Temperature changes row probability without changing the similarities
One normalized image row has verified positive similarity 0.8 and two comparison similarities 0.4 and 0. Use divisor temperature 0.2, then 0.4. All scores are finite, and this example considers only the image-to-text row loss.
At τ=0.2, logits are[4,2,0]. Subtracting the maximum gives[0,−2,−4], so positive probability is 1/(1+e⁻²+e⁻⁴)≈0.86681333 and loss isabout 0.14293163.
At τ=0.4, logits are[2,1,0]. Positive probability is 1/(1+e⁻¹+e⁻²)≈0.66524096 and loss isabout 0.40760596. The larger divisor made this row distribution less concentrated.
If the 0.4 comparison is actually an equally valid description, the one-positive objective still pushes against it. Neither temperature calculation repairs that label conflict, and neither row probability measures open-world semantic truth.
Score geometry, temperature convention, candidate composition, and positive semantics all matter. A smaller numerical loss can follow scaling alone without a change in the underlying embeddings.
The living notebook
Explore the model
Interactive lab · vectors
Verify a cosine input without pretending to train encoders
Reset, set both angle 0° and magnitude 1, predict x-projection 1, then inspect or Play. Reset and re-enter both angle 60° and magnitude 1 for x-projection 0.5. With a fixed reference(1,0), these are unit-vector dot products. The model has no learned encoder, candidate matrix, temperature, negative labels, softmax, or loss; playback only traces its selected vector.
- x component
- 1.393
- y component
- 0.975
- Magnitude
- 1.7
Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA correct similarity geometry is only one part of the contrastive supervision contract.
Pause & reason
Check your understanding
Your turn
Try it yourself
A row has one verified positive score and one negative score, both 0.3. With any finite positive divisor temperature, compute the positive probability and one-positive loss. What happens if the second entry is another valid positive under the task?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Equal logits stay equal after any common positive scaling.
Compare with the solution
Both logits are equal, so positive probability is 1/2 and loss is log 2≈0.69314718. Temperature cannot distinguish equal scores. If both entries are valid, the one-positive formulation still penalizes probability assigned to the unlabeled valid entry; the positive-set semantics need a deliberate change rather than a temperature adjustment.
Keep the idea
Take it with you
- State whether temperature divides logits or a reciprocal scale multiplies them.
- Batch entries are negatives only under an intended semantic relation, not merely because their row differs.
- Training loss, retrieval quality, semantic grounding, and calibrated probabilities need separate evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.