PAL: Program-aided Language Models

Luyu Gao, Aman Madaan, Shuyan Zhou, Uri Alon, Pengfei Liu, Yiming Yang, Jamie Callan, Graham Neubig

TL;DR

PAL (Program-aided Language models) is a novel prompting strategy that offloads the "execution" phase of reasoning from a Large Language Model (LLM) to a Python interpreter. By having the LLM generate Python code as its intermediate reasoning steps instead of free-form text, PAL achieves state-of-the-art accuracy on complex math and symbolic tasks, outperforming models ten times its size.

The "Calculation Gap" in Language Models

While Large Language Models (LLMs) have become remarkably good at "Chain-of-Thought" (CoT) reasoning—breaking a problem down into step-by-step natural language instructions—they remain notoriously unreliable at the actual execution of those steps.

An LLM might correctly identify that it needs to multiply 143 by 27, but then hallucinate an incorrect product. This "calculation gap" is especially pronounced when dealing with large numbers, complex arithmetic, or intricate symbolic logic. The authors argue that while neural models are excellent at understanding and decomposing problems, they shouldn't be trusted to do the "grunt work" of computation when deterministic tools like code interpreters already exist.

How PAL Works

The authors propose PAL, which replaces the natural language "thoughts" in a prompt with interleaved Python code. This approach shifts the LLM’s role from being a "solver" to being a "translator" that maps natural language problems into executable algorithms.

An example of PAL prompting, showing how natural language reasoning is interleaved with Python code.
  1. Prompting: The model is provided with a few examples (few-shot prompting) where a natural language question is followed by a Python snippet that solves it.
  2. Decomposition as Coding: Instead of writing "First, I add the apples...", the LLM generates code like apples_initial = 5.
  3. Meaningful Variables: A key part of the method is using descriptive variable names (e.g., loaves_baked instead of x). This helps the LLM "ground" its reasoning in the programmatic structure.
  4. Offloaded Execution: Once the LLM finishes generating the code, the entire block is sent to a standard Python interpreter to compute the final answer.

Evaluated Datasets

The authors evaluated PAL across 13 different tasks:

  • Mathematical Reasoning: GSM8K, SVAMP, ASDIV, and various MAWPS subsets.
  • Symbolic/Algorithmic Reasoning: Tasks from the BIG-Bench Hard suite, including Colored Objects, Penguins in a Table, Date Understanding, Object Counting, and Repeat Copy.
  • GSM-HARD (New): The authors introduced this benchmark by taking the GSM8K dataset and replacing the small integers with much larger numbers (up to 7 digits). This specifically tests whether a model's reasoning is robust to arithmetic complexity.

Key Insights and Results

The Neural-Symbolic Synergy: The core "aha moment" is that LLMs are better at writing programs than being programs. By delegating the execution to a symbolic interpreter, PAL combines the linguistic flexibility of neural networks with the mathematical precision of traditional software.

Robustness to Scale: Standard CoT performance collapses when numbers get larger because the LLM tries to "guess" the result of the math. PAL’s accuracy remains nearly identical regardless of whether the numbers are 2 or 2,000,000, because the Python interpreter handles the magnitude flawlessly.

PAL maintains high accuracy compared to standard Chain-of-Thought (CoT) reasoning, which degrades as complexity increases.

State-of-the-Art Performance: * GSM8K: PAL using the Codex model achieved 72.0% accuracy, surpassing the much larger PaLM-540B model using Chain-of-Thought (56.9%) by a massive 15% absolute margin. * GSM-HARD: On the "hard" version of the math benchmark, standard CoT accuracy plummeted from 65.6% to 20.1%. In contrast, PAL remained stable at 61.5%, outperforming CoT by over 40%. * Symbolic Gains: PAL showed significant improvements in non-math tasks as well, such as a 23.7% absolute gain over CoT in the Object Counting task.

Limitations and Future Work

  • Coding Proficiency Required: PAL depends entirely on the LLM's ability to generate valid code. While models like Codex are highly proficient, smaller or non-code-specialized models may struggle with this prompting style.
  • Programmatic Scope: Not all reasoning tasks are easily expressed as a Python script. Tasks requiring subjective judgment or deep common-sense nuance might still be better suited for natural language CoT.
  • Single-Pass Execution: The current work uses a "post-hoc" execution (the model writes the whole script, then it runs). The authors suggest that future work could involve iterative execution, where the LLM writes a line of code, sees the result from the interpreter, and then decides what to write next.

Summary updated

BibTeX
@inproceedings{gao2023pal,
  author = {Luyu Gao and Aman Madaan and Shuyan Zhou and Uri Alon and Pengfei Liu and Yiming Yang and Jamie Callan and Graham Neubig},
  title = {{PAL: Program-aided Language Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=M1fd9Z00sj},
}
Figure