Update model card: v9 evals, architecture details, comparison with LLMLingua-2
Browse files
README.md
CHANGED
|
@@ -2,28 +2,24 @@
|
|
| 2 |
license: apache-2.0
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
-
library_name: transformers
|
| 6 |
tags:
|
| 7 |
- token-compression
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
- agentic
|
| 11 |
- modernbert
|
| 12 |
-
- llmlingua
|
| 13 |
-
- headroom
|
| 14 |
-
- tool-outputs
|
| 15 |
-
- structured-data
|
| 16 |
-
pipeline_tag: token-classification
|
| 17 |
-
base_model: answerdotai/ModernBERT-base
|
| 18 |
datasets:
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
model-index:
|
| 28 |
- name: kompress-base
|
| 29 |
results:
|
|
@@ -31,142 +27,154 @@ model-index:
|
|
| 31 |
type: token-classification
|
| 32 |
name: Token Compression
|
| 33 |
metrics:
|
| 34 |
-
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
---
|
| 41 |
|
| 42 |
-
# Kompress: Token
|
| 43 |
-
|
| 44 |
-
**Kompress** is a ModernBERT-based token compressor trained on **330K examples** of structured tool outputs β JSON API responses, git diffs, error logs, source code, CLI output, database results, and agentic conversation traces. It is a drop-in replacement for [LLMLingua-2](https://arxiv.org/abs/2403.12968).
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
##
|
| 49 |
|
| 50 |
| Metric | Kompress | LLMLingua-2 |
|
| 51 |
|--------|----------|-------------|
|
| 52 |
-
|
|
| 53 |
-
|
|
| 54 |
-
|
|
| 55 |
-
|
|
| 56 |
-
|
|
|
|
|
| 57 |
|
| 58 |
-
###
|
| 59 |
|
| 60 |
-
|
|
| 61 |
-
|---------|----------|-------------|
|
| 62 |
-
|
|
| 63 |
-
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|--------|----------|-------------|
|
| 69 |
-
| Entity Preservation | **91.1%** | 13.5% |
|
| 70 |
-
| Compression Ratio | **49.9%** | 85.8% |
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
- **Expands instead of compressing**: 206% average ratio on agentic data
|
| 78 |
-
- **Fragments UUIDs**: `4e149fea-6eb8-4feb` β `4e149fea - 6eb8 - 4feb`
|
| 79 |
-
- **Has no cross-chunk awareness**: 512-token limit
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|--------|----------|------|
|
| 91 |
-
| Toucan-1.5M (MCP tool outputs) | ~80K | Real MCP server tool responses |
|
| 92 |
-
| SWE-agent trajectories | ~60K | Bash output, file reads, git diffs |
|
| 93 |
-
| ToolBench | ~50K | REST API JSON responses |
|
| 94 |
-
| Glaive Function Calling | ~40K | Function call/response pairs |
|
| 95 |
-
| CodeSearchNet | ~40K | Source code (Python, JS, Java, Go, Ruby, PHP) |
|
| 96 |
-
| JetBrains diff-xyz | ~10K | Git unified diffs |
|
| 97 |
-
| SQL create-context | ~10K | Database schemas + queries |
|
| 98 |
-
| Claude Code sessions | ~15K | Real agentic coding traces (API-labeled) |
|
| 99 |
-
| SWE-bench trajectories | ~15K | Open-source coding agent traces |
|
| 100 |
-
| Glaive + SWE (API-labeled) | ~10K | Function calling + coding (API-labeled) |
|
| 101 |
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
-
#
|
|
|
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
```
|
| 107 |
-
Input tokens β ModernBERT-base encoder (149M params, 8K context) β
|
| 108 |
-
Head 1: Token-level keep/discard (Linear β Softmax)
|
| 109 |
-
Head 2: Span importance (Conv1d β GELU β Conv1d β Sigmoid)
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
```
|
| 113 |
|
| 114 |
-
|
| 115 |
|
| 116 |
-
##
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
|
| 134 |
-
##
|
| 135 |
|
| 136 |
-
|
| 137 |
-
from kompress.integration.headroom_bridge import patch_content_router
|
| 138 |
-
from headroom.transforms import ContentRouter
|
| 139 |
-
|
| 140 |
-
router = ContentRouter()
|
| 141 |
-
patch_content_router(router) # Swaps LLMLingua β Kompress
|
| 142 |
-
```
|
| 143 |
|
| 144 |
-
|
| 145 |
|
| 146 |
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
-
|
| 150 |
-
-
|
| 151 |
|
| 152 |
-
##
|
| 153 |
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
##
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
author={Tejas Chopra},
|
| 162 |
-
year={2025},
|
| 163 |
-
url={https://huggingface.co/chopratejas/kompress-base},
|
| 164 |
-
}
|
| 165 |
-
```
|
| 166 |
|
| 167 |
-
##
|
| 168 |
|
| 169 |
-
|
| 170 |
-
- [Headroom](https://github.com/chopratejas/headroom) β Context compression framework
|
| 171 |
-
- [LLMLingua-2](https://arxiv.org/abs/2403.12968) β The model Kompress replaces
|
| 172 |
-
- [ModernBERT](https://huggingface.co/answerdotai/ModernBERT-base) β Base encoder
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
language:
|
| 4 |
- en
|
|
|
|
| 5 |
tags:
|
| 6 |
- token-compression
|
| 7 |
+
- context-optimization
|
| 8 |
+
- llm
|
| 9 |
- agentic
|
| 10 |
- modernbert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
datasets:
|
| 12 |
+
- lmsys/lmsys-chat-1m
|
| 13 |
+
- cnn_dailymail
|
| 14 |
+
- EdinburghNLP/xsum
|
| 15 |
+
- ccdv/govreport-summarization
|
| 16 |
+
- ccdv/arxiv-summarization
|
| 17 |
+
- huuuyeah/meetingbank
|
| 18 |
+
- knkarthick/samsum
|
| 19 |
+
metrics:
|
| 20 |
+
- f1
|
| 21 |
+
- accuracy
|
| 22 |
+
pipeline_tag: token-classification
|
| 23 |
model-index:
|
| 24 |
- name: kompress-base
|
| 25 |
results:
|
|
|
|
| 27 |
type: token-classification
|
| 28 |
name: Token Compression
|
| 29 |
metrics:
|
| 30 |
+
- name: Quality Score (Claude-judged)
|
| 31 |
+
type: custom
|
| 32 |
+
value: 6.9
|
| 33 |
+
- name: LLMLingua-2 Quality Score
|
| 34 |
+
type: custom
|
| 35 |
+
value: 6.2
|
| 36 |
+
- name: Latency (median, Apple Silicon)
|
| 37 |
+
type: latency
|
| 38 |
+
value: 49ms
|
| 39 |
+
- name: LLMLingua-2 Latency
|
| 40 |
+
type: latency
|
| 41 |
+
value: 113ms
|
| 42 |
---
|
| 43 |
|
| 44 |
+
# Kompress: ModernBERT Token Compressor for LLM Context Windows
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
**Kompress compresses text in LLM context windows so agents can do more with less.** It's a drop-in replacement for LLMLingua-2 that's higher quality and 2.3x faster.
|
| 47 |
|
| 48 |
+
## Results
|
| 49 |
|
| 50 |
| Metric | Kompress | LLMLingua-2 |
|
| 51 |
|--------|----------|-------------|
|
| 52 |
+
| **Quality (Claude-judged, 1-10)** | **6.9** | 6.2 |
|
| 53 |
+
| **Latency (median)** | **49ms** | 113ms |
|
| 54 |
+
| Speed | **2.3x faster** | baseline |
|
| 55 |
+
| Model size | 600MB (150M params) | 710MB (179M params) |
|
| 56 |
+
| Max sequence length | **8,192 tokens** | 512 tokens |
|
| 57 |
+
| Architecture | ModernBERT-base (2024) | mBERT (2018) |
|
| 58 |
|
| 59 |
+
### Quality on Real Agent Data
|
| 60 |
|
| 61 |
+
| Eval Set | Kompress | LLMLingua-2 |
|
| 62 |
+
|----------|----------|-------------|
|
| 63 |
+
| Unstructured NL text | **6.9/10** | 6.2/10 |
|
| 64 |
+
| Claude Code sessions (text) | **6.7/10** | 5.2/10 |
|
| 65 |
+
| Claude Code sessions (raw) | **6.6/10** | 5.2/10 |
|
| 66 |
|
| 67 |
+
Quality scores are judged by Claude Sonnet 4.6: "Can an LLM fully understand and act on the compressed version?" (1-10 scale).
|
| 68 |
|
| 69 |
+
## How It Works
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
Kompress is a **dual-head ModernBERT** model trained to classify each token as keep or discard:
|
| 72 |
|
| 73 |
+
- **Token head**: Binary classifier (keep/discard per token via argmax)
|
| 74 |
+
- **Span head**: 1D CNN that identifies important regions, boosts borderline tokens in critical spans
|
| 75 |
|
| 76 |
+
The model decides how much to compress based on content density β no fixed compression ratio.
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
### Example
|
| 79 |
|
| 80 |
+
```
|
| 81 |
+
ORIGINAL (98 words):
|
| 82 |
+
After investigating the memory leak, I traced it to the event listener
|
| 83 |
+
registration in the WebSocket handler. Every time a client connects, we
|
| 84 |
+
register a new listener on the global event bus, but when the client
|
| 85 |
+
disconnects, the cleanup function only removes the WebSocket connection
|
| 86 |
+
from the pool β it doesn't unregister the event listener. Over time,
|
| 87 |
+
these orphaned listeners accumulate and each one holds a reference to
|
| 88 |
+
the connection's closure, which in turn holds the entire request context.
|
| 89 |
+
The fix is straightforward: store the listener reference at connection
|
| 90 |
+
time and explicitly remove it in the disconnect handler.
|
| 91 |
+
|
| 92 |
+
COMPRESSED (59 words, 60% kept):
|
| 93 |
+
investigating memory leak, traced event listener registration WebSocket
|
| 94 |
+
handler. Every time client connects, register new listener global event
|
| 95 |
+
bus, client disconnects, cleanup function only removes WebSocket
|
| 96 |
+
connection pool β doesn't unregister event listener. Over time, orphaned
|
| 97 |
+
listeners accumulate each one holds reference connection's closure, holds
|
| 98 |
+
entire request context. fix straightforward: store listener reference
|
| 99 |
+
connection time explicitly remove disconnect handler.
|
| 100 |
+
```
|
| 101 |
|
| 102 |
+
An LLM can fully understand and act on the compressed version.
|
| 103 |
|
| 104 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
```python
|
| 107 |
+
from kompress.inference.pytorch_runner import KompressRunner
|
| 108 |
|
| 109 |
+
# Auto-downloads from HuggingFace on first use
|
| 110 |
+
runner = KompressRunner()
|
| 111 |
|
| 112 |
+
result = runner.compress("Your long text here...")
|
| 113 |
+
print(result.compressed) # Compressed text
|
| 114 |
+
print(result.compression_ratio) # e.g., 0.62
|
| 115 |
+
print(result.tokens_saved) # Number of tokens saved
|
| 116 |
```
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
### With Headroom (LLM Proxy)
|
| 119 |
+
|
| 120 |
+
```bash
|
| 121 |
+
pip install headroom-ai
|
| 122 |
```
|
| 123 |
|
| 124 |
+
Kompress is built into [Headroom](https://github.com/headroom-ai/headroom) as the default text compressor. It auto-downloads and runs on every API request that passes through the proxy.
|
| 125 |
|
| 126 |
+
## Training
|
| 127 |
|
| 128 |
+
### Architecture
|
| 129 |
+
- **Base**: `answerdotai/ModernBERT-base` (149M params, 8192 token context)
|
| 130 |
+
- **Token head**: Linear(768, 2) β binary keep/discard classifier
|
| 131 |
+
- **Span head**: Conv1d(768β256, k=5) β GELU β Conv1d(256β1, k=3) β Sigmoid
|
| 132 |
+
- **Total**: 150M params
|
| 133 |
|
| 134 |
+
### Data
|
| 135 |
+
215K extractive compression labels from 8 diverse datasets, labeled by Claude Sonnet 4.6:
|
| 136 |
|
| 137 |
+
| Dataset | Count | Type |
|
| 138 |
+
|---------|-------|------|
|
| 139 |
+
| LMSYS-Chat-1M | 57K | LLM conversations |
|
| 140 |
+
| CNN/DailyMail | 50K | News articles |
|
| 141 |
+
| WikiHow | 50K | How-to guides |
|
| 142 |
+
| MeetingBank | 50K | Meeting transcripts |
|
| 143 |
+
| XSum | 47K | News articles |
|
| 144 |
+
| GovReport | 25K | Government reports |
|
| 145 |
+
| ArXiv | 25K | Academic papers |
|
| 146 |
+
| SAMSum | 14K | Dialogues |
|
| 147 |
|
| 148 |
+
### Labeling Approach
|
| 149 |
|
| 150 |
+
Key insight: the labels must be **strictly extractive** β a subset of original words in original order. Previous versions failed because the labeling LLM rephrased text, causing alignment failures (5-12% keep ratio instead of the intended 40-60%).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
The fix: prompt Claude to "select words like highlighting with a marker" rather than "compress this text." This ensures every word in the compressed output exists in the original, and the greedy alignment recovers 95%+ of the intended labels.
|
| 153 |
|
| 154 |
+
### Training Details
|
| 155 |
+
- 3 epochs, batch size 32, learning rate 2e-5
|
| 156 |
+
- BF16 mixed precision on NVIDIA H100
|
| 157 |
+
- HuggingFace Trainer with warmup + cosine schedule
|
| 158 |
+
- ~3 hours training time
|
| 159 |
|
| 160 |
+
## Comparison with LLMLingua-2
|
| 161 |
|
| 162 |
+
| | Kompress | LLMLingua-2 |
|
| 163 |
+
|---|---|---|
|
| 164 |
+
| Architecture | ModernBERT (2024) | mBERT (2018) |
|
| 165 |
+
| Max context | 8,192 tokens | 512 tokens |
|
| 166 |
+
| Training data | 215K from 8 datasets | 41K from MeetingBank |
|
| 167 |
+
| Labeling model | Claude Sonnet 4.6 | GPT-4 |
|
| 168 |
+
| Compression style | Content-adaptive | Fixed ratio |
|
| 169 |
+
| Quality | **6.9/10** | 6.2/10 |
|
| 170 |
+
| Latency | **49ms** | 113ms |
|
| 171 |
|
| 172 |
+
## Limitations
|
| 173 |
|
| 174 |
+
- English only (ModernBERT is English-focused)
|
| 175 |
+
- Best on natural language text; structured data (JSON, code, logs) should use specialized compressors
|
| 176 |
+
- Compression ratio varies by content (60-80% kept for dense text, 40-60% for verbose text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
## License
|
| 179 |
|
| 180 |
+
Apache 2.0
|
|
|
|
|
|
|
|
|