HyperAIHyperAI

Command Palette

Search for a command to run...

acl 2026

Lies wie ein Mensch: Komprimierung von Kontext durch parallelisierbares genaues Lesen und Überfliegen

Zusammenfassung

Große Sprachmodelle (LLMs) zeigen außergewöhnliche Fähigkeiten in verschiedenen Aufgaben. Ihre Bereitstellung in Szenarien mit langem Kontext wird jedoch durch zwei Herausforderungen behindert: Rechenineffizienz und redundante Informationen. Wir schlagen RAM (Read As HuMan) vor, ein Rahmenwerk zur Kontextkomprimierung, das eine adaptive hybride Lesestrategie anwendet, um diese Herausforderungen zu bewältigen. Inspiriert vom menschlichen Leseverhalten (d. h. genaues Lesen wichtiger Inhalte, während weniger relevante Inhalte überflogen werden), partitioniert RAM den Kontext in Segmente und kodiert diese parallel mit der Eingabeabfrage. Segmente mit hoher Relevanz werden vollständig beibehalten (genaues Lesen), während solche mit geringer Relevanz abfragegesteuert in kompakte Zusammenfassungsvektoren komprimiert werden (Überfliegen). Sowohl explizite Textsegmente als auch implizite Zusammenfassungsvektoren werden konkateniert und in den Dekoder eingespeist, um sowohl überlegene Leistung als auch Interpretierbarkeit im natürlichen Sprachformat zu erreichen. Um die Entscheidungsgrenze zwischen genauem Lesen und Überfliegen zu verfeinern, führen wir weiterhin ein kontrastives Lernziel ein, das auf positiven und negativen Abfrage-Segment-Paaren basiert. Experimente zeigen, dass RAM bei mehreren Benchmarks für Fragenbeantwortung und Zusammenfassung über zwei Backbones hinweg bestehende Baselines übertrifft und dabei eine End-to-End-Beschleunigung von bis zu 12-fach bei langen Eingaben (durchschnittliche Länge 16.000; maximale Länge 32.000) erzielt.

One-sentence Summary

Researchers from Tsinghua University, Alibaba, and Northeastern University propose RAM, a context compression framework that adopts a human-inspired hybrid reading strategy by partitioning contexts into segments and encoding them with the input query in parallel, fully retaining high-relevance segments (close reading) while compressing low-relevance ones into query-guided summary vectors (skimming), and refine the close-reading/skimming decision boundary via a contrastive learning objective, achieving superior performance on question answering and summarization benchmarks across two backbones with up to a 12×12\times12× end-to-end speedup on long inputs (average length 16 K16\,\text{K}16K; maximum length 32 K32\,\text{K}32K).

Key Contributions

  • RAM is a context compression framework that combines explicit textual segments and implicit summary vectors by partitioning the context and encoding each segment in parallel with the input query, fully retaining high-relevance segments while compressing low-relevance ones through query-guided summarization.

  • A contrastive learning objective models query-segment relevance through positive and negative pairs, enabling a more robust decision boundary between close reading and skimming and improving compression quality.

  • RAM outperforms existing baselines on multiple question answering and summarization benchmarks across two backbones, delivering up to 12x end-to-end speedup on long inputs (average length 16K; maximum 32K) compared to the lightweight baseline Provence.

Introduction

Large Language Models (LLMs) have transformed natural language processing, but the growing use of prompt engineering techniques like Retrieval-Augmented Generation (RAG) means input prompts now routinely stretch to tens of thousands of tokens. Deploying LLMs in these long-context scenarios introduces two core problems: the quadratic time complexity of self-attention in Transformer architectures makes computation increasingly inefficient, and the inherent redundancy of natural language, amplified at long lengths, degrades model performance.

Context compression has emerged as a promising remedy by shrinking sequence length and filtering out irrelevant content. Existing approaches fall into two camps. Task-agnostic methods compress without any query guidance, which risks discarding query-relevant information. Task-aware methods use the query to guide compression and preserve key information, but they face their own obstacles: most either process the entire long context in one pass or rely on autoregressive compression, both of which are computationally expensive, and they struggle with a trade-off between retaining key details and keeping the output interpretable. Some methods prune low-relevance tokens outright, which sacrifices information, while others compress context into implicit semantic vectors, losing the natural language format that users can inspect.

