Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Learning to Prompt for Vision-Language Models

Learned prompt vectors replace hand-written wording for CLIP image classification

  • Problem Zero-shot CLIP depends on hand-written prompts whose wording can change accuracy a lot. Tuning that wording takes domain expertise and a lot of time.
  • Method CoOp replaces the manual context words of a prompt with learnable vectors. It trains them on a few labeled images while all CLIP parameters stay frozen.
  • Results With 16 shots, CoOp averages around 15% above hand-crafted prompts across 11 datasets. The highest gain is over 45%.

Why hand-written prompts limit deployment

CLIP-style models classify without task-specific training by turning class descriptions into classifier weights. The usual description is a fixed template with the class name inserted into it. The wording of that template is a practical bottleneck. On Caltech101, adding the article a before the class token raised accuracy by more than 5%.

Good wording depends on the task. Adding task context such as flower for Flowers102, texture for DTD or satellite for EuroSAT changes results substantially, so a person has to know the domain and tune on held-out data. Even after extensive tuning, the resulting prompts are not guaranteed to be optimal for the downstream task.

The authors ask whether this wording can be learned instead of written by hand. Their answer models the context words as continuous vectors that are optimized from data.

How CLIP turns text into classifier weights

CLIP has an image encoder and a text encoder. The image encoder can be a ResNet-50 or a ViT, and the text encoder is a Transformer. Text is tokenized with byte pair encoding into IDs from a vocabulary of 49,152 entries, and each sequence is padded to a fixed length of 77 with start and end tokens. The IDs are mapped to 512-dimensional word embeddings, and the feature at the end-of-sequence token is layer normalized and projected into the shared space.

Zero-shot recognition compares an image feature f with one weight vector w_i per class, and each weight is produced by the text encoder from a prompt that contains the class name. The class probability is a softmax over cosine similarities scaled by a temperature tau that CLIP learns. \[ p(y=i \mid x)=\frac{\exp(\cos(w_i,f)/\tau)}{\sum_{j=1}^{K}\exp(\cos(w_j,f)/\tau)} \]

Learnable context in CoOp

In the unified version, the prompt is a sequence of M learnable vectors followed by the class token, and each vector has the same dimension as a word embedding, 512 for CLIP. Because the vectors are shared by all classes, the class name is the only part that changes between the prompts for different classes.

The class token can also sit in the middle of the context. This lets the prompt add words after the class name or end the sentence early with a full stop. The class-specific variant, called CSC, gives each class its own set of context vectors, which makes it more flexible but also larger.

The context vectors are trained by minimizing the cross-entropy classification loss over the labeled training images. Gradients pass through the whole text encoder, so the context is shaped by knowledge already stored in the frozen CLIP parameters, while only the context vectors are updated. The vectors start either as random values drawn from a zero-mean Gaussian or from the word embeddings of a manual phrase.

Training setup and baselines

Experiments use 11 image classification datasets that were used in CLIP, covering generic objects, scenes, actions, fine-grained categories, textures and satellite imagery. The few-shot protocol uses 1, 2, 4, 8 and 16 shots per class, deploys the models on the full test sets, and averages results over three runs.

Unless stated otherwise, the image encoder is a ResNet-50 and the number of context tokens M is 16. The class token is either at the end or in the middle, and the context can be unified or class-specific. Training uses SGD with an initial learning rate of 0.002 and cosine annealing. The maximum number of epochs is 200 for 16 and 8 shots, 100 for 4 and 2 shots, and 50 for 1 shot, with ImageNet fixed at 50.

A warmup step fixes the learning rate at 1e-5 during the first epoch to limit explosive gradients early in training.

The first baseline is zero-shot CLIP with hand-crafted prompts. Generic objects and scenes use a photo of a [CLASS], while fine-grained and specialized datasets get task context such as a type of pet or a type of food. The second baseline is a linear probe trained on CLIP features, following the training method used by the CLIP authors.

Few-shot results against hand-crafted prompts

Its average gap grows with more shots, reaching around 15% with 16 shots, and the highest gain across datasets is over 45%.

At 16 shots, the per-dataset gains in Figure 4 are largest on EuroSAT at +45.97 and on DTD at +21.26. Other large gains appear on Flowers102 at +28.37, StanfordCars at +17.75 and FGVCAircraft at +13.98, as well as on SUN397 and UCF101. ImageNet gains +4.77 over hand-crafted prompts, which the authors note is meaningful for a dataset with 1,000 classes.

The two datasets with the weakest results are Food101, at -2.64, and OxfordPets, at +1.24. Those two datasets are where the authors report a loss of momentum with more shots, discussed in the limitations.

Comparison with the linear probe

The gaps are largest at one and two shots, which the authors read as CoOp being much more effective than learning a linear classifier from scratch in the extreme low-data regime.

On DTD, EuroSAT, Flowers102 and FGVCAircraft the linear probe is comparable to CLIP+CoOp, and the authors explain this by the strength of the pre-trained CLIP space. The class-specific CSC version still beats the linear probe on these datasets and shows more potential as more shots become available.

Unified context, class-specific context and context length

