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.
翻译:在解码过程中,基于现有大型语言模型的代码生成管道通常使用光学搜索或抽样算法。虽然它们产生的程序实现了高符号匹配分数,但它们往往无法编集或产生不正确的输出。 主要原因是常规变换器解码算法可能不是代码生成的最佳选择。 在这项工作中,我们提议了一个新的变换器解码算法,即规划- 指导变换器解码法(PG-TD),它使用一种规划算法来进行外观搜索并指导变换器生成更好的程序。 具体地说,变换器不是仅仅优化生成序列的可能性,而是利用一个规划器生成候选程序,并在公共测试案例中测试它们。因此,变换器可以做出更知情的决定,并产生最终导致更高质量的程序。我们还设计了一个机制,在变换器和规划器之间共享信息,以便提高算法效率。我们用几个大语言模型对框架进行了实证地评估,作为公共编码的挑战基准的基础,显示1)它可以生成一个程序,与竞相性更精确的代码相比,从而实现更精确的生成更精确的操作。</s>