← Terse Blog
Research

LLMLingua vs Rule-Based Compression

By ·Founder, Terse·Updated

There are two serious approaches to prompt compression. LLMLingua-style systems use a small language model to score each token's importance and drop the low scorers; rule-based pipelines like Terse's apply deterministic linguistic transformations. The ML approach wins on compression ratio for long documents; the rule-based approach wins on latency, determinism, hardware requirements, and meaning safety — which is why it fits interactive use.

How Each Approach Works

LLMLingua, from Microsoft Research, treats compression as an estimation problem: a small language model computes how surprising (high-perplexity) each token is in context, on the theory that predictable tokens carry information the big model can reconstruct. Low-information tokens are dropped until the target ratio is met. Later variants — LongLLMLingua for long-context retrieval, LLMLingua-2 with a trained token classifier — refine the scoring, and on long documents the family reports up to 20× compression with modest quality loss.

Rule-based compression, the approach behind Terse, encodes what's known about low-information language directly: typo correction, whitespace normalization, filler and politeness removal, verbose-phrase substitution, safe abbreviations, and — at the aggressive end — telegraph compression that drops articles and redundant pronouns. Every transformation is a named rule with explicit protected regions: code, quoted strings, URLs, negations, and ALL-CAPS emphasis are never touched.

The Comparison That Matters

                    LLMLingua (ML)         Rule-based (Terse)
Mechanism           per-token perplexity   linguistic rules
Compression ratio   up to ~20× (long docs) ~1.4–3× (typical prompts)
Latency             100ms–seconds          <2ms
Hardware            GPU (or slow CPU)      none — runs anywhere
Determinism         model-dependent        same input → same output
Meaning safety      statistical            guaranteed protected regions
Best at             long docs, RAG context interactive prompts, agents

Latency and hardware

Perplexity scoring requires a forward pass of a language model over every candidate token — hundreds of milliseconds to seconds, and realistically a GPU for interactive speeds. A rule pipeline is string processing: under 2ms on a laptop CPU, no model download, no VRAM, fully offline. For a tool that intercepts every prompt you type, the difference isn't incremental — it's the difference between imperceptible and disruptive, and it's why on-device optimizers are rule-based.

Determinism

Rules give the same output for the same input, every time. That matters for automated pipelines (reproducible requests, diffable behavior, cacheable prefixes — see the caching guide for why byte-stability pays) and for trust: you can read the diff of what was removed and know the same edit will happen tomorrow. ML scoring can shift with model version and context, which is acceptable for offline document crunching and awkward for anything a developer watches in real time.

Meaning safety

LLMLingua's strength — judging importance in context — is also its risk: a statistically predictable token can still be semantically critical ("not" is often very predictable), and a dropped token is unrecoverable. Rule-based systems are categorically conservative: they only remove token classes that are known-safe (filler, articles, redundant pronouns) and hard-protect negations, conditionals, and code. The ceiling on compression ratio is lower; the floor on meaning preservation is higher.

Which Should You Use?

The deeper point: the two approaches agree about what to remove — low-information tokens — and differ on how sure you need to be before removing it. For a background batch job, statistical confidence is fine. For the prompt you're sending right now, a guarantee is better. Our LLMLingua research page covers the papers in more depth, and Tokenization 101 explains the token mechanics both approaches exploit.

Deterministic Compression, On-Device

Terse's rule pipeline compresses prompts in under 2ms with guaranteed protection for code, negations, and quoted strings — no GPU, no cloud, no surprises.

Download Terse

Frequently Asked Questions

What is LLMLingua?

LLMLingua is a prompt-compression method from Microsoft Research that uses a small language model to score each token's information content (perplexity) and drops low-scoring tokens. It achieves up to ~20x compression on long documents and RAG contexts.

Is rule-based compression worse than ML compression?

It's a different trade-off. ML compression reaches higher ratios on long documents; rule-based compression is thousands of times faster, fully deterministic, runs without a GPU, and guarantees semantically critical tokens like negations and code are never removed — which suits interactive and agent use.

Can LLMLingua remove important words?

It can. Perplexity measures predictability, not importance, and predictable tokens (like 'not' in some contexts) can be semantically critical. Quality is high on average but not guaranteed per prompt — the key difference from rule pipelines with hard protected regions.

Do I need a GPU for prompt compression?

For perplexity-based methods at interactive speed, effectively yes. Rule-based compression needs no model at all — Terse runs the full pipeline on a laptop CPU in under 2 milliseconds, entirely offline.

Further Reading

Related reading

GitHub Copilot Free vs Pro: Worth Upgrading?GitHub Copilot Free vs Pro in 2026: what each plan includes, how AI Credits work, a side-by-side… Windsurf vs Cursor: The 2026 AI IDE ShowdownWindsurf vs Cursor in 2026: both $20/mo, Cascade autonomy vs Composer control, 40+ IDEs vs a VS … Selective Context Pruning — How Terse Removes Redundant Context from AI Selective context pruning removes redundant information from AI conversation history. Learn how … 10 Best Claude Code Alternatives in 2026The best Claude Code alternatives in 2026 — terminal agents and AI IDEs, free and paid. Compare …