Opposite Is Not Different: The Cosine-Similarity Bug in CLIP and Contrastive Learning

· 10 min read

#ml#geometry#contrastive#embeddings#cosine-similarity#clip#siglip#infonce#orthogonality#simplex-packing

Part 2 of 8Geometry of Representations
  1. 1Activations Are Bad for Geometry
  2. 2Opposite Is Not Different: The Cosine-Similarity Bug in CLIP and Contrastive Learningyou are here
  3. 3Not All Infinities Are Equal: The Cross-Entropy Asymmetry Behind Hallucination
  4. 4Untangling the Moons: A Visual History of Contrastive Learning
  5. 5What Makes a Good Latent Space? The Welch Bound and the Simplex
  6. 6Latent on the Spectrum: Why Cats Sit Closer to Dogs Than to Cars
  7. 7The Three States of Information
  8. 8Distillation Is a Geometry, Not an Answer Key

Suppose you are training a contrastive model, and you want two embeddings, a photo of a dog and a paragraph of tax law, to end up as different as possible. Where on the cosine axis do you send them? Every instinct says 1-1: the scale runs from +1+1 for identical down to 1-1 for opposite, so maximal difference should live at the bottom. That instinct is wired into the losses behind CLIP, SimCLR, and most of modern contrastive learning, whose gradients push every negative pair toward opposition.

But look at what a pair at cosine 1-1 actually is. Two unit vectors u,v\mathbf{u}, \mathbf{v} with cosθ(u,v)=1\cos\theta(\mathbf{u}, \mathbf{v}) = -1 are antiparallel, v=u\mathbf{v} = -\mathbf{u}, and antiparallel means linearly dependent. They span a single one-dimensional subspace; knowing u\mathbf{u} determines v\mathbf{v} exactly. In every algebraic, geometric, and information-theoretic sense they are the same direction with a sign flip. Two vectors at cos=1\cos = -1 are not different. They are redundant.

The geometry of difference is orthogonality. Vectors with cosθ=0\cos\theta = 0 are linearly independent: their span has dimension two, the projection of one onto the other is zero, and neither can be reconstructed from the other. Orthogonality is where genuinely new information lives.

If that is right, then some of the most influential losses of the past decade have been asking their embeddings for the wrong thing. The question worth chasing is what that mistake actually cost, and which losses quietly avoided it.

The cosine scale has three landmarks

The standard mental model puts cosine similarity on a single axis from +1+1 (“most similar”) to 1-1 (“most different”). That model is missing the structure of vector spaces. Three points on the scale are qualitatively different:

cosθ\cos\thetaAlgebraic statusInformation content
+1+1Parallel (same direction)Maximally redundant
1-1Antiparallel (opposite direction)Maximally redundant (sign-flipped)
0\phantom{-}0Orthogonal (perpendicular)Zero shared information

The “difference” axis runs from ±1\pm 1 (dependent) to 00 (independent), not from +1+1 to 1-1.

snap to:
drag the green vector tip
θ
cos θ
cos²θ
1 − cos²θ
dim span(u, v)
Drag the green tip around the unit circle. When v lines up with ±u (cos θ = ±1), the span of (u, v) collapses to a single line, the two vectors are linearly dependent. Anywhere else, the span fills the plane and the dimension is 2. The two cases that look 'most different' on the cosine axis (the parallel and antiparallel snap-points) are the two cases where the span is degenerate. Orthogonality is the configuration that actually carries new information.

The information argument is the cleanest way to see it. As a working measure for this post (not an established quantity, but a natural one), define the directional information Idir(u;v)=cos2θI_\text{dir}(\mathbf{u}; \mathbf{v}) = \cos^2 \theta, the fraction of v\mathbf{v}‘s variance explained by u\mathbf{u}. Both parallel and antiparallel give cos2=1\cos^2 = 1: each one is reconstructable from the other up to a sign. Only orthogonality gives cos2=0\cos^2 = 0: neither carries any information about the other.

— cos θ   ‒ ‒ cos² θ (shared info)   ···· 1 − cos² θ (independence) θ = 90°
Three quantities on the cosine axis. The similarity cos θ (accent solid) bottoms out at 180°. Shared information cos²θ (dashed) is the actual redundancy measure, it is maximized at both 0° and 180°, so 'opposite' and 'identical' are equally redundant. The independence curve 1 − cos²θ (dotted) peaks at exactly 90°. Drag along the chart to read the three values at any angle.

The thesis in one line:

  max difference    cos2θ=0    uv  \boxed{\;\text{max difference} \;\Longleftrightarrow\; \cos^2 \theta = 0 \;\Longleftrightarrow\; \mathbf{u} \perp \mathbf{v}\;}

Where does CLIP send its negatives?

The natural first test is the loss behind the most famous embedding space in the field. OpenAI’s CLIP is trained with InfoNCE, a softmax contrastive loss over a batch of NN image-text pairs:

LCLIP=1Nilogexp(simii/τ)kexp(simik/τ).\mathcal{L}_\text{CLIP} = -\frac{1}{N}\sum_i \log \frac{\exp(\mathrm{sim}_{ii}/\tau)}{\sum_k \exp(\mathrm{sim}_{ik}/\tau)}.

