Long Document Ranking with Query-Directed Sparse Transformer

Jyun-Yu Jiang, Chenyan Xiong, Chia-Jung Lee, Wei Wang

Abstract

Standard Transformer models face a quadratic computational bottleneck when processing long documents. QDS-Transformer addresses this by introducing a "Query-Directed Sparse" attention mechanism that incorporates Information Retrieval (IR) principles—local context, sentential structure, and query proximity—directly into the attention matrix. This approach achieves superior ranking performance on long documents while significantly improving computational efficiency, reaching speeds twice as fast as vanilla BERT.

Introduction

Transformer-based models like BERT have set new benchmarks in NLP, yet their $O(n^2)$ self-attention complexity makes them impractical for long documents. Common workarounds, such as document truncation or "split-and-pool" strategies, often sacrifice context or introduce pipeline complexity. QDS-Transformer proposes that a document token only needs to attend to its local neighborhood, its sentence structure, and the user's query to determine relevance, bypassing the need for full self-attention.

Methodology: Query-Directed Sparsity

The core of QDS-Transformer is the sparse attention matrix $A_{QDS}$, which replaces the standard fully-connected matrix with three IR-inspired patterns:

  1. Local Attention: Tokens attend to a small window ($w$) of nearby tokens to capture local syntax and phrase-level information.
  2. Sentential Global Attention: Special [SOS] (start-of-sentence) tokens are prepended to every sentence. Every token in a sentence attends to its [SOS] token, allowing the model to capture hierarchical document structure.
  3. Query-Directed Global Attention: Every document token attends to every query token, ensuring the model remains focused on query-oriented proximity matching throughout all layers.
The QDS-Transformer sparse attention matrix illustrates local, sentential, and query-directed attention patterns.

To ensure these algorithmic gains translate to hardware speedups, the authors utilized TVM (Tensor Virtual Machine) to compile optimized CUDA kernels, avoiding the inefficiencies of standard masking.

Experimental Setup

The model was evaluated on the TREC 2019 Deep Learning Track for large-scale ad-hoc retrieval and several few-shot benchmarks: Robust04 (RB04), ClueWeb09-B (CW09), and ClueWeb12-B13 (CW12). These datasets test both raw performance and generalization capabilities when training data is scarce.

Analysis and Insights

Empirical analysis of the model revealed distinct layer-wise behaviors. Lower layers prioritize local interactions and document hierarchy (attending to [SOS] tokens), while higher layers increasingly focus on matching document terms with the query. This "NLP pipeline" behavior suggests that the model naturally decomposes the ranking task into structural understanding followed by relevance matching.

Extracted figure from page 7 of Long Document Ranking with Query-Directed Sparse Transformer

Furthermore, the authors found that algorithmic sparsity requires custom engineering (like TVM kernels) to be effective. Pruning distant, noisy connections not only improves speed but also serves as a form of denoising, focusing the model on relevant signals rather than distant, irrelevant terms.

Key Results

  • Effectiveness: QDS-Transformer consistently outperformed standard BERT retrofitting methods (like MaxP) by approximately 5% in NDCG@10. It also surpassed other sparse architectures like Longformer, proving that query-directed sparsity is superior for ranking.
  • Efficiency: The model achieved a 200%+ speedup in training and inference compared to vanilla BERT on long documents.
  • Scalability: It successfully processed sequences up to 2,048 tokens, quadrupling the standard BERT limit of 512.

Conclusion and Future Work

QDS-Transformer demonstrates that baking IR axioms into Transformer architectures can solve the long-document bottleneck. Future work includes exploring dynamic window sizes and further optimizing the joint structural-efficiency trade-offs. A current limitation is the pre-training mismatch, as the base RoBERTa model was not originally trained on the long-range dependencies enabled by this sparse architecture.

Summary updated

BibTeX
@inproceedings{jiang2020long,
  author = {Jyun-Yu Jiang and Chenyan Xiong and Chia-Jung Lee and Wei Wang},
  title = {{Long Document Ranking with Query-Directed Sparse Transformer}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.412},
}
Figure