Explaining Predictions of Non-Linear Classifiers in NLP

Leila Arras, Franziska Horn, Grégoire Montavon, Klaus-Robert Müller, Wojciech Samek

Introduction

Following seminal work by ?) and ?), the use of deep learning models for natural language processing (NLP) applications received an increasing attention in recent years. In parallel, initiated by the computer vision domain, there is also a trend toward understanding deep learning models through visualization techniques [Erhan et al., 2010, Landecker et al., 2013, Zeiler and Fergus, 2014, Simonyan et al., 2014, Bach et al., 2015, Lapuschkin et al., 2016a] or through decision tree extraction [Krishnan et al., 1999]. Most work dedicated to understanding neural network classifiers for NLP tasks [Denil et al., 2014, Li et al., 2015] use gradient-based approaches. Recently, a technique called layer-wise relevance propagation (LRP) [Bach et al., 2015] has been shown to produce more meaningful explanations in the context of image classifications [Samek et al., 2015]. In this paper, we apply the same LRP technique to a NLP task, where a neural network maps a sequence of word2vec vectors representing a text document to its category, and evaluate whether similar benefits in terms of explanation quality are observed.

In the present work we contribute by (1) applying the LRP method to the NLP domain, (2) proposing a technique for quantitative evaluation of explanation methods for NLP classifiers, and (3) qualitatively and quantitatively comparing two different explanation methods, namely LRP and a gradient-based approach, on a topic categorization task using the 20Newsgroups dataset.

Explaining Predictions of Classifiers

We consider the problem of explaining a prediction f(x)f(\boldsymbol{x}) associated to an input x\boldsymbol{x} by assigning to each input variable xdx_{d} a score RdR_{d} determining how relevant the input variable is for explaining the prediction. The scores can be pooled into groups of input variables (e.g. all word2vec dimensions of a word, or all components of a RGB pixel), such that they can be visualized as heatmaps of highlighted texts, or as images.

Layer-wise relevance propagation [Bach et al., 2015] is a newly introduced technique for obtaining these explanations. It can be applied to various machine learning classifiers such as deep convolutional neural networks. The LRP technique produces a decomposition of the function value f(x)f(\boldsymbol{x}) on its input variables, that satisfies the conservation property:

The decomposition is obtained by performing a backward pass on the network, where for each neuron, the relevance associated with it is redistributed to its predecessors. Considering neurons mapping a set of nn inputs (xi)i∈[1,n](x_{i})_{i\in[1,n]} to the neuron activation xjx_{j} through the sequence of functions:

where for convenience, the neuron bias bjb_{j} has been distributed equally to each input neuron, and where g(⋅)g(\cdot) is a monotonously increasing activation function. Denoting by RiR_{i} and RjR_{j} the relevance associated with xix_{i} and xjx_{j}, the relevance is redistributed from one layer to the other by defining messages Ri←jR_{i\leftarrow j} indicating how much relevance must be propagated from neuron xjx_{j} to its input neuron xix_{i} in the lower layer. These messages are defined as:

where s(zj)=ϵ⋅(1zj≥0−1zj<0)s(z_{j})=\epsilon\cdot(1_{z_{j}\geq 0}-1_{z_{j}<0}) is a stabilizing term that handles near-zero denominators, with ϵ\epsilon set to 0.010.01. The intuition behind this local relevance redistribution formula is that each input xix_{i} should be assigned relevance proportionally to its contribution in the forward pass, in a way that the relevance is preserved (∑iRi←j=Rj\sum_{i}R_{i\leftarrow j}=R_{j}).

Each neuron in the lower layer receives relevance from all upper-level neurons to which it contributes

This pooling ensures layer-wise conservation: ∑iRi=∑jRj\sum_{i}R_{i}=\sum_{j}R_{j}. Finally, in a max-pooling layer, all relevance at the output of the layer is redistributed to the pooled neuron with maximum activation (i.e. winner-take-all). An implementation of LRP can be found in [Lapuschkin et al., 2016b] and downloaded from www.heatmapping.orgCurrently the available code is targeted on image data..

2 Sensitivity Analysis

An alternative procedure called sensitivity analysis (SA) produces explanations by scoring input variables based on how they affect the decision output locally [Dimopoulos et al., 1995, Gevrey et al., 2003]. The sensitivity of an input variable is given by its squared partial derivative:

Here, we note that unlike LRP, sensitivity analysis does not preserve the function value f(x)f(\boldsymbol{x}), but the squared l2l_{2}-norm of the function gradient:

This quantity is however not directly related to the amount of evidence for the category to detect. Similar gradient-based analyses [Denil et al., 2014, Li et al., 2015] have been recently applied in the NLP domain, and were also used by ?) in the context of image classification. While recent work uses different relevance definitions for a group of input variables (e.g. gradient magnitude in ?) or max-norm of absolute value of simple derivatives in ?)), in the present work (unless otherwise stated) we employ the squared l2l_{2}-norm of gradients allowing for decomposition of Eq. 2 as a sum over relevances of input variables.

Experiments

For the following experiments we use the 20news-bydate version of the 20Newsgroupshttp://qwone.com/%7Ejason/20Newsgroups/ dataset consisting of 11314/7532 train/test documents evenly distributed among twenty fine-grained categories.

As a document classifier we employ a word-based CNN similar to ?) consisting of the following sequence of layers:

