Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Learning to see from captions
Imagine learning what things look like by browsing hundreds of millions of photos with their captions: the only rule is that each photo should match its own caption better than the others. That is contrastive vision-language training, and the image half of the trained model turns out to be an excellent general-purpose eye. CLIP scores every photo against every caption in a batch together. SigLIP instead asks a simpler yes-or-no question for each photo–caption pair, which is cheaper to compute and works even with small batches. The demo compares how the two losses start out.
CLIP-style encoders let an analyst search a satellite archive with text (‘flooded road’, ‘aircraft on apron’) without training a detector, and they are the visual front end of most vision-language-action robot policies.
- 1. Contrastive image–text training makes each image closest to…
- 2. SigLIP treats each image–caption pair as…
- 3. The image encoder of a CLIP model is widely used as…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The contrastive encoder family (2021–2026)
- CLIP (Radford et al., 2021): ViT or ResNet image encoder, Transformer text encoder, symmetric softmax loss over a batch of 32,768 pairs, 400M web pairs; ViT-L/14 at 336 px became LLaVA’s encoder.
- Open replications and scaling: OpenCLIP on LAION-2B/5B; Cherti et al. (CVPR 2023) fitted scaling laws in model, data and compute; EVA-CLIP (2023) scaled to 18B parameters by 2024.
- Data matters most: DataComp (Gadre et al., NeurIPS 2023) fixed the model and benchmarked filtering; Data Filtering Networks (Fang et al., ICLR 2024) filter with a trained model; MetaCLIP (Xu et al., ICLR 2024) balances pairs over metadata concepts.
- SigLIP (Zhai et al., ICCV 2023): loss −Σ log σ(zᵢⱼ(t·cos(xᵢ, yⱼ) + b)) with zᵢᵢ = +1, zᵢⱼ = −1; learned t (init 10) and bias b (init −10, because negatives vastly outnumber positives). No batch-wide normalisation: each device computes its block and texts are passed between devices. Better than softmax at small batches, equal by about 32k. So400m/14 is a shape-optimised ViT (SoViT).
- SigLIP 2 (Tschannen et al., 2025): adds a captioning decoder (LocCa), self-distillation and masked prediction (from SILC and TIPS), online data curation, multilingual data and NaFlex (native aspect ratio): better localisation and dense features.
- Perception Encoder (Bolya et al., Meta, 2025): a contrastively trained ViT whose best features for dense tasks and VLMs sit in intermediate layers, aligned out with extra tuning.
- Using the image encoder: zero-shot with prompt ensembles; linear probes on frozen embeddings; robust fine-tuning (WiSE-FT weight averaging, FLYP fine-tuning with the contrastive loss); patch tokens for VLMs. CLIP features are global and semantic; patch-level localisation is weaker than DINOv2’s unless trained for it (SigLIP 2).
- Known issues: the modality gap (image and text embeddings occupy separate cones; Liang et al., NeurIPS 2022), bag-of-words behaviour on compositional captions, web-data biases.
- 1. SigLIP initialises the bias b to −10 because…
- 2. DataComp benchmarks…
- 3. SigLIP 2 improves dense features by adding…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Training and using contrastive encoders
Exercise 1.
- CLIP’s softmax loss and SigLIP’s sigmoid loss.
- SigLIP computed in chunks (as across devices) equals the full loss.
- Zero-shot classification with prompt ensembling.
Practice.
- Start from an open checkpoint: SigLIP 2 (So400m/14 or B/16), OpenCLIP, EVA-CLIP, PE-Core; check licence and training data.
- Zero-shot first, with several prompts per class in your domain’s language; then a linear probe on frozen embeddings with a few hundred labels.
- If you fine-tune, keep the contrastive objective (FLYP) or average fine-tuned and original weights (WiSE-FT) to keep robustness.
- For your own contrastive training on small hardware, prefer the sigmoid loss; its memory does not need a full batch × batch matrix.
- For dense tasks or VLM projectors, try intermediate-layer patch tokens and compare with DINOv2/v3 features.
import torch, open_clip
from PIL import Image
model, _, preprocess = open_clip.create_model_and_transforms("ViT-SO400M-14-SigLIP2", pretrained="webli")
tok = open_clip.get_tokenizer("ViT-SO400M-14-SigLIP2")
img = preprocess(Image.open("tile.png")).unsqueeze(0)
txt = tok(["an aerial photo of a runway", "an aerial photo of a flooded road", "an aerial photo of a forest"])
with torch.no_grad():
u = model.encode_image(img, normalize=True); v = model.encode_text(txt, normalize=True)
p = torch.sigmoid(u @ v.T * model.logit_scale.exp() + model.logit_bias) # independent probabilities
print(p)- 1. With a few hundred labels, the usual first step after zero-shot is…
- 2. WiSE-FT keeps robustness by…
- 3. SigLIP outputs for one image are…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Two losses. For a batch of B normalised pairs with cosine similarities Sᵢⱼ, CLIP’s loss is ½[CE over rows + CE over columns] of tSᵢⱼ: each image must win against B − 1 captions, and each loss term depends on the whole row through the normaliser. SigLIP’s loss is Σᵢⱼ log(1 + exp(−zᵢⱼ(tSᵢⱼ + b))) / B: a sum of independent terms.
Consequences. (1) The sigmoid loss decomposes over blocks of the matrix, so devices can compute their blocks and pass text embeddings around; no all-gather of the full B × B similarities is needed (32,768² fp32 entries are 4.3 GB). (2) Each positive pair gets a gradient of its own size, independent of how many negatives are in the batch; with softmax and a small batch, the few negatives are quickly beaten and the gradient vanishes, so learning stalls. (3) At initialisation with b = 0 the loss is about B·ln 2, dominated by easy negatives; b = −10 gives ≈ 10 + (B − 1)·e⁻¹⁰, a balanced start.
Zero-shot as a linear classifier. Averaging normalised prompt embeddings per class gives class weight vectors; zero-shot classification is then a linear classifier on image embeddings whose weights come from text. A linear probe learns those weights from labels instead, which is why it usually wins when labels are available.
- 1. The sigmoid loss can be computed in chunks because it is…
- 2. With b = 0 at initialisation, the sigmoid loss per image is about…
- 3. Zero-shot classification with prompts is…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does the sigmoid loss beat the softmax loss at small batch sizes, and what does that do to the image encoder?
History.
- A. Radford et al., “Learning transferable visual models from natural language supervision” (CLIP, ICML 2021).
- X. Zhai, B. Mustafa, A. Kolesnikov and L. Beyer, “Sigmoid loss for language image pre-training” (SigLIP, ICCV 2023).
- M. Tschannen et al., “SigLIP 2: multilingual vision-language encoders with improved semantic understanding, localization, and dense features” (2025).
Exercise 2. Linear contrastive encoders on synthetic image–caption pairs.
- World: 200 concepts (16-dimensional latents). Images (40 dimensions) mix the concept with strong nuisance factors (lighting, viewpoint) and noise; captions (24 dimensions) are a noisy view of the concept.
- Training: linear image and text encoders to 16 dimensions, normalised, logit scale t = 10; softmax (CLIP) or sigmoid (SigLIP, learned bias from −10); Adam, 150 steps at batch 4, 16, 64 or 256 on 160 concepts. Larger batches also see more pairs, so compare the losses within a batch size.
- Measures: zero-shot accuracy on 40 unseen concepts (5 captions per class averaged), a 5-shot nearest-centroid probe on image embeddings over all 200 concepts (how good the image encoder is on its own), and the modality gap.
| batch | zero-shot, softmax | zero-shot, sigmoid | image probe, softmax | image probe, sigmoid |
|---|---|---|---|---|
| 4 | 0.209 | 0.596 | 0.015 | 0.500 |
| 16 | 0.810 | 0.858 | 0.630 | 0.763 |
| 64 | 0.953 | 0.953 | 0.929 | 0.908 |
| 256 | 0.976 | 0.971 | 0.940 | 0.961 |
- Small batches: the sigmoid loss was far better at batch 4 on every seed (zero-shot 0.544 and 0.476 against 0.323 and 0.246 on seeds 1 and 2), and the softmax-trained image encoder was nearly useless on its own (probe 0.015–0.053, chance 0.005).
- Batch 16: sigmoid still gave a better image encoder on all seeds (probe 0.731 and 0.800 against 0.630 and 0.682); zero-shot was mixed (seed 1: 0.769 against 0.782).
- Large batches: the two losses were level, as SigLIP reported (batch 256, seeds 1 and 2: 0.949 and 0.941 against 0.950 and 0.946).
- Null result: the modality gap stayed small for both losses (0.014–0.062); in real models it comes from deep encoders’ initial cones, which linear encoders do not have.
Contrastive encoders in AI, robotics and aerospace
- Earth observation: RemoteCLIP, GeoRSCLIP (RS5M) and SkyCLIP adapt CLIP to satellite and aerial images for text search and zero-shot land-cover labelling; SigLIP-based encoders back many geospatial VLMs.
- Robotics: OpenVLA and π0 use SigLIP (with DINOv2 in OpenVLA) as the visual front end of their policies; language-conditioned grasping ranks candidate objects by image–text similarity.
- Space operations: text queries over large image archives (debris, anomalies) without labelled training sets, followed by a linear probe once a few examples are confirmed.
References
- A. Radford et al. (2021). “Learning transferable visual models from natural language supervision.” ICML.
- X. Zhai, B. Mustafa, A. Kolesnikov and L. Beyer (2023). “Sigmoid loss for language image pre-training.” ICCV.
- M. Tschannen et al. (2025). “SigLIP 2: multilingual vision-language encoders with improved semantic understanding, localization, and dense features.” arXiv.
- M. Cherti et al. (2023). “Reproducible scaling laws for contrastive language-image learning.” CVPR.
- S. Y. Gadre et al. (2023). “DataComp: in search of the next generation of multimodal datasets.” NeurIPS.
- A. Fang et al. (2024). “Data filtering networks.” ICLR.
- H. Xu et al. (2024). “Demystifying CLIP data.” ICLR.
- D. Bolya et al. (2025). “Perception Encoder: the best visual embeddings are not at the output of the network.” arXiv.
- W. Liang et al. (2022). “Mind the gap: understanding the modality gap in multi-modal contrastive representation learning.” NeurIPS.
- M. Wortsman et al. (2022). “Robust fine-tuning of zero-shot models.” CVPR.