RefineStat: Efficient Exploration for Probabilistic Program Synthesis

Madhav Kanda (UIUC), Shubham Dipak Ugare (UIUC), Sasa Misailovic (UIUC)

International Conference on Learning Representations 2026 · Oral

Overview

The talk "RefineStat: Efficient Exploration for Probabilistic Program Synthesis" by Madhav Kanda, Shubham Dipak Ugare, and Sasa Misailovic from the University of Illinois Urbana-Champaign (UIUC) introduces a novel approach to automate the challenging process of scientific model discovery. It addresses the critical gap between the capabilities of Large Language Models (LLMs) to generate code and their inherent limitations in producing statistically sound and reliable probabilistic programs. The core problem RefineStat tackles is that while LLMs can propose models from natural language, the resulting code often suffers from subtle semantic errors or inference pathologies that only become apparent during costly execution and diagnostic checks.

Watch on SlidesLive

Visual summary for RefineStat: Efficient Exploration for Probabilistic Program Synthesis by Madhav Kanda, Shubham Dipak Ugare, Sasa Misailovic
Visual summary for RefineStat: Efficient Exploration for Probabilistic Program Synthesis by Madhav Kanda, Shubham Dipak Ugare, Sasa Misailovic

Key moments

  1. 0:40 Understanding what a probabilistic program is
  2. 2:50 Common errors in LLM-generated probabilistic programs
  3. 4:00 RefineStat's three key ideas for reliable synthesis
  4. 5:30 Semantic constraint decoding: preventing invalid program generation
  5. 6:20 Diagnostic-aware refinement using the Bayesian workflow
  6. 8:20 RefineStat's performance compared to expert-written programs
  7. 8:50 Ablation study highlighting importance of semantic constraints

RefineStat: Efficient Exploration for Probabilistic Program Synthesis

Speakers: Madhav Kanda (UIUC), Shubham Dipak Ugare (UIUC), Sasa Misailovic (UIUC)

Conference: ICLR 2026

YouTube: https://slideslive.com/39062158

Overview

The talk "RefineStat: Efficient Exploration for Probabilistic Program Synthesis" by Madhav Kanda, Shubham Dipak Ugare, and Sasa Misailovic from the University of Illinois Urbana-Champaign (UIUC) introduces a novel approach to automate the challenging process of scientific model discovery. It addresses the critical gap between the capabilities of Large Language Models (LLMs) to generate code and their inherent limitations in producing statistically sound and reliable probabilistic programs. The core problem RefineStat tackles is that while LLMs can propose models from natural language, the resulting code often suffers from subtle semantic errors or inference pathologies that only become apparent during costly execution and diagnostic checks.

RefineStat is designed to bridge this gap by integrating semantic correctness and inference reliability directly into the program generation and refinement process. It leverages a single, small language model, making it an efficient and open-source alternative to expensive, closed-source systems. The significance of this work lies in its potential to democratize and accelerate scientific discovery by providing a trustworthy and scalable automation framework for Bayesian modeling, allowing scientists to focus more on insights rather than debugging complex statistical code.

The work is particularly relevant in the current landscape where LLMs are increasingly used for code generation. While their syntactic proficiency is high, their understanding of domain-specific semantic and statistical constraints remains a challenge. RefineStat’s contribution is a robust methodology that ensures generated probabilistic programs are not only syntactically valid but also statistically meaningful and amenable to reliable inference, thereby enhancing the utility of AI in scientific research and data analysis.

Background

▶ Watch: Understanding what a probabilistic program is (0:40)

Scientists routinely employ statistical models to decipher complex data, uncover relationships, and identify latent structures. This process is inherently iterative: a model is specified, inference is run, results are analyzed, and the model is refined—often repeatedly—until a satisfactory representation of the underlying data-generating process is achieved. This iterative nature makes finding the "right" model a challenging and time-consuming endeavor.

