arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.09121cs.LGcs.AIcs.CLcs.SE

用于代码生成的选择性提示锚定

Selective Prompt Anchoring for Code Generation

Purdue University(普渡大学)

Yuan Tian, Tianyi Zhang

AI总结:

针对代码生成中 LLM 随代码 token 增加而忽视用户提示的注意力稀释问题,提出选择性提示锚定 SPA,在六个模型和六个基准上最高提升 Pass@1 12.9%。

摘要:

大型语言模型(LLM)的最新进展通过根据自然语言自动生成代码,改变了软件开发。然而,生成符合用户意图的完全正确代码仍存在挑战。我们的研究表明,随着生成的代码 token 增多,LLM 往往会减少对用户提示的关注。我们假设,这种注意力稀释问题是代码生成错误的一个重要原因。为缓解该问题,我们提出了 Selective Prompt Anchoring(SPA,选择性提示锚定),用于引导代码 LLM 在生成代码时更加关注用户意图。我们在六个基准上使用六个基础 LLM 评估了 SPA。结果表明,SPA 将 Pass@1 最高提升了 12.9%,并在所有设置下持续优于 SOTA 代码生成方法。我们的代码可在 https://github.com/magic-YuanTian/Selective-Prompt-Anchoring 获取。

英文摘要:

Recent advances in large language models (LLMs) have transformed software development by automatically generating code from natural language. Yet challenges remain in generating fully correct code that aligns with user intent. Our study reveals that LLMs tend to pay less attention to user prompts as more code tokens are generated. We hypothesize that this attention dilution issue is an important reason for code generation errors. To mitigate this issue, we propose Selective Prompt Anchoring (SPA) to guide code LLMs to pay more attention to user intent when generating code. We evaluate SPA using six base LLMs across six benchmarks. Our results demonstrate that SPA enhances Pass@1 by up to 12.9%, consistently outperforming SOTA code generation methods in all settings. Our code is available at https://github.com/magic-YuanTian/Selective-Prompt-Anchoring.

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

↑