The authors address these limitations by drawing on cognitive science and modeling human reading behavior, where people close read content relevant to their current goal and skim background information. They propose RAM (Read As HuMan), which formalizes context compression as a hybrid reading strategy. RAM partitions a long context into segments and processes all segments in parallel with the input query, avoiding the efficiency bottlenecks of full-sequence loading or autoregressive compression. It then adaptively treats each segment based on query relevance: highly relevant segments are fully retained in natural language to preserve key information, while less relevant segments are compressed into compact, query-guided implicit summary vectors that capture only the semantic gist. These explicit and implicit representations are concatenated into a hybrid contextual representation for the decoder. To sharpen the distinction between the two reading modes, the authors introduce a contrastive learning objective over annotated positive and negative query-segment pairs. RAM achieves superior performance across multiple QA and summarization benchmarks under varying compression budgets on two backbones, and delivers roughly 12x end-to-end speedup on long inputs (average length 16K, maximum 32K) compared to a lightweight baseline.

Method

The authors propose RAM, a novel context compression framework that mimics human reading behavior: it closely reads highly relevant segments while skimming over less relevant ones via query-guided compression. RAM operates within an encoder–decoder architecture and consists of two core stages: query-aware parallel encoding of context segments, and adaptive compression and training. This design avoids the quadratic cost of full-sequence attention and eliminates the need for iterative compression.

3.1 Query-Aware Parallel Encoding

Given a query QQQ and a long context CCC segmented into NNN equal-length chunks {S1,S2,…,SN}\{ S_1, S_2, \ldots, S_N \}{S1​,S2​,…,SN​}, RAM processes all segments in parallel with the query using a shared encoder. The original input sequence {S1,S2,…,SN,Q}\{ S_1, S_2, \ldots, S_N, Q \}{S1​,S2​,…,SN​,Q} is passed through a trainable LLM-based encoder (e.g., LLaMA or Qwen) to obtain contextualized hidden states. Let H\mathbf{H}H denote the last-layer hidden states.

For each text sequence, a compact representation is constructed by mean-pooling its last hidden states. For segment SiS_iSi​ with length LsegL_{\mathrm{seg}}Lseg​, its representation is:

ri=1Lseg∑j=1Lseghi,j,\mathbf{r}_i = \frac{1}{L_{\mathrm{seg}}} \sum_{j=1}^{L_{\mathrm{seg}}} \mathbf{h}_{i,j},ri​=Lseg​1​j=1∑Lseg​​hi,j​,

where hi,j\mathbf{h}_{i,j}hi,j​ is the last hidden state of the jjj-th token in SiS_iSi​. The query representation rq\mathbf{r}_qrq​ is obtained similarly by mean-pooling the query token hidden states. This parallel encoding step ensures that the query is contextualized against each segment independently, providing a relevance signal without full-sequence attention.

3.2 Adaptive Compression and Training

Based on relevance to the query, RAM dynamically decides whether to preserve each segment verbatim (“close reading”) or compress it into a single vector (“skimming”), guided by a learnable selection mechanism.

Query-Guided Attention

The relevance of each segment to the query is computed via cosine similarity between rq\mathbf{r}_qrq​ and each ri\mathbf{r}_iri​, followed by a softmax to obtain segment probabilities:

pi=exp⁡(rq⊤ri/τ)∑jexp⁡(rq⊤rj/τ),p_i = \frac{\exp\left(\mathbf{r}_q^\top \mathbf{r}_i / \tau\right)}{\sum_{j} \exp\left(\mathbf{r}_q^\top \mathbf{r}_j / \tau\right)},pi​=∑j​exp(rq⊤​rj​/τ)exp(rq⊤​ri​/τ)​,

where τ\tauτ is a temperature parameter. Given a sampled compression rate α\alphaα (sampled from {2,4,8,16,32}\{2, 4, 8, 16, 32\}{2,4,8,16,32}), the number of segments kkk to fully preserve is determined by:

k=⌊LorgαLseg⌋,k = \left\lfloor \frac{L_{\mathrm{org}}}{\alpha L_{\mathrm{seg}}} \right\rfloor,k=⌊αLseg​Lorg​​⌋,

where LorgL_{\mathrm{org}}Lorg​ is the token length of the original input. The top-kkk segments with the highest pip_ipi​ are selected for verbatim retention; the remaining segments are compressed.

Query-Guided Compression (Skimming)

For segments marked for skimming, a query-aware weighted average of token hidden states is computed:

