Introduction
Contrastively trained text-image models, such as CLIP and ALIGN, have demonstrated a remarkable ability to perform zero-shot classification. By providing an image and a list of class names, these models can accurately categorize unseen images without explicit training on those specific classes. However, this zero-shot capability comes with a significant caveat: performance relies heavily on how the class names are presented. Wrapping class names in textual templates or "prompts" (e.g., "A photo of a {class_name}") drastically improves accuracy.
This paper introduces Zero-shot Prompt Ensembling (ZPE), a novel method to automatically score and weight a large pool of prompts. By correcting for frequency biases inherent in pre-training and test data, ZPE achieves superior zero-shot classification accuracy compared to labor-intensive, hand-crafted prompts—all without requiring any labeled validation data.
The Prompt Engineering Bottleneck
Finding the optimal prompts is currently a manual, trial-and-error process known as prompt engineering. Researchers often spend months hand-crafting sets of 80 or more prompts tailored to specific datasets. This paradigm presents several critical issues:
- Labor-Intensive: Manual curation is time-consuming and unscalable.
- Validation Paradox: Tuning prompts typically requires a labeled validation set, which fundamentally contradicts the "zero-shot" (label-free) philosophy.
- Model Specificity: Prompts optimized for one architecture (like CLIP) often do not transfer optimally to another (like LiT).
The central question addressed by the authors is: Can we automatically select and weight the best prompts from a large pool for a specific task without relying on any ground-truth labels?
Methodology: Zero-shot Prompt Ensembling (ZPE)
The authors propose ZPE, which leverages the model's own confidence scores (logits) as a signal for a prompt's suitability for a given dataset. The methodology is built on four key pillars:
- Max Logit Scoring: Intuitively, if a prompt consistently produces high confidence scores across a dataset, it is likely a strong candidate.
- Bias Correction: Raw confidence scores can be highly deceptive. Prompts containing words that are highly frequent in the pre-training data (e.g., "person") or words that map to spurious concepts in the test images receive artificially inflated scores. ZPE corrects this by subtracting expected logits:
- Word Frequency Bias: Corrected by subtracting the expected logit calculated from a small random sample of pre-training data (e.g., LAION-400m).
- Spurious Concept Bias: Corrected by subtracting the expected logit calculated directly from the test images.
- Softmax Weighting: Prompt quality typically follows a "long tail" distribution, with a few excellent prompts and many mediocre ones. ZPE applies a softmax function over the prompt scores to ensure inferior prompts do not dilute the performance of the ensemble.
- Prompt Selection: The authors also utilize Median Absolute Deviation (an outlier detection technique) for "hard" selection, isolating top-tier prompts and discarding the rest.
Experimental Setup
The researchers evaluated ZPE across a comprehensive suite of 16 datasets:
- General and Variants: ImageNet, ImageNet-A, ImageNet-R, ImageNet-Sketch, and ImageNet-V2.
- Fine-grained Classification: Caltech101, Cars196, CIFAR10, CIFAR100, DTD, EuroSat, Food-101, Oxford Flowers, Oxford Pets, Resisc45, and Sun397.
- Reference Data: A 20,000-image subsample of LAION-400m was utilized to estimate pre-training biases efficiently.
Key Insights and Results
The implementation of ZPE yielded several critical insights and performance breakthroughs:
- Overcoming the "Person" Pathology: A naive scoring system disproportionately favors prompts like "a photo of a person practicing {}" because the word "person" is ubiquitous in pre-training data. By subtracting the expected logits, ZPE effectively performs a likelihood ratio test. This shifts the evaluation from "how much does the model like this prompt?" to "how much more does the model like this prompt for this specific image compared to a random baseline?"
- Outperforming Human Engineering: On ImageNet, ZPE achieved 68.60% accuracy using CLIP ViT-B/16. This outperforms both the standard hand-crafted ensemble (68.31%) and a simple equal-average of the prompt pool (67.59%).
- Fine-grained Success: On fine-grained classification tasks, ZPE with prompt selection reached an average accuracy of 71.15%, a significant improvement over the pool average of 68.98%.
- Efficiency and Robustness: The method is highly computationally efficient. Estimating bias requires only 5k to 20k random images. Furthermore, ZPE is robust to sample size; using just 10% of the test data to estimate spurious concept bias yielded nearly identical results to using the entire test set.
- Model Agnosticism: Because the process is automated and data-driven, it adapts seamlessly to models like LiT, where standard CLIP-optimized prompts fall short.
Limitations and Future Directions
While ZPE offers a robust automated solution, it is not without limitations. The method remains dependent on the initial "pool" of prompts; if the pool lacks relevant templates for a highly niche domain, ZPE cannot generate them out of thin air.
Additionally, ZPE currently scores prompts independently. The authors suggest that evaluating combinations of prompts could unlock further performance gains. Finally, while this research focuses on dataset-level weighting, preliminary findings indicate that dynamically weighting prompts for every individual image represents a highly promising frontier for future zero-shot research.
Summary updated