On average the unified context performs better. It is clearly better for ImageNet, Caltech101, SUN397 and UCF101, and it also works better on OxfordPets and Food101. The class-specific CSC version is preferred on StanfordCars, Flowers102 and FGVCAircraft.

At 16 shots CSC performs better on DTD and EuroSAT, but it mostly underperforms the unified context with fewer than 8 shots, which the authors link to CSC having more parameters to fit.

The authors varied the context length from 4 to 8 to 16 across the 11 datasets. More context tokens gave better average performance, and placing the class token in the middle gained more with longer contexts. Fewer tokens were better for robustness to distribution shift, so the authors state that there is no fixed rule for picking the length and that the choice balances accuracy and robustness.

Robustness under ImageNet distribution shift

Learning on one distribution risks learning spurious correlations, while zero-shot CLIP is not tied to one data distribution, so the authors test whether CoOp stays robust. The source is ImageNet, and the targets are ImageNetV2, ImageNet-Sketch, ImageNet-A and ImageNet-R. The class names are compatible across these sets, so the learned prompts transfer directly.

With ResNet-50 and 16 context tokens, CLIP+CoOp reaches 55.11 on ImageNetV2 against 51.34 for zero-shot CLIP, and 22.12 on ImageNet-A against 21.65. On ImageNet-Sketch it reaches 32.74 against 33.32, and on ImageNet-R 54.96 against 56.00, so these two targets are slightly below zero-shot.

With 4 context tokens and the same ResNet-50 backbone, CLIP+CoOp scores 55.40 on ImageNetV2, 34.67 on ImageNet-Sketch, 23.06 on ImageNet-A and 56.60 on ImageNet-R, which is higher than the 16-token version on all four targets. The authors relate this to the shorter context giving better robustness.

The linear probe is below zero-shot on every ResNet-50 target, for example 19.07 against 33.32 on ImageNet-Sketch.

On the DOSCO-2k benchmark for contextual domain shift, the authors report that CoOp and CoCoOp both clearly outperform the zero-shot model across the four architectures, with CoOp's average higher than CoCoOp's.

Prompt ensembling and other tuning methods

Prompt ensembling averages zero-shot classifiers built from several hand-crafted prompts. The ensemble uses the select prompts from CLIP that were tuned on ImageNet. On ImageNet with ResNet-50, prompt ensembling scores 60.41, against 62.95 for CoOp with 16 shots, and the gap also appears on ResNet-101, ViT-B/32 and ViT-B/16.

With 16 shots on ImageNet, fine-tuning the CLIP image encoder reaches 18.28, a large drop from zero-shot CLIP's 58.18. Optimizing a transformation layer on the text encoder output reaches 58.86, and optimizing a bias term reaches 60.93, against 62.95 for CoOp.

The authors read the bias-term result as showing that gradients flowing through the text encoder carry more useful information than adjusting only the output.

Initialization and what the learned vectors encode

Random initialization and manual initialization from the embeddings of a photo of a reached the same average of 72.65 over the 11 datasets, with random initialization using context length 4. The authors conclude that a good initialization makes little difference and recommend random initialization in practice.

To inspect the learned vectors, the authors search the vocabulary for the words nearest to each vector by Euclidean distance. The vocabulary is byte pair encoded, so it includes subwords such as hu. Some nearest words relate to the task, such as enjoyed for Food101, fluffy and paw for OxfordPets and pretty for DTD. Taken together, however, the words do not form sensible prompts.

With manual initialization, the nearest words are mostly the words used for initialization, which the authors take as a sign that the vectors may encode meanings beyond the vocabulary.

Limitations

On OxfordPets and Food101, gains stop growing even with more shots, which the authors describe as overfitting. The authors suggest higher regularization, such as a larger weight decay, as a possible remedy, but this was not tested.

The authors attribute the weak results of learning-based methods on Food101 to noisy training labels, and they note that CoOp is sensitive to noisy labels.

The learned context vectors are hard to interpret, and the nearest-word analysis does not yet support a firm conclusion about what they encode. The results rely on 11 benchmark datasets for few-shot learning and on ImageNet as the only source for the domain generalization tests.

Paper info

Authors
Kaiyang Zhou, Jingkang Yang, Chen Change Loy, Ziwei Liu
Venue
arXiv · Preprint
First published
2021-9-2
Added
2026-11-12
Updated
2022-10-6
Version
v6
arXiv
2109.01134
DOI
10.1007/s11263-022-01653-1
Category
cs.CV · cs.AI · cs.LG
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Kaiyang Zhou, Jingkang Yang, Chen Change Loy, Ziwei Liu (2021). Learning to Prompt for Vision-Language Models. arXiv:2109.01134v6. https://doi.org/10.1007/s11263-022-01653-1

BibTeX
@article{zhou2021learning,
  title = {{Learning to Prompt for Vision-Language Models}},
  author = {Kaiyang Zhou and Jingkang Yang and Chen Change Loy and Ziwei Liu},
  year = {2021},
  eprint = {2109.01134},
  archivePrefix = {arXiv},
  doi = {10.1007/s11263-022-01653-1},
  url = {https://arxiv.org/abs/2109.01134v6}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up