wi,t=softmaxt(cos⁡(hi,t,rq)),ci=∑t=1Lsegwi,thi,t,\begin{aligned} w_{i,t} &= \mathrm{softmax}_t \big( \cos(\mathbf{h}_{i,t}, \mathbf{r}_q) \big), \\ \mathbf{c}_i &= \sum_{t=1}^{L_{\mathrm{seg}}} w_{i,t} \mathbf{h}_{i,t}, \end{aligned}wi,t​ci​​=softmaxt​(cos(hi,t​,rq​)),=t=1∑Lseg​​wi,t​hi,t​,​

where cos⁡(⋅,⋅)\cos(\cdot, \cdot)cos(⋅,⋅) denotes cosine similarity. This yields a single embedding ci∈Rd\mathbf{c}_i \in \mathbb{R}^dci​∈Rd per skimmed segment, where ddd is the hidden dimension.

Hybrid Compressed Representation Construction

Let K⊆{1,…,N}\mathcal{K} \subseteq \{1, \ldots, N\}K⊆{1,…,N} denote the set of segment indices selected for close reading, and let Kˉ\bar{\mathcal{K}}Kˉ be its complement. For each segment iii, the contribution to the compressed context representation is:

M~i=I{i∈K}⋅e(Si)+I{i∈Kˉ}⋅Walignci,\tilde{\mathbf{M}}_i = \mathbf{I}_{\{i \in \mathcal{K}\}} \cdot \mathbf{e}(S_i) + \mathbf{I}_{\{i \in \bar{\mathcal{K}}\}} \cdot \mathbf{W}_{\mathrm{align}} \mathbf{c}_i,M~i​=I{i∈K}​⋅e(Si​)+I{i∈Kˉ}​⋅Walign​ci​,

where e(⋅)\mathbf{e}(\cdot)e(⋅) denotes the word embedding lookup in the decoder LLM, ci\mathbf{c}_ici​ is the query-guided compressed vector, and Walign∈Rd×d\mathbf{W}_{\mathrm{align}} \in \mathbb{R}^{d \times d}Walign​∈Rd×d is a trainable semantic alignment matrix applied only to skimmed segments to bridge the representation gap between explicit tokens and implicit vectors. The indicator I{⋅}\mathbf{I}_{\{\cdot\}}I{⋅}​ selects the appropriate representation path per segment. The final compressed context is formed by concatenating all segment representations in their original order:

M=[M~1;M~2;…;M~N]∈RLc×d,\mathbf{M} = \left[ \tilde{\mathbf{M}}_1; \tilde{\mathbf{M}}_2; \ldots; \tilde{\mathbf{M}}_N \right] \in \mathbb{R}^{L_c \times d},M=[M~1​;M~2​;…;M~N​]∈RLc​×d,

where Lc=∑i∈KLseg+∣Kˉ∣L_c = \sum_{i \in \mathcal{K}} L_{\mathrm{seg}} + |\bar{\mathcal{K}}|Lc​=∑i∈K​Lseg​+∣Kˉ∣ is the total length after compression. This hybrid representation preserves verbatim tokens for high-relevance segments while replacing low-relevance ones with compact, query-guided summaries, achieving both fidelity and efficiency.

Training Objective

The compressed memory M\mathbf{M}M is concatenated with the query embeddings and answer tokens, then fed into the decoder for standard teacher-forced language modeling. Let Y=[y1,…,yNa]\mathbf{Y} = [y_1, \ldots, y_{N_a}]Y=[y1​,…,yNa​​] denote the answer token sequence. The language modeling loss is:

Lnll=−1Na∑t=1Nalog⁡P(yt∣y<t,M,Q),\mathcal{L}_{\mathrm{nll}} = -\frac{1}{N_a} \sum_{t=1}^{N_a} \log P(y_t \mid y_{<t}, \mathbf{M}, Q),Lnll​=−Na​1​t=1∑Na​​logP(yt​∣y<t​,M,Q),

where P(yt∣⋅)P(y_t \mid \cdot)P(yt​∣⋅) is derived from the softmax-normalized logits, and the loss is computed only over answer positions.

To improve relevance discrimination, a contrastive loss is introduced during training. Given ground-truth positive/negative segment labels (e.g., from answer span annotations), the loss encourages higher similarity between the query and positive segments, and lower similarity with negative ones:

