代码注释如何帮助LLM代码生成:正确内容而非形式是关键
原标题:Talking to Itself While Coding: What Makes Comments Help Code Generation?
AI 摘要
该研究通过观察分析和控制实验,探究代码注释对LLM代码生成性能的影响。在LiveCodeBench上,注释频率和意图无法可靠预测pass@1;但用强模型生成的正确注释预填充弱模型,可使pass@1平均提升17.2%,而错误注释无增益,不同问题的注释则降低20.8%。提示工程最多只能恢复约24%的外部注释增益,表明注释帮助代码生成的关键在于其包含正确解题内容,而非表面形式。
正文节选
Talking to Itself While Coding: What Makes Comments Help Code Generation? Abstract Large Language Models (LLMs) often generate natural-language comments while writing code, and these comments become part of the context used to generate the code that follows. However, it remains unclear which properties of comments affect code-generation performance. We study this question through observational analyses and controlled interventions. On LiveCodeBench, neither comment frequency nor broad comment in