The advent of Large Language Models (LLMs) has introduced a paradigm shift, offering the promise of generating statistical models directly from natural language prompts, leveraging their vast domain knowledge. These models can represent statistical hypotheses as probabilistic programs. A probabilistic program describes how data could have been generated, defining parameters (e.g., intercept, slope, noise term) and their relationships. This program is then passed to a probabilistic program runtime, which automatically performs inference, typically using Markov Chain Monte Carlo (MCMC) methods such as No-U-Turn Sampler (NUTS). The output is a set of posterior samples, providing a distribution over possible parameter values that explain the data, rather than a single point estimate. For instance, in Bayesian linear regression, one defines priors for parameters like alpha, beta, and sigma, a likelihood function describing the linear relationship between variables, and then MCMC yields a distribution of possible regression lines consistent with the observed data.

However, the practical application of LLMs for probabilistic program synthesis is fraught with challenges. While LLMs can produce code that appears syntactically correct and reasonable, it frequently fails in subtle yet critical ways. Common failure modes observed include:

  • Semantically incorrect parameter usage: This involves issues like mismatched parameter names, incorrect parameter roles for distributions (e.g., passing a standard deviation where a variance is expected), or violating support constraints (e.g., a negative value for a parameter that must be positive).
  • Invalid or deprecated distributions and APIs: LLMs might hallucinate non-existent statistical distributions or use outdated API calls, leading to runtime errors.
  • Sampling pathologies: Even if a program is syntactically and semantically valid, the underlying statistical model might be poorly specified, leading to unreliable inference. This manifests as low effective sample size (ESS), indicating poor mixing of the MCMC chains, or frequent divergences, signaling issues with the geometry of the posterior distribution that prevent the sampler from exploring the space effectively. These issues are particularly insidious as they only become apparent during the expensive inference process.

Consequently, simply using language model-based approaches naively does not solve the problem. Unconstrained generation often leads to code that fails due to a multitude of errors spanning syntax and semantics. While syntax-only constraints can improve parseability, they do not guarantee statistical sense or reliable inference. Furthermore, existing solutions like large, closed-source models and systems such as BoxLM may yield better results but are often prohibitively expensive and raise significant privacy concerns, as sensitive scientific data cannot typically be shared with external APIs. This creates a critical unmet need for an open, efficient, and robust approach that simultaneously enforces semantic correctness and inference reliability in probabilistic program synthesis. RefineStat is explicitly designed to address this precise gap.

Key Findings

▶ Watch: RefineStat's three key ideas for reliable synthesis (4:00)

RefineStat presents a groundbreaking solution to the challenge of reliably synthesizing probabilistic programs using language models. Its key findings demonstrate that it is possible to generate statistically sound and inferentially robust models without relying on large, closed-source, or multi-agent systems.

The primary finding is that RefineStat achieves Expected Log Predictive Density (ELPD) values that are comparable with expert-written programs found in PosteriorDB. This is a significant benchmark, indicating that the system can produce models of equivalent quality to those crafted by human experts. Furthermore, RefineStat's performance surpasses that of multi-agent systems like BoxLM and is at par with state-of-the-art methods like OpenAI-O1, all while utilizing a single, small open language model (fewer than 8 billion parameters). This efficiency and openness address critical limitations of prior approaches, offering a low-cost and privacy-preserving alternative.

A crucial insight from the ablation studies is the dominant role of semantic constraints in ensuring the robustness and executability of generated programs. While syntactic constraints are necessary for basic parseability, semantic constraints contribute the largest gains in reliability. Specifically, removing semantic constraints from RefineStat's full pipeline causes the program executability (run rate) to drop from 50% to 26.5%, whereas removing syntactic constraints (making it essentially unconstrained decoding) further reduces it to a mere 11%. This clearly establishes semantic constraints as the primary driver of robustness in probabilistic program synthesis.

In summary, RefineStat demonstrates that by combining semantic constraint decoding with diagnostic-aware refinement and a reliability-first program search, it is possible to enable low-cost, open, and reliable Bayesian modeling. This breakthrough opens up exciting possibilities for scalable and trustworthy automation in various scientific disciplines, significantly narrowing the performance gap between LLM-generated and expert-crafted probabilistic programs.

Technical Deep Dive

▶ Watch: Semantic constraint decoding: preventing invalid program generation (5:30)

