Understanding Convolutional Neural Networks for Text Classification

Alon Jacovi, Oren Sar Shalom, Yoav Goldberg

Introduction

While Convolutional Neural Networks (CNNs) have become standard tools for Natural Language Processing (NLP), their internal mechanisms have often been treated as a "black box." In computer vision, filters can be visualized as geometric shapes or textures, but the discrete nature of text makes such interpretations difficult. The prevailing assumption has been that CNN filters act as simple n-gram detectors. However, this model fails to explain how networks handle linguistic nuances like negation, varying intensities, and the inherent noise of natural language. This paper investigates the underlying behavior of 1D CNNs to define how they identify salient features and filter out irrelevant information.

Methodology

The study analyzes a standard 1D CNN architecture (convolutions followed by max-pooling, ReLU, and a fully connected layer) across several sentiment analysis benchmarks, including MR, Elec, and Yelp Review Polarity. To probe the network's logic, the authors introduced several analytical lenses:

  • Thresholding Analysis: A "purity" metric was developed to establish a threshold for each filter, distinguishing "deliberate" n-grams (those correlating with final predictions) from "accidental" n-grams (noise).
  • Slot Activation Vectors: This technique decomposes the total score of an n-gram into individual word contributions within the sequence.
  • Mean Shift Clustering: Used to determine if filters are homogeneous or if they detect multiple distinct semantic patterns.
  • Negative N-gram Search: A search for "flipped" versions of high-scoring n-grams (e.g., "is very good" vs. "is not good") to observe how filters suppress specific linguistic constructs.

Max-Pooling as a Noise Filter

A primary finding of the research is that max-pooling functions as a sophisticated gatekeeper rather than a simple feature selector. The authors discovered that approximately 44% of n-grams surviving the max-pooling layer are "accidental" and irrelevant to the final classification.

Impact of purity threshold on training loss (a), test accuracy (b), and n-gram coverage (c).

As shown in the figure above, increasing the purity threshold—effectively making the model more selective—allows for a significant reduction in n-gram coverage without a corresponding loss in test accuracy. In fact, replacing the standard ReLU activation with a hard threshold based on purity actually improved model performance in some cases, proving that a large portion of pooled data is essentially noise.

Filter Specialization and Activation Patterns

Contrary to the "one filter, one n-gram" theory, the study demonstrates that filters are "multi-talented." Clustering analysis revealed that a single filter can specialize in specific grammatical structures (e.g., DET + ADVERB + ADJECTIVE) or multiple unrelated but semantically similar phrases.

Filter coverage (a) and activation distributions across training examples (b, c) showing how thresholds separate positive signals from noise.

Furthermore, filters exhibit a "Natural Gap": a 30% difference between the maximum theoretical activation and the highest activation seen in real-world text. This suggests that filters rarely encounter the "perfect" mathematical combination of words. Additionally, filters utilize "Negative Signaling" to veto certain constructs. For example, a filter for "pleased" might have a strong negative weight in its first slot to ensure that the phrase "not pleased" results in a low total score that fails to pass the max-pooling threshold.

Key Results and Interpretability

The research successfully validated that 40% of pooled n-grams can be discarded with zero loss in performance. By identifying "Case 2" negative n-grams—where a specific word actively suppresses a filter—the authors provide a framework for explaining why a model might ignore seemingly obvious keywords. This bridges the interpretability gap between computer vision and NLP, allowing researchers to list the semantic patterns a filter detects and the specific words it suppresses.

Limitations and Future Work

The "Natural Gap" identified in the study suggests a potential adversarial vulnerability; an attacker could craft "non-natural" n-grams that produce activations far outside the range seen during training, potentially misleading the classifier. While these insights are robust for one-layer CNNs, future research is required to determine if these behaviors persist in deeper architectures or more complex attention-based models like Transformers. Additionally, the purity threshold remains a heuristic that may require task-specific tuning.

Summary updated

BibTeX
@inproceedings{jacovi2018understanding,
  author = {Alon Jacovi and Oren Sar Shalom and Yoav Goldberg},
  title = {{Understanding Convolutional Neural Networks for Text Classification}},
  booktitle = {BlackboxNLP @ EMNLP},
  year = {2018},
  doi = {10.18653/v1/w18-5408},
}
Figure