Abstract
Neural networks, particularly Transformer-based architectures, have achieved significant performance improvements on several retrieval benchmarks. When the items being retrieved are documents, the time and memory cost of employing Transformers over a full sequence of document terms can be prohibitive. A popular strategy involves considering only the first $n$ terms of the document. This can, however, result in a biased system that under retrieves longer documents. In this work, we propose a local self-attention which considers a moving window over the document terms and for each term attends only to other terms in the same window. This local attention incurs a fraction of the compute and memory cost of attention over the whole document. The windowed approach also leads to more compact packing of padded documents in minibatches resulting in additional savings. We also employ a learned saturation function and a two-staged pooling strategy to identify relevant regions of the document. The Transformer-Kernel pooling model with these changes can efficiently elicit relevance information from documents with thousands of tokens. We benchmark our proposed modifications on the document ranking task from the TREC 2019 Deep Learning track and observe significant improvements in retrieval quality as well as increased retrieval of longer documents at moderate increase in compute and memory costs.
Addressing the Length Bias in Document Retrieval
Transformer-based models like BERT have revolutionized Information Retrieval (IR), but they face a fundamental scalability challenge: the computational cost of self-attention grows quadratically ($O(L^2)$) with the length of the text. To maintain low latency, most production systems truncate documents to the first 200–500 tokens.
This truncation introduces a significant "first-$n$ bias." Standard models are physically unable to see relevant information buried deeper in long documents. As shown in the analysis below, there is a substantial gap between the probability that a long document is relevant and the probability that a truncated model (like TK-200) will successfully retrieve it.
The TKL Model: Efficient Local Attention
To overcome these limitations, we propose TKL (Transformer-Kernel for Long text). TKL modifies the Transformer-Kernel (TK) architecture with three key innovations designed for long-form content:
- Local Self-Attention: Instead of calculating attention across the entire document, TKL uses a sliding window approach. Each term only attends to other terms within a fixed-size window (e.g., 40 neighbors). This reduces complexity from $O(L^2)$ to $O(L \times l)$, where $l$ is the window size. These windows overlap to ensure contextual continuity across the document.
- Learned Saturation Function: Traditional kernel-pooling models use a fixed logarithmic function to count term matches. TKL introduces a learned saturation function that adjusts based on the "salience" (importance) of the query term and the length of the document region.
- Two-Stage Aggregation (Top-Local-Max): To produce a final relevance score, the model identifies the "top-$t$" most relevant regions in a document and aggregates their signals. This allows the model to ignore "noise" in long documents and focus on the most pertinent sections, regardless of where they appear.
Experimental Setup
We evaluated TKL using the TREC 2019 Deep Learning track dataset, derived from MS MARCO. This collection contains 3.21 million documents with a median length of 804 words. Notably, the 90th percentile reaches 3,267 words, making it an ideal testbed for long-text retrieval. We utilized both the "Dev" set (sparse labels) and the official TREC 2019 "Deep" judgements (dense, high-quality labels) for evaluation.
Key Results and Efficiency
TKL-4000 (processing up to 4,000 tokens) achieved an nDCG@10 of 0.644, matching the performance of state-of-the-art BERT-based models while processing 20 times more text. It significantly outperformed the baseline TK model (0.594), which was limited by truncation.
Beyond effectiveness, TKL is highly efficient. Because local windows are independent, they can be packed into minibatches more effectively by skipping segments that only contain padding. TKL can process a 2,000-token document in roughly 1.1 ms. In contrast, a standard BERT model—even if it could handle such lengths—would be orders of magnitude slower due to quadratic scaling.
Conclusion
The TKL model demonstrates that "looking at more text" yields substantial gains in retrieval quality without the prohibitive costs of global self-attention. By analyzing the positions of relevant regions, we found that a significant portion of relevant signals occur after the 500th word—information that truncated models miss entirely. While TKL currently operates as a re-ranker, future work could explore combining local attention with other efficient Transformer variants to further push the boundaries of long-document retrieval.
Summary updated