Code Prompting Elicits Conditional Reasoning Abilities in Text+Code LLMs

Haritz Puerto, Martin Tutek, Somak Aditya, Xiaodan Zhu, Iryna Gurevych
1/18/2024
cs.CL

No official code found. Best implementation: UKPLab/emnlp2024-code-prompting (27 stars, Apache-2.0, last commit 2024-11-13).

Abstract

Reasoning is a fundamental component of language understanding. Recent prompting techniques, such as chain of thought, have consistently improved LLMs' performance on various reasoning tasks. Nevertheless, there is still little understanding of what triggers reasoning abilities in LLMs in the inference stage. In this paper, we introduce code prompting, a chain of prompts that transforms a natural language problem into code and directly prompts the LLM using the generated code without resorting to external code execution. We hypothesize that code prompts can elicit certain reasoning capabilities of LLMs trained on text and code and utilize the proposed method to improve conditional reasoning, the ability to infer different conclusions depending on the fulfillment of certain conditions. We find that code prompting exhibits a high-performance boost for multiple LLMs (up to 22.52 percentage points on GPT 3.5, 7.75 on Mixtral, and 16.78 on Mistral) across multiple conditional reasoning datasets. We then conduct comprehensive experiments to understand how code prompts trigger reasoning abilities and which capabilities are elicited in the underlying models. Our analysis of GPT 3.5 reveals that the code formatting of the input problem is essential for performance improvement. Furthermore, code prompts improve sample efficiency of in-context learning and facilitate state tracking of variables or entities.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Code Prompting Elicits Conditional Reasoning Abilities in Text+Code LLMs. EMNLP 2024

274Python, Jupyter NotebookJan 10, 20241 years agoApache-2.0
code-promptingconditional-reasoninggptlarge-language-modelsllm+5 more

Similar Papers

Cite this paper

@article{puerto2024code,
  title  = {Code Prompting Elicits Conditional Reasoning Abilities in Text+Code LLMs},
  author = {Haritz Puerto and Martin Tutek and Somak Aditya and Xiaodan Zhu and Iryna Gurevych},
  year   = {2024},
  eprint = {2401.10065},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2401.10065v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2401.10065.svg)](https://codeofpaper.com/paper/2401.10065)

Discussion