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.
翻译:尽管大型语言模型在代码生成方面展示了令人印象深刻的能力,但在处理人类提供的复杂意图时仍面临挑战。人们普遍认为,人类通常会在实施之前通过规划来分解复杂问题并安排解决步骤。因此,我们将规划引入代码生成,以帮助模型理解复杂意图并降低问题解决的难度。本文提出了一种基于大型语言模型的自我规划代码生成方法,该方法包含两个阶段,即规划阶段和实施阶段。具体而言,在规划阶段,语言模型结合上下文学习,从意图中规划出解决步骤;随后进入实施阶段,模型在解决步骤的引导下逐步生成代码。自我规划代码生成的有效性已在多个代码生成数据集上得到严格评估,结果表明其显著优于使用语言模型简单直接生成的方法。性能的大幅提升凸显了自我规划在代码生成任务中的重要性。