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中混杂偏差的有效方法。