Neural code models have introduced significant improvements over many software analysis tasks like type inference, vulnerability detection, etc. Despite the good performance of such models under the common intra-project independent and identically distributed (IID) training and validation setting, we observe that they usually fail to generalize to real-world inter-project out-of-distribution (OOD) setting. In this work, we show that such phenomenon is caused by model heavily relying on project-specific, ungeneralizable tokens like self-defined variable and function names for downstream prediction, and we formulate it as the project-specific bias learning behavior. We propose a measurement to interpret such behavior, termed as Cond-Idf, which combines co-occurrence probability and inverse document frequency to measure the level of relatedness of token with label and its project-specificness. The approximation indicates that without proper regularization with prior knowledge, model tends to leverage spurious statistical cues for prediction. Equipped with these observations, we propose a bias mitigation mechanism Batch Partition Regularization (BPR) that regularizes model to infer based on proper behavior by leveraging latent logic relations among samples. Experimental results on two deep code benchmarks indicate that BPR can improve both inter-project OOD generalization and adversarial robustness while not sacrificing accuracy on IID data.
翻译:在这项工作中,我们表明,这种现象是由许多软件分析任务,如类型推断、脆弱性检测等的神经代码模型带来的显著改进。尽管在共同的独立和分布相同的项目内部(IID)培训和验证设置下,这类模型的业绩良好,但我们看到,这些模型通常无法概括到现实世界项目间分配外(OOOD)的设置。在这项工作中,我们表明,造成这种现象的原因在于模型严重依赖特定项目、非通用的象征物,如用于下游预测的自定义变量和函数名称,我们把它作为项目特有的偏差学习行为。我们建议用一种测量方法来解释此类行为,即Cond-Idf, 将共同发生概率和反向文件频率结合起来,以测量象征性与标签及其项目具体性之间的关联程度。这种近似性表明,如果不对先前的知识进行适当的规范,模型往往会利用刺激的统计线索来进行预测。根据这些观察,我们提出了一种偏差减少偏差的分分定调机制,作为项目特有的偏差学习行为。我们建议用一种测量模型来规范正确的行为,即利用O-Id-ID的逻辑关系,而没有精确的精确的实验性模型,同时显示精确的实验性样品的精确性。