Cross-Modal Contrastive Alignment and the Modality Gap
Train a text tower and a chart tower with the same symmetric CLIP loss and the two modalities settle into disjoint cones on the sphere — a modality gap between the centroids that contrastive training shrinks but never quite closes. We prove the gap is the coherent, rank-one part of cross-modal misalignment (an orthogonal split L_align = gap² + dispersion) and that it is INVISIBLE to maximum-inner-product ranking: a shared offset is a per-query constant, so recall is exactly gap-invariant. The gap is a calibration artifact — it shifts absolute similarities, never the order — and lower training temperature preserves a larger residual gap.
Overview and motivation
The prerequisite topics trained a single dual encoder: one tower for queries, one for documents, taught by InfoNCE to place a query near its answer, and read by dense retrieval as a maximum-inner-product lookup. A multimodal system trains two encoders for two modalities — a text tower and a chart tower — with the same symmetric contrastive loss, so a text query can retrieve a chart of the same company, and a chart can retrieve its filing. This is the CLIP recipe (Radford et al., 2021), and it is the engine of the multimodal financial RAG capstone.
Liang et al. (2022) noticed something unsettling about the result. After training, the two modalities do not interleave on the sphere — they occupy disjoint cones. The text embeddings cluster in one region, the chart embeddings in another, and there is a measurable modality gap between the two centroids that contrastive training shrinks but never quite closes. The natural worry is that this gap is a defect: if the cones are pulled apart, surely cross-modal retrieval suffers, and surely we should center the embeddings to close it.
We will prove the opposite. The gap is the coherent, rank-one part of cross-modal misalignment, it is bounded by the alignment loss, and — the headline — it is invisible to ranking. A modality gap is a calibration artifact: it shifts absolute cross-modal similarities, never their order. The lab below makes all three readings interactive; we develop them in turn.
Offsetting every chart embedding by α·g changes each MIPS score by the per-query constant α⟨t_i, g⟩, so the argsort — and recall@1 — cannot move. The green line is recomputed live from the baked score matrix as you drag: it stays pinned at 0.4583 for every α. The gap is invisible to ranking. Cosine, which renormalizes the offset keys, is not gap-invariant: its recall climbs to 1.000 as α → 1 removes the gap. The gap is a calibration artifact — it shifts absolute similarities (a threshold, a softmax), never the order.
We write and for the unit embeddings of company ‘s text view and chart view, paired by construction (the diagonal is the positive). The two cones are vMF clusters around modality-specific mean directions; a tilt parameter controls how strongly each view is pulled toward its modality cone versus its company identity, so is the no-gap control and larger pulls the cones apart.
Movement 1 — what the gap is: an orthogonal decomposition
The contrastive loss controls paired distances. The natural measure of how far apart the paired views sit is the alignment loss of Wang & Isola (2020), inherited from the prerequisite,
The modality gap is a different object: the distance between the two centroids,
so the gap vector is the mean of the per-pair differences. These two quantities are related by an exact decomposition.
Theorem 1 (The modality gap is the coherent part of misalignment).
Stack the per-pair differences as the rows of , . Then the alignment loss splits orthogonally into the squared gap and a dispersion term,
where is the gap vector. The gap is the coherent, rank-one component of the misalignment (the shared offset every pair carries); the dispersion is its orthogonal complement.
Proof (Proof).
Decompose the difference matrix into a coherent rank-one part and a remainder, , where is the all-ones vector and has rows . The rows of sum to zero, because . The two parts are orthogonal in the Frobenius inner product:
Pythagoras in then gives . Dividing by yields .
∎The decomposition is the geometric content of the modality gap. The gap is exactly the projection of the cross-modal misalignment onto the one-dimensional shared-offset subspace — equivalently, is the constant vector that minimizes , the centroid. Because a projection can only shorten a vector, the gap is bounded by the loss.
Corollary 1 (The gap is bounded by the alignment loss).
, with equality if and only if the dispersion vanishes, i.e. every is the same constant vector — a rigid translation between the two cones. In general the inequality is strict, and contrastive training can drive down by collapsing the dispersion while a coherent gap survives.
This is the cone effect in one line. Minimizing the contrastive loss reduces , but the loss does not distinguish between reducing the gap and reducing the dispersion. A solution that scatters the incoherent part while keeping a coherent offset between the cones is, to the loss, almost as good as one that closes the gap. Panel A of the lab sweeps the tilt : the gap² bar climbs toward four-fifths of the alignment loss while the dispersion bar shrinks, and the two-dimensional projection shows the text cone (left) and chart cone (right) pulled apart along the gap vector.
Movement 2 — the headline: the gap is invisible to ranking
If the gap is a coherent offset between the cones, what does it cost retrieval? The instinct is that pulling the cones apart must hurt: a text query lives in the text cone, the charts live in the chart cone, and the gap is the distance the query must “reach across.” We will see that under the scoring rule dense retrieval actually uses — maximum inner product — the gap costs nothing.
Cross-modal retrieval scores a text query against every chart by the inner product and returns the top-. To ask what the gap costs, we intervene on it directly: shift every chart embedding by a multiple of the gap vector, . At the chart centroid moves onto the text centroid and the gap is removed; at the gap is intact.
Theorem 2 (Gap-invariance of maximum-inner-product ranking).
Under the offset , every cross-modal score changes by a quantity that depends only on the query,
The added term is constant in . Therefore, for every query , the ordering of the scores over — and hence the top- set and — is exactly invariant to . The modality gap is invisible to MIPS ranking.
Proof (Proof).
Fix a query . Adding the same constant to every entry of the score row is a monotone transformation of that row: for any , . A monotone transformation preserves the argsort, so , and in particular the set of the largest entries is unchanged. Since this holds for every query, is identical for every .
∎This is the thesis. The gap is not a ranking defect; it is a calibration artifact. It shifts the absolute similarities — every cross-modal score drops by a per-query amount when the cones are apart — but it leaves the order untouched, and ranking reads only the order. Panel B of the lab recomputes MIPS recall live from the baked score matrix as you drag : the green line does not move, pinned at its hard-corpus value, while the chart you are reordering is the same one every time. The gap is real, and retrieval does not care.
The honest exception is cosine. Most embeddings are unit-normalized, and cosine retrieval renormalizes the offset key, . The denominator depends on , so the added term no longer factors out of the argsort.
Remark (Cosine retrieval is not gap-invariant).
Renormalizing the offset keys reintroduces a -dependence, so cosine ranking is not invariant to . On the corpus of the lab, cosine recall@1 starts equal to the MIPS recall at (both score unit vectors) and rises to as removes the gap. So removing the gap helps cosine retrieval — but the lesson is not “close the gap,” it is that the gap is an absolute-similarity effect. Anything that reads the cosine, a fixed relevance threshold, or a temperature-scaled softmax across modalities is miscalibrated by the gap; the pure ranking is not.
Movement 3 — where the gap comes from: the cone effect and temperature
The decomposition says the gap can survive training; it does not say it will. To see where the gap comes from and what controls it, we model the two cones at “initialization” — two vMF clusters separated by the tilt — and then train. Training is a deterministic full-batch projected gradient descent on the symmetric CLIP loss, which is two of the prerequisite’s in-batch InfoNCE losses, one per direction,
reusing the prerequisite’s loss byte-for-byte (the notebook checks this to machine precision). We run the descent to convergence at a range of temperatures and read off the residual gap.
The naive headline — “contrastive training preserves the gap” — is false on this toy, and worth stating plainly. Full-batch descent to convergence is far more thorough than stochastic training: at moderate temperature it closes the gap to zero. What survives is a direction, not a fixed amount.
Remark (Lower temperature preserves a larger residual gap).
Across the temperature ladder, the residual gap after training is monotone: at moderate-to-high temperature () the descent closes the gap to zero, and as falls the residual gap grows. Lower temperature buys tighter, higher-concentration cones — the inverse-temperature-as-concentration reading of the prerequisite’s alignment/uniformity trade-off — and a tighter cone holds a larger coherent offset. We assert only this direction, never a fixed residual.
This is the cone effect made operational. Temperature is the knob the prerequisite identified as trading alignment against uniformity; here it also sets how much of the initialization gap the trained encoders keep. Panel C of the lab reads the ladder: the residual gap rises as falls, with the alignment loss and the union uniformity tracking alongside. In a real CLIP-style system the persistent gap is a stochastic-training and finite-step phenomenon our full-batch surrogate does not model — which is exactly why we keep the claim to the monotone direction and flag the rest.
Honest accounting
Where this sits
This topic closes the neural-retrieval track. The lineage ran from InfoNCE (how a dual encoder is trained) through dense retrieval (how its geometry becomes a MIPS lookup with a rank ceiling), late interaction and learned sparse, cross-encoders and distillation; cross-modal alignment is the same machinery with a second modality bolted on, and the modality gap is what that second tower introduces. The decomposition and the gap-invariance theorem are the new mathematics; everything else — the symmetric loss, the alignment and uniformity functionals, the MIPS ranking, the vMF cone geometry — is imported, never rebuilt.
The forward connections run into evaluation and generation. The gap is a calibration object, so it belongs with the work on recalibrating over-confident retrieval scores; and it is the missing piece under the multimodal capstone, which fuses text, charts, and tables of the same companies and names the modality gap without proving why fusion must recombine ranks rather than cross-modal scores. The answer is Theorem 2: across modalities, ranks are gap-invariant and absolute scores are not.
Connections
- The direct prerequisite and the engine of the whole topic: the symmetric cross-modal loss is two of its in-batch InfoNCE losses, one per direction, and the alignment and uniformity functionals it defines are exactly what the modality gap decomposes — L_align is its alignment loss byte-for-byte, and the cone effect is its alignment/uniformity trade-off read across two encoders instead of one. infonce-contrastive-objective
- The second prerequisite: cross-modal retrieval is its maximum-inner-product search with the document tower swapped for a second modality's tower, so the gap-invariance theorem is a statement about its MIPS ranking — a shared key offset is a per-query constant the argsort ignores — and the recall it measures is the recall this topic proves the gap cannot change. dense-retrieval-dual-encoders
- The sphere the cones live on: the two modality cones are vMF clusters, the gap is the distance between their mean directions, and the cone concentration that decides whether companies stay resolvable within a cone is the mean resultant length A_d(kappa) developed there. hypersphere-vmf-geometry
- Where the gap actually bites: a modality gap leaves ranking untouched but corrupts absolute cross-modal similarities, so a fixed relevance threshold or a temperature-scaled softmax read across modalities is miscalibrated — the gap is a calibration object, recalibrated exactly as that topic recalibrates over-confident retrieval scores. significance-testing-calibration
- The system this topic supplies the missing mathematics for: the capstone fuses text, charts, and tables of the same companies, and the modality gap it names without proving is the cone separation analyzed here — the reason fusion recombines ranks rather than absolute cross-modal scores. capstone-multimodal-financial-rag
References & Further Reading
- paper Mind the Gap: Understanding the Modality Gap in Multi-modal Contrastive Representation Learning — Liang, Zhang, Kwon, Yeung & Zou (2022) The paper that named and measured the modality gap: a cone effect from random initialization, preserved by contrastive training, that this topic formalizes on a vMF toy.
- paper Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere — Wang & Isola (2020) The alignment/uniformity decomposition of the contrastive loss; the modality gap is the coherent residual that uniformity cannot remove because alignment only constrains paired distances.
- paper Learning Transferable Visual Models From Natural Language Supervision — Radford, Kim, Hallacy, Ramesh, Goh, Agarwal, Sastry, Askell, Mishkin, Clark, Krueger & Sutskever (2021) CLIP: the symmetric cross-modal contrastive loss whose two in-batch InfoNCE directions this topic trains and decomposes.
- paper Dense Passage Retrieval for Open-Domain Question Answering — Karpukhin, Oğuz, Min, Lewis, Wu, Edunov, Chen & Yih (2020) The dual-encoder retrieval setting the cross-modal towers inherit; the MIPS ranking whose gap-invariance is the headline theorem.
- paper Representation Learning with Contrastive Predictive Coding — van den Oord, Li & Vinyals (2018) The InfoNCE objective and its mutual-information reading, inherited from the prerequisite and applied symmetrically across modalities.