GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
ICML 2023

PAL: Program-aided Language Models

Have the model translate a word problem into Python and let the interpreter compute. Codex beat a 540B model on grade-school math, and led by 38 points once the numbers got large.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2022
AUTHORS
Gao, Madaan, Zhou, Alon, Liu, Yang, Callan, Neubig
FROM
Carnegie Mellon University
PUBLISHED
Nov 2022 · ICML 2023
CITED BY
880Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 19% of this breakdown.

01

The paper in one minute

Chain-of-thought prompting made language models much better at word problems by having them write out intermediate steps. It left a gap: the model can decompose a problem correctly and still get 93 + 39 wrong, and the errors multiply with larger numbers or longer chains. Luyu Gao, Aman Madaan, Shuyan Zhou, Graham Neubig and colleagues at Carnegie Mellon asked why the model should do the arithmetic at all.

PAL, program-aided language models, keeps the model's role to understanding the problem and writing the steps, but writes those steps as Python. The few-shot prompt shows example questions answered with short programs: meaningful variable names, comments in plain language, and a final answer variable. Given a new question, the model writes a similar program, a Python interpreter runs it, and the result is the answer. The model never computes anything itself.

Across 13 tasks, eight math word-problem sets, three symbolic-reasoning tasks from BIG-Bench Hard and two algorithmic tasks, PAL with the Codex code model beat chain-of-thought prompting with the same model, and often beat much larger models. The most telling result is GSM-HARD, the authors' version of GSM8K with one number in each problem replaced by an integer of up to seven digits. Chain of thought fell from 65.6% to 23.1%; PAL went from 72.0% to 61.2%.

THE IDEA, VISUALLY
SAME STEPS, DIFFERENT CALCULATOR 200 loaves baked; 93 sold in the morning, 39 in the afternoon; a store returned 6. How many are left? CHAIN OF THOUGHT They sold 93 + 39 = 132 loaves. The store returned 6. So they had 200 - 132 + 6 = 74. The answer is 74. the model does the arithmetic, and can get it wrong PAL loaves_baked = 200 loaves_sold = 93 + 39 loaves_returned = 6 answer = loaves_baked - loaves_sold + loaves_returned Python computes 74; the model only writes the program What Python cannot catch: a program that encodes the wrong reading, such as subtracting the returned loaves. It runs and returns 62. CODEX: CHAIN OF THOUGHT VS PAL solve rate %, Tables 1 and 2 GSM8K 65.6 72.0 GSM-HARD (big numbers) 23.1 61.2 Colored objects 86.3 95.1 Date understanding 64.8 76.2 Object counting 73.0 96.7 Repeat copy 68.8 90.6 chain of thought PAL
PAL keeps the model's job to reading the problem and writing the steps, and gives the computing to Python. The benefit grew with the size of the numbers, but a program that encodes a wrong reading still runs.
Research notes: the problem, approach and results
61.2 vs 23.1

GSM-HARD solve rate, PAL versus chain of thought with the same model (Codex)

16 of 25

inspected failures where chain of thought wrote the same reasoning for big and small numbers: arithmetic, not logic, broke

23.2

GSM8K solve rate when the model wrote Python but executed it itself, against 72.0 with an interpreter

THE PROBLEM

Chain-of-thought prompting gets models to decompose problems into steps, but they still make arithmetic and logical slips when executing those steps, especially with large numbers.

THE IDEA

Prompt with examples whose reasoning is written as Python statements with comments. The model writes a program for the new problem; a Python interpreter runs it and its result is the answer.

THE RESULT

With Codex, PAL beat chain-of-thought on all 13 math, symbolic and algorithmic tasks tested, reached 72.0% on GSM8K against 56.9% for PaLM-540B with chain of thought, and held 61.2% on a large-number version where chain of thought fell to 23.1%.

02

Why it matters to an FDE

Customer workflows are full of arithmetic: invoice totals, prorated refunds, inventory counts, date windows, unit conversions. A model that reasons in prose will occasionally get the arithmetic wrong, confidently and invisibly. PAL is the pattern that removes that class of error.

Never let the model do the math in text. Have it produce an expression, a small program or a structured calculation that code executes. The paper's large-number test shows how fast in-text arithmetic degrades.

The remaining errors are reading errors. A program that subtracts returned items instead of adding them runs perfectly and gives the wrong answer. The interpreter guarantees the arithmetic, not the interpretation. Validate inputs and add sanity checks to generated programs.

Readable code is reviewable. Variable names and comments make each step inspectable, by a person or by an automated check. That is an audit trail chain of thought does not give you.

It is the seed of code actions. PAL is one program per question with no feedback. CodeAct and later agents extend the same idea to multi-step tasks with tools and error messages.

Sandbox it. Running model-written code needs the same containment as any code action, even when it only does arithmetic.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    How PAL prompts are built, every result family, the ablations, and the misreadings to avoid

    Free account
  2. 04How it works

    The prompt format, inference, the benchmarks including GSM-HARD, and the ablation setups

    Premium
  3. 05The numbers that matter

    Margins, robustness to number size, model dependence, and one inconsistency

    Premium
  4. 06Try it yourself

    Run PAL's own example, break it with a misreading, and model why big numbers hurt text arithmetic

    Premium
  5. 07Where it breaks

    The limits of offloading to an interpreter, and of this evaluation

    Premium
  6. 08Using it on a deployment

    Putting program-aided reasoning into a customer workflow safely

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →