arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2510.12082cs.SEcs.AI
收藏

增强神经代码表示与附加上下文

Enhancing Neural Code Representation with Additional Context

The University of Melbourne(墨尔本大学);Singapore Management University(新加坡管理大学)

Huy Nguyen, Christoph Treude, Patanamon Thongtanunam

AI总结:

本研究实证探究在代码表示中融入版本历史和调用图等上下文信息,能显著提升代码克隆检测与摘要性能,并获人工评估验证。

摘要:

自动化程序理解支撑着许多软件工程任务,从代码摘要到克隆检测。最近的深度学习模型取得了强劲的结果,但通常仅依赖源代码,忽视了诸如版本历史或结构关系等上下文信息。这限制了它们捕捉代码如何演变和运作的能力。我们进行了一项实证研究,探讨用此类上下文信号丰富代码表示如何影响神经模型在关键理解任务上的性能。两个下游任务,代码克隆检测和代码摘要,分别使用SeSaMe(1,679个Java方法)和CodeSearchNet(63,259个方法)进行评估。五个代表性模型(CodeBERT、GraphCodeBERT、CodeT5、PLBART、ASTNN)在仅代码和上下文增强的设置下进行微调。结果表明,上下文通常能提升性能:版本历史持续提升克隆检测(例如,CodeT5的F1分数提高15.92%)和摘要(例如,GraphCodeBERT的METEOR分数提高5.56%),而调用图的效果因模型和任务而异。结合多种上下文可带来进一步收益(宏F1分数最高提升21.48%)。对100个Java片段的人工评估证实,上下文增强的摘要在准确性和内容充分性方面显著更受青睐(p <= 0.026;|delta|最高达0.55)。这些发现凸显了上下文信号在增强代码理解方面的潜力,并为优化神经SE模型中的上下文编码开辟了新方向。

英文摘要:

Automated program comprehension underpins many software engineering tasks, from code summarisation to clone detection. While recent deep learning models have achieved strong results, they typically rely on source code alone, overlooking contextual signals such as version history or structural relationships. We conduct an empirical study of how enriching code representations with such signals affects model performance on four tasks: code clone detection, code classification, code summarisation, and vulnerability detection, using three datasets (SeSaMe, CodeSearchNet-Java, Vul4J). We evaluate five foundational code models (CodeBERT, GraphCodeBERT, CodeT5, PLBART, ASTNN) and seven code-specialised LLMs (CodeLlama, Qwen2.5-Coder, DeepSeek-Coder), comparing prompt-based context injection against fine-tuned use of context. Context improves classification for all five foundational models and, after fine-tuning, for most LLMs. For summarisation, the effect depends on the model family: version history improves all four foundational models on every metric, whereas prompt-level context helps two of the seven LLMs and hurts the other five. Combining context types reaches up to +21.48% macro-F1 in code classification and +15.04% F1 in clone detection. A human evaluation of CodeT5 summaries on 100 Java snippets ranks context-augmented summaries significantly higher for Accuracy and Content Adequacy. An exploratory vulnerability detection evaluation provides initial evidence of transfer to security-oriented tasks.

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

↑