GenCode: A Generic Data Augmentation Framework for Boosting Deep Learning-Based Code Understanding

📄 arXiv: 2402.15769v3 📥 PDF

作者: Zeming Dong, Qiang Hu, Xiaofei Xie, Maxime Cordy, Mike Papadakis, Yves Le Traon, Jianjun Zhao

分类: cs.SE, cs.AI

发布日期: 2024-02-24 (更新: 2026-01-28)

备注: Accepted by Empirical Software Engineering (EMSE) 2026


💡 一句话要点

提出GenCode框架以解决代码数据增强不足问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码理解 数据增强 深度学习 预训练模型 软件开发 自动化测试 代码智能

📋 核心要点

  1. 现有的代码数据增强方法研究不足,导致开发者在准备训练数据时面临挑战。
  2. GenCode框架通过生成新代码候选项并选择重要数据,提升代码理解模型的训练效果。
  3. 实验结果显示,GenCode在多个任务上相较于MixCode提高了2.92%的准确性和4.90%的对抗鲁棒性。

📝 摘要(中文)

预训练代码模型引领了代码智能的新时代,但在代码数据的自动增强方面仍缺乏研究。本文提出了一种通用的数据增强框架GenCode,以提升代码理解模型的训练效果。GenCode遵循生成与选择的范式,首先生成新的代码候选项,然后通过影响评分识别出重要的训练数据。通过在四个代码理解任务和多个预训练模型上的实验,GenCode在准确性和对抗鲁棒性上均显著优于现有方法MixCode。

🔬 方法详解

问题定义:本文旨在解决代码数据增强不足的问题,现有方法无法有效帮助开发者准备训练数据,影响了代码理解模型的性能。

核心思路:GenCode框架采用生成与选择的策略,首先生成多样化的代码候选项,然后通过影响评分筛选出对模型训练最有价值的数据。

技术框架:GenCode的整体架构包括两个主要阶段:代码生成阶段和数据选择阶段。在生成阶段,应用多种代码增强技术生成新代码;在选择阶段,利用影响评分评估每个候选项的重要性。

关键创新:GenCode的创新在于其生成与选择的双重策略,显著提高了训练数据的质量,与现有单一生成或选择方法相比,提供了更全面的解决方案。

关键设计:在实现中,GenCode使用了特定的影响评分算法来评估代码候选项的重要性,并结合了多种代码增强技术,如代码变换和重构,以确保生成数据的多样性和有效性。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

在实验中,GenCode相较于现有的MixCode方法,平均提高了2.92%的准确性和4.90%的对抗鲁棒性。此外,对于代码特定的大型语言模型,GenCode在准确性和自然鲁棒性上分别提高了0.93%和0.98%。这些结果表明GenCode在提升代码理解模型性能方面的有效性。

🎯 应用场景

GenCode框架在软件开发、代码分析和自动化测试等领域具有广泛的应用潜力。通过提升代码理解模型的训练效果,GenCode能够帮助开发者更高效地进行代码审查、缺陷检测和代码推荐,进而提高软件开发的整体效率和质量。未来,该框架还可以扩展到其他编程语言和开发环境中,进一步推动代码智能的发展。

📄 摘要(原文)

Pre-trained code models lead the era of code intelligence, with multiple models designed with impressive performance. However, one important problem, data augmentation for code data that automatically helps developers prepare training data lacks study in this field. In this paper, we introduce a generic data augmentation framework, GenCode, to enhance the training of code understanding models. Simply speaking, GenCode follows a generation-and-selection paradigm to prepare useful training code data. Specifically, it employs code augmentation techniques to generate new code candidates first and then identifies important ones as the training data by influence scores. To evaluate the effectiveness of GenCode, we conduct experiments on four code understanding tasks (e.g., code clone detection) and three pre-trained code models (e.g., CodeT5) and two recent released code-specific Large Language Models (LLMs) (e.g., Qwen2.5-Coder). Compared to the state-of-the-art (SOTA) code augmentation method MixCode, GenCode produces pre-trained code models with 2.92% higher accuracy and 4.90% adversarial robustness on average. For code-specific LLMs, GenCode achieves an average improvement of 0.93% in accuracy and 0.98% in natural robustness.