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.
翻译:代码的神经语言模型,或称神经代码模型,正从研究原型快速演进为商业开发者工具。因此,理解这类模型的能力与局限性变得至关重要。然而,这些模型的能力通常通过自动化指标衡量,而这些指标往往仅揭示其实际性能的一部分。尽管神经代码模型的性能总体表现令人振奋,但当前关于这些模型如何做出决策仍存在诸多未知。为此,本文提出$do_{code}$——一种专门针对神经代码模型的、能够解释模型预测的事后可解释性方法。$do_{code}$基于因果推理,旨在提供面向编程语言的解释。尽管$do_{code}$的理论基础可扩展至探索不同模型属性,但我们提供了一个具体实例,通过将模型行为的解释建立在编程语言属性之上,以减轻虚假相关性的影响。为展示$do_{code}$的实际效用,我们通过两个主流深度学习架构及十个神经代码模型的案例研究,阐释该框架所能带来的洞见。案例研究结果表明,所研究的神经代码模型对代码句法变化敏感。除了类似BERT的模型外,所有神经代码模型在统计上都能学习预测与代码块相关的令牌(例如括号、圆括号、分号),且相比其他编程语言结构具有更少的混杂偏差。这些洞见表明$do_{code}$作为一种检测并促进消除神经代码模型中混杂偏差的有效方法具有潜力。