Contrastive and Multimodal Representation Learning
Paired views do not teach a model what the world is; they teach which changes should count as the same.
TLDR
- A contrastive model learns an equivalence relation chosen by its pairs. Positive views are pulled together; everything that varies between them is pressured to matter less.
- Multimodal alignment learns mainly from information shared across modalities. Captions, reports and audio descriptions act as selective labels, preserving mentioned concepts while neglecting unspoken detail.
- Negatives decide which distinctions remain visible. Random negatives support coarse retrieval; false negatives can tear semantic neighbours apart, while well-designed hard negatives can force attributes, relations and order into the representation.
- Feature loss is not inevitable or caused by the loss alone. Capacity, architecture, optimisation and auxiliary objectives can preserve view-private information, so matched controls are required before blaming contrastive training.
- The design decision moves upstream. Audit the pair generator, augmentation policy and evaluation probes as an invariance contract before choosing batch size, temperature or model scale.
The traffic light that became colourless
Imagine training a street-scene encoder from pairs of photographs and captions. Every photograph of a traffic light is paired with text such as “traffic light at a junction”. To make training robust, each photograph is also subjected to heavy colour jitter. The model sees the same lamp under warmer, colder and partially desaturated renderings, and every one of those views is declared a positive match.
For an object-retrieval system, this is useful. The representation should recognise the same physical category under shade, camera variation and weather. Now reuse the encoder in a driving controller that must distinguish a red signal from a green one. The very transformation that protected object identity has made the control state unreliable. The model did not mysteriously forget colour. Its training procedure repeatedly supplied evidence that colour changes should not alter identity, while the captions supplied no countervailing reason to preserve the signal state.
Change one causal feature at a time. Keep the photographs, architecture and optimiser fixed, but replace the captions with “red traffic light” and “green traffic light”. Colour now helps solve the pairing task. Or keep the original captions and change only the downstream decision from signal control to object retrieval. The representation can now appear excellent without changing at all. The success or failure belongs to the relation between the pair policy and the later decision, not to an abstract quantity called representation quality.
This is the central answer of contrastive learning. A positive pair says, “treat these observations as the same for the purpose of this objective”. A negative comparison says, “retain enough difference to choose one over the other”. In multimodal learning, the overlap between image, text, sound or structured data determines what can support alignment. Details available to only one view receive weak or absent cross-modal supervision. The resulting representation is powerful precisely because it discards variation, but the discarded variation may be the next task's evidence.
Part IThe pair is the task
A supervised classifier receives an explicit target such as “cat”, “pneumonia” or “late payment”. Contrastive learning often looks less prescriptive because it can work without class labels. Yet it still receives a target. The target is encoded in the pairing rule. Two crops from one photograph, two adjacent segments of speech, an image and its caption, or a document and its translation are declared related. Other items in the comparison set are treated as alternatives.
That declaration is a small programme of invariance. A crop pair says that some translation, occlusion and scale change should preserve what matters. An audio-transcript pair says that voice, microphone response and background noise should not block access to the linguistic content. An image-caption pair says that the visual scene should be recoverable through the concepts selected by the caption. None of these statements is universal. A speaker-identification task needs voice; an acoustic-fault detector may need background vibration; an image-forensics task may need the exact crop boundary.
A graph before a geometry
It helps to picture the training data as a graph before picturing an embedding space. Each observation is a node. A positive edge joins two views that should agree. A batch supplies competing nodes that should not win the same match. Training then constructs a geometry that makes those graph relations easy to recover.
Suppose repeated positive edges connect an object across camera angles, crops and captions. In an idealised limit, those edges generate an equivalence relation: observations connected by the permitted transformations belong to one class. The learned map compresses each class into a neighbourhood while keeping rival classes distinguishable. Mathematicians would call the resulting object a quotient of the original observation space. The useful intuition is that the representation operates on “world observations modulo the changes declared irrelevant”.
The analogy has limits. Real positive relations can be noisy and non-transitive. A model rarely maps every positive view to exactly one point. Finite capacity, optimisation, projection heads and auxiliary losses can leave view-specific detail intact. Still, the quotient picture exposes the causal burden: every edge added to the positive graph is a vote for invariance, and every missing distinction must be recovered from some other signal.
Part IIWhat the loss actually asks
Consider a batch of N paired observations. An image encoder maps item xi to a normalised vector zi. A text encoder maps its paired caption yi to a normalised vector wi. Their dot product is cosine similarity. A common symmetric contrastive objective is:
The first term asks each image to identify its paired text among the batch. The second asks each text to identify its paired image. The temperature τ controls how sharply similarity differences affect the probabilities. A smaller temperature concentrates pressure on the nearest competitors. A larger one spreads credit and blame across more of the batch. Changing τ changes optimisation geometry, but it does not tell the system whether colour, count or causal order deserves preservation.
The gradient has two visible jobs. It pulls the positive score zi·wi upward and pushes competing scores downward in proportion to their current softmax probabilities. Wang and Isola described related asymptotic properties as alignment of positive pairs and uniformity of the representation distribution on the hypersphere.[3] This language is useful because collapse avoidance and pair agreement are separate pressures. A representation that maps every input to one point has perfect agreement but cannot identify a partner.
Contrastive predictive coding introduced a probabilistic contrastive objective for extracting information useful to predict future observations.[1] InfoNCE is therefore often discussed as a mutual-information estimator or lower bound. That connection is informative, but it should not become a metaphysics of representation. Variational mutual-information bounds can develop severe bias or variance in high-dimensional settings, and a high estimate does not identify which semantic factor has been preserved.[5] Mutual information is a lens on dependence, not a list of the distinctions a decision will require.
The operational interpretation is simpler. The loss rewards any feature combination that reliably identifies partners. If object category alone separates most items, category may dominate. If every batch contains many instances of the same category but different attributes, the system must use finer distinctions. If captions repeatedly omit a factor, the cross-modal loss offers little reason for the text interface to expose it. The loss optimises discriminability under the sampled comparisons, not semantic completeness.
Part IVNegatives carve the boundary
Positive pairs say what may remain close. Negatives say what must be distinguishable in the current comparison. This second half of the objective is easy to underestimate because “all other items in the batch” sounds neutral. It is not neutral. A batch is a sampled boundary around every example.
If an image of a dog chasing a person is contrasted mostly with captions about buses, kitchens and oceans, the words “dog”, “person” and “chasing” are enough. A bag-of-words representation can win. Replace one easy negative with “a person chasing a dog”. The nouns no longer identify the positive. Word order and relation direction become decision-relevant. Nothing about the architecture changed. The sampled alternative changed what the model had to know.
Benchmarks have exposed this gap. ARO was designed around attributes, relations and word order, showing that strong vision-language systems could perform poorly when success required composition rather than unordered concept overlap.[15] Winoground used two images and two captions containing the same words in different orders, so a correct match required relational understanding.[16] Such tests do not prove that one benchmark fully isolates composition, but they demonstrate why ordinary retrieval accuracy can reward a weaker solution.
The reverse problem is a false negative. Two different photographs may both depict the same disease pattern, product type or intent. Instance-level contrastive training treats them as competitors merely because they are not the designated pair. Debiased contrastive learning analysed this mismatch and proposed correcting for negatives that may share the latent class.[10] In specialised domains, false negatives are especially common because many cases legitimately share semantics while only one report is paired to one record.
Hard-negative mining therefore needs a truth test. Select examples that are close under the current model but genuinely different under the required decision. A colour-swapped caption is useful when colour must be retained. It is harmful when the image is monochrome or the colour word is metaphorical. A relation-swapped sentence is useful when the scene visually establishes the relation. It is noise when the image is ambiguous. Hardness is an optimisation property; validity is an evidence property.
Batch size and temperature affect how many competitors matter, but they do not solve semantic sampling. SigLIP replaced the globally normalised softmax with pairwise sigmoid losses and showed that strong image-text learning need not depend on the same giant-batch regime.[9] This is an important systems alternative. It still requires a defensible account of which pairs are positive and which are negative.
The strongest objection: pressure is not destiny
The argument so far can be overstated as “anything absent from a caption is erased”. That statement is false. A high-capacity image encoder can preserve colour while using shape for cross-modal alignment. A projection head can expose an invariant interface while the backbone retains detail. Pretraining may already encode a feature, and a later objective may not remove it. Training dynamics and inductive bias decide which of many loss-minimising solutions is reached.
Research supports this caution. Shortcut analyses found that contrastive objectives can suppress predictive features while favouring alternatives that separate sampled pairs.[11] Other work documented subclass collapse and suppression of harder class-relevant features, with embedding dimension and augmentation quality affecting the result.[12] Yet theoretical analysis also showed that augmentations and loss alone are insufficient to explain generalisation without the function class and training algorithm.[13] Feature Dropout further complicates a simple preservation rule: in multi-task foundation-model settings, augmentations that destroy one label can sometimes prevent that feature from dominating and improve transfer to other tasks.[14]
A serious negative control
Train two systems on identical paired data. In the first, fine-tune the complete image encoder with the contrastive loss. In the second, freeze the same pretrained image encoder and train only the text encoder and projection. Evaluate colour, count and relation at three locations: the image backbone, the projected embedding and the actual downstream interface. Also include a non-contrastive reconstruction or supervised head using the same backbone capacity and data where appropriate.
If colour disappears from the projected embedding but remains decodable in the frozen backbone, the correct claim is interface-level suppression, not destruction of visual knowledge. If colour disappears only in the fully fine-tuned system, contrastive updates become a plausible cause. If both systems retain colour yet the downstream application ignores it, the failure belongs to readout or task design. If every matched control loses colour, the dataset or architecture may be the common cause.
Decodability is still not causal use. A probe may extract information that the deployed head never consults. Add interventions: alter colour while preserving shape, trace the resulting embedding and decision change, and compare it with a colour-preserving control. The aim is not to locate an essence called “the representation”. It is to determine which factor changes which consumed state under a controlled intervention.
Part VThe invariance contract
Contrastive projects often begin with model family, batch size and compute budget. The causal decision comes earlier: what transformations are allowed to preserve identity, and what distinctions must survive? Write that answer as an invariance contract before training. It is a compact agreement between the pair generator, the representation interface and the downstream decision.
| Factor | Positive-pair policy | Decision requirement | Counter-signal | Release probe |
|---|---|---|---|---|
| Object identity | May vary crop, lighting and viewpoint within an object. | Must remain stable for retrieval. | Same-view negatives from other objects. | Retrieval under held-out viewpoint and weather. |
| Signal colour | Do not use hue transforms that cross operational states. | Must separate red, amber and green. | Colour-labelled positives and colour-swapped valid negatives. | Intervention test with fixed shape and changed state. |
| Count | Crops may not remove counted instances without changing the label. | Must distinguish one, two and many. | Count-specific captions or auxiliary count loss. | Balanced count probe plus occlusion stress test. |
| Relation and order | Geometric transforms must update relation text consistently. | Must preserve subject, object and direction. | Relation-swapped hard negatives verified against the image. | Paired captions with identical words and different order. |
| Modality provenance | Alignment need not erase source identity. | Must retain source, time and confidence for review. | Typed metadata outside the embedding. | Evidence receipt can reconstruct each source. |
| Rare subtype | Do not treat another subtype as a negative merely because it is unpaired. | Must remain discoverable despite low frequency. | Group-aware sampling and subtype supervision. | Per-subtype recall with confidence intervals. |
The table is not a universal taxonomy. It forces five questions to meet in one place: the latent factor, the transformation applied to positives, the later decision, the evidence that preserves a distinction, and the test that can reject the design. A useful contract contains explicit contradictions. Lighting should be invariant for object identity, but signal colour should not. Crop should be invariant for texture classification, but not when it changes count.
- Define the consumed decision. Name the action, retrieval or classification that will use the representation. “General embedding” is not a decision. Record the harm of merging two states and the cost of keeping them separate.
- Inventory latent factors. Enumerate attributes, relations, quantities, source conditions and temporal variables that could vary. Mark each as must-merge, must-separate, conditionally relevant or currently unknown.
- Interrogate every positive generator. For each augmentation, pairing rule or temporal window, ask which factors can change across the pair. Run transformation-specific probes rather than one average score.
- Audit the negative population. Estimate false-negative rates by group, inspect nearest mined negatives, and add valid counterfactual negatives for distinctions that random batches rarely test.
- Localise retention. Probe the backbone, projection, shared embedding and downstream head. Use controlled interventions as well as decoders. Compare frozen, fine-tuned and auxiliary-objective controls.
- Release against a factor ledger. Report retrieval or zero-shot quality beside must-keep factor scores, subgroup uncertainty, out-of-distribution transformations and known unresolved distinctions. Withdraw the representation from a decision when its contract is violated.
Dataset curation belongs inside this contract. DataComp held the training procedure and compute budget comparatively fixed while varying selection from a large candidate pool, demonstrating how data design changes downstream outcomes.[18] The lesson is broader than ranking filtering methods. The pair population is part of the model specification because it defines the empirical equivalence relation the optimiser sees.
stateDiagram-v2 [*] --> Claim state "A graph before a geometry" as Claim state "Four meanings of “the feature<br/>is gone”" as Test state "A minimal worked example" as Revision Claim --> Test: expose mechanism Test --> Decision: evidence survives Test --> Revision: rival survives Revision --> Claim: narrow or rebuild Decision --> [*]
Run the contrastive invariance lab
The companion Python lab makes the paper's claim falsifiable on synthetic data. Each “image” vector contains a one-hot shape, a one-hot colour and noise. Each “text” vector always contains shape but contains colour with probability 0, 0.1 or 1. Two linear encoders produce six-dimensional normalised embeddings and train with the symmetric loss above.
After training, text prototypes test zero-shot shape and colour recognition from held-out image vectors. The positive case predicts that shape remains strong when every caption names it, while colour approaches chance when captions omit it and rises when even a minority of captions mention it. The negative case shuffles pairings. No meaningful cross-modal direction should survive.
python -m pip install torch
python contrastive_invariance_lab.py
| Condition | Shape accuracy | Colour accuracy | Interpretation |
|---|---|---|---|
| Colour omitted | 99.9% ± 0.2 | 27.7% ± 1.4 | Shared shape aligns; private colour stays near 25% chance. |
| Colour in 10% of captions | 100.0% ± 0.0 | 84.1% ± 1.0 | Sparse cross-modal evidence creates a usable colour direction. |
| Colour always mentioned | 96.0% ± 4.2 | 93.6% ± 3.8 | Both factors are shared, with some finite-capacity trade-off. |
| Shuffled pairs | 27.3% ± 5.6 | 22.5% ± 6.0 | Broken correspondence destroys both alignments. |
The first condition is the minimal positive case: shape is consistently shared and reaches 99.9%, while colour remains 27.7%, close to the 25% chance level. Mentioning colour in only 10% of captions raises colour accuracy to 84.1% without hurting shape. Always mentioning colour supports both factors, although a six-dimensional embedding and small synthetic sample produce greater variance. Shuffling pairs collapses both scores towards chance.
This result does not establish that real multimodal models erase every unmentioned factor. The image encoder here is linear, trained from scratch and evaluated through text prototypes. Those assumptions deliberately make the cross-modal bottleneck visible. Change the capacity, pretraining, layer or auxiliary objective and the result can change. The lab's value is causal transparency: pair coverage is the only intended difference across the first three conditions.
Full executable Python artefact
The script requires Python 3.10 or later and PyTorch 2.x. It uses synthetic data, three fixed seeds, positive assertions and a shuffled-pair negative assertion.
"""Synthetic contrastive-invariance lab for paper 55.
Python 3.10+ with PyTorch 2.x. The data are synthetic teaching fixtures.
The positive case preserves shape across image and text. Colour is either
omitted, mentioned in some captions, or always mentioned. The negative case
shuffles image-text pairings. Results are averaged over three seeds.
"""
from __future__ import annotations
from dataclasses import dataclass
from statistics import mean, pstdev
import torch
import torch.nn.functional as F
N = 256
N_SHAPES = 4
N_COLOURS = 4
NOISE_DIMS = 4
EMBED_DIM = 6
STEPS = 300
TAU = 0.07
SEEDS = (0, 1, 2)
def make_data(n: int, colour_mention_probability: float, seed: int):
"""Create paired image/text vectors with shared shape and optional colour."""
generator = torch.Generator().manual_seed(seed)
shape = torch.randint(N_SHAPES, (n,), generator=generator)
colour = torch.randint(N_COLOURS, (n,), generator=generator)
image = torch.cat(
[
F.one_hot(shape, N_SHAPES).float(),
F.one_hot(colour, N_COLOURS).float(),
0.25 * torch.randn(n, NOISE_DIMS, generator=generator),
],
dim=1,
)
mentions_colour = (
torch.rand(n, generator=generator) < colour_mention_probability
).float().unsqueeze(1)
text = torch.cat(
[
F.one_hot(shape, N_SHAPES).float(),
mentions_colour * F.one_hot(colour, N_COLOURS).float(),
0.25 * torch.randn(n, NOISE_DIMS, generator=generator),
],
dim=1,
)
return image, text, shape, colour
class DualEncoder(torch.nn.Module):
def __init__(self, input_dim: int, embedding_dim: int):
super().__init__()
self.image = torch.nn.Linear(input_dim, embedding_dim, bias=False)
self.text = torch.nn.Linear(input_dim, embedding_dim, bias=False)
def encode_image(self, x: torch.Tensor) -> torch.Tensor:
return F.normalize(self.image(x), dim=1)
def encode_text(self, y: torch.Tensor) -> torch.Tensor:
return F.normalize(self.text(y), dim=1)
def train(
colour_mention_probability: float,
seed: int,
shuffle_pairs: bool = False,
) -> DualEncoder:
torch.manual_seed(seed)
image, text, _, _ = make_data(N, colour_mention_probability, seed)
if shuffle_pairs:
permutation = torch.randperm(
N, generator=torch.Generator().manual_seed(seed + 111)
)
text = text[permutation]
model = DualEncoder(image.shape[1], EMBED_DIM)
optimiser = torch.optim.AdamW(model.parameters(), lr=0.05, weight_decay=1e-3)
labels = torch.arange(N)
for _ in range(STEPS):
z_image = model.encode_image(image)
z_text = model.encode_text(text)
logits = z_image @ z_text.T / TAU
loss = 0.5 * (
F.cross_entropy(logits, labels)
+ F.cross_entropy(logits.T, labels)
)
optimiser.zero_grad()
loss.backward()
optimiser.step()
return model
def prototypes() -> tuple[torch.Tensor, torch.Tensor]:
"""Text prompts for zero-shot shape and colour classification."""
shape_prompts = []
for shape in range(N_SHAPES):
shape_prompts.append(
torch.cat(
[
F.one_hot(torch.tensor(shape), N_SHAPES).float(),
torch.zeros(N_COLOURS + NOISE_DIMS),
]
)
)
colour_prompts = []
for colour in range(N_COLOURS):
colour_prompts.append(
torch.cat(
[
torch.zeros(N_SHAPES),
F.one_hot(torch.tensor(colour), N_COLOURS).float(),
torch.zeros(NOISE_DIMS),
]
)
)
return torch.stack(shape_prompts), torch.stack(colour_prompts)
def evaluate(
model: DualEncoder,
colour_mention_probability: float,
seed: int,
) -> tuple[float, float]:
image, _, shape, colour = make_data(
N, colour_mention_probability, seed + 1000
)
shape_prompts, colour_prompts = prototypes()
with torch.no_grad():
z_image = model.encode_image(image)
z_shape = model.encode_text(shape_prompts)
z_colour = model.encode_text(colour_prompts)
shape_prediction = (z_image @ z_shape.T).argmax(dim=1)
colour_prediction = (z_image @ z_colour.T).argmax(dim=1)
shape_accuracy = (shape_prediction == shape).float().mean().item()
colour_accuracy = (colour_prediction == colour).float().mean().item()
return shape_accuracy, colour_accuracy
@dataclass(frozen=True)
class Result:
condition: str
shape_mean: float
shape_sd: float
colour_mean: float
colour_sd: float
def run_condition(
name: str,
colour_mention_probability: float,
shuffle_pairs: bool = False,
) -> Result:
scores = []
for seed in SEEDS:
model = train(colour_mention_probability, seed, shuffle_pairs)
scores.append(evaluate(model, colour_mention_probability, seed))
shape_scores = [score[0] for score in scores]
colour_scores = [score[1] for score in scores]
return Result(
condition=name,
shape_mean=mean(shape_scores),
shape_sd=pstdev(shape_scores),
colour_mean=mean(colour_scores),
colour_sd=pstdev(colour_scores),
)
def main() -> None:
torch.set_num_threads(2)
results = [
run_condition("colour omitted", 0.0),
run_condition("colour in 10% of captions", 0.10),
run_condition("colour always mentioned", 1.0),
run_condition("shuffled image-text pairs", 0.0, shuffle_pairs=True),
]
print("condition shape accuracy colour accuracy")
for result in results:
print(
f"{result.condition:34} "
f"{100 * result.shape_mean:5.1f}% ± {100 * result.shape_sd:4.1f} "
f"{100 * result.colour_mean:5.1f}% ± {100 * result.colour_sd:4.1f}"
)
# Positive and negative cases make the causal claim executable.
assert results[0].shape_mean > 0.95
assert results[0].colour_mean < 0.40
assert results[1].colour_mean > 0.70
assert results[3].shape_mean < 0.45
if __name__ == "__main__":
main()
Design the equivalence before training it
The traffic-light example fails only when two decisions are confused. For category retrieval, colour invariance can be desirable. For signal control, it destroys the boundary that matters. The inspection example has the same structure. Aligning images, traces and notes around “bearing fault” improves discovery, but it does not authorise a maintenance action without location, severity, trend and source quality.
Contrastive learning is therefore best understood as controlled forgetting in service of discrimination. Positive pairs define the changes that should cease to matter. Negatives define the alternatives that must remain apart. Multimodal pairs privilege what their views share. Capacity, architecture and optimisation decide how completely those pressures reshape each layer.
The changed engineering decision is concrete. Before scaling a model, write the invariance contract. State what may merge, what must separate, where private evidence remains available, which negatives make the boundary real, and which intervention can reject the design. Then choose augmentations, pair sources, loss, temperature, batch and model size. A representation is defensible when its learned equivalences match the decision's permissible equivalences, not when one retrieval score is high.
sequenceDiagram participant Q as Question participant M as Mechanism participant E as Evidence participant D as Decision Q->>M: The traffic light that became colourless M->>E: A graph before a geometry E-->>M: compare rival explanations E->>D: Sources D-->>Q: revise scope or act
Sources
- van den Oord, A., Li, Y. and Vinyals, O. (2018). Representation Learning with Contrastive Predictive Coding. arXiv.
- Chen, T. et al. (2020). A Simple Framework for Contrastive Learning of Visual Representations. ICML.
- Wang, T. and Isola, P. (2020). Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere. ICML.
- Tian, Y. et al. (2020). What Makes for Good Views for Contrastive Learning? NeurIPS.
- Poole, B. et al. (2019). On Variational Bounds of Mutual Information. ICML.
- Radford, A. et al. (2021). Learning Transferable Visual Models From Natural Language Supervision. ICML.
- Jia, C. et al. (2021). Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Supervision. ICML.
- Zhai, X. et al. (2022). LiT: Zero-Shot Transfer with Locked-image Text Tuning. CVPR.
- Zhai, X. et al. (2023). Sigmoid Loss for Language Image Pre-Training. ICCV.
- Chuang, C.-Y. et al. (2020). Debiased Contrastive Learning. NeurIPS.
- Robinson, J. et al. (2021). Can Contrastive Learning Avoid Shortcut Solutions? NeurIPS.
- Xue, Y. et al. (2023). Which Features are Learnt by Contrastive Learning? On the Role of Simplicity Bias in Class Collapse and Feature Suppression. ICML.
- Saunshi, N. et al. (2022). Understanding Contrastive Learning Requires Incorporating Inductive Biases. ICML.
- Tamkin, A. et al. (2023). Feature Dropout: Revisiting the Role of Augmentations in Contrastive Learning. NeurIPS.
- Yuksekgonul, M. et al. (2023). When and Why Vision-Language Models Behave like Bags-of-Words, and What to Do About It? ICLR.
- Thrush, T. et al. (2022). Winoground: Probing Vision and Language Models for Visio-Linguistic Compositionality. CVPR.
- Liang, W. et al. (2022). Mind the Gap: Understanding the Modality Gap in Multi-modal Contrastive Representation Learning. NeurIPS.
- Gadre, S. Y. et al. (2023). DataComp: In Search of the Next Generation of Multimodal Datasets. NeurIPS.