All models

TextCaps

Capsule network with dynamic routing that classifies text from n-gram convolutional features.

Language · 307 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (14 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
6.2M
Operations
307
Framework
PyTorch
Recurrent
No
Published
EMNLP 2018
Cited by
101 (as of 5 October 2026)
Authors
Wei Zhao, Jianbo Ye, Min Yang and others
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m14424
Graph hash
a677ec6889c88b1d749b742cd4f863903f7eded2c577cb42c4b9dcd376bad268
Skeleton hash
48ba95ffe65c705119874c812b81216e64c19951e37ce6868f7e4c37511f2e65
Architecture hash
3568175df7865e0fdea40967792d7d45fb377d9ac5da253fa92fc300a4841550
Diagram SHA-256
b466f889f8f5d36329cefaef72aab699c3edd1c7c30b5ffd11750048ebfb91a3
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

This is a capsule network for text classification: instead of pooling n-gram features into a flat vector, it routes small vector capsules up through the layers until one capsule per category remains. The authors present it as the first empirical study of capsule networks for text modeling. The network is a variant of earlier capsule networks and has four layers: an n-gram convolutional layer, a primary capsule layer, a convolutional capsule layer and a fully connected capsule layer.

Two arrangements are traced here. Capsule-A embeds each word as a 300-dimensional vector and runs a 3-gram convolution with 32 filters, then a primary capsule layer with 32 filters, a convolutional capsule layer with 16 filters and a fully connected capsule layer. Each capsule carries 16 instantiation parameters, and its length encodes the probability that what it represents is present. Capsule-B keeps the same structure but runs three parallel networks with filter windows of 3, 4 and 5 and averages their outputs, which the authors find consistently performs better. The last capsule layer produces a capsule vector and a probability for each category, where the category count includes an extra orphan category.

The paper's main technical additions are three strategies that stabilise dynamic routing against noise capsules that carry background information or were never trained well. The orphan category soaks up stop words and words unrelated to any class, which the authors argue matters more in text than in images because stop words are a consistent background. A leaky softmax replaces the standard softmax when updating connection strengths, and a coefficients amendment uses the existence probability of child capsules to adjust those strengths. Across six text classification benchmarks, capsule networks reached state of the art on 4 of the 6 and showed a marked gain when transferring from single-label to multi-label classification.

Key idea. Bringing capsule networks with dynamic routing to text, with an orphan category, leaky softmax and coefficient amendment that stabilise routing against background capsules.

  • TextCaps
  • capsule network text classification
  • Capsule-A
  • Capsule-B
  • dynamic routing
  • routing by agreement
  • capsule networks for NLP
  • Zhao et al. 2018
  • multi-label text classification
  • orphan category
  • leaky softmax

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{zhao2018investigatingcapsulenetworksdynamic,
      title={Investigating Capsule Networks with Dynamic Routing for Text Classification}, 
      author={Wei Zhao and Jianbo Ye and Min Yang and Zeyang Lei and Suofei Zhang and Zhou Zhao},
      year={2018},
      eprint={1804.00538},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/1804.00538}, 
}