By 1-Max-Pool we denote a max-pooling layer where the pooling regions span the whole text length, as introduced in [Collobert et al., 2011]. Conv, ReLU and FC denote the convolutional layer, rectified linear units activation and fully-connected linear layer. For building the CNN numerical input we concatenate horizontally 300-dimensional pre-trained word2vecGoogleNews-vectors-negative300, https://code.google.com/p/word2vec/ vectors [Mikolov et al., 2013], in the same order the corresponding words appear in the pre-processed document, and further keep this input representation fixed during training. The convolutional operation we apply in the first neural network layer is one-dimensional and along the text sequence direction (i.e. along the horizontal direction). The receptive field of the convolutional layer neurons spans the entire word embedding space in vertical direction, and covers two consecutive words in horizontal direction. The convolutional layer filter bank contains 800 filters.

2 Experimental Setup

As pre-processing we remove the document headers, tokenize the text with NLTKWe employ NLTK’s version 3.1 recommended tokenizers sent_tokenize and word_tokenize, module nltk.tokenize., filter out punctuation and numbersWe retain only tokens composed of the following characters: alphabetic-character, apostrophe, hyphen and dot, and containing at least one alphabetic-character., and finally truncate each document to the first 400 tokens. We train the CNN by stochastic mini-batch gradient descent with momentum (with l2l_{2}-norm penalty and dropout). Our trained classifier achieves a classification accuracy of 80.19%To the best of our knowledge, the best published 20Newsgroups accuracy is 83.0% [Paskov et al., 2013]. However we notice that for simplification we use a fixed-length document representation, and our main focus is on explaining classifier decisions, not on improving the classification state-of-the-art..

In particular, in case of SA, the above word relevance can equivalently be expressed as:

where f(d)f({d}) represents the classifier’s prediction for document dd.

Note that the resulting LRP word relevance is signed, while the SA word relevance is positive.

In all experiments, we use the term target class to identify the function f(x)f(x) to analyze in the relevance decomposition. This function maps the neural network input to the neural network output variable corresponding to the target class.

3 Evaluating Word-Level Relevances

In order to evaluate different relevance models, we perform a sequence of “word deletions” (hereby for deleting a word we simply set the word-vector to zero in the input document representation), and track the impact of these deletions on the classification performance. We carry out two deletion experiments, starting either with the set of test documents that are initially classified correctly, or with those that are initially classified wronglyFor the deletion experiments we consider only the test documents whose pre-processed length is greater or equal to 100 tokens, this amounts to a total of 4963 documents.. We estimate the LRP/SA word relevances using as target class the true document class. Subsequently we delete words in decreasing resp. increasing order of the obtained word relevances.

We find that LRP yields the best results in both deletion experiments. Thereby we provide evidence that LRP positive relevance is targeted to words that support a classification decision, while LRP negative relevance is tuned upon words that inhibit this decision. In the first experiment the SA classification accuracy curve decreases significantly faster than the random curve representing the performance change when randomly deleting words, indicating that SA is able to identify relevant words. However, the SA curve is clearly above the LRP curve indicating that LRP provides better explanations for the CNN predictions. Similar results have been reported for image classification tasks [Samek et al., 2015]. The second experiment indicates that the classification performance increases when deleting words with the lowest LRP relevance, while small SA values points to words that have less influence on the classification performance than random word selection. This result can partly be explained by the fact that in contrast to SA, LRP provides signed explanations. More generally the different quality of the explanations provided by SA and LRP can be attributed to their different objectives: while LRP aims at decomposing the global amount of evidence for a class f(x)f(x), SA is build solely upon derivatives and as such describes the effect of local variations of the input variables on the classifier decision. For a more detailed view of SA, as well as an interpretation of the LRP propagation rules as a deep Taylor decomposition see ?).

4 Document Highlighting

Word-level relevances can be used for highlighting purposes. In Fig. 2 we provide such visualizations on one test document for different relevance target classes, using either LRP or SA relevance models. We can observe that while the word ride is highly negative-relevant for LRP when the target class is not rec.motorcycles, it is positively highlighted (even though not heavily) by SA. This suggests that SA does not clearly discriminate between words speaking for or against a specific classifier decision, while LRP is more discerning in this respect.

5 Document Visualization

Word2vec embeddings are known to exhibit linear regularities representing semantic relationships between words [Mikolov et al., 2013]. We explore if these regularities can be transferred to a document representation, when using as a document vector a linear combination of word2vec embeddings. As a weighting scheme we employ LRP or SA scores, with the classifier’s predicted class as the target class for the relevance estimation. For comparison we perform uniform weighting, where we simply sum up the word embeddings of the document words (SUM).

For word-based models d′d^{\prime}, we observe that while standard SA and LRP both provide similar visualization quality, the SA variant with simple l2l_{2}-norm yields partly overlapping and dense clusters, still all schemes are better than uniformWe also performed a TFIDF weighting of word embeddings, the resulting 2D-visualization was very similar to uniform weighting (SUM). weighting. In case of SA note that, even though the power to which word gradient norms are raised (l2l_{2} or l22l_{2}^{2}) affects the present visualization experiment, it has no influence on the earlier described “word deletion” analysis.

Conclusion

Through word deleting we quantitatively evaluated and compared two classifier explanation models, and pinpointed LRP to be more effective than SA. We investigated the application of word-level relevance information for document highlighting and visualization. We derive from our empirical analysis that the superiority of LRP stems from the fact that it reliably not only links to determinant words that support a specific classification decision, but further distinguishes, within the preeminent words, those that are opposed to that decision.

Future work would include applying LRP to other neural network architectures (e.g. character-based or recurrent models) on further NLP tasks, as well as exploring how relevance information could be taken into account to improve the classifier’s training procedure or prediction performance.

Acknowledgments

This work was supported by the German Ministry for Education and Research as Berlin Big Data Center BBDC (01IS14013A) and the Brain Korea 21 Plus Program through the National Research Foundation of Korea funded by the Ministry of Education.

References