arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2303.05510cs.LGcs.AIcs.CLcs.PL
收藏

用大语言模型规划代码生成

Planning with Large Language Models for Code Generation

MIT-IBM Watson AI Lab(麻省理工学院-IBM沃森人工智能实验室);The University of Hong Kong(香港大学);MIT(麻省理工学院);UMass Amherst(马萨诸塞大学阿默斯特分校)

Shun Zhang, Zhenfang Chen, Yikang Shen, Mingyu Ding, Joshua B. Tenenbaum, Chuang Gan

摘要:

现有的基于大型语言模型的代码生成流水线通常在解码过程期间使用束搜索或采样算法。虽然它们生成的程序获得了很高的基于标记匹配的分数,但它们通常无法编译或生成不正确的输出。主要原因是传统的Transformer解码算法可能不是代码生成的最佳选择。在这项工作中,我们提出了一种新的Transformer解码算法,规划引导的Transformer解码(PG-TD),使用规划算法做前瞻搜索,并指导Transformer生成更好的程序。具体地说,Transformer不是简单地优化生成序列的可能性,而是利用规划器来生成候选程序并在公共测试用例上测试它们。因此,Transformer可以做出更明智的决策,并生成最终导致更高质量程序的令牌。我们还设计了一个机制,共享信息之间的Transformer和规划,使我们的算法计算效率。我们以几个大语言模型作为公共编码挑战基准测试的主干,对我们的框架进行了经验评估,结果表明:1)与竞争基线方法相比,它可以生成持续实现更高性能的程序; 2)它可以通过优化修改目标来实现可控的代码生成,例如简洁代码和高度注释的代码。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