Lcon=−1∣P∣∑i∈Plog⁡exp⁡(cos⁡(rq,ri)/τ)∑j=1Nexp⁡(cos⁡(rq,rj)/τ),\mathcal{L}_{\mathrm{con}} = -\frac{1}{|\mathcal{P}|} \sum_{i \in \mathcal{P}} \log \frac{\exp(\cos(\mathbf{r}_q, \mathbf{r}_i) / \tau)}{\sum_{j=1}^{N} \exp(\cos(\mathbf{r}_q, \mathbf{r}_j) / \tau)},Lcon​=−∣P∣1​i∈P∑​log∑j=1N​exp(cos(rq​,rj​)/τ)exp(cos(rq​,ri​)/τ)​,

where P\mathcal{P}P is the set of positive segment indices and τ\tauτ is the same temperature parameter used in query-guided attention. The total training objective combines both terms:

LRAM=Lnll+Lcon.\mathcal{L}_{\mathrm{RAM}} = \mathcal{L}_{\mathrm{nll}} + \mathcal{L}_{\mathrm{con}}.LRAM​=Lnll​+Lcon​.

This design enables RAM to achieve high compression efficiency, strong task performance, and natural language format interpretability.

Efficiency Analysis

By segmenting the long context and encoding each segment with the query in parallel, followed by “skimming” low-relevance segments via lightweight compression, RAM fundamentally avoids the bottlenecks of conventional approaches that either process the full input in one shot or rely on autoregressive iteration. The entire pipeline consists of two stages: (1) compression, which includes query-aware parallel encoding and adaptive compression, and (2) decoding, whose floating-point operations (FLOPs) can be modeled separately.

Compression Stage

This stage involves two core components. First, the original context CCC of length LorgL_{\mathrm{org}}Lorg​ is split into NNN segments, each encoded in parallel alongside the query QQQ (length LqL_qLq​). Second, a query-guided attention mechanism computes a relevance score for each segment to decide whether to retain it as-is or compress it into a compact vector. Compressed segments are aggregated via a lightweight operation (e.g., weighted average) into a single summary vector. Let LcL_cLc​ denote the total effective length fed to the decoder (i.e., sum of retained token lengths and number of skimmed vectors), and α=Lc/Lorg\alpha = L_c / L_{\mathrm{org}}α=Lc​/Lorg​ the compression ratio. The FLOPs of this stage are:

FLOPscomp=FParaEnc(Q,C)+FQueryAttn(Q,R),\mathrm{FLOPs}_{\mathrm{comp}} = F_{\mathrm{ParaEnc}}(Q, \mathbf{C}) + F_{\mathrm{QueryAttn}}(Q, \mathbf{R}),FLOPscomp​=FParaEnc​(Q,C)+FQueryAttn​(Q,R),

where FParaEnc(Q,C)F_{\mathrm{ParaEnc}}(Q, \mathbf{C})FParaEnc​(Q,C) denotes the cost of parallel encoding. Since each segment has length LsegL_{\mathrm{seg}}Lseg​ and is processed independently, its complexity is O(N⋅Lseg2)=O(Lseg⋅Lorg)O(N \cdot L_{\mathrm{seg}}^2) = O(L_{\mathrm{seg}} \cdot L_{\mathrm{org}})O(N⋅Lseg2​)=O(Lseg​⋅Lorg​), which is substantially lower than the O(Lorg2)O(L_{\mathrm{org}}^2)O(Lorg2​) cost of full-sequence encoding (note N⋅Lseg=LorgN \cdot L_{\mathrm{seg}} = L_{\mathrm{org}}N⋅Lseg​=Lorg​ and Lseg≪LorgL_{\mathrm{seg}} \ll L_{\mathrm{org}}Lseg​≪Lorg​). Meanwhile, FQueryAttn(Q,R)F_{\mathrm{QueryAttn}}(Q, \mathbf{R})FQueryAttn​(Q,R) (the cost of query-guided attention over NNN relevance scores) incurs only O(N)O(N)O(N) computational overhead, which is linear in the number of segments.

Decoding Stage

Assuming the generated answer has length LaL_aLa​, decoding requires LaL_aLa​ forward passes. The FLOPs of the iii-th pass depend on the compressed context length LcL_cLc​ and query length LqL_qLq​:

FLOPsiforward=FDecoder(M,Q,i),\mathrm{FLOPs}_i^{\mathrm{forward}} = F_{\mathrm{Decoder}}(\mathbf{M}, Q, i),FLOPsiforward​=FDecoder​(M,Q,i),

where M\mathbf{M}M denotes the mixed input (retained tokens and skimmed vectors). The total FLOPs are therefore:

FLOPs=∑i=1LaFLOPsiforward+FLOPscomp.\mathrm{FLOPs} = \sum_{i=1}^{L_a} \mathrm{FLOPs}_i^{\text{forward}} + \mathrm{FLOPs}_{\text{comp}}.FLOPs=i=1∑La​​FLOPsiforward​+FLOPscomp​.