RefineStat's architecture is built upon three foundational ideas that collectively enable reliable and efficient probabilistic program synthesis: semantic constraint decoding, diagnostic-aware refinement, and a sophisticated program search algorithm.

The process begins with an input akin to what a scientist would provide: a dataset and a general prompt describing the desired statistical model. A language model then generates a candidate probabilistic program. The innovation lies in how RefineStat guides this generation and subsequent evaluation.

1. Semantic Constraint Decoding

The first key idea addresses the inherent limitations of LLMs that often produce syntactically valid but semantically meaningless or statistically incorrect code. Traditional grammar-based constraints only ensure parseability; they do not guarantee that a program makes statistical sense. Many common modeling errors, such as using incorrect parameters for a statistical distribution or violating support constraints (e.g., a standard deviation must be positive), are syntactically valid but semantically incorrect.

RefineStat encodes these semantic rules directly into the decoding process of the language model. As each component of the probabilistic program is generated (e.g., defining a prior, specifying a likelihood, or declaring a parameter), it is immediately checked against a set of predefined semantic constraints. These checks include:

  • Distribution validity: Ensuring that only valid and recognized statistical distributions are used.
  • Correct parameterization: Verifying that the correct types and number of parameters are passed to each distribution (e.g., a normal distribution requires mean and standard deviation).
  • Support constraints: Checking that parameter values adhere to their natural domain (e.g., scale parameters must be positive, probabilities must be between 0 and 1).

If a semantic violation is detected, RefineStat does not discard the entire generation. Instead, it performs local backtracking, specifically on the offending component. It then explores an alternative generation for that particular component while keeping the rest of the already generated program intact. The crucial benefit of this approach is that invalid programs are never fully executed or passed to the inference engine. This dramatically improves reliability by preventing the generation of statistically nonsensical models and significantly enhances search efficiency by avoiding costly inference runs on programs that are known to be invalid from the outset.

2. Diagnostic-Aware Refinement

Once a probabilistic program is deemed semantically valid, the next critical step is to assess whether its inference behaves reliably. RefineStat integrates a diagnostic-aware refinement mechanism that mirrors the established Bayesian workflow. In this workflow, models are not accepted immediately after generation; instead, they are rigorously evaluated using Bayesian diagnostics that probe different aspects of the inference process.

RefineStat employs standard diagnostic checks:

  • R-hat (Gelman-Rubin statistic): Checks for convergence of multiple MCMC chains. An R-hat value close to 1 indicates good convergence.
  • Effective Sample Size (ESS): Measures the number of independent samples obtained from the MCMC chains, reflecting sample quality. Low ESS suggests poor mixing or autocorrelation.
  • Divergences: Indicates issues with the geometry of the posterior distribution, often signaling that the MCMC sampler is struggling to explore the parameter space effectively, leading to biased estimates.

If any of these diagnostics fail to meet predefined reliability thresholds, the generated model is flagged as unreliable. RefineStat then triggers a refinement step. During refinement, specific parts of the program are resampled or regenerated to produce alternate candidates. This iterative loop of "evaluate, diagnose, and refine" is automated, allowing the system to systematically improve model reliability until a statistically robust program is obtained. This effectively automates a crucial, often manual, part of the Bayesian modeling process.

3. Program Search Algorithm

With mechanisms for generation and refinement in place, the final challenge is to efficiently navigate the space of potential programs and identify the most suitable ones. RefineStat employs a sophisticated program search algorithm that prioritizes reliability over raw predictive performance. This ordering is critical because models that appear highly predictive can often be fundamentally unreliable during inference, leading to misleading conclusions.

The search operates in two distinct phases:

  • Reliability Filter: RefineStat first computes a Bayesian reliability score for each candidate program. This score aggregates multiple diagnostic signals (e.g., R-hat, ESS, divergences) into a single, comprehensive measure of a model's inferential soundness. Only programs that exceed a predefined minimum reliability threshold are considered further. This acts as a robust filter, ensuring that only statistically trustworthy models proceed to the next stage.
  • Predictive Performance Evaluation: Among the set of reliable candidates, their predictive performance is then evaluated. RefineStat uses Expected Log Predictive Density (ELPD-LOO), a measure derived from leave-one-out cross-validation, to quantify how well a model predicts new data. Models are then ranked based on their ELPD-LOO scores, allowing the system to select the most predictively accurate among the reliable options.

