Extractive prompt compressor for LLM proxies. Predicts a keep/drop label per
token; the surviving tokens form a compressed version of the input that
preserves meaning while reducing token count.
Based on ModernBERT-base (149M params) with a LoRA adapter (3.4M trainable
params, 2.2%) plus a custom dual head (token classifier + 1-D span conv).
Trained on 126,617 accepted Pipeline A+B labels (compressor + faithfulness
judge) across 17 domains: narrative, dialog, code, agent traces, healthcare,
finance, government, scientific, web, summary, and tool-calling.
Quick start
python
1import torch
2from transformers import AutoTokenizer
34# Option A: load the merged checkpoint (no LoRA needed)5state = torch.load("merged.pt", map_location="cpu")67# Option B: load via the kompress package8from kompress.model.architecture import HeadroomCompressorV2
9from kompress.model.config import V2_BASE
10import json
1112withopen("config.json")as f:13 cfg_dict = json.load(f)14cfg = V2_BASE # or rebuild from cfg_dict15model = HeadroomCompressorV2(cfg)16model.load_state_dict(torch.load("merged.pt", map_location="cpu"), strict=False)17model.eval().cuda()1819tokenizer = AutoTokenizer.from_pretrained("chopratejas/kompress-v2-base")2021# Compress22text ="The quick brown fox jumps over the lazy dog."23enc = tokenizer(text, return_tensors="pt").to("cuda")24with torch.no_grad():25 out = model(**enc)26scores = out["final_scores"][0]# P(keep) per subword27keep =(scores >=0.5)28kept_tokens = enc["input_ids"][0][keep]29print(tokenizer.decode(kept_tokens, skip_special_tokens=True))
Threshold tuning
The model emits final_scores ∈ [0, 1] per subword. Adjust the threshold to
trade compression aggressiveness for must-keep recall.
Threshold
keep_rate
must_keep_recall
F1
best for
0.30
0.917 (8% drop)
0.994
0.904
Conservative
0.40
0.867 (13% drop)
0.987
0.913
Safe
0.50 (default)
0.815 (18% drop)
0.974
0.918
Balanced
0.60
0.765 (23% drop)
0.950
0.915
Aggressive
0.70
0.705 (30% drop)
0.908
0.898
Very aggressive
Evaluated on the held-out test split (n=7,037 examples, stratified by domain).
Training data
126,617 labeled examples after min_drop_ratio=0.05 filtering and
same-conversation packing.