arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2207.11104cs.SE
收藏

同一枚硬币的两面:利用标识符在神经代码理解中的影响

Two Sides of the Same Coin: Exploiting the Impact of Identifiers in Neural Code Comprehension

Shuzheng Gao, Cuiyun Gao, Chaozheng Wang, Jun Sun, David Lo, Yue Yu

摘要:

先前的研究表明,神经代码理解模型容易受到标识符命名的影响。通过在源代码中重命名一个标识符,模型将输出完全不相关的结果,这表明标识符可能会误导模型预测。然而,标识符并不完全不利于代码理解,因为标识符名称的语义可以与程序语义相关。充分利用标识符的两种相反的影响对于增强神经代码理解的鲁棒性和准确性至关重要,并且仍然未得到充分探索。在这项工作中,我们建议从一个新的因果关系的角度来模拟标识符的影响,并提出了一个反事实推理为基础的框架命名为CREAM。CREAM在训练阶段通过多任务学习明确地捕捉标识符的误导信息,在推理阶段减少反事实推理的误导影响。我们评估CREAM在三个流行的神经代码理解任务,包括函数命名,缺陷检测和代码分类。实验结果表明,CREAM不仅在鲁棒性方面显著优于基线(例如,在F1分数的函数命名任务上,+37.9%),而且在原始数据集上也实现了改进的结果(例如,在F1得分时,函数命名任务的得分为+0.5%)。

英文摘要:

Previous studies have demonstrated that neural code comprehension models are vulnerable to identifier naming. By renaming as few as one identifier in the source code, the models would output completely irrelevant results, indicating that identifiers can be misleading for model prediction. However, identifiers are not completely detrimental to code comprehension, since the semantics of identifier names can be related to the program semantics. Well exploiting the two opposite impacts of identifiers is essential for enhancing the robustness and accuracy of neural code comprehension, and still remains under-explored. In this work, we propose to model the impact of identifiers from a novel causal perspective, and propose a counterfactual reasoning-based framework named CREAM. CREAM explicitly captures the misleading information of identifiers through multi-task learning in the training stage, and reduces the misleading impact by counterfactual inference in the inference stage. We evaluate CREAM on three popular neural code comprehension tasks, including function naming, defect detection and code classification. Experiment results show that CREAM not only significantly outperforms baselines in terms of robustness (e.g., +37.9% on the function naming task at F1 score), but also achieve improved results on the original datasets (e.g., +0.5% on the function naming task at F1 score).

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

↑