This reliability-first approach prevents the selection of models that might superficially appear to fit the data well but suffer from severe inferential pathologies, ensuring that the final output is both statistically sound and predictively powerful.

Experimental Setup & Results

▶ Watch: RefineStat's performance compared to expert-written programs (8:20)

To validate the effectiveness of RefineStat, the researchers conducted a series of experiments comparing its performance against various baselines across established benchmark datasets.

Experimental Setup:

  • Language Models: RefineStat was implemented using open language models with fewer than 8 billion parameters. This choice underscores the efficiency and accessibility goals of the project, contrasting with approaches relying on very large or proprietary models.
  • Baselines: RefineStat's performance was evaluated against three categories of baselines:
  1. Unconstrained generation: Represents naive LLM output without any explicit constraints.
  2. Syntax-only constrained generation: Incorporates basic syntactic parsing to ensure code executability but lacks semantic or diagnostic feedback.
  3. Advanced systems: This included multi-agent systems like BoxLM and state-of-the-art approaches such as OpenAI-O1, which represent more sophisticated (and often closed-source) methods for code generation.
  • Datasets: The evaluation utilized benchmark datasets from PosteriorDB, a curated collection of probabilistic models and datasets, ensuring a robust and standardized comparison.
  • Evaluation Metrics: The performance was assessed across three critical dimensions:
  1. Execution success: Whether the generated program could run without runtime errors.
  2. Inference reliability: Measured by Bayesian diagnostics (R-hat, ESS, divergences).
  3. Predictive performance: Quantified using Expected Log Predictive Density (ELPD) values, where higher ELPD indicates better out-of-sample prediction.

Headline Results:

  1. Predictive Performance (ELPD):
  • RefineStat, using a single open language model, achieved ELPD values that were comparable with expert-written programs in PosteriorDB. This is a testament to its ability to generate high-quality statistical models.
  • Crucially, RefineStat demonstrated superior ELPD values compared to multi-agent systems like BoxLM.
  • It also performed at par with state-of-the-art closed-source methods such as OpenAI-O1.
  • These results collectively demonstrate that RefineStat effectively narrows the performance gap between LLM-generated and human-expert models without the need for closed-source APIs or expensive, large-scale models.
  1. Ablation Study on Executability (Run Rate):

A detailed ablation study was conducted to isolate the individual contributions of syntactic and semantic constraints to the executability of generated programs. The "run rate" indicates the percentage of generated programs that successfully executed without errors.

  • RefineStat (all components enabled): Achieved a 50% run rate. This indicates that half of the programs generated and refined by RefineStat were fully executable and reliable.
  • Removing semantic constraints: When the semantic constraint decoding component was disabled, the run rate dropped significantly to 26.5%. This highlights the profound impact of semantic checks in preventing common modeling errors.
  • Removing syntactic constraints (unconstrained decoding): When both semantic and syntactic constraints were removed, reducing the generation to essentially unconstrained decoding by the LLM, the run rate plummeted to 11%.

Conclusion from Results:

The ablation study unequivocally demonstrates that while syntactic constraints are necessary for basic program parseability, semantic constraints contribute the largest gains in robustness and executability. They are the primary driver of RefineStat's ability to produce reliable probabilistic programs. The overall experimental findings confirm that by combining semantic constraints with diagnostic feedback and a reliability-first search, RefineStat provides a low-cost, open, and reliable solution for automated Bayesian modeling.

Practical Implications

▶ Watch: Ablation study highlighting importance of semantic constraints (8:50)

RefineStat offers significant practical implications for a wide range of stakeholders in the scientific and ML/systems communities, fundamentally changing how probabilistic models can be discovered, built, and deployed.

