Sub topic 15
Limitations, biases, and failure modes
This chapter assumes you know how CLIP's dual encoder, symmetric contrastive loss, and zero-shot classification work, and that you can read basic PyTorch. CLIP is strong on broad recognition and retrieval, but it fails in predictable ways. Most failures trace back to three things: the training objective, the web-scraped training data, and the prompt-based interface. Knowing them helps you decide when to trust a CLIP score.
Where the failures come from
Each limitation connects to one stage of the pipeline.
Compositional reasoning and the bag-of-words problem
The contrastive loss only needs the model to pick the right caption out of a batch of unrelated captions. Most batch negatives differ from the true caption in their nouns, so the model can succeed by matching objects and ignoring structure. Word order, attribute binding and relations are rarely needed to lower the loss.
Typical failures:
- Attribute binding. "A red cube on a blue sphere" and "a blue cube on a red sphere" often get nearly the same score for the same image.
- Relations and order. "A horse riding a man" scores close to "a man riding a horse".
- Negation. "A photo with no dogs" is embedded close to "a photo with dogs", because the word "dogs" dominates the text vector.
- Counting. "Three apples" and "five apples" are hard to separate.
You can test this yourself with a pair of captions that use the same words in a different order.
import torch
import torch.nn.functional as F
from PIL import Image
from transformers import CLIPModel, CLIPProcessor
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
image = Image.open("photo.jpg") # e.g. a photo of a dog chasing a cat
captions = ["a dog chasing a cat", "a cat chasing a dog"]
inputs = processor(text=captions, images=image, return_tensors="pt", padding=True)
with torch.no_grad():
outputs = model(**inputs)
# Raw cosine similarity, without the logit scale
img = F.normalize(outputs.image_embeds, dim=-1)
txt = F.normalize(outputs.text_embeds, dim=-1)
print((img @ txt.t()).squeeze(0).tolist())If the two scores differ by only a few thousandths, the model is not using word order to separate the captions. Models trained with hard negatives of this kind, such as swapped-word captions, do better on these tests, but the base CLIP objective does not push toward it.
Fine-grained and abstract tasks
CLIP's zero-shot accuracy depends heavily on how often the concept appears in web captions.
- Fine-grained categories. Distinguishing car models, aircraft variants or flower species is weak when captions rarely use the precise name.
- Specialized domains. Medical images, satellite imagery, microscopy and industrial inspection are thinly covered, and zero-shot accuracy there can be near chance.
- Abstract or systematic tasks. Counting objects, estimating distance, or reading a specific digit style can fall below a simple trained baseline.
- Out-of-distribution images. Handwritten digits are an example. CLIP can do poorly on MNIST zero-shot even though it handles natural photos well, because such images are rare in web captions.
When zero-shot accuracy is poor, a linear probe on the frozen image features (see the previous chapter on evaluation) often recovers much of the gap. That tells you the image features hold the information, but the text side cannot name the concept well.
Prompt sensitivity and the closed label set
Zero-shot classification only chooses among the labels you provide. Two consequences follow:
- No "none of the above". Softmax over your labels always sums to 1. An image of a truck, scored against "cat", "dog" and "car", still gives probabilities that add up to 1, and it may look confident.
- Wording changes results. "A photo of a boxer" could mean a dog or an athlete. A label with no context is ambiguous, and small template changes can shift accuracy by several points.
The softmax uses the learned logit scale, which makes scores look sharper than the cosine similarities warrant. Check the raw cosine similarity too, and set a minimum threshold when you need rejection.
import torch
import torch.nn.functional as F
from PIL import Image
from transformers import CLIPModel, CLIPProcessor
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
image = Image.open("photo.jpg")
labels = ["cat", "dog", "car"]
prompts = [f"a photo of a {label}" for label in labels]
inputs = processor(text=prompts, images=image, return_tensors="pt", padding=True)
with torch.no_grad():
outputs = model(**inputs)
probs = outputs.logits_per_image.softmax(dim=1)[0]
cosine = (
F.normalize(outputs.image_embeds, dim=-1)
@ F.normalize(outputs.text_embeds, dim=-1).t()
)[0]
best = probs.argmax().item()
print(labels[best], "prob:", round(probs[best].item(), 3), "cosine:", round(cosine[best].item(), 3))A high probability with a low cosine similarity is a warning that none of your labels fit. The best cutoff depends on the model and the data, so choose it on a labeled validation set instead of copying a number.
Typographic attacks and shortcuts
CLIP reads text inside images, and this can override the visual content. If you put a handwritten label reading "iPod" on an apple, the model may rank "iPod" above "apple". This is a typographic attack. It shows that the embedding mixes what the image shows with the words it contains. The same behavior is useful for OCR-like retrieval, but it makes the model easy to fool in a moderation or inspection setting.
Other shortcuts come from the data. If a class often appears with a particular background or watermark, the model may use that cue instead of the object.
Bias and representational harms
The training pairs come from the public web, so the model learns that web's patterns: whose photos are common, how groups are described, and which captions are attached to which faces. Documented effects include:
- Different accuracy across skin tone, gender presentation and geography. Everyday objects from lower-income regions are recognized worse than those from higher-income regions.
- Stereotyped associations when you query with occupations or traits.
- Harmful label assignments when people images are classified against categories such as crime-related terms. Results vary with the class set, and the label set you choose can create the harm.
Retrieval systems carry the same issue. A search for "a CEO" or "a nurse" returns the dominant stereotype in the training data. Filtering the data did not remove this, because the associations are in the captions themselves.
Data and evaluation caveats
- Noisy pairs. Alt-text and captions are often incomplete, off-topic, or SEO text. The loss treats every pair in the batch as correct, so noise becomes training signal.
- False negatives. Two images of dogs in one batch with different dog captions are treated as negatives of each other, even though both captions could be right. Larger batches make this more likely.
- Language coverage. Original CLIP data is mostly English, so non-English queries work worse unless you use a multilingual variant.
- Benchmark overlap. Web-scale data may include test images or near copies of them, which can inflate reported zero-shot numbers.
- Resolution and length. Inputs are resized to a fixed resolution, so small details vanish. The text encoder has a short context length (77 tokens), so long captions are truncated.
Mitigation checklist
| Problem | Practical response |
|---|---|
| Compositional errors | Use hard-negative fine-tuning, or add a detector or captioning model for structure |
| Fine-grained or domain gap | Train a linear probe, or fine-tune on labeled domain data |
| Prompt sensitivity | Use several templates and average their text embeddings, and validate on labeled data |
| No rejection option | Add an "other" prompt or a cosine threshold tuned on validation data |
| Bias | Audit per group, avoid sensitive uses, and keep a human in the loop |
| Non-English text | Use a multilingual variant or translate queries |
| Long text | Chunk the text and embed each chunk, or use a model with a longer context |
Later models address some of these problems. OpenCLIP trains on larger open datasets, and SigLIP changes the loss to remove the softmax over the batch. Neither fully solves compositional reasoning or bias, so test on your own data before relying on any of them.
Exercise
A CLIP classifier is run on a photo of a truck with the labels "cat", "dog" and "car". It returns "car" with 0.97 probability. Why can this number be misleading, and what two checks would you add?
Show answer
The softmax is taken over only the labels you supplied, so the probabilities always sum to 1 even when no label fits. The learned logit scale also sharpens the distribution. Add a check on the raw cosine similarity of the top label against a threshold tuned on labeled validation data, and add an "other" or "something else" prompt so the model has an option for images that match none of the classes.
Exercise
Why can CLIP give almost the same score to "a man riding a horse" and "a horse riding a man"? Name one training-data or objective reason and one way to reduce the problem.
Show answer
The contrastive loss only asks the model to pick the correct caption among unrelated captions in the batch, and those captions usually differ in their nouns, not in word order. Matching objects is enough to lower the loss, so the model has little reason to encode relations. Fine-tuning with hard negatives, such as captions with swapped subjects and objects, pushes the model to use word order.