← Latest papers
🤖 machine learning

On the modality gap and the contrastive loss in multi-modal representation learning

This paper identifies the modality gap in CLIP-style contrastive learning as a low-temperature failure of the InfoNCE objective with independent encoders and proposes xNCE, a modified loss function incorporating intra-modality negatives that eliminates this gap while improving zero-shot classification performance without sacrificing retrieval accuracy.

Original authors: Fabian Mager, Hiba Nassar, Lars Kai Hansen

Published 2026-07-14
📖 5 min read🧠 Deep dive

Original authors: Fabian Mager, Hiba Nassar, Lars Kai Hansen

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have two best friends: one who speaks only "Picture" and another who speaks only "Word." You want them to hang out in the same room (a shared digital space) so they can understand each other perfectly. This is what AI models like CLIP try to do: they learn to match images with their descriptions.

But here's the weird thing: even after training, these two friends often end up standing in opposite corners of the room. They can still talk to each other, but they never actually mix. The image-embeddings huddle in one cluster, and the text-embeddings huddle in another. This is called the "modality gap."

For a long time, scientists thought this separation happened because the friends started with different personalities (random initialization) or because they came from different neighborhoods (different data). But this paper, by Fabian Mager, Hiba Nassar, and Lars Kai Hansen, says: "Wait a minute. That's not it."

The Real Culprit: A Bad Game of "Hot Potato"

The authors ran a clever experiment to prove their point. They took two identical twins (two independent encoders with the exact same starting weights) and fed them the exact same pictures, just slightly tweaked (like rotating or zooming in). In a perfect world, these twins should produce identical outputs.

But when they used the standard training method (called InfoNCE) with a very specific setting (a "low temperature," which makes the AI very picky), the twins still drifted apart. One twin started speaking "Picture," and the other "Text," even though they were looking at the same thing!

This proves that the gap isn't caused by the data or the starting point. Instead, the paper argues that the InfoNCE formula itself has a glitch when used with two separate encoders.

Think of it like this: The training game tells the AI, "Make the matching pair (image + text) super close, and make all the non-matching pairs super far away."

  • The Glitch: To make the non-matching pairs "far away," the AI finds a lazy shortcut. It pushes the entire "Image" group to one side of the room and the entire "Text" group to the other side. This satisfies the rule "keep them apart" without actually learning to mix them. The paper calls this a "mode-failure"—the AI found a local minimum where it thinks it's doing a good job, but it's actually just hiding the two groups in separate corners.

This happens specifically when the AI is set to be very strict (low temperature). If you make the AI more relaxed (high temperature), the groups mix, but then the AI forgets how to tell different objects apart, which ruins its ability to recognize things later.

The Solution: xNCE (The "Mixologist")

The authors propose a simple fix called xNCE.

Imagine the training game again. In the old version, when the AI tried to push a "non-matching" image away from a "non-matching" text, it just pushed them to opposite corners.
In the new xNCE version, the game changes the rules: "You can't just push the text away from the image. You also have to push the text away from other texts, and the image away from other images."

By mixing the "negative" examples (the things the AI should not match) so that they come from both groups, the AI is forced to stop hiding in the corners. It has to learn to keep the groups mixed together while still keeping the specific matches close.

What Happened in the Lab?

The authors tested this on two things:

  1. MNIST (Handwritten Digits): They treated the two encoders as if they were two different "modalities."
    • The Result: With the old method at low temperatures, the two groups were completely separate (100% separable). With xNCE, the gap shrank dramatically, even at those strict low temperatures.
  2. COCO (Images and Captions): This is the real-world test.
    • The Gap: The standard method left a huge gap (distance of 0.88). The new method shrank it to 0.12 (with a tiny mix) and even 0.05 (with a heavy mix).
    • The Trade-off: The authors found a sweet spot. If they mixed just a little bit (1% to 5% of the negatives), they could almost completely close the gap without hurting the AI's ability to find the right image for a text (retrieval).
    • The Bonus: Most importantly, this new method made the AI better at guessing what an image is without being taught (zero-shot classification). On four different tests, the new method beat the old one. For example, on the CIFAR-100 test, it improved accuracy by 4.2 percentage points.

What the Paper Doesn't Say

It's important to know what this paper doesn't claim:

  • It does not say that high temperatures are the answer. In fact, the paper shows that just turning up the temperature to mix the groups destroys the AI's ability to recognize specific objects (dropping ImageNet accuracy from 51.9% to 15.5%).
  • It does not say that adding extra "regularization" (forcing the AI to be uniform) is the best fix. The authors tested a regularized version, and it didn't improve zero-shot performance as well as their mixing method did.
  • It does not claim this is a magic bullet for every problem. The paper suggests that for tasks needing extreme precision (like finding the #1 exact match), you might want to mix very little (1-5%). For tasks needing a more general understanding, you might mix more.

The Bottom Line

The paper suggests that the "modality gap" isn't a mystery of nature; it's a bug in the standard training recipe. By simply mixing up the "negative" examples in the training game, the authors created a method (xNCE) that forces the AI to actually learn a shared language, rather than just hiding in separate corners. It's a small tweak that makes the AI smarter, more unified, and better at guessing new things, all while keeping the strict "picky" settings that usually make it so good at spotting details.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →