Beyond Words: A Topological Exploration of Coherence in Text Documents

Samyak Jain, Rishi Singhal, Sriram Krishna, Yaman K Singla, Rajiv Ratn ShahICLR 2024

Introduction

In Natural Language Processing (NLP), coherence is the invisible glue that makes a text feel like a unified whole rather than a random collection of sentences. While modern Transformer models like BERT or RoBERTa excel at capturing the semantics (meaning) of words, they often overlook the underlying structural "flow" of a document.

This paper introduces a novel approach to measuring text coherence by applying Topological Data Analysis (TDA) to the attention maps of a Transformer model. By treating attention weights as a geometric graph and extracting structural "signatures," the authors achieve state-of-the-art results on standard coherence benchmarks using a surprisingly simple neural network.

The Challenge: Structure vs. Semantics

A passage can be semantically correct but still feel disjointed if the transitions and organizational patterns are weak. Existing models often struggle with this abstract, structural quality. The core insight of this paper is that coherence can be treated as a geometric problem. By looking at the topology of attention—how a model attends to different parts of a text—we can visualize the "skeleton" of the document's logic, which word embeddings alone might miss.

Methodology: Topology Meets Attention

The researchers propose a pipeline that translates raw text into structural features:

  1. Attention Graph Extraction: The authors use a pre-trained RoBERTa model to extract attention matrices. These matrices are treated as weighted graphs where tokens act as nodes and attention weights serve as edges.
Text to Attention Graph
  1. TDA Feature Generation: Three specific types of features are extracted from these graphs:
  2. Topological Features: By applying "filtrations" (thresholding the graph at different weight levels), the team measures standard graph properties like cycles, connected components, and Betti numbers (which count "holes" in different dimensions).
  3. Barcode Features: Using persistent homology, they create "barcodes" representing how long certain topological features persist as the threshold changes, capturing multi-scale structural signals.
  4. Distance to Patterns: They calculate how much the document's attention map deviates from known linguistic patterns (e.g., attending to the next token, previous token, or special [CLS] tokens).
  5. Classification: These extracted features form a 9216-dimensional vector, which is fed into a simple two-layer Multi-Layer Perceptron (MLP) to classify the text's coherence as "low," "medium," or "high."

Datasets

The model was evaluated on the Grammarly Corpus of Discourse Coherence (GCDC), which contains authentic texts from four distinct domains: Yahoo forum posts, Clinton office emails, Enron corporate emails, and Yelp business reviews. Notably, the dataset is imbalanced, with significantly fewer "Medium" coherence samples compared to "Low" and "High."

Key Results

One of the most striking findings is that a simple MLP trained on TDA features can outperform massive, state-of-the-art Transformer-based architectures. This suggests that the topological features themselves are doing the heavy lifting by capturing the right kind of structural information.

The proposed TDA-MLP model achieved an average accuracy of 61.1% across the GCDC dataset, surpassing previous benchmarks like PARSEQ (55.7%) and Fact-aware MTL (60.8%).

Results Table

The model performed particularly well in the Clinton (67.5%) and Yahoo (61.0%) domains. Ablation studies confirmed that while individual feature types performed adequately, combining Topological, Barcode, and Pattern Distance features provided a significant performance boost.

Limitations and Future Work

While promising, the approach has limitations:

  • The "Medium" Coherence Gap: The model struggled significantly with "Medium" coherence samples, averaging only 1.7% accuracy for that specific class. The authors attribute this to the inherent class imbalance in the GCDC dataset.
  • Computational Complexity: Calculating persistent homology and TDA features can be computationally expensive, especially for very long documents.

Future work will explore how TDA can be used in few-shot learning scenarios or for analyzing longer documents with complex hierarchical structures. The authors also plan to investigate if TDA can complement existing semantic models rather than acting as a standalone classifier.

Summary updated

BibTeX
@inproceedings{jain2024beyond,
  author = {Samyak Jain and Rishi Singhal and Sriram Krishna and Yaman K Singla and Rajiv Ratn Shah},
  title = {{Beyond Words: A Topological Exploration of Coherence in Text Documents}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=QJxVhljAyS},
}
Figure