Planning with Large Language Models for Code Generation

By Shun Zhang, Zhenfang Chen, Yikang Shen, Mingyu Ding, Josh Tenenbaum, Chuang Gan. 2023

256 citations recorded by the source corpus.

Existing large language model-based code generation pipelines typically use beam search or sampling algorithms during the decoding process. Although the programs they generate achieve high token-matching-based scores, they often fail to compile or generate incorrect outputs. The main reason is that conventional Transformer decoding algorithms may not be the best choice for code generation. In this work, we propose a novel Transformer decoding algorithm, Planning-Guided Transformer Decoding (PG-TD), that uses a planning algorithm to do lookahead search and guide the Transformer to generate better programs. Specifically, instead of simply optimizing the likelihood of the generated sequences, the Transformer makes use of a planner to generate candidate programs and test them on public test cases. The Transformer can therefore make more informed decisions and generate tokens that will eventually lead to higher-quality programs. We also design a mechanism that shares information between the Transformer and the planner to make our algorithm computationally efficient. We empirically evaluate our framework with several large language models as backbones on public coding challenge benchmarks, showing that 1) it can generate programs that consistently achieve higher performance compared with competing baseline methods; 2) it enables controllable code generation, such as concise codes and highly-commented codes by optimizing modified objective.

Subfields: Artificial Intelligence, Information Systems, Software, Large Language Models, Natural Language Processing

How researchers see this paper

The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.

In Artificial Intelligence

  1. Gabriel Synnaeve
  2. Jianfeng Gao
  3. Mohit Bansal
  4. Yossi Adi
  5. Karthik Narasimhan
  6. Sergey Levine
  7. Percy Liang
  8. Quoc V. Le

In Information Systems

  1. Koushik Sen
  2. Mark Harman
  3. Shin Yoo
  4. Gabriel Synnaeve
  5. Baptiste Rozière
  6. Joseph E. Gonzalez
  7. Shubho Sengupta
  8. Mitya Lyubarskiy

In Software

  1. Mark Harman
  2. Koushik Sen
  3. Shin Yoo
  4. Gabriel Synnaeve
  5. Baptiste Rozière
  6. Shubho Sengupta
  7. Mitya Lyubarskiy
  8. Jie M. Zhang

In Large Language Models

  1. Hayden S. Helm
  2. Carey E. Priebe
  3. Shunyu Yao
  4. Thomas Scialom
  5. Karthik Narasimhan
  6. Ion Stoica
  7. Naman Jain
  8. Yuan Cao

In Natural Language Processing

  1. Gabriel Synnaeve
  2. Shunyu Yao
  3. Yossi Adi
  4. Karthik Narasimhan
  5. Nicolas Usunier
  6. Thomas Scialom
  7. Hayden S. Helm
  8. Zirui Zhao

Citations in the corpus