Before you move a control in the demo, say what you expect to change.
Foundation reference
Multimodal Foundations: Vision Encoders, Contrastive Learning & Cross-Attention Fusion
Contrastively trained image encoders such as CLIP's are a common front end for multimodal language models, and CLIP embeddings condition text-to-image models such as DALL·E 2 (Liu et al., 2023; Ramesh et al., 2022).
Study guide
Where to start
Why does contrastive training on whole images and captions give good global semantics but weak localization, and what extra losses or architectures fix this?
How to study this pagePredict · Check · Generalize · Continue
Compare what the demo shows with the key equation and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
Use the prerequisites and related concepts at the end of the page to fill the next gap.
Why It Matters for Modern Models
- Contrastively trained image encoders such as CLIP's are a common front end for multimodal language models, and CLIP embeddings condition text-to-image models such as DALL·E 2 (Liu et al., 2023; Ramesh et al., 2022).
- SigLIP 2 extends image–text training with captioning-based pretraining, self-supervised losses (self-distillation and masked prediction) and online data curation, to produce better encoders for vision–language models (Tschannen et al., 2025).
- CLOC adds region-level objectives because image-level contrastive training alone does not give the localized features needed for grounding (Chen et al., 2024).
- The shared embedding space links this concept to diffusion and to representation learning: it is how text can steer an image generator.
- Zero-shot classification follows directly: embed each class name as a caption and choose the one closest to the image (Radford et al., 2021).
Questions to Think About
- Why do batch size and the number of negatives matter so much for contrastive training, and how does SigLIP's sigmoid loss change that?
- What does a dual encoder gain in retrieval speed, and what does it lose in grounding, compared with fusing image and text tokens inside one model?
- How does the temperature τ change the loss: why does a low τ concentrate the gradient on the hardest negatives while a high τ spreads it out?
- Images and text do not start out aligned; what in the loss pulls matched pairs together and pushes mismatched pairs apart?
Interactive Demo
Core Math
If you prefer intuition first, try the demo above, then come back for the math.
Vision–language pretraining trains an image encoder and a text encoder so that matching images and captions land close together in a shared embedding space. The encoders are then used to feed images into multimodal language models and to condition image generators on text.
Dual-encoder similarity (normalized embeddings):
Here is the cosine similarity between image and caption , divided by a temperature .
CLIP's contrastive loss (symmetric cross-entropy over a batch):
averaged over the images in the batch. Each image must pick out its own caption among all captions in the batch, and each caption its own image; the other pairs act as negatives (Radford et al., 2021). SigLIP replaces the softmax with an independent sigmoid loss on every image–caption pair, which removes the normalization over the whole batch (Zhai et al., 2023).
Feeding images to a language model:
Flamingo lets text tokens attend to image features through added cross-attention layers (Alayrac et al., 2022):
Many later models instead project the image-patch embeddings into the language model's input sequence and let ordinary self-attention mix them with the text (Liu et al., 2023).