Calibration, Not Compilation: Detecting and Repairing Misspecified Probabilistic Programs Written by Language Models
This paper argues that for probabilistic programs generated by language models, statistical correctness is defined by calibration rather than compilation, demonstrating that Bayesian workflow-based detection and repair significantly outperform traditional unit testing and self-review methods in identifying and fixing statistical misspecifications.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Core Problem: "Running" Doesn't Mean "Right"
Imagine you ask a very smart robot to write a recipe for a cake. The robot gives you a list of ingredients and steps. You follow the instructions, the oven works, the cake comes out of the oven, and it looks like a cake.
In the world of computer code, this is called "compiling and running." If the code runs without crashing, traditional software testers say, "Great! The program works."
But in the world of probabilistic programs (code used for statistics and data science), this is dangerous. A program can run perfectly and produce a cake, but if the recipe called for "salt" instead of "sugar," the cake will taste terrible. The code didn't crash, but the result is statistically wrong.
The authors call these "code-invisible bugs." They are errors that a computer can't see just by looking at the code or running it. They only show up when you look at the data the program produces.
The Old Way vs. The New Way
The Old Way (The Unit Test):
Traditionally, to check if code is good, we use "unit tests." These are like checking if the cake has the right shape and weight.
- Does the program run? Yes.
- Does it output numbers? Yes.
- Result: "Pass!"
The paper shows that for statistical programs, this is useless. A program using the wrong math (like using a straight line to describe a curve) will still pass these tests. It's like saying a cake is perfect because it fits in the pan, even if it tastes like soap.
The New Way (The Calibration Oracle):
The authors propose a new verifier called the Calibration Oracle. Instead of just checking if the code runs, it checks if the story the code tells matches reality.
Think of it like a taste test or a weather forecast check:
- Posterior Predictive Checks: The program predicts what the data should look like. The Oracle compares this prediction to the actual data. If the real data has huge spikes and the program predicts a flat line, the Oracle says, "You missed the mark."
- Sampler Diagnostics: It checks if the program is struggling to find the answer (like a hiker getting lost in a foggy mountain). If the program is confused, it flags an error.
- Held-out Density: It tests the program on data it hasn't seen before. If the program fails to predict new data accurately, it's misspecified.
The Experiment: Teaching the Robot to Fix Itself
The researchers tested this idea in three main ways:
1. Detection (Finding the Bug)
They created 200 fake scenarios where robots wrote statistical programs with hidden mistakes (like using the wrong type of math for the data).
- The Result: The old "Unit Test" found 0% of the bugs. The new "Calibration Oracle" found 88% of them. It was like having a master chef who could taste the salt error, while the old method only checked the pan size.
2. Repair (Fixing the Bug)
They let Large Language Models (LLMs) try to fix their own broken programs. They gave the robots three types of feedback:
No Feedback: "Try again."
Unit Test Feedback: "Your code passed all tests. It's fine." (This actually made things worse because the robot thought it was already perfect and stopped trying to fix the hidden errors).
Calibration Feedback: "Your code runs, but your predictions don't match the data. The spread is too narrow."
The Result: The robots using Calibration Feedback fixed their mistakes much better. For some advanced models, the success rate jumped from 33% to 92%. The "Unit Test" feedback was harmful, acting like a false confidence booster that stopped the robot from fixing the real problem.
3. Real-World Test
They asked robots to write programs from scratch based on simple descriptions (no hints).
- The Result: Even though 80-90% of the programs "ran," 15% to 47% were statistically wrong. The unit tests didn't catch a single one. The Calibration Oracle found the errors and helped the robots fix them, beating even other advanced AI reviewers.
Key Takeaways
- Correctness is Calibration, Not Compilation: Just because a statistical program runs without crashing doesn't mean it's right. It's only right if its predictions are "calibrated" to the real world.
- Tests Can Be Tricky: Telling a smart robot "all tests passed" can actually stop it from fixing deep, hidden errors. It creates a false sense of security.
- The Sweet Spot: This new method works best for robots that are already quite smart but not yet perfect. It gives them the specific "taste test" feedback they need to improve.
In short: If you want a robot to write a statistical model, don't just ask it to "run the code." Ask it to "taste the cake" and make sure it matches the recipe. The paper proves that this "taste test" (Calibration) is the only way to catch and fix the invisible errors that standard code tests miss.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.