Papers › Learning to Prompt for Vision-Language Models

Learning to Prompt for Vision-Language Models

2 Sep 2021arXiv:2109.01134archive 2025-07-28

Kaiyang Zhou, Jingkang Yang, Chen Change Loy, Ziwei Liu

Large pre-trained vision-language models like CLIP have shown great potential in learning representations that are transferable across a wide range of downstream tasks. Different from the traditional representation learning that is based mostly on discretized labels, vision-language pre-training aligns images and texts in a common feature space, which allows zero-shot transfer to a downstream task via prompting, i.e., classification weights are synthesized from natural language describing classes of interest. In this work, we show that a major challenge for deploying such models in practice is prompt engineering, which requires domain expertise and is extremely time-consuming -- one needs to spend a significant amount of time on words tuning since a slight change in wording could have a huge impact on performance. Inspired by recent advances in prompt learning research in natural language processing (NLP), we propose Context Optimization (CoOp), a simple approach specifically for adapting CLIP-like vision-language models for downstream image recognition. Concretely, CoOp models a prompt's context words with learnable vectors while the entire pre-trained parameters are kept fixed. To handle different image recognition tasks, we provide two implementations of CoOp: unified context and class-specific context. Through extensive experiments on 11 datasets, we demonstrate that CoOp requires as few as one or two shots to beat hand-crafted prompts with a decent margin and is able to gain significant improvements over prompt engineering with more shots, e.g., with 16 shots the average gain is around 15% (with the highest reaching over 45%). Despite being a learning-based approach, CoOp achieves superb domain generalization performance compared with the zero-shot model using hand-crafted prompts.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2109.01134")

Code

Syntology Ran 3 of 12 code samples harvested from 3 repositories linked to this paper; 9 have no recorded run. Of those that ran: 1 ran · our draft was wrong; 2 ran with no contract checked.

By repository: community (archive-listed): 12 samples from 3 repositories, 3 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

18 repositories listed; official and paper-mentioned ones first.

kaiyangzhou/coop officialmentioned in papermentioned on GitHubpytorchMIT report
ArsenalCheng/Meta-Adapter mentioned on GitHubpytorch report
Gahyeonkim09/AAPL mentioned on GitHubpytorchMIT report
ThomasWangY/2024-AAAI-HPT mentioned on GitHubpytorch report
Vill-Lab/2024-TIP-MetaPrompt mentioned on GitHubpytorch report
YangYongJin/APEX mentioned on GitHubpytorch report
azshue/TPT mentioned on GitHubpytorch report
farinamatteo/zero mentioned on GitHubpytorchMIT report
healthx-lab/biomedcoop mentioned on GitHubpytorchMIT report
hhenryd/tap mentioned on GitHubpytorch report
kaiyangzhou/on-device-dg mentioned on GitHubpytorchNOASSERTION report
kenomo/industrial-clip mentioned on GitHubpytorchMIT report
mlvlab/dapt mentioned on GitHubpytorchMIT report
muzairkhattak/multimodal-prompt-learning mentioned on GitHubpytorchMIT report
muzairkhattak/protext mentioned on GitHubpytorchMIT report
saic-fi/bayesian-prompt-learning mentioned on GitHubpytorchMIT report
srvcodes/clap4clip mentioned on GitHubpytorch report
vill-lab/2024-aaai-hpt mentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

12 samples harvested; 3 ran; 0 honoured the contract we drafted; 9 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · our draft was wrong
2ran
9unverified

Licence: 0 of the 12 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 3 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

CrossAttention hhenryd/tap/trainers/TAP.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · aa2102c5842a8045 · report
PromptLearner ThomasWangY/2024-AAAI-HPT/trainers/hpt.py community (archive-listed) ran · metamorphic tier: deterministic MIT (permissive) · 8a2b72f24481ca15 · report
make_description_batch hhenryd/tap/trainers/TAP.py community (archive-listed) ran · our draft was wrong MIT (permissive) · c568c664a705cfa6 · report
AttentionPooling hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · e8079fe48af584cb · report
CustomCLIP_TAP hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · 7c02c9c890628418 · report
PromptLearner Vill-Lab/2024-TIP-MetaPrompt/trainers/meta.py community (archive-listed) unverified MIT (permissive) · 39be90830c4c1621 · report
TextEncoder hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · c1fabc9fbf753209 · report
TextPromptLearner hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · 0746a2da2f73c0eb · report
VisualEncoder hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · e1f5a7fb2fb95e19 · report
VisualPromptLearner hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · d75235fc5acba1a6 · report
load_clip_to_cpu hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · 0f982cfc0f69d842 · report
load_gpt_descriptions hhenryd/tap/trainers/TAP.py community (archive-listed) unverified MIT (permissive) · bf5154cf822c8f6a · report

Tasks

Domain GeneralizationFew-shot Age EstimationPrompt EngineeringPrompt LearningRepresentation Learning

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Few-shot Age Estimation MORPH Album2 CoOp MAE 5.09 #2 of 2 Archive leaderboard report
Few-shot Age Estimation MORPH Album2 CoOp MAE (16 shot) 3.23 #2 of 2 Archive leaderboard report
Few-shot Age Estimation MORPH Album2 CoOp MAE (2 shot) 4.50 #2 of 2 Archive leaderboard report
Few-shot Age Estimation MORPH Album2 CoOp MAE (4 shot) 3.81 #2 of 2 Archive leaderboard report
Few-shot Age Estimation MORPH Album2 CoOp MAE (8 shot) 3.57 #2 of 2 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

Introduced by this paper: CoOp

CLIPCoOp

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections