Self-planning Code Generation with Large Language Models

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Jiang, Xue, Dong, Yihong, Wang, Lecheng, Fang, Zheng, Shang, Qiwei, Li, Ge, Jin, Zhi, Jiao, Wenpin
Format: Preprint
Published: 2023
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866911221397061632
author Jiang, Xue
Dong, Yihong
Wang, Lecheng
Fang, Zheng
Shang, Qiwei
Li, Ge
Jin, Zhi
Jiao, Wenpin
author_facet Jiang, Xue
Dong, Yihong
Wang, Lecheng
Fang, Zheng
Shang, Qiwei
Li, Ge
Jin, Zhi
Jiao, Wenpin
contents Although large language models (LLMs) have demonstrated impressive ability in code generation, they are still struggling to address the complicated intent provided by humans. It is widely acknowledged that humans typically employ planning to decompose complex problems and schedule solution steps prior to implementation. To this end, we introduce planning into code generation to help the model understand complex intent and reduce the difficulty of problem-solving. This paper proposes a self-planning code generation approach with large language models, which consists of two phases, namely planning phase and implementation phase. Specifically, in the planning phase, LLM outlines concise and formatted planning steps from the intent. Subsequently, in the implementation phase, the model generates code step by step, guided by the preceding planning steps. We conduct extensive experiments on various code-generation benchmarks across multiple programming languages. Experimental results show that self-planning code generation achieves a relative improvement of up to 25.4% in Pass@1 compared to direct code generation, and up to 11.9% compared to Chain-of-Thought code generation. Moreover, our self-planning approach also enhances the quality of the generated code with respect to correctness, readability, and robustness, as assessed by humans.
format Preprint
id arxiv_https___arxiv_org_abs_2303_06689
institution arXiv
publishDate 2023
record_format arxiv
spellingShingle Self-planning Code Generation with Large Language Models
Jiang, Xue
Dong, Yihong
Wang, Lecheng
Fang, Zheng
Shang, Qiwei
Li, Ge
Jin, Zhi
Jiao, Wenpin
Software Engineering
Although large language models (LLMs) have demonstrated impressive ability in code generation, they are still struggling to address the complicated intent provided by humans. It is widely acknowledged that humans typically employ planning to decompose complex problems and schedule solution steps prior to implementation. To this end, we introduce planning into code generation to help the model understand complex intent and reduce the difficulty of problem-solving. This paper proposes a self-planning code generation approach with large language models, which consists of two phases, namely planning phase and implementation phase. Specifically, in the planning phase, LLM outlines concise and formatted planning steps from the intent. Subsequently, in the implementation phase, the model generates code step by step, guided by the preceding planning steps. We conduct extensive experiments on various code-generation benchmarks across multiple programming languages. Experimental results show that self-planning code generation achieves a relative improvement of up to 25.4% in Pass@1 compared to direct code generation, and up to 11.9% compared to Chain-of-Thought code generation. Moreover, our self-planning approach also enhances the quality of the generated code with respect to correctness, readability, and robustness, as assessed by humans.
title Self-planning Code Generation with Large Language Models
topic Software Engineering
url https://arxiv.org/abs/2303.06689