Empirical results show that under the same compression ratio, RAM achieves significantly lower end-to-end latency compared to task-relevant baselines.

Experiment

The experiments evaluate RAM against task-specific and task-agnostic compression baselines on question answering and summarization benchmarks, using LLaMA-3.1-8B and Qwen3-4B backbones. RAM consistently outperforms all baselines under various compression ratios (2x to 32x) and across different model architectures, while also maintaining strong performance on inputs exceeding its training length, demonstrating robust length extrapolation. Efficiency analysis shows RAM reduces inference costs via parallel encoding and query-guided adaptive compression, and ablation studies confirm that each component, including skimming, close reading, query-aware compression, and contrastive learning, is essential to its effectiveness. Overall, RAM proves to be both accurate and efficient, with stable performance across diverse compression settings where baseline methods degrade.

RAM consistently outperforms existing compression baselines across multiple QA benchmarks and a summarization task under different compression constraints, achieving state-of-the-art exact match and F1 scores in most settings. It also maintains stable performance across different backbone models, indicating robustness to model choice. RAM surpasses compression baselines on all benchmarks under both 4x and 8x constraints, with best exact match and F1 in most cases. RAM's performance is stable across LLaMA-3.1-8B and Qwen3-4B backbones, showing robustness. Even when slightly below the fine-tuned original prompt, RAM still beats a task-related baseline after fine-tuning.

On four QA benchmarks with a Qwen3-4B backbone, RAM consistently outperforms a fine-tuned task-specific baseline under both 4x and 8x compression constraints, and often nears or exceeds the fine-tuned original prompt. Its advantage over the baseline grows at higher compression, indicating strong semantic preservation and robustness. RAM surpasses the fine-tuned Provence decoder on all benchmarks under both 4x and 8x compression. Even when RAM trails the fine-tuned original prompt, it remains competitive, and on NarrativeQA it exceeds it at both compression levels. Under 8x compression, RAM's scores drop less than the baseline's, showing better resilience to aggressive compression.

RAM achieves exceptionally low and stable compression latency across all compression ratios, drastically outperforming baseline methods. Its compression latency remains near 0.1 seconds regardless of the compression constraint, while baselines like EXIT incur hundreds of seconds and LongLLMLingua scales down but stays much higher. This efficiency stems from parallel segment encoding and query-guided adaptive compression. RAM's compression latency is around 0.1 seconds across all compression constraints, orders of magnitude lower than all baselines. EXIT shows consistently high compression latency near 300 seconds, while Provence stays around 2.1 seconds and LongLLMLingua decreases from 24.3 to 4.7 seconds as compression becomes more aggressive. RAM's compression latency is nearly invariant to the compression ratio, indicating robust efficiency even at high compression levels.

An ablation study on two datasets shows that removing any core component degrades performance, with the close reading mechanism causing the largest drop. Query-guided skimming outperforms average pooling, and contrastive learning is essential for distinguishing segments that require different processing. Removing close reading leads to the sharpest performance decline, especially on NaturalQA where EM drops from 62.41 to 46.40. Replacing query-guided skimming with average pooling reduces scores, confirming that query-aware compression retains more relevant information. Omitting contrastive learning also markedly hurts results, indicating its role in preventing overcompression of important content.

RAM consistently outperforms existing compression baselines on QA and summarization benchmarks under 4x and 8x compression, achieving state-of-the-art exact match and F1 scores in most settings while maintaining stable performance across different backbone models. Its compression latency remains near 0.1 seconds regardless of compression ratio, orders of magnitude faster than baselines, due to parallel encoding and query-guided adaptive compression. Ablation studies show every core component is essential, with close reading being most critical, query-guided skimming outperforming average pooling, and contrastive learning preventing overcompression of important content.


KI mit KI entwickeln

Von der Idee bis zum Launch – beschleunigen Sie Ihre KI-Entwicklung mit kostenlosem KI-Co-Coding, sofort einsatzbereiter Umgebung und bestem GPU-Preis.

KI-gestütztes kollaboratives Programmieren
Sofort einsatzbereite GPUs
Die besten Preise

HyperAI Newsletters

Abonnieren Sie unsere neuesten Updates
Wir werden die neuesten Updates der Woche in Ihren Posteingang liefern um neun Uhr jeden Montagmorgen
Unterstützt von MailChimp