Abstract
Bayesian inference provides a rigorous framework for combining prior knowledge with observed data, yet its implementation requires significant expertise in statistics and probabilistic programming. We present Large Language Bayes (LLB), a framework that leverages Large Language Models (LLMs) to bridge the gap between informal natural language descriptions and formal statistical models. By generating an ensemble of candidate models and weighting them by their marginal likelihood, LLB automates the inference process, providing robust predictions without manual coding.
Introduction
The utility of Bayesian inference is often limited by the high barrier to entry. Users must typically translate conceptual "hunches" into precise mathematical specifications within Probabilistic Programming Languages (PPLs) like Stan or PyMC—a process that is both time-consuming and error-prone. While LLMs demonstrate proficiency in code generation, they frequently produce models with subtle statistical flaws or inappropriate assumptions.
Large Language Bayes (LLB) addresses this by treating the LLM as a generator of a broad prior distribution over the space of programs. Rather than seeking a single "perfect" model, LLB generates a diverse ensemble of candidates and utilizes observed data to perform a second layer of Bayesian updates, effectively filtering out low-quality models through statistical verification.
Methodology
The LLB framework follows a structured pipeline to transform informal user intent into a final posterior distribution.
The process consists of four primary stages:
- Model Generation: An LLM (e.g., Llama-3.3-70B) receives an informal problem description and generates hundreds of candidate models in the Stan PPL.
- Individual Inference: For each syntactically valid model, the system executes standard Bayesian inference (MCMC/NUTS) to produce local predictions.
- Marginal Likelihood Estimation: Each model is assigned a score based on its marginal likelihood—the probability of the observed data given the model's assumptions. This is estimated using importance-weighted variational bounds (ELBO).
- Bayesian Model Averaging (BMA): The final prediction is a weighted average of all candidate models. Models that align well with the data receive high weights, while inconsistent or poorly specified models are marginalized.
Experimental Evaluation
To evaluate LLB without the risk of training data contamination, several synthetic problems were designed, including binary rain sequences, coin bias estimation, and gold density modeling.
Key Results: The Rain Problem
In the "Rain" task, the system was asked to predict the probability of precipitation following a specific sequence of dry and wet days.
As shown in Figure 6, a "flat average" (treating all LLM outputs as equally valid) resulted in a ~57% probability of rain. In contrast, LLB's weighted approach correctly identified models capturing temporal dependencies, yielding a more accurate ~79% prediction. This demonstrates that data-driven weighting is essential for correcting the "mediocre" average of raw LLM outputs.
Robustness and Diversity
A critical insight from the research is that LLB benefits from a broad, diverse set of initial model proposals. Even when only a small fraction (e.g., 1%) of generated models are valid, the system can still produce high-quality results by identifying the few "good" models in the ensemble. This shifts the requirement for the LLM from "precision" to "breadth."
Conclusion and Future Work
Large Language Bayes demonstrates a viable path toward "No-Code" Bayesian inference. By combining the creative brainstorming capabilities of LLMs with the rigorous verification of PPLs, the framework achieves robustness that neither system could provide in isolation.
Future work will focus on reducing the significant computational cost of running MCMC on large ensembles. Potential optimizations include constrained generation to ensure code validity and shared computation strategies for similar model structures.
Summary updated