Text Classification using Capsules

Jaeyoung Kim, Sion Jang, Sungchul Choi, Eunjeong ParkarXiv 2018

TL;DR

This paper explores the application of Capsule Networks (CapsNets) to text classification, moving beyond their traditional use in computer vision. The authors introduce a simplified static routing mechanism and an ELU-gate to replace standard max-pooling, achieving results comparable to or better than state-of-the-art CNNs and RNNs while being more robust to word-order variations.

What Problem Does This Paper Address?

In the world of deep learning for NLP, Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs) are the workhorses. However, CNNs have a significant drawback: max-pooling. While pooling helps extract prominent features, it discards spatial and positional information—essentially throwing away the context of where a word appears relative to others.

Capsule Networks were originally proposed by Hinton et al. to solve this in images by using vectors (capsules) instead of scalar neurons to represent entities and their properties. This paper investigates whether the "spatial" relationships in text (like syntax and word order) can similarly benefit from the capsule architecture, potentially overcoming the information loss inherent in traditional pooling layers.

Methods

The authors propose a specific architecture tailored for text, as shown in Figure 1:

Figure 1: Capsule networks for text. Each document passes a gate layer, convolutional capsule layer, and a text capsule layer.
  1. Input Layer: Documents are represented as word embeddings.
  2. ELU-gate Layer: Instead of max-pooling, they use a gated linear unit variant called an ELU-gate. This acts as a "control tower," selecting relevant features to propagate without losing the spatial/positional context of the words.
  3. Convolutional Capsule Layer: This layer uses large kernels to capture a wide viewpoint of the text, applying a nonlinear "squashing" function to ensure the length of the capsule vector represents the probability of an entity's existence.
  4. Static Routing: The most significant contribution is the shift from Dynamic Routing to Static Routing. Dynamic routing is an iterative process where lower-level capsules "agree" on which upper-level capsule to activate. The authors argue that because language is highly variable (e.g., word order can change without changing meaning), a fixed weight matrix (static routing) is actually more robust and computationally efficient for text.

Datasets

The model was evaluated on seven diverse benchmark datasets to ensure broad applicability:

  • 20news & Reuters10: Topic classification.
  • MR (2004/2005) & IMDb: Sentiment analysis.
  • TREC-QA: Question type classification.
  • MPQA: Opinion polarity detection.

Detailed hyperparameters and dataset statistics are provided in the paper's summary table:

Dataset statistics and hyperparameters

Key Insights and Ideas

  • Vectors > Scalars: By using vectors (capsules) instead of scalar neurons, the model can represent multiple attributes of a text entity simultaneously (e.g., not just that a word is "good," but its specific intensity and context).
  • The Flexibility of Static Routing: In images, the position of a nose relative to eyes is strict. In text, word order is flexible. The authors found that dynamic routing's attempt to find strict "agreement" between layers was too rigid for language. Static routing allows the model to be more flexible and robust to noise or shuffled word orders.
  • Preserving the "Where": By replacing max-pooling with the ELU-gate, the model maintains a global view of the input, allowing it to learn syntactic representations that CNNs often miss.

Key Results

  • Superiority of Static Routing: The CapsNet with static routing outperformed the dynamic routing version on almost all datasets. For example, on the TREC-QA dataset, static routing achieved 94.84% accuracy compared to 93.80% for dynamic routing.
  • Robustness to Perturbations: In a specific test where word orders were shuffled (Table 6 in the paper), static routing maintained an accuracy of 87%, while dynamic routing dropped to 64%.
  • Interpretability: Using LIME (Local Interpretable Model-agnostic Explanations), the authors showed that their model identifies important words more effectively than dynamic routing, which sometimes assigns negative importance to relevant context words.
Figure 4: Words are highlighted according to their importance for prediction for the TREC- QA dataset, where the ground truth class is 2 (ENTITY). Green and red labels are posi- tive and negative effects, respectively. Higher intensity indicates greater importance of the word.

Limitations and Future Work

While the paper demonstrates that static routing is effective, the authors admit it moves away from some of the original "philosophies" of capsule networks (like the iterative agreement process). Additionally, while they used MNIST to visualize how capsules capture properties like rotation and scale (Figure 3), visualizing similar "textual properties" remains a challenge.

Future work could involve exploring how these capsules can be used for more complex tasks like machine translation or natural language inference, where hierarchical relationships are even more critical.

Summary updated

BibTeX
@misc{kim2018text,
  author = {Jaeyoung Kim and Sion Jang and Sungchul Choi and Eunjeong Park},
  title = {{Text Classification using Capsules}},
  year = {2018},
  eprint = {1808.03976},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1808.03976},
}
Figure