SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2409.01227 · 2024

Prompt Compression with Context-Aware Sentence Encoding for Fast and Improved LLM Inference

arXiv · PDF · Open in the Atlas

Code that ran

We lifted 6 functions out of this paper's own repositories and ran 4 of them in a sandbox. "Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results.

RepositoryRoleRan
workday/cpc canonical 4 of 6
FunctionStatusWhere it lives
ensure_model_type Ran workday/cpc/model/common.py
code served (permissive licence) · get_code("4bef5196affc51fe")
get_model_mock_class Ran workday/cpc/model/common.py
code served (permissive licence) · get_code("c323089674fe4e87")
make_phi3_qa_prompt Ran workday/cpc/data_collection/common.py
code served (permissive licence) · get_code("f43e18f8d41f3054")
similarity Ran workday/cpc/model/mistral.py
code served (permissive licence) · get_code("eb431a43f666e4a2")
parse_args Not yet run workday/cpc/args.py
code served (permissive licence) · get_code("6c79f4310563d127")
sentence_is_good Not yet run workday/cpc/data_collection/common.py
code served (permissive licence) · get_code("82027084aacc5aa3")

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large language models (LLMs) have triggered a new stream of research focusing on compressing the context length to reduce the computational cost while ensuring the retention of helpful information for LLMs to answer the given question. Token-based removal methods are one of the most prominent approaches in this direction, but risk losing the semantics of the context caused by intermediate token removal, especially under high compression ratios, while also facing challenges in computational efficiency. In this work, we propose context-aware prompt compression (CPC), a sentence-level prompt compression technique where its key innovation is a novel context-aware sentence encoder that provides a relevance score for each sentence for a given question. To train this encoder, we generate a new dataset consisting of questions, positives, and negative pairs where positives are sentences relevant to the question, while negatives are irrelevant context sentences. We train the encoder in a contrastive setup to learn context-aware sentence representations. Our method considerably outperforms prior works on prompt compression on benchmark datasets and is up to 10.93x faster at inference compared to the best token-level compression method. We also find better improvement for shorter length constraints in most benchmarks, showing the effectiveness of our proposed solution in the compression of relevant information in a shorter context. Finally, we release the code and the dataset for quick reproducibility and further development: https://github.com/Workday/cpc.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2409.01227")
get_code_for_paper("2409.01227")
have("2409.01227")

Connect an agent — have() is free.