SHAP values for Explaining CNN-based Text Classification Models

Wei Zhao, Tarun Joshi, Vijayan N. Nair, Agus Sudjianto · DOI

Abstract

Deep neural networks are increasingly used in natural language processing (NLP) models. However, the need to interpret and explain the results from complex algorithms limits their widespread adoption in regulated industries such as banking. While work exists on interpretability for structured data, NLP remains challenging due to high dimensionality and the necessity of maintaining textual coherence. This paper develops a methodology to compute SHAP values for local and global explainability of CNN-based text classification models, illustrated through sentiment analysis of Amazon Electronic Review data.

Introduction

Deep learning models often operate as "black boxes," a significant hurdle in sectors like finance where regulatory compliance requires transparency. Shapley Additive Explanations (SHAP) offer a robust framework for interpretability, yet applying SHAP to NLP faces two primary obstacles: the curse of dimensionality, where complexity grows exponentially with vocabulary size, and the loss of context, where word-level (unigram) explanations ignore the multi-word phrases that often drive model decisions.

Methodology: CNN SHAP

The proposed methodology, CNN SHAP, addresses these issues by treating the Convolutional Neural Network (CNN) as a dimension-reduction feature extractor.

Architecture and Feature Extraction

The approach leverages the standard 1D CNN architecture for text, where an embedding matrix is processed by multiple filters of varying sizes (e.g., unigrams, bigrams, trigrams).

Overview of the CNN architecture for text classification, highlighting the feature extraction and classification parts.

Filter-Level SHAP

Instead of calculating SHAP values for every individual word or high-dimensional embedding, the authors calculate them for the outputs of the CNN's max-pooling layer. Because each filter is designed to activate upon detecting specific n-grams, the SHAP value of a filter output can be directly mapped back to a specific phrase in the original text.

Illustration of a bigram filter mapping a specific sequence ("are afraid") from the embedding matrix through the convolutional and max-pool layers.

Optimization and Aggregation

To make calculations feasible, the authors utilize Kernel SHAP to approximate values. Furthermore, they implement de-duplication strategies to handle redundant filters:

  • Exact De-duplication: Merging identical n-grams identified by different filters.
  • Merge De-duplication: Combining overlapping n-grams (e.g., "called the customer" and "customer service" into "called the customer service") by summing their additive SHAP scores.

For global interpretability, the paper introduces rank-based methods—Inverse Rank Average (IRA) and Uniform Rank Average (URA)—to aggregate local n-gram importance across the entire dataset.

Experimental Results

The methodology was evaluated using 75,000 samples from the Amazon Electronic Review dataset for sentiment analysis.

Local Explanations

CNN SHAP successfully identified key sentiment drivers. For instance, in positive reviews, phrases like "no problems" and "is the excellent" were assigned high positive SHAP values. The de-duplication process effectively cleaned redundant filter outputs into coherent, human-readable phrases.

Global Insights

Using URA ranking, the study identified the most significant global indicators of sentiment. Positive sentiment was strongly driven by n-grams such as "easy," "very pleased with," and "no problems," while negative sentiment was primarily linked to "poor" and "the problem."

Conclusion and Future Work

CNN SHAP provides a computationally feasible path toward explaining complex NLP models by focusing on the internal "summaries" created by CNN filters. While the current use of marginal expectations simplifies calculations, future work could explore more robust conditional expectation methods to handle complex feature dependencies. Additionally, the potential for using CNNs as surrogate models to explain even more complex architectures, such as Transformers, remains a promising area for investigation.

Summary updated

Abstract

Deep neural networks are increasingly used in natural language processing (NLP) models. However, the need to interpret and explain the results from complex algorithms are limiting their widespread adoption in regulated industries such as banking. There has been recent work on interpretability of machine learning algorithms with structured data. But there are only limited techniques for NLP applications where the problem is more challenging due to the size of the vocabulary, high-dimensional nature, and the need to consider textual coherence and language structure. This paper develops a methodology to compute SHAP values for local explainability of CNN-based text classification models. The approach is also extended to compute global scores to assess the importance of features. The results are illustrated on sentiment analysis of Amazon Electronic Review data.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.836Sentiment Analysis
Source quote
L434: 0.836 poor
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.757Sentiment Analysis
Source quote
L435: 0.757 very pleased with
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.727Sentiment Analysis
Source quote
L438: 0.727 terrible
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.689Sentiment Analysis
Source quote
L447: 0.689 beat
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.663Sentiment Analysis
Source quote
L442: 0.663 same problem
Amazon Electronics · Amazon Elec ReviewsCNN SHAP (URA)Global CNN SHAP score0.733Sentiment Analysis
Source quote
L439: 0.733 very happy with
BibTeX
@misc{zhao2020shap,
  author = {Wei Zhao and Tarun Joshi and Vijayan N. Nair and Agus Sudjianto},
  title = {{SHAP values for Explaining CNN-based Text Classification Models}},
  year = {2020},
  eprint = {2008.11825},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2008.11825},
}
Figure