Sub topic 16
Successors and variants: OpenCLIP, ALIGN, SigLIP
This chapter assumes you know the CLIP dual-encoder design, the symmetric softmax contrastive loss, and the learned temperature from earlier chapters. You should also be comfortable with PyTorch tensors and with sigmoid versus softmax. The chapter covers what later models changed (data, encoders, loss), when each is the better choice, and the errors people hit when switching between them.
What changed after CLIP
CLIP showed that contrastive pretraining on image-text pairs yields strong zero-shot classifiers and general-purpose features. Its weights were released, but the training data and training code were not. Later work follows three directions:
- Reproduce and open it up. OpenCLIP trains CLIP-style models on public data.
- Scale the data and relax the filtering. ALIGN uses a much larger and noisier dataset.
- Change the loss. SigLIP replaces the batch-wide softmax with a per-pair sigmoid.
The dual-encoder idea stays the same in all three. Each model still maps an image and a text into one normalized vector space and scores them by cosine similarity.
OpenCLIP
OpenCLIP is an open-source implementation of CLIP training and inference, developed by LAION and collaborators. It matters for three practical reasons.
- Open data. Models are trained on public datasets such as LAION-400M, LAION-2B and DataComp. You can inspect the data, which CLIP's data never allowed.
- Many architectures. It supports ResNet and ViT image encoders at many sizes, including large ViT-H/14 and ViT-bigG/14 variants. It also supports other encoders such as ConvNeXt.
- Scaling studies. Published results show zero-shot accuracy following predictable curves in data and compute. Larger open models match or exceed the original CLIP on ImageNet zero-shot.
Each OpenCLIP checkpoint is identified by an architecture name plus a pretrained tag. The tag names the training data and schedule, so ViT-B-32 with openai and ViT-B-32 with laion2b_s34b_b79k are different weights with the same shape.
import torch
import torch.nn.functional as F
import open_clip
from PIL import Image
model, _, preprocess = open_clip.create_model_and_transforms(
"ViT-B-32", pretrained="laion2b_s34b_b79k"
)
tokenizer = open_clip.get_tokenizer("ViT-B-32")
model.eval()
image = preprocess(Image.open("photo.jpg")).unsqueeze(0)
labels = ["cat", "dog", "car"]
text = tokenizer([f"a photo of a {label}" for label in labels])
with torch.no_grad():
image_emb = F.normalize(model.encode_image(image), dim=-1)
text_emb = F.normalize(model.encode_text(text), dim=-1)
probs = (model.logit_scale.exp() * image_emb @ text_emb.t()).softmax(dim=-1)
print(dict(zip(labels, probs[0].tolist())))The calling pattern matches the Hugging Face CLIP example from the zero-shot chapter. The differences are that preprocess and the tokenizer come from OpenCLIP, and that you normalize explicitly.
ALIGN
ALIGN ("A Large-scale ImaGe and Noisy-text embedding", from Google) tested a different trade-off. Instead of building a curated dataset, it used about 1.8 billion image and alt-text pairs with only simple frequency-based filtering. The authors argued that scale can compensate for noise.
ALIGN's architecture also differs from CLIP's:
- The image encoder is an EfficientNet.
- The text encoder is BERT.
- The loss is still a symmetric softmax contrastive loss, and the temperature is still learned.
ALIGN's main finding is that a larger but dirtier corpus can match or beat a smaller curated one. The cost is that the data is harder to audit, which makes the bias issues from the limitations chapter harder to diagnose. ALIGN's weights were not released in the same way as CLIP's. In practice you meet ALIGN as a result in papers more often than as a model you run.
SigLIP
SigLIP ("Sigmoid Loss for Language Image Pre-training", from Google) changes the loss. The CLIP loss treats each row of the similarity matrix as a classification over the batch. That means every row needs a softmax normalization over all batch columns, so the full batch-by-batch matrix must be available. SigLIP instead treats every image-text pair as an independent binary decision: matching (label +1) or not matching (label -1).
For a batch of size n, with normalized embeddings, scale t and a learned bias b, the loss is:
L = -(1/n) · Σᵢ Σⱼ log σ( zᵢⱼ · (t · xᵢ·yⱼ + b) )
Here zᵢⱼ is +1 when i = j and -1 otherwise, and σ is the sigmoid. The bias b matters. With n² pairs and only n positives, the negatives dominate at the start of training. SigLIP initializes the bias at a large negative value (around -10) so the model begins with the right prior. Without it, early training is dominated by negative pairs.
import torch
import torch.nn.functional as F
def siglip_loss(image_emb, text_emb, logit_scale, logit_bias):
# image_emb, text_emb: (batch, dim); row i of each is a matching pair
image_emb = F.normalize(image_emb, dim=-1)
text_emb = F.normalize(text_emb, dim=-1)
n = image_emb.size(0)
logits = logit_scale.exp() * image_emb @ text_emb.t() + logit_bias
# +1 on the diagonal (matches), -1 elsewhere (non-matches)
signs = 2 * torch.eye(n, device=logits.device) - 1
return -F.logsigmoid(signs * logits).sum() / n
# Initial values used in the SigLIP paper: temperature 10 and bias -10
logit_scale = torch.tensor(10.0).log()
logit_bias = torch.tensor(-10.0)
loss = siglip_loss(torch.randn(8, 64), torch.randn(8, 64), logit_scale, logit_bias)
print(loss.item())The sigmoid loss has two practical consequences:
- No global normalization. The loss is a sum over pairs, so it can be computed in chunks across devices without gathering the whole similarity matrix. This lowers memory use and simplifies distributed training.
- Better behavior at small batch sizes. The paper reports that sigmoid loss does well with modest batches, while the benefit of larger batches levels off at roughly tens of thousands of examples.
At inference, SigLIP scores each label independently. The scores are not a distribution over classes.
import torch
from PIL import Image
from transformers import AutoModel, AutoProcessor
name = "google/siglip-base-patch16-224"
model = AutoModel.from_pretrained(name)
processor = AutoProcessor.from_pretrained(name)
image = Image.open("photo.jpg")
labels = ["cat", "dog", "car"]
prompts = [f"This is a photo of a {label}." for label in labels]
inputs = processor(text=prompts, images=image, padding="max_length", return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
probs = torch.sigmoid(outputs.logits_per_image) # independent per label
print(dict(zip(labels, probs[0].tolist())))Because each label gets its own probability, the values need not sum to 1. If none of the labels fit, all of them can score low. A softmax-based CLIP always spreads probability across the labels you supply, even when none applies.
SigLIP 2 is a later release that adds further training objectives and multilingual data to the same sigmoid foundation.
Choosing between them
| Model | Main change | Data | Loss | Typical reason to pick it |
|---|---|---|---|---|
| CLIP (OpenAI) | Original recipe | 400M curated pairs, not public | Softmax | Baseline and compatibility |
| OpenCLIP | Open reproduction | LAION, DataComp | Softmax | Many sizes, open data, strong accuracy |
| ALIGN | Scale over cleanliness | 1.8B noisy pairs | Softmax | Mostly a research reference |
| SigLIP | Pairwise loss | Web image-text | Sigmoid | Strong accuracy per size, multi-label scoring |
Common errors
- Mixing components across checkpoints. The tokenizer, preprocessing and weights must come from the same checkpoint. A ViT-B-32 tokenizer is not interchangeable across all models.
- Applying softmax to SigLIP logits. Use
sigmoid. A softmax forces the labels to compete, which discards SigLIP's calibration. - Wrong padding for SigLIP. The Hugging Face SigLIP models expect
padding="max_length". Other padding can degrade results without raising an error. - Comparing embeddings across models. Each model defines its own space. A CLIP image vector and a SigLIP text vector are not comparable, even at the same dimension.
- Reusing an index after changing checkpoints. A retrieval index built with one checkpoint must be rebuilt for another.
- Assuming a bigger training set is a better fit. Accuracy on your domain depends on data coverage. Evaluate on your own labelled sample, using the zero-shot and linear-probe protocols from earlier chapters.
Exercise
A SigLIP model scores the labels "cat", "dog" and "car" on a photo of a bicycle and returns sigmoid probabilities 0.03, 0.02 and 0.05. A CLIP-style softmax model scores the same labels and returns 0.2, 0.1 and 0.7. Explain the difference and which output is more informative here.
Show answer
The softmax model must distribute probability 1 over the given labels, so it reports 0.7 for "car" even though no label fits. The sigmoid model scores each label independently, so all three can be low, which correctly signals that none applies. The SigLIP output is more informative here, because low scores across all labels flag an out-of-vocabulary image.
Exercise
In the SigLIP loss with a batch of 8, how many pair terms are summed, how many of them are positives, and why is the bias initialized to a large negative value?
Show answer
There are 8 × 8 = 64 pair terms, and 8 of them are positives (the diagonal). The 56 negatives dominate, so a bias near -10 gives the model the correct prior that most pairs do not match. This keeps early training from being dominated by the large negative term.