A Simple Zero-shot Prompt Weighting Technique to Improve Prompt Ensembling in Text-Image Models

James Urquhart Allingham, Jie Ren, Michael W. Dusenberry, Jeremiah Zhe Liu, Xiuye Gu, Yin Cui, Dustin Tran, Balaji Lakshminarayanan · DOI

Introduction

Contrastive text-image models like CLIP have significantly advanced zero-shot classification capabilities. However, these models exhibit a high degree of sensitivity to the specific "prompts" used to describe classes. For instance, using a simple class name like "dog" often yields substantially lower accuracy than a more descriptive template such as "A photo of a {dog}."

Currently, achieving optimal performance necessitates extensive manual prompt engineering, where experts design and validate dozens of templates. This process is not only labor-intensive but typically requires a labeled validation set to identify the most effective prompts for specific domains, such as satellite imagery or fine-grained biological classification. This paper introduces Zero-shot Prompt Ensembling (ZPE), a fully automated method to improve the accuracy of text-image models without manual engineering or labeled data.

Zero-shot Prompt Ensembling (ZPE)

The core objective of ZPE is to automatically identify and weight the most effective prompts from a large, generic pool for any given unlabeled dataset.

Max Logit Scoring and Bias Correction

The proposed weighting scheme is grounded in Max Logit Scoring. The intuition is that if a prompt consistently produces high confidence (logits) across a dataset, it is likely a good fit for that data. However, a direct application of this logic is hindered by two primary pathologies:

  1. Word Frequency Bias: Prompts containing words frequent in the model's pre-training data (e.g., "person") receive high scores regardless of the actual image content.
  2. Spurious Concept Bias: If a test dataset frequently contains irrelevant background elements (e.g., people in scene recognition tasks), prompts mentioning those elements will be incorrectly favored.

To address these, the authors implement Logit Normalization. By subtracting an "expected" logit value—derived from both a random sample of pre-training images (e.g., LAION400m) and the target test images—the raw scores are de-biased. This ensures a prompt is only highly weighted if it provides discriminative information specific to the classes in the dataset.

The ZPE pipeline: Text and image representations are combined, prompts are scored (s), and a weighted ensemble is created to produce the final prediction.

Softmax Weighting

The final step involves applying a Softmax Weighting to the calculated scores. Because the initial pool often contains many irrelevant or "bad" prompts, a simple average would allow their collective noise to degrade performance. Softmax effectively silences these low-scoring prompts, focusing the ensemble on the most relevant templates.

Key Insights: The Role of Filtering

A critical observation in the development of ZPE was the "Person" problem, where naive scoring heavily favored prompts related to people due to their semantic over-representation in large-scale training sets. By treating the average logit across a dataset as a baseline, the method identifies prompts that react to specific class features rather than background noise.

Furthermore, the authors found that the prompt pool contains a "long tail" of low-quality templates. As illustrated in the figure below, without softmax weighting, accuracy begins to decline as more prompts are added to the pool. Softmax weighting acts as a filter, allowing the model to leverage a large pool of candidates while remaining robust to irrelevant noise.

Impact of softmax weighting. The green line shows prompt scores. Without softmax (left), accuracy drops as lower-scoring prompts are added. With softmax (right), accuracy remains stable even as the pool grows.

Experimental Results

ZPE was evaluated using CLIP and LiT models across various benchmarks, including ImageNet (and its variants) and 11 fine-grained datasets (e.g., EuroSat, Oxford Flowers, Sun397).

  • ImageNet Performance: Using a CLIP ViT-B/16 model, ZPE achieved 68.60% accuracy, surpassing the 68.31% achieved by the 80 hand-crafted prompts developed by the OpenAI team over several months.
  • Fine-grained Classification: Across 11 diverse datasets, ZPE averaged 71.15% accuracy, compared to 70.67% for standard hand-crafted sets.
  • Model Agnosticism: The benefits of ZPE were particularly evident with the LiT model. Because hand-crafted prompts were originally optimized for CLIP, they were sub-optimal for the LiT architecture. ZPE automatically identified superior weights for the new model without manual intervention.

Conclusion

ZPE provides a robust, automated alternative to manual prompt engineering. While highly effective, the method's performance is currently bounded by the quality and diversity of the initial prompt pool. Future work may explore scoring combinations of prompts rather than individual ones, or moving from per-dataset weighting to per-image weighting to further refine the ensembling process.

Summary updated

BibTeX
@inproceedings{allingham2023simple,
  author = {James Urquhart Allingham and Jie Ren and Michael W. Dusenberry and Jeremiah Zhe Liu and Xiuye Gu and Yin Cui and Dustin Tran and Balaji Lakshminarayanan},
  title = {{A Simple Zero-shot Prompt Weighting Technique to Improve Prompt Ensembling in Text-Image Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=6MU5xdrO7t},
}
Figure