For practitioners and domain scientists, RefineStat promises to accelerate scientific discovery by automating a notoriously time-consuming and error-prone part of their workflow: model specification and debugging. Instead of manually iterating through model adjustments and inference diagnostics, scientists can leverage RefineStat to generate statistically sound starting points or even complete models from natural language prompts. This frees up valuable time for deeper analysis, hypothesis testing, and interpreting results, rather than wrestling with implementation details or statistical pathologies. The ability to use smaller, open-source language models also makes this technology accessible to researchers without access to massive computational resources or budgets for proprietary APIs.

For ML infrastructure and MLOps teams, RefineStat presents an opportunity to build more robust and efficient automated modeling pipelines. By ensuring that generated probabilistic programs are semantically correct and inferentially reliable before expensive inference runs, it drastically reduces wasted compute cycles and debugging efforts. This leads to more predictable resource utilization and higher throughput for model generation tasks. The system's emphasis on open models also aligns with trends towards greater transparency and auditability in AI-driven scientific workflows, which is crucial for reproducibility and trust.

For model builders and deployers, RefineStat addresses the critical challenge of model reliability in production environments. Deploying an LLM-generated model that might look plausible but suffers from hidden inference pathologies can lead to incorrect predictions, biased insights, and ultimately, flawed decision-making. RefineStat's diagnostic-aware refinement and reliability-first search algorithm mitigate this risk by ensuring that only statistically robust models are considered for deployment. This enhances the trustworthiness of AI-assisted model building, especially in sensitive domains like healthcare or finance where model integrity is paramount.

Tradeoffs and Limitations: While RefineStat marks a significant leap, it's important to acknowledge its inherent tradeoffs. The system, while largely automated, is still iterative. It might not always produce the perfect model on the first attempt, requiring several refinement cycles. Its reliance on established Bayesian diagnostics means it might inherit their limitations; for instance, complex, non-standard posteriors could potentially be misdiagnosed. Furthermore, while it performs exceptionally well with small LMs, the complexity of models it can synthesize might still be bounded by the LLM's inherent knowledge and the richness of the semantic constraint rules. Highly novel or extremely specialized statistical models might still require human expert intervention. However, RefineStat provides a powerful foundation, significantly raising the baseline for automated probabilistic programming and making sophisticated Bayesian modeling more accessible and reliable. The privacy benefits of using local, open models are also a substantial advantage, especially for scientific data that cannot be shared with external services.

Key Takeaways

  • LLMs alone are insufficient for reliable probabilistic program synthesis: While LLMs can generate code, they often produce statistically unsound programs with semantic errors or inference pathologies (low ESS, divergences) that are only evident during costly execution.
  • RefineStat bridges the gap with a three-pronged approach: It combines semantic constraint decoding, diagnostic-aware refinement, and a reliability-first program search algorithm to ensure both correctness and inferential robustness.
  • Semantic constraints are crucial for robustness: Ablation studies show that semantic constraints contribute the largest gains in program executability and reliability, significantly outperforming syntax-only or unconstrained generation.
  • Achieves expert-level performance with open, small LMs: RefineStat matches the ELPD performance of expert-written programs and state-of-the-art closed systems (like OpenAI-O1), while outperforming multi-agent systems (like BoxLM), all using language models with fewer than 8 billion parameters.
  • Automates the Bayesian workflow: The system effectively automates the iterative process of evaluating, diagnosing, and refining models, making Bayesian modeling more accessible and efficient for scientists.
  • Enables low-cost, open, and privacy-preserving Bayesian modeling: By leveraging small, open-source LLMs and operating locally, RefineStat offers a scalable and trustworthy solution for scientific discovery without the cost, privacy, or vendor lock-in concerns of closed-source alternatives.

About the Speaker(s)

The work on RefineStat was presented by Madhav Kanda, who is affiliated with the University of Illinois Urbana-Champaign (UIUC). The project is a collaborative effort, with significant contributions from Shubham Dipak Ugare and Sasa Misailovic, both also from UIUC. Their collective research focuses on advancing the capabilities of AI and machine learning, particularly in the domain of scientific computing and the synthesis of reliable probabilistic programs.

Reviews

→ Top-rated talks at International Conference on Learning Representations 2026

All talks from International Conference on Learning Representations 2026