Task-agnostic Prompt Compression with Context-aware Sentence Embedding and Reward-guided Task Descriptor

Barys Liskavets, Shuvendu Roy, Maxim Ushakov, Mark Klibanov, Ali Etemad, Shane K. Luke

Abstract

The rise of Large Language Models (LLMs) has led to significant interest in prompt compression, a technique aimed at reducing the length of input prompts while preserving critical information. However, the prominent approaches in prompt compression often require explicit questions or handcrafted templates for compression, limiting their generalizability. We propose Task-agnostic Prompt Compression (TPC), a novel framework that generalizes compression across tasks and domains without requiring input questions or templates. TPC generates a context-relevant task description using a task descriptor trained on a curated dataset of context and query pairs, and fine-tuned via reinforcement learning with a reward function designed to capture the most relevant information. The task descriptor is then utilized to compute the relevance of each sentence in the prompt to generate the compressed prompt. We introduce 3 model sizes (Base, Large, and Huge), where the largest model outperforms the existing state-of-the-art methods on LongBench and ZeroSCROLLS, and our smallest model performs comparable to the existing solutions while being considerably smaller.

Introduction

As Large Language Models (LLMs) handle increasingly massive contexts, prompt compression has become a vital research area for reducing computational costs and latency. However, existing techniques usually fall into one of two traps: token-level pruning, which often results in incoherent "word salad," or a heavy dependency on task-awareness, requiring specific user questions to determine relevance. This second trap is a major bottleneck in real-world scenarios like summarization or code analysis, where explicit questions are often unavailable. TPC addresses these challenges by enabling high-quality, task-agnostic compression that preserves the information an LLM will eventually need for high-quality response generation.

Methodology

The TPC framework introduces a three-stage process to automate context inference and sentence ranking.

Overview of the TPC framework architecture, showing the interaction between the Task Descriptor and Sentence Encoder.
  • Context-relevant Task Descriptor (CTD): Instead of requiring a user question, TPC uses a small, causal LLM to generate a concise "task description" based on the input prompt, essentially inferring the core concept of the text.
  • Reward-guided Refinement: To ensure the task descriptor is effective, it is fine-tuned using Reinforcement Learning. The reward is based on KL-divergence: the model is rewarded if the downstream LLM produces the same answer using the compressed prompt as it does with the original.
  • Context-aware Sentence Encoder (CSE): Once the task description is generated, a sentence encoder calculates the relevance of every sentence in the original prompt to that description, retaining only the top-$k$ most relevant sentences.
  • Efficiency via LoRA: To maintain a lightweight footprint, both the CTD and CSE share the same model backbone, using low-rank adaptation (LoRA) heads to switch between tasks.

Experimental Setup

The researchers curated two new datasets for training: the CTD Dataset (4,100 context-question pairs) and the Multi-hop Context-Question Relevant (MCQR) Dataset (9,300 samples). The MCQR dataset is particularly crucial as it forces the sentence encoder to understand that the importance of a sentence often depends on its relationship to other sentences, which is vital for complex reasoning. Evaluation was performed on the industry-standard LongBench and ZeroSCROLLS benchmarks.

Key Results

TPC demonstrates state-of-the-art performance while maintaining significant parameter efficiency.

Detailed performance comparison on LongBench for both task-aware and task-agnostic compression scenarios.
  • Task-Agnostic Superiority: In setups where no question was provided, TPC showed massive improvements—up to 35 points on synthetic tasks and 20-27 points on document-based tasks compared to previous methods like LLMLingua.
  • Massive Efficiency: The TPC-Base (0.5B) model achieved competitive results while being 14x smaller than the 7B-parameter models it competed against. Meanwhile, TPC-Huge (7B) outperformed all existing methods on LongBench and ZeroSCROLLS.
  • Coherence and Latency: By compressing at the sentence level rather than the token level, the model maintains grammatical coherence, making it easier for downstream LLMs to process. While the two-step process adds minor overhead, the overall system remains faster than most SOTA methods due to efficient sentence-level filtering.

Conclusion and Future Work

TPC successfully bridges the gap between task-aware and task-agnostic prompt compression. By generating synthetic task descriptions, the framework allows existing sentence-ranking algorithms to solve previously "blind" compression problems. Future work will focus on refining the Reinforcement Learning process to avoid overfitting and exploring more granular compression levels, such as sub-sentence chunks, for even longer contexts.

Summary updated

BibTeX
@article{liskavets2025task,
  author = {Barys Liskavets and Shuvendu Roy and Maxim Ushakov and Mark Klibanov and Ali Etemad and Shane K. Luke},
  title = {{Task-agnostic Prompt Compression with Context-aware Sentence Embedding and Reward-guided Task Descriptor}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=TpGcX9UTOt},
}
Figure