Bayesian Prompt Ensembles: Model Uncertainty Estimation for Black-Box Large Language Models

Francesco Tonolini, Nikolaos Aletras, Jordan Massiah, Gabriella Kazai

Introduction

As Large Language Models (LLMs) are increasingly deployed in high-stakes environments, the ability to quantify model uncertainty—knowing when a model is "guessing"—becomes critical. Most current LLMs are overconfident and struggle to signal a lack of knowledge (epistemic uncertainty). A significant hurdle is that many state-of-the-art models are proprietary "black boxes" accessed via APIs, making standard uncertainty techniques like Monte Carlo Dropout or Deep Ensembles, which require internal weight access, inapplicable.

The BayesPE Framework

To address this, we introduce BayesPE (Bayesian Prompt Ensembles), a robust framework for uncertainty estimation that treats the choice of a prompt as a latent variable. Instead of relying on a single task instruction, BayesPE utilizes an ensemble of $N$ semantically equivalent prompt variations (e.g., "Classify this sentiment" vs. "Is this review positive or negative?").

Unlike "flat" ensembles that weight all prompts equally, BayesPE learns optimal weights ($w_i$) for each prompt through variational inference. Using a small labeled validation set (as few as 50 examples), the framework finds weights that maximize data likelihood while maintaining high entropy to prevent over-reliance on any single prompt.

Overview of the BayesPE framework, showing the optimization of prompt weights on validation data (a) and their application during inference (b).

Theoretical Foundation: The Bayesian Input Layer

A key contribution of this work is the proof that prompt ensembling is mathematically equivalent to adding a "Bayesian input layer" to the LLM. The disagreement between equivalent prompts serves as a proxy for the model's lack of knowledge, providing a theoretical lower bound on reducible error.

Theoretical comparison between a continuous Bayesian layer (a) and the discrete BayesPE approximation (b).

This approach bridges the gap between traditional Bayesian deep learning and the constraints of modern API-based AI deployment. By automatically down-weighting poorly performing prompts, BayesPE also mitigates the sensitivity of LLMs to manual prompt engineering.

Experimental Evaluation

BayesPE was evaluated across 10 diverse NLP classification tasks, including sentiment analysis (Amazon, IMDb), topic modeling (DBPedia, Yahoo), and semantic relations (MRPC, SNLI). Testing involved five open-source LLMs—Falcon (7b/40b), MPT (7b/30b), and Mistral-7b—in both zero-shot and few-shot scenarios.

Key Results

  • Superior Calibration: BayesPE achieved a 32.1% average reduction in Expected Calibration Error (ECE) and a 23.7% improvement in AUC for uncertainty detection compared to single-prompt baselines.
  • Statistical Dominance: In 96% of the 100 experimental setups, BayesPE was either the top performer or statistically tied for the lead in Negative Log-Likelihood (NLL) and Brier score.
  • Efficiency: Optimizing weights is computationally lightweight, taking only 1–2 seconds on a standard CPU, making it a "plug-and-play" solution for production environments.

Limitations and Future Outlook

While highly effective for classification, extending BayesPE to open-ended text generation remains a challenge due to the non-binary nature of "correctness." Additionally, the method currently assumes semantic equivalence between prompts and requires access to token-level probabilities, which most major APIs provide. Future work may involve integrating BayesPE with Automatic Prompt Engineering (APE) to automate the generation of the initial prompt pool, further streamlining the uncertainty estimation pipeline.

Summary updated

BibTeX
@inproceedings{tonolini2024bayesian,
  author = {Francesco Tonolini and Nikolaos Aletras and Jordan Massiah and Gabriella Kazai},
  title = {{Bayesian Prompt Ensembles: Model Uncertainty Estimation for Black-Box Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.728},
}
Figure