[Paper Review] Code Prompting: a Neural Symbolic Method for Complex Reasoning in Large Language Models
This paper introduces code prompting, a neural-symbolic method that enhances complex reasoning in large language models (LLMs) by generating executable code as intermediate steps instead of natural language rationales. It demonstrates that zero-shot and few-shot code prompting outperform chain-of-thought prompting on symbolic and arithmetic reasoning tasks, achieving up to 97.2% accuracy on the last letter concatenation task, with improved robustness due to code's unambiguous, structured representation.
Large language models (LLMs) have scaled up to unlock a wide range of complex reasoning tasks with the aid of various prompting methods. However, current prompting methods generate natural language intermediate steps to help reasoning, which can cause imperfect task reduction and confusion. To mitigate such limitations, we explore code prompting, a neural symbolic prompting method with both zero-shot and few-shot versions which triggers code as intermediate steps. We conduct experiments on 7 widely-used benchmarks involving symbolic reasoning and arithmetic reasoning. Code prompting generally outperforms chain-of-thought (CoT) prompting. To further understand the performance and limitations of code prompting, we perform extensive ablation studies and error analyses, and identify several exclusive advantages of using symbolic promptings compared to natural language. We also consider the ensemble of code prompting and CoT prompting to combine the strengths of both. Finally, we show through experiments how code annotations and their locations affect code prompting.
Motivation & Objective
- To address limitations in chain-of-thought prompting, such as imperfect task reduction and ambiguity in natural language rationales.
- To explore whether code as an intermediate reasoning format can improve reasoning accuracy and robustness in LLMs.
- To evaluate the effectiveness of code prompting in zero-shot and few-shot settings across diverse reasoning benchmarks.
- To analyze failure cases and identify advantages of symbolic over natural language prompting.
- To investigate the impact of code annotations and execution environments on performance.
Proposed method
- Proposes a two-stage pipeline: first, the LLM generates a code solution; second, the model either self-executes the code or uses an external interpreter.
- Uses zero-shot and few-shot prompting to induce LLMs to produce code that decomposes complex reasoning into structured, executable operations.
- Employs code as a formal, unambiguous representation to reduce confusion and improve task decomposition compared to natural language steps.
- Conducts ablation studies to evaluate the role of code annotations and execution environments (self-contained vs. external interpreter).
- Ensembles code prompting with chain-of-thought prompting to combine strengths of both symbolic and natural language reasoning.
- Evaluates performance on 7 benchmarks, including symbolic reasoning (e.g., last letter concatenation) and arithmetic reasoning (e.g., GSM8K, SVAMP).
Experimental results
Research questions
- RQ1Does code prompting outperform chain-of-thought prompting in zero-shot and few-shot settings for complex reasoning tasks?
- RQ2How does the use of executable code as an intermediate step improve reasoning accuracy and reduce ambiguity compared to natural language rationales?
- RQ3What are the main failure modes of code prompting, and how do they differ from those of chain-of-thought prompting?
- RQ4How do code annotations and execution environments (self-contained vs. external interpreter) affect the performance of code prompting?
- RQ5Can the ensemble of code prompting and chain-of-thought prompting achieve superior performance by combining their respective strengths?
Key findings
- Zero-shot code prompting outperforms zero-shot chain-of-thought prompting by 26.2 percentage points on the last letter concatenation task, achieving 97.2% accuracy compared to 71.0%.
- On average, zero-shot code prompting improves performance by 11.7% on the coin flip task, reaching 87.0% accuracy versus 75.3% for chain-of-thought.
- Few-shot code prompting achieves competitive results, with 97.44% accuracy on the SingleEq dataset and 96.83% on MultiArith, approaching or exceeding baseline performance.
- Error analysis reveals that code prompting is more sensitive to ambiguity in question wording, particularly when ground-truth annotations are incorrect or ambiguous.
- The study finds that external interpreters are not necessary, as LLMs can self-execute code accurately in many cases, indicating strong self-contained reasoning capability.
- Ensembling code prompting with chain-of-thought prompting improves performance on GSM8K, reducing error overlap and enhancing robustness.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.