[论文解读] On the Robustness of Code Generation Techniques: An Empirical Study on GitHub Copilot
该论文通过实证研究语义等价的自然语言描述如何影响 GitHub Copilot 在 Java 方法生成中的预测,发现输入改述在约 46% 的情形下会改变预测,且在约 28% 的情景中可能降低正确性。
Software engineering research has always being concerned with the improvement of code completion approaches, which suggest the next tokens a developer will likely type while coding. The release of GitHub Copilot constitutes a big step forward, also because of its unprecedented ability to automatically generate even entire functions from their natural language description. While the usefulness of Copilot is evident, it is still unclear to what extent it is robust. Specifically, we do not know the extent to which semantic-preserving changes in the natural language description provided to the model have an effect on the generated code function. In this paper we present an empirical study in which we aim at understanding whether different but semantically equivalent natural language descriptions result in the same recommended function. A negative answer would pose questions on the robustness of deep learning (DL)-based code generators since it would imply that developers using different wordings to describe the same code would obtain different recommendations. We asked Copilot to automatically generate 892 Java methods starting from their original Javadoc description. Then, we generated different semantically equivalent descriptions for each method both manually and automatically, and we analyzed the extent to which predictions generated by Copilot changed. Our results show that modifying the description results in different code recommendations in ~46% of cases. Also, differences in the semantically equivalent descriptions might impact the correctness of the generated code ~28%.
研究动机与目标
- 评估自动改述是否可以用于测试像 Copilot 这样的基于 DL 的代码生成器的鲁棒性。
- 量化在给定语义等价描述时 Copilot 生成的代码的变化程度。
- 评估改述引起的变化如何通过测试和相似度指标影响预测正确性。
- 提供可复现数据和自动化 Copilot 交互的工作流,用于鲁棒性研究。
提出的方法
- 汇集包含 892 个 Java 方法及其对应 Javadoc 首句自然语言描述的数据集。
- 使用 PEGASUS 和 Translation Pivoting(及人工改述)生成语义等价的改述。
- 在两种上下文设置(全上下文与部分上下文)下自动化 Copilot 交互,基于原始与改述描述生成方法体。
- 用测试结果、CodeBLEU 和逐字标记的 Levenshtein 距离来评估预测的相似性与正确性。
- 分析改述质量与输入上下文如何影响 Copilot 的输出及正确性。
实验结果
研究问题
- RQ1RQ0: 自动改述技术能否检测基于 DL 的代码生成器的鲁棒性?
- RQ2RQ1: Copilot 的输出在多大程度上受输入代码描述的影响?
- RQ3(隐含)改述派生的变化与预测相似性及测试结果之间有何关联?
主要发现
- 改述原始描述在约 46% 的情形下改变了 Copilot 的代码预测。
- 约 13% 的预测通过测试,约 15% 失败或产生错误,约 72-73% 未产生有效的方法。
- PEGASUS 生成了 666 条等效改述(75%),TP 生成了 688 条等效改述(77%)。
- 仅考虑等效改述时,Copilot 的输出在平均水平上保持相似,但在 CodeBLEU 和 Levenshtein 指标上可能出现显著分歧。
- 在 28% 的通过测试的用例中,改述导致不同的预测,无法通过相同的测试,表明鲁棒性问题。
- 一些改述导致的预测通过了测试但在语义上与目标实现存在差异,凸显基于测试的评估存在潜在缺口。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。