arXiv:2510.12082cs.SEcs.AI2025-10

给代码模型加上下文信息,能显著提升代码理解效果。

Enhancing Neural Code Representation with Additional Context

  • 用版本历史和调用图等上下文增强代码表示
  • 代码克隆检测准确率最高提升21.48%(多上下文融合)
  • 适合做代码生成、理解与维护的工程师参考

自动化程序理解支撑代码摘要、克隆检测等软件工程任务。现有深度学习模型多仅依赖源码,忽略版本历史或结构关系等上下文信息,限制了对代码演进与运行机制的理解。我们通过实证研究,考察在代码表示中引入此类上下文信号对神经模型性能的影响。在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;Δ最高0.55)。这些发现凸显了上下文信号在提升代码理解中的潜力,并为优化神经软件工程模型的上下文编码提供新方向。

原文摘要 · Abstract (English)

Automated program comprehension underpins many software engineering tasks, from code summarisation to clone detection. Recent deep learning models achieve strong results but typically rely on source code alone, overlooking contextual information such as version history or structural relationships. This limits their ability to capture how code evolves and operates. We conduct an empirical study on how enriching code representations with such contextual signals affects neural model performance on key comprehension tasks. Two downstream tasks, code clone detection and code summarisation, are evaluated using SeSaMe (1,679 Java methods) and CodeSearchNet (63,259 methods). Five representative models (CodeBERT, GraphCodeBERT, CodeT5, PLBART, ASTNN) are fine-tuned under code-only and context-augmented settings. Results show that context generally improves performance: version history consistently boosts clone detection (e.g., CodeT5 +15.92% F1) and summarisation (e.g., GraphCodeBERT +5.56% METEOR), while call-graph effects vary by model and task. Combining multiple contexts yields further gains (up to +21.48% macro-F1). Human evaluation on 100 Java snippets confirms that context-augmented summaries are significantly preferred for Accuracy and Content Adequacy (p <= 0.026; |delta| up to 0.55). These findings highlight the potential of contextual signals to enhance code comprehension and open new directions for optimising contextual encoding in neural SE models.

代码理解上下文增强模型改进

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。