Bayesian Prompt Learning for Image-Language Model Generalization

Mohammad Mahdi Derakhshani, Enrique Sanchez, Adrian Bulat, Victor Guilherme Turrisi da Costa, Cees G. M. Snoek, Georgios Tzimiropoulos, Brais Martínez

Abstract

Adapting foundational image-language models like CLIP to downstream tasks often involves prompt learning. However, standard methods frequently overfit to training data, failing to generalize to unseen classes or domain shifts. We present a Bayesian framework that treats prompts as probabilistic distributions rather than deterministic vectors. By optimizing the Evidence Lower Bound (ELBO), our approach introduces a robust regularization mechanism. Experimental results across 15 benchmarks demonstrate significant improvements in generalization, outperforming existing state-of-the-art methods in cross-dataset and cross-domain scenarios.

Introduction

Foundational models have revolutionized computer vision and natural language processing. Adapting these models via "prompt learning"—optimizing continuous vectors instead of manual text engineering—has become a standard practice. Despite its success, current methods like CoOp and CoCoOp rely on Empirical Risk Minimization (ERM), which is prone to capturing spurious features. This leads to a significant generalization gap when the model encounters new categories or distributional shifts. This paper addresses this gap by introducing a probabilistic, Bayesian approach to prompt learning.

Methodology

The core innovation lies in framing prompt learning as a variational inference problem. Instead of identifying a single optimal prompt, the model learns a distribution over the prompt space.

Comparison of standard prompt learning and the proposed Bayesian framework across unconditional and conditional settings.

Probabilistic Modeling

The prompt is modeled as a combination of fixed learnable tokens and a latent residual prompt $r$, where $r \sim \mathcal{N}(\mu, \Sigma)$.

  • Unconditional Variant: Learns a global distribution $p(r)$ applicable to all images.
  • Conditional Variant: Employs a posterior network $\pi_\phi(x)$ to predict image-specific distribution parameters ($\mu(x)$ and $\Sigma(x)$).

Optimization and Inference

The model is optimized by maximizing the Evidence Lower Bound (ELBO). This objective includes a classification accuracy term and a KL-divergence term that acts as a regularizer, preventing the distribution from collapsing. During inference, a "variational ensemble" is created by sampling $K$ prompts from the learned distribution, capturing a broader semantic range than a single point estimate.

Experimental Setup

The framework was evaluated on a comprehensive suite of 15 benchmarks, covering:

  • General Recognition: ImageNet, Caltech101.
  • Fine-grained Classification: OxfordPets, StanfordCars, Flowers102, Food101, FGVCAircraft.
  • Specialized Tasks: SUN397 (scenes), UCF101 (actions), DTD (textures), EuroSAT (satellite).
  • Cross-Domain Generalization: ImageNetV2, ImageNet-Sketch, ImageNet-A, ImageNet-R.

Key Insights

Regularization and Semantic Coverage

Injecting noise through the probabilistic distribution forces the model to prioritize invariant features over training-specific shortcuts. While the "mean prompt" is highly informative, ensembling multiple samples further enhances performance by covering more of the semantic space.

Capturing Sub-domains

The Bayesian approach allows the model to capture various "factors of variation" within a single class. Different modes or samples from the distribution can correspond to different visual styles or sub-species, providing a more nuanced categorical understanding.

Visualization of how the learned prompt distribution captures distinct visual clusters (sub-domains) within a category.

Results

  • Unseen Class Generalization: The Bayesian approach achieved an average accuracy of 74.94% across 11 datasets, a 3.25% improvement over CoCoOp.
  • Cross-Dataset Robustness: Superior transferability was observed when training on ImageNet and testing on diverse datasets like EuroSAT and DTD.
  • Domain Resilience: The model showed increased robustness against adversarial attacks (ImageNet-A) and artistic renditions (ImageNet-R).
  • Efficiency: Performance plateaus at approximately 20 Monte Carlo samples, maintaining manageable inference overhead.

Conclusion

Bayesian Prompt Learning provides a "plug-and-play" framework that significantly enhances the generalization of image-language models. By moving from deterministic to probabilistic prompts, the model becomes more resilient to overfitting and domain shifts. Future work may explore non-Gaussian distributions, such as normalizing flows or diffusion models, to further refine the prompt space modeling.

Summary updated

BibTeX
@inproceedings{derakhshani2022bayesian,
  author = {Mohammad Mahdi Derakhshani and Enrique Sanchez and Adrian Bulat and Victor Guilherme Turrisi da Costa and Cees G. M. Snoek and Georgios Tzimiropoulos and Brais Martínez},
  title = {{Bayesian Prompt Learning for Image-Language Model Generalization}},
  booktitle = {UvA-DARE},
  year = {2022},
}
Figure