Introduction
Modern Natural Language Processing is largely defined by the "BERT paradigm," which excels at sentence-level tasks but struggles with long-form content. The core issue lies in the self-attention mechanism's quadratic complexity ($O(n^2)$), which forces standard models to truncate input text to a mere 512 tokens.
In specialized fields such as law (ECtHR) or medicine (MIMIC-III), documents frequently span thousands of words. Truncating these texts results in the loss of critical information often found in the middle or end of the document. Historically, this limitation led researchers to believe that older CNN or RNN-based architectures were superior for long-document classification. This paper re-evaluates that assumption, investigating whether the performance gap is a fundamental flaw of Transformers or simply a consequence of suboptimal configuration and "short-text bias."
Methodology
The study compares two primary Transformer-based Long Document Classification (TrLDC) strategies:
- Sparse-Attention Transformers (Longformer): This approach replaces full self-attention with a local window, where tokens only attend to their immediate neighbors. To maintain global context, a small subset of "global" tokens is permitted to attend to the entire sequence.
- Hierarchical Transformers: The document is partitioned into segments (e.g., 128 or 512 tokens). Each segment is encoded by a shared Transformer (like RoBERTa), and the resulting representations are aggregated—either through a second-order Transformer or a pooling mechanism—to form a final document vector.
Additionally, the authors explored Task-Adaptive Pre-training (TAPT)—continuing masked language modeling on the task-specific dataset—and Label-wise Attention Networks (LWAN) to allow the model to focus on different document regions for different labels.
Datasets
The models were rigorously tested across four datasets with distinct length profiles:
- MIMIC-III: Clinical discharge summaries averaging ~2,700 tokens.
- ECtHR: Legal cases from the European Court of Human Rights averaging ~2,500 tokens.
- Hyperpartisan: News articles with extreme political bias averaging ~800 tokens.
- 20 News: Classic newsgroup posts averaging ~550 tokens.
Key Insights and Results
The "More is Better" Rule
The most striking finding is the consistent performance gain as the maximum sequence length increases. Moving from 512 to 4096 tokens significantly boosts Micro F1 scores, confirming that truncation is a primary bottleneck in document classification.
Optimization Strategies
- Attention Windows: In Longformers, small local attention windows (32 or 64) perform nearly as well as larger ones (512) while being much more efficient.
- Global Tokens: Distributing global tokens evenly based on position proved more stable than heuristic-based selection (e.g., TF-IDF).
- Context Fragmentation: For hierarchical models, allowing segments to overlap (e.g., 25%) prevents context loss at the boundaries and consistently improves results.
- Domain Adaptation: TAPT provided a massive performance boost for medical notes (MIMIC-III), though its impact was less pronounced in the legal domain (ECtHR), likely due to the latter's better representation in general pre-training corpora.
Performance Benchmarks
On the MIMIC-III dataset, the Longformer (4096 tokens) achieved a 68.2 Micro F1, vastly outperforming the standard BERT baseline of 56.1. The best-performing hierarchical model (8192 tokens + LWAN) reached 71.1 Micro F1, effectively matching state-of-the-art RNN models like LAAT (71.5). Furthermore, hierarchical models were found to be more GPU-memory efficient than Longformers at extreme sequence lengths.
Conclusion
This research demonstrates that Transformers are highly capable of long-document classification when properly configured. By moving beyond simple truncation and employing sparse or hierarchical attention, Transformers can match or exceed the performance of specialized architectures. Future work will look toward "hierarchy-aware" classifiers and the integration of domain-specific knowledge, such as medical code hierarchies, to further close the gap in complex clinical and legal tasks.
Summary updated