Although large language models 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 the solution steps prior to implementation. Thus 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 method with large language model, which consists of two phases, namely planning phase and implementation phase. Specifically, in the planning phase, the language model plans out the solution steps from the intent combined with in-context learning. Then it enters the implementation phase, where the model generates code step by step, guided by the solution steps. The effectiveness of self-planning code generation has been rigorously evaluated on multiple code generation datasets and the results have demonstrated a marked superiority over naive direct generation approaches with language model. The improvement in performance is substantial, highlighting the significance of self-planning in code generation tasks.
翻译:尽管大语言模型在代码生成方面展现出令人印象深刻的能力,但在处理人类提供的复杂意图时仍面临挑战。众所周知,人类通常会采用规划方法,在执行前将复杂问题分解并安排解决步骤。因此,我们将规划引入代码生成过程,以帮助模型理解复杂意图并降低问题解决难度。本文提出一种基于大语言模型的自我规划代码生成方法,该方法包含两个阶段:规划阶段与实现阶段。具体而言,在规划阶段,语言模型结合上下文学习从意图中规划出解决步骤;随后进入实现阶段,模型在解决步骤的引导下逐步生成代码。我们通过多个代码生成数据集严格评估了自我规划代码生成的有效性,结果表明该方法显著优于语言模型直接生成的朴素方法。性能的大幅提升凸显了自我规划在代码生成任务中的重要性。