arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.07433cs.CL
收藏

从标记到行:通过长期视角增强代码生成

From Token to Line: Enhancing Code Generation with a Long-Term Perspective

Tingwei Lu, Yangning Li, Liyuan Wang, Binghuai Lin, Qingsong Lv, Zishan Xu, Hai-Tao Zheng, Yinghui Li, Hong-Gee Kim

AI总结:

本文提出LSR-MCTS算法,通过MCTS逐行生成代码并引入自我修正机制,提升代码生成质量与多样性。

摘要:

大型语言模型(LLMs)的出现显著推动了代码生成任务的发展,引发了相关文献的激增。当前研究受到冗余生成结果和短期过度拟合局部模式的限制。尽管现有研究尝试通过采用多标记预测策略来缓解这一问题,但对生成过程中选择适当处理长度仍缺乏关注。通过分析生成过程中令牌之间的注意力,可以观察到注意力分数的高尖峰通常出现在行末。这一见解表明,将每行代码视为基本处理单元并按顺序生成是合理的。受此启发,我们提出了LSR-MCTS算法,该算法利用MCTS确定代码行-by-行并选择最优路径。进一步,我们在每个节点中集成了自我修正机制,通过错误修正增强多样性并生成更高质量的程序。在三个公开编码基准上的广泛实验和全面分析表明,我们的方法在性能上优于最先进的方法。

英文摘要:

The emergence of large language models (LLMs) has significantly promoted the development of code generation task, sparking a surge in pertinent literature. Current research is hindered by redundant generation results and a tendency to overfit local patterns in the short term. Although existing studies attempt to alleviate the issue by adopting a multi-token prediction strategy, there remains limited focus on choosing the appropriate processing length for generations. By analyzing the attention between tokens during the generation process of LLMs, it can be observed that the high spikes of the attention scores typically appear at the end of lines. This insight suggests that it is reasonable to treat each line of code as a fundamental processing unit and generate them sequentially. Inspired by this, we propose the LSR-MCTS algorithm, which leverages MCTS to determine the code line-by-line and select the optimal path. Further, we integrate a self-refine mechanism at each node to enhance diversity and generate higher-quality programs through error correction. Extensive experiments and comprehensive analyses on three public coding benchmarks demonstrate that our method outperforms the state-of-the-art performance approaches.

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

↑