The gradient with respect to any negative similarity is strictly positive: the loss decreases monotonically as that similarity decreases. Cosine similarity is bounded below by 1-1, so the global minimum of every negative term is antiparallel alignment. CLIP wants every pair of unlike concepts to be linearly dependent on each other.

This is not merely hard at scale; it is unsatisfiable outright. Antiparallelism is not a resource a bigger space supplies more of: the Gram matrix of kk unit vectors with every pairwise cosine equal to 1-1 has a negative eigenvalue as soon as k>2k > 2, so no more than two vectors can be pairwise opposite in any dimension. What a dd-dimensional space does supply is dd mutually orthogonal antipodal pairs, one per axis of an orthonormal basis, which is why CLIP’s 512-dimensional embedding space carries at most 512 binary oppositions. ImageNet has 1,000 classes; the real world has millions of concepts. A loss demanding cos=1\cos = -1 for every negative is asking for a configuration that does not exist in the space it’s being computed in.

So does CLIP end up somewhere terrible? No, and the distinction matters. Separate where the loss lands from how it gets there. Because the all-pairs-at-1-1 configuration is unreachable, what the softmax family actually converges to is the regular simplex, the near-optimal packing derived below, so the equilibrium is fine. The cost lives in the dynamics: the per-pair gradient keeps pointing at 1-1 with no notion of “far enough,” and the optimiser spends its steps, and its batches, pushing toward a target the geometry cannot honour. I trace this equilibrium-versus-dynamics split through the whole contrastive lineage, loss by loss on live points, in Untangling the Moons.

The computational bill of those dynamics is easy to itemise. Random unit vectors in Sd1\mathbb{S}^{d-1} concentrate near cosine zero with variance 1/d1/d, for d=512d = 512, the standard deviation of a random pair’s cosine is around 0.0440.044. The loss’s gradient is dominated by the rare negatives that happen to lie far enough from the equator to register; most of the batch contributes near-zero signal. To accumulate enough gradient, CLIP was trained with N=32,768N = 32{,}768 pairs per step, an N×NN \times N similarity matrix at 4{\sim}4 GB per device, and a multi-year engineering effort in distributed training, gradient caching, and memory-efficient attention. The geometry is not the sole reason those batches help, large batches also surface hard negatives and tame gradient variance, but it is one steady drain among them, and the one this post can state exactly: part of that engineering paid for a target the space could never deliver.

What would a stopping point look like?

If the damage is in the open-ended push, the fix should be a loss that knows when a negative is far enough, and one loss in the lineage has exactly that. Google’s SigLIP replaces the softmax with a pairwise sigmoid:

LSigLIP=i,jlog ⁣(1+exp(yij(simij/τb))),\mathcal{L}_\text{SigLIP} = \sum_{i, j} \log\!\big(1 + \exp\big(-y_{ij}(\mathrm{sim}_{ij}/\tau - b)\big)\big),

with yij=±1y_{ij} = \pm 1 for matched/mismatched and bb a learnable bias. The sigmoid gradient on mismatched pairs vanishes once simij<b\mathrm{sim}_{ij} < b by a few multiples of τ\tau. The loss does not push negatives toward 1-1; it requires only that they fall below the bias.

That single change aligns the objective with the geometry. Random embeddings on Sd1\mathbb{S}^{d-1} already concentrate around cosine zero, exactly where SigLIP is willing to leave them. The loss isn’t fighting the spherical geometry to drag every negative across the equator. The pairwise structure eliminates the N×NN \times N softmax competition. The result is better zero-shot accuracy with smaller batches and less compute. The headline framing is “sigmoid beats softmax,” but the structural framing is sharper: targeting orthogonality lets the network use the geometry it is operating on instead of fighting against it.

Cross-entropy has always targeted orthogonality

The cross-entropy loss has been doing the right thing the whole time. For discrete distributions p,qp, q,

H(p,q)=xp(x)logq(x),H(p, q) = -\sum_x p(x) \log q(x),

and the key fact is its singularity structure: if supp(p)supp(q)=\mathrm{supp}(p) \cap \mathrm{supp}(q) = \varnothing, then H(p,q)=+H(p, q) = +\infty. Disjoint supports are the probabilistic analog of orthogonal vectors, distributions that share no mass, like vectors that share no projection. The cross-entropy singularity is the orthogonality condition lifted into probability.

