Introduction
Decoder-only Large Language Models (LLMs) have become the standard for generative tasks. However, their inherent "causal" architecture—where attention is restricted to preceding tokens—presents a significant challenge for text embeddings. In a causal model, early tokens remain unaware of subsequent context, leading to suboptimal document representations. While methods like Echo Embeddings or simple Token Prepending (TP) attempt to bridge this gap, they often suffer from high computational costs or information bottlenecks. This paper introduces Hierarchical Token Prepending (HTP), a training-free method that restructures information flow to create high-quality embeddings for long documents.
The Information Bottleneck in Causal Decoders
Text embeddings aim to compress the semantic essence of a document into a single vector. In causal models, the first token of a long sequence has no access to the information contained in the following thousands of tokens. Existing solutions are often inefficient:
- Echo Embeddings repeat the input twice, doubling sequence length and significantly increasing computational overhead.
- Token Prepending moves a single summary token to the front, creating an "over-compression" bottleneck where one token must represent the entire document.
The authors identify two primary bottlenecks: an attention-level bottleneck (loss during compression) and a readout-level bottleneck (loss during the final pooling stage, often referred to as "over-squashing").
Methodology: Hierarchical Token Prepending
HTP addresses these bottlenecks through a multi-level summary structure that "rewires" information from the end of semantic blocks back to the beginning of the sequence.
The HTP process consists of three main stages:
- Input Partitioning: The document is divided into semantic blocks (e.g., sentences). Local summary placeholders (
<PST>) are placed before each block, and global summary placeholders (<B-PST>) are prepended to the entire sequence. - Local Prepending: During the forward pass, the hidden state of each block's final token—which has naturally aggregated information from that block—is dynamically re-injected into its corresponding
<PST>token across Transformer layers. - Global Prepending: These local summaries are then propagated to the
<B-PST>tokens at the start of the sequence. This hierarchy allows every token in the document to attend to summaries of all subsequent content.
Theoretical Justification for Mean-Pooling
Standard embedding practices often rely on "last-token pooling." However, the authors provide a theoretical proof using Jacobian norms demonstrating that last-token pooling suffers from "over-squashing" in deep networks, where the influence of early tokens decays exponentially. In contrast, mean-pooling aggregates influence across the entire attention matrix, making it "topologically depth-agnostic" and more robust for representing long-range dependencies.
Experimental Results
HTP was evaluated using Mistral-7B, Gemma2-9B, and Qwen2-1.5B across benchmarks including BEIR, MTEB, and LongEmbed.
Long-Context Retrieval
On the LongEmbed benchmark, HTP consistently outperformed vanilla mean-pooling and standard token prepending. As shown in the results, HTP maintains high performance even as document length increases to 16k tokens. For Gemma2-9B, HTP achieved an average NDCG@10 of 30.22, surpassing the Vanilla Mean baseline of 29.85.
Efficiency and Generalization
HTP is significantly more efficient than Echo embeddings. While Echo embeddings incur a ~3.5x time overhead and 4x memory cost, HTP adds only a marginal overhead (1.1x to 1.2x). Furthermore, HTP is complementary to supervised fine-tuning; it improved the performance of models already optimized for embeddings, such as NV-Embed-v2.
Conclusion
Hierarchical Token Prepending offers a scalable, training-free solution to the causal bottleneck in decoder-only LLMs. By introducing a hierarchical information flow and utilizing mathematically robust mean-pooling, HTP enables these models to produce high-quality embeddings for long-form content without the prohibitive costs of repetition-based methods.
Summary updated