Program-Aided Reasoners (Better) Know What They Know

Anubha Kabra, Sanketh Rangreji, Yash Mathur, Aman Madaan, Emmy Liu, Graham Neubig

Abstract

Large language models (LLMs) are increasingly capable of solving complex reasoning tasks, yet they frequently suffer from overconfidence, leading to incorrect answers presented as facts. This paper investigates whether Program-Aided Language Models (PAL)—which reason by generating and executing code—offer better calibration than traditional Chain-of-Thought (CoT) prompting. The study finds that PAL significantly reduces calibration error, in some cases by nearly 50%, making models more reliable and self-aware.

Introduction: The Calibration Gap

In machine learning, accuracy is only one dimension of performance. For a model to be truly reliable in real-world applications, it must be calibrated: its predicted confidence should align with its actual probability of being correct. Current LLMs are notoriously poorly calibrated, often providing incorrect answers with high confidence.

While Chain-of-Thought (CoT) prompting improves accuracy by encouraging step-by-step reasoning, it does not necessarily improve a model's understanding of its own limitations. This research explores if forcing a model to reason through code—a more structured and deterministic medium—helps it become a more "honest" reasoner.

Comparison of Chain-of-Thought (CoT) and Program-Aided Language Models (PAL) on a simple math problem. CoT fails to correctly divide the total cost, while PAL's code-based approach yields the correct answer.

Methodology

The researchers compared two primary strategies across several LLMs, including GPT-3.5 and LLaMA2:

  1. Chain-of-Thought (CoT): The model generates a sequence of natural language sentences to solve a problem.
  2. Program-Aided Language Models (PAL): The model generates a Python script representing its logic, which is then executed by a deterministic interpreter to find the final answer.

To measure confidence in black-box models, the authors used Self-Consistency. By sampling the model 10 times for the same question, they calculated confidence based on the frequency of the most common answer (e.g., an answer appearing 8/10 times results in 0.8 confidence). Calibration was then quantified using Expected Calibration Error (ECE), measuring the gap between confidence and actual accuracy.

Key Insights: Why Code Helps

The study identified several reasons why PAL outperforms CoT in calibration:

  • Structural Constraints: Code is inherently more formal than natural language. There are fewer ways to write a correct program than a correct paragraph, leading to lower "answer entropy" and more reliable self-consistency metrics.
  • Diversity and Reliability: Prompting styles that produce less diverse generations (like PAL) tend to be better calibrated. Natural language allows for too many "ways to be wrong," which adds noise to confidence estimates.
  • Deterministic Execution: By offloading calculations to a Python interpreter, PAL removes common arithmetic errors that plague natural language reasoning, allowing the model to focus on the logic of the problem.

Results and Analysis

PAL improved calibration in 75% of experimental settings across benchmarks such as GSM8K (math), Date Understanding (symbolic logic), and Object Counting (algorithmic reasoning). For OpenAI models, PAL resulted in an approximately 50% relative reduction in calibration error.

Reliability plots comparing CoT and PAL across GSM-8K and Object Counting datasets. The proximity of the green line to the blue dashed line (perfect reliability) indicates better calibration in PAL.

Beyond calibration, PAL-equipped models were more accurate, showing an average improvement of 18.42% over CoT. Statistical analysis confirmed that the prompting style was a significant factor in reducing calibration error, even when controlling for accuracy gains.

Conclusion

The findings suggest that "thinking in code" does more than just make LLMs smarter; it makes them more self-aware. By leveraging the structured nature of programming, models can better align their confidence with their actual capabilities, paving the way for more reliable AI assistants in technical and logical domains.

Summary updated

BibTeX
@inproceedings{kabra2024program,
  author = {Anubha Kabra and Sanketh Rangreji and Yash Mathur and Aman Madaan and Emmy Liu and Graham Neubig},
  title = {{Program-Aided Reasoners (Better) Know What They Know}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.125},
}
Figure