Contrastive Document Representation Learning with Graph Attention Networks

Peng Xu, Xinchi Chen, Xiaofei Ma, Zhiheng Huang, Bing Xiang

Introduction

Standard Transformer models like BERT and RoBERTa have fundamentally changed natural language processing. However, their reliance on self-attention mechanisms with quadratic complexity ($O(n^2)$) creates a "memory wall," typically limiting input to 512 tokens. While sparse-attention "X-formers" like Longformer and BigBird attempt to mitigate this, they often treat documents as flat sequences, ignoring the inherent semantic structure of long-form text. Furthermore, the scarcity of labeled document-level data hinders the development of robust, universal representations.

Researchers at AWS AI Labs have addressed these challenges by introducing "Graph-RoBERTa." This approach combines the local encoding precision of Transformers with the structural awareness of Graph Attention Networks (GATs), utilizing a contrastive pretraining strategy to learn high-quality document embeddings from unlabeled data.

Methodology

Graph Document Architecture

The proposed architecture treats a document not as a sequence, but as a graph of interconnected passages. The process involves two primary components:

  1. Passage Encoding: The document is partitioned into passages (approximately 100 words each). Each passage is processed through a pretrained RoBERTa model to generate dense vector representations that capture local context.
  2. Graph Attention (GAT): These passage representations serve as nodes in a graph. A central "Document Node" ($v_D$) is introduced to aggregate information across the entire document. Multiple GAT layers facilitate information flow between passage nodes and the document node, allowing the model to dynamically weight the importance of different sections.
Graph Document Architecture with GAT

Contrastive Pretraining

To overcome data scarcity, the authors employ a self-supervised contrastive learning objective. For any given document in a large unlabeled corpus (e.g., OpenWebText), the model generates two "sub-documents" by sampling different subsets of its constituent passages. The training objective is to maximize the agreement between embeddings of sub-documents derived from the same source while minimizing similarity with those from different documents.

Contrastive Pretraining Strategy

This strategy encourages the model to capture the core semantic "essence" of a document, providing a powerful initialization for downstream tasks.

Evaluation and Results

The model was evaluated across diverse benchmarks, including document classification (arXiv, Newsgroup, IMDB, Hyperpartisan) and semantic retrieval (Robust04, MSMARCO DR, WIKIR).

Key Findings

  • Superior Unsupervised Clustering: On the arXiv dataset, Graph-RoBERTa achieved a Normalized Mutual Information (NMI) of 0.437, significantly outperforming BigBird (0.180) and Longformer (0.168).
  • State-of-the-Art Classification: The model reached an average accuracy of 92.07% across four major classification datasets, surpassing standard long-sequence Transformer baselines.
  • Enhanced Retrieval Performance: On the MSMARCO document ranking task, the model achieved a Mean Reciprocal Rank (MRR) of 34.85. When integrated with traditional BM25 search, the performance rose to 37.60, demonstrating a strong synergy between deep semantic representations and classical lexical matching.

Discussion

The success of Graph-RoBERTa highlights several critical insights. First, the graph structure acts as a computational shortcut, allowing distant passages to interact in a single "hop," which is far more efficient than maintaining massive attention windows. Second, contrastive pretraining serves as an effective "warm-up," accelerating convergence during fine-tuning.

However, limitations remain. The advantages of graph structures diminish on shorter texts (like movie reviews) where hierarchical structure is less prevalent. Additionally, while the model is more efficient than full $O(n^2)$ attention for long sequences, the two-step encoding process introduces some computational overhead compared to highly optimized sparse-attention models. Future work may explore more complex graph topologies, such as those based on explicit section headers or citation networks.

Summary updated

BibTeX
@inproceedings{xu2021contrastive,
  author = {Peng Xu and Xinchi Chen and Xiaofei Ma and Zhiheng Huang and Bing Xiang},
  title = {{Contrastive Document Representation Learning with Graph Attention Networks}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.findings-emnlp.327},
}
Figure