The same structure shows up directly in classifier weights. For a softmax classifier with logits zk=wkhz_k = \mathbf{w}_k^\top \mathbf{h} and class label yy, the gradient on wrong-class logits zkz_k pushes them toward -\infty. On the unit sphere the loss has competing pressures: wy\mathbf{w}_y wants to be parallel to h\mathbf{h} to maximise zyz_y, and each wk\mathbf{w}_k with kyk \neq y wants to be antiparallel to h\mathbf{h} to minimise zkz_k. With nn classes sharing the same h\mathbf{h}, the antiparallel target cannot be reached by all n1n-1 wrong-class weights simultaneously, they cannot all be h-\mathbf{h}. The equilibrium is whatever configuration best balances those pressures subject to mutual diversity of the wk\mathbf{w}_k, and the next section shows that configuration is the regular simplex with wk,h=1/(n1)\langle\mathbf{w}_k, \mathbf{h}\rangle = -1/(n-1): approximately orthogonal for any non-trivial multi-class problem, exactly orthogonal in the nn \to \infty limit, and exactly antiparallel only in the binary case n=2n = 2. The “well-separated representations” that plain cross-entropy classifiers produce without any contrastive auxiliary loss are not a happy accident. They are the simplex, sitting where the geometry says it should.

The simplex packing result

What is the optimal arrangement of nn class representations on Sd1\mathbb{S}^{d-1} for nd+1n \le d + 1? It is the regular simplex: nn unit vectors with all pairwise cosines equal to

cosθij=1n1.\cos\theta_{ij} = -\frac{1}{n - 1}.

For n=2n = 2 this is 1-1, exactly antiparallel. The binary case is where the opposition-is-difference intuition came from, and where it is correct. The confusion starts when that intuition is generalized.

The optimal inter-class cosine cos θ = −1/(n−1) for n classes on the simplex. The curve crosses from opposition territory (the bottom dotted line, n=2) into orthogonality territory (the top dashed line, the asymptote) almost immediately. By n=3 the optimal cosine is already only −0.5; by n=10 it is −0.11; by n=50, −0.02. Multi-class is orthogonality up to vanishing corrections. Drag the n slider to see where any specific problem sits.

For n3n \ge 3 the optimal configuration moves rapidly toward orthogonality. n=3n = 3: 12-\tfrac{1}{2}. n=10n = 10: 190.11-\tfrac{1}{9} \approx -0.11. n=50n = 50: 0.02{\sim} -0.02. As nn \to \infty, cosθ0\cos\theta \to 0. Beyond the smallest cases the simplex is orthogonal up to a vanishing correction, and any loss that insists on cos=1\cos = -1 for every negative is asking the geometry for something it cannot supply.

What changes if you get the target right

So what does getting the target right buy? The methods that target orthogonality (SigLIP, plain cross-entropy) share two properties: they align with the natural concentration of measure on Sd1\mathbb{S}^{d-1}, and they reach comparable or better accuracy with substantially less compute. The methods whose gradients chase opposition (SimCLR, CLIP, SupCon) run with enormous batches, and while batch size earns its keep in other ways too, more hard negatives, lower gradient variance, part of what those batches pay for is the standing tension between the objective and the sphere it lives on.

The thesis, in one sentence: the geometry of difference is not opposition; it is orthogonality. The equilibrium was never the problem, the simplex these losses settle into is nearly optimal; the problem is a gradient that never knows where to stop. The most influential contrastive losses of the past five years spent real engineering effort compensating for that geometric mistake, one factor among several behind their appetite for compute, and the loss that did not make the mistake was sitting beside them the whole time, in the form of plain cross-entropy.

Cite as

Bouhsine, T. (). Opposite Is Not Different. Records of the !mmortal Data Scientist. https://tahabouhsine.com/blog/opposite-is-not-different/

BibTeX
@misc{bouhsine2026oppositeisnotdifferent,
  author       = {Bouhsine, Taha},
  title        = {Opposite Is Not Different},
  year         = {2026},
  month        = {feb},
  howpublished = {\url{https://tahabouhsine.com/blog/opposite-is-not-different/}},
  note         = {Blog post, Records of the !mmortal Data Scientist}
}

For the underlying paper

Bouhsine, T. (2026). Opposite ≠ Different: The Orthogonality Thesis. Unpublished manuscript. [PDF]

BibTeX
@unpublished{bouhsine2026opposite,
  author = {Bouhsine, T.},
  title  = {Opposite ≠ Different: The Orthogonality Thesis},
  year   = {2026},
  note   = {Unpublished manuscript}
}

References

  1. van den Oord, A., Li, Y., Vinyals, O. (2018). Representation Learning with Contrastive Predictive Coding (InfoNCE). arXiv:1807.03748
  2. Chen, T., Kornblith, S., Norouzi, M., Hinton, G. (2020). A Simple Framework for Contrastive Learning of Visual Representations (SimCLR). ICML 2020.arXiv:2002.05709
  3. Khosla, P., et al. (2020). Supervised Contrastive Learning. NeurIPS 2020.arXiv:2004.11362
  4. Papyan, V., Han, X. Y., Donoho, D. L. (2020). Prevalence of Neural Collapse During the Terminal Phase of Deep Learning Training. Proceedings of the National Academy of Sciences 117(40).arXiv:2008.08186
  5. Radford, A., et al. (2021). Learning Transferable Visual Models From Natural Language Supervision (CLIP). ICML 2021.arXiv:2103.00020
  6. Zhai, X., Mustafa, B., Kolesnikov, A., Beyer, L. (2023). Sigmoid Loss for Language Image Pre-Training (SigLIP). ICCV 2023.arXiv:2303.15343