Previous studies have demonstrated that code intelligence models are sensitive to program transformation among which identifier renaming is particularly easy to apply and effective. By simply renaming one identifier in source code, the models would output completely different results. The prior research generally mitigates the problem by generating more training samples. Such an approach is less than ideal since its effectiveness depends on the quantity and quality of the generated samples. Different from these studies, we are devoted to adjusting models for explicitly distinguishing the influence of identifier names on the results, called naming bias in this paper, and thereby making the models robust to identifier renaming. Specifically, we formulate the naming bias with a structural causal model (SCM), and propose a counterfactual reasoning based framework named CARBON for eliminating the naming bias in neural code comprehension. CARBON explicitly captures the naming bias through multi-task learning in the training stage, and reduces the bias by counterfactual inference in the inference stage. We evaluate CARBON on three neural code comprehension tasks, including function naming, defect detection and code classification. Experiment results show that CARBON achieves relatively better performance (e.g., +0.5% on the function naming task at F1 score) than the baseline models on the original benchmark datasets, and significantly improvement (e.g., +37.9% on the function naming task at F1 score) on the datasets with identifiers renamed. The proposed framework provides a causal view for improving the robustness of code intelligence models.
翻译:先前的研究显示, 代码情报模型对程序转换非常敏感, 其标识重命名特别容易应用和有效。 通过简单地在源代码中重新命名一个标识符, 模型将产生完全不同的结果。 先前的研究通常会通过生成更多的培训样本来缓解问题。 这种方法并不理想, 因为其有效性取决于生成样本的数量和质量。 不同于这些研究, 我们致力于调整模型, 以明确区分标识名称对结果的影响, 在本文件中点名偏差, 从而使得模型对标识重命名更加强大。 具体地说, 我们用结构性因果模型( SCM) 来制定偏差命名, 并提出一个以 CARBON 为基础的反事实推理框架, 以消除神经代码理解中的偏差。 CARBON 明确通过培训阶段的多任务学习来捕捉命名偏差, 并通过推断阶段的反事实推理来减少偏差。 我们专门评估CARBON 三项神经代码解任务, 包括函数命名、 缺陷检测和代码分类。 实验结果表明, CARBON 取得了相对更好的业绩(ef. g. g.