Abstract
Deep pretrained transformer networks are effective at various ranking tasks, such as question answering and ad-hoc document ranking. However, their computational expenses deem them cost-prohibitive in practice. Our proposed approach, called PreTTR (Precomputing Transformer Term Representations), considerably reduces the query-time latency of deep transformer networks (up to a 42x speedup on web document ranking) making these networks more practical to use in a real-time ranking scenario. Specifically, we precompute part of the document term representations at indexing time (without a query), and merge them with the query representation at query time to compute the final ranking score. Due to the large size of the token representations, we also propose an effective approach to reduce the storage requirement by training a compression layer to match attention scores. Our compression technique reduces the storage required up to 95% and it can be applied without a substantial degradation in ranking performance.
Introduction
In modern Information Retrieval (IR), a common strategy is the "cascading" approach. A fast, lightweight model like BM25 initially retrieves a candidate set of documents, which are then re-ranked by a more sophisticated, computationally intensive model like BERT. While effective, standard transformer architectures are notoriously slow because they require the query and document to be processed together from the first layer. This "early interaction" means that all heavy computation occurs at query time, leading to unacceptable latency for production environments.
The core challenge is precomputing document information when the transformer's self-attention mechanism expects every document token to interact with every (initially unknown) query token.
The PreTTR Approach
The authors introduce PreTTR (Precomputing Transformer Term Representations) to decouple the transformer's computation. The process is divided into three main stages: training, indexing, and query-time computation.
- Index Time (Precomputation): The first $l$ layers of the transformer are modified using an attention mask. This mask isolates query tokens from document tokens, allowing document representations to be computed and stored in an index before a query is ever received.
- Query Time: When a query arrives, it is processed through the first $l$ layers. The system then retrieves the precomputed document representations and combines them with the query representation. This combined sequence is fed into the remaining $n-l$ layers, where full cross-attention is permitted to calculate the final ranking score.
Attention-Aware Compression
Storing 768-dimensional vectors for every word in a large document collection is storage-prohibitive. To address this, PreTTR incorporates a specialized compression layer between the precomputed and query-time layers.
Unlike standard autoencoders that focus on vector reconstruction, this compression layer is trained to minimize the difference in attention scores in subsequent layers. By ensuring that the compressed representations preserve the attention patterns the transformer relies on, the authors achieved an 83% reduction in vector dimensionality (from 768 to 128) with minimal impact on ranking accuracy.
Experimental Results
PreTTR was evaluated on two major IR benchmarks: TREC WebTrack 2012 (50 million web documents) and TREC Robust 2004 (news documents).
- Speed and Efficiency: On the WebTrack dataset, PreTTR achieved a 42.2x speedup, reducing the re-ranking time for 100 documents from 1.9 seconds to just 46 milliseconds.
- Storage Optimization: The attention-aware compression technique, combined with 16-bit quantization, reduced the storage footprint by 95%. For ClueWeb09-B, this transformed a projected 112TB index into a manageable 2.8TB.
- Ranking Performance: On web search tasks, there was no statistically significant drop in Precision@20, even when precomputing 11 out of 12 layers. However, the Robust 2004 dataset, which features longer and more complex queries, showed higher sensitivity to precomputation depth, suggesting that the optimal split point ($l$) may be domain-dependent.
Conclusion
PreTTR demonstrates that full "cross-pollination" between query and document terms in early transformer layers is not strictly necessary for high-quality ranking. By shifting the bulk of computation to index time and utilizing attention-preserving compression, state-of-the-art transformer models can finally be deployed in real-time search scenarios. Future work will focus on further reducing storage through aggressive quantization and exploring the model's performance on more complex, long-form query datasets.
Summary updated