Neural Language Models of Code, or Neural Code Models (NCMs), are rapidly progressing from research prototypes to commercial developer tools. As such, understanding the capabilities and limitations of such models is becoming critical. However, the abilities of these models are typically measured using automated metrics that often only reveal a portion of their real-world performance. While, in general, the performance of NCMs appears promising, currently much is unknown about how such models arrive at decisions. To this end, this paper introduces $do_{code}$, a post hoc interpretability method specific to NCMs that is capable of explaining model predictions. $do_{code}$ is based upon causal inference to enable programming language-oriented explanations. While the theoretical underpinnings of $do_{code}$ are extensible to exploring different model properties, we provide a concrete instantiation that aims to mitigate the impact of spurious correlations by grounding explanations of model behavior in properties of programming languages. To demonstrate the practical benefit of $do_{code}$, we illustrate the insights that our framework can provide by performing a case study on two popular deep learning architectures and ten NCMs. The results of this case study illustrate that our studied NCMs are sensitive to changes in code syntax. All our NCMs, except for the BERT-like model, statistically learn to predict tokens related to blocks of code (\eg brackets, parenthesis, semicolon) with less confounding bias as compared to other programming language constructs. These insights demonstrate the potential of $do_{code}$ as a useful method to detect and facilitate the elimination of confounding bias in NCMs.
翻译:神经代码语言模型,或称神经代码模型(NCMs),正迅速从研究原型发展为商业开发者工具。因此,理解此类模型的能力与局限性变得至关重要。然而,这些模型的能力通常通过自动化指标来衡量,而这些指标往往只能揭示其在真实世界中的一部分性能。尽管总体上NCMs的性能看起来前景广阔,但目前对于这些模型如何做出决策仍知之甚少。为此,本文提出了$do_{code}$,一种专门针对NCMs、能够解释模型预测的事后可解释性方法。$do_{code}$基于因果推断,旨在提供面向编程语言的解释。虽然$do_{code}$的理论基础可扩展至探索不同模型属性,但我们提供了一个具体的实例化,旨在通过将模型行为解释植根于编程语言属性来减轻虚假相关性的影响。为了展示$do_{code}$的实际益处,我们通过对两种流行的深度学习架构和十种NCMs进行案例研究,展示了我们的框架所能提供的洞见。该案例研究的结果表明,我们研究的NCMs对代码句法变化敏感。除类似BERT的模型外,我们所有NCMs在统计上都学会了预测与代码块相关的标记(例如括号、圆括号、分号),且与其他编程语言构造相比,其混杂偏倚更少。这些洞见证明了$do_{code}$作为一种检测并促进消除NCMs中混杂偏倚的有用方法的潜力。