HDT: Hierarchical Document Transformer

Haoyu He, Markus Flicke, Jan Buchmann, Iryna Gurevych, Andreas Geiger

TL;DR

This paper introduces the Hierarchical Document Transformer (HDT), a novel architecture that leverages the inherent structure of documents (like sections and sentences) to process long texts more efficiently. By using "anchor tokens" and a specialized sparse attention mechanism, HDT achieves faster training, better sample efficiency, and improved performance on downstream tasks compared to existing methods.

What Problem Does This Paper Address?

Modern NLP tasks, such as summarization and question answering, often require processing very long documents. While Transformer models have achieved state-of-the-art results, their self-attention mechanism has a quadratic complexity with respect to input length, making them computationally expensive for long documents. Existing solutions often treat documents as flat sequences of tokens, ignoring their natural hierarchical structure (words -> sentences -> sections -> documents). This can lead to inefficient learning and performance degradation, especially on resource-constrained hardware. While some methods attempt hierarchical processing, they often require more layers or separate processing stages.

Methods

The core innovation is the Hierarchical Document Transformer (HDT), a sparse Transformer architecture designed for structured documents. HDT introduces two key components:

  1. Auxiliary Anchor Tokens: Special tokens are added to represent structural elements like sentences ([SENT]), sections ([SEC]), and the entire document ([DOC]). These tokens act as bridges for information flow between different hierarchical levels.
  2. Hierarchical Sparse Attention: The standard self-attention mechanism is redesigned into a multi-level hierarchy. Attention is computed not only between tokens within the same level (siblings) but also between parent and child tokens. This creates a sparse attention pattern that is sample-dependent, meaning it adapts to the specific structure of each document.

To efficiently implement this sample-dependent attention, the authors developed a custom hierarchical attention kernel. This kernel builds upon the tiling-based approach of FlashAttention but incorporates a sorting heuristic for keys and values based on hierarchy levels. This reordering helps aggregate related tokens, creating larger empty blocks that can be skipped, thus improving computational and memory efficiency.

Datasets

The authors trained and evaluated their models on several datasets:

  • arXiv: A large corpus of scientific papers (1.9M documents).
  • HUPD Patents: Utility patent applications.
  • Wikipedia: Processed Wikipedia dumps.
  • SciRepEval: A scientific document representation benchmark. They used a subset with full-text articles available from unarXive.
  • FacetSum: A dataset for section-level summarization of scientific articles.
  • SCROLLS: A benchmark containing 7 tasks (summarization, QA, NLI) for long texts, where document structure is not explicitly available.
  • ListOps: A mathematical reasoning task dataset used for proof-of-concept evaluation.

Key Insights and Ideas

  • Structure is an Inductive Bias: Explicitly incorporating document structure into the model acts as a powerful inductive bias, leading to faster learning and better generalization.
  • Sample-Dependent Sparsity is Key: Unlike fixed sparse attention patterns, HDT's dynamic, sample-dependent attention is crucial for effectively leveraging document structure and achieving efficiency gains.
  • Anchor Tokens Simplify Hierarchy: The introduction of anchor tokens provides a clean mechanism for inter-level communication, simplifying the hierarchical processing.
  • Efficiency Gains are Real: The custom attention kernel, combined with the hierarchical sparse attention, significantly reduces computational and memory overhead, enabling processing of longer documents on standard hardware.

Key Results

  • Faster Convergence: HDT pre-trains significantly faster than Longformer and HAT, reaching comparable or better performance in fewer steps. For example, HDT pre-trained in 10k iterations while Longformer required 64k.
  • Improved Performance: HDT-E (encoder-only) achieved state-of-the-art or competitive results on SciRepEval proximity tasks, outperforming baselines like BERT, Longformer, and HAT. On ListOps, HDT showed stable performance across varying input lengths, unlike other models.
  • Efficient Inference: HDT's attention mechanism has a theoretical complexity of O(n × s) (where 's' is the longest sentence length), compared to O(n²) for dense attention. This translates to significant speedups and reduced memory usage, as shown in Figure 8. For example, at 32k input length, HDT's memory usage was 5909 MB compared to 21259 MB for standard attention.
  • Expressive Representations: HDT-ED (encoder-decoder) demonstrated competitive performance on FacetSum summarization, even when the decoder attended only to section anchor tokens, highlighting the expressiveness of the learned intermediate representations.

Limitations and Future Work

  • Scaling: The authors mention that scaling HDT to larger sizes and more data is a direction for future work.
  • Generalization to Flat Texts: While HDT performs well on structured and pseudo-structured texts, its performance on truly "flat" long texts (where structure is absent) is still being explored. The paper shows it can be applied, but the gains might be less pronounced compared to explicitly structured documents.
  • Advanced Permutation Algorithms: The current sorting heuristic for keys and values is simple. Investigating more advanced permutation algorithms could potentially lead to larger computational savings.
  • Emergent Abilities: It remains an open question whether scaling laws apply to hierarchical language models and if they can unlock emergent abilities similar to large language models.
  • Byte-Level Hierarchies: Extending the hierarchical structure down to the byte-level could enable token-free language models.
  • Novel Decoder Architectures: Hierarchical ideas might inspire new decoder architectures for structured language generation.
  • Combinations with Other Models: Hierarchical models could be advantageously combined with state-space models, RNNs, or ConvNets.

Summary updated

BibTeX
@inproceedings{he2024hdt,
  author = {Haoyu He and Markus Flicke and Jan Buchmann and Iryna Gurevych and Andreas Geiger},
  title = {{HDT: Hierarchical Document Transformer}},
  booktitle = {COLM},
  year = {2024},
  url = {https://openreview.net/forum?id=dkpeWQRmlc},
}
Figure