一句话:从因果视角提出反事实推理框架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).
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{GaoGWSLY23,
title = {Two Sides of the Same Coin: Exploiting the Impact of Identifiers in Neural Code Comprehension},
author = {Shuzheng Gao and Cuiyun Gao and Chaozheng Wang and Jun Sun and David Lo and Yue Yu},
booktitle = {ICSE},
year = {2023},
doi = {10.1109/icse48619.2023.00164}
}