✂️ LEAN-base
LEAN-base is a lightweight extractive context compressor for retrieval-augmented generation, from the paper LEAN: Lightweight Evidence Extraction for Advanced Context Compression through Goal-aligned Training. With 0.1B parameters, it compresses top-20 retrieved passages in 20 ms per query and reaches 0.968 CES, the best quality–compression–latency balance among eight compressors including 7B LLM-based ones.
Key Characteristics
- Extractive, sentence-level: keeps or drops whole sentences of the retrieved passages, so the compressed context is a subset of the original text.
- One encoder pass per passage: the question and every sentence of a passage are encoded together, and all keep/drop decisions come from that single forward pass.
- Trained on the reader's answers: after a supervised warm-up on HotpotQA supporting facts, the policy is optimized with RLOO against a frozen Llama-3.1-8B-Instruct reader, with the reward
EM + F1 - F1^2 * (kept sentences / all sentences). - 149M parameters: a ModernBERT-base encoder with 8-head attention pooling and a keep/drop head; up to 512 tokens per (question, passage) input.
Usage
The model class lives in the LEAN repository, not in transformers. Run the snippet from the repository root:
git clone https://github.com/dltmddbs100/LEAN.git && cd LEAN
pip install torch transformers huggingface_hub
import torch
from huggingface_hub import snapshot_download
from transformers import AutoTokenizer
from src.models.compressor import SentenceCompressor
from src.sft.dataset import tokenize_passage
path = snapshot_download("nlpai-lab/LEAN-base")
tokenizer = AutoTokenizer.from_pretrained(path)
model = SentenceCompressor.from_checkpoint(path).eval()
query = "Who wrote the novel Nineteen Eighty-Four?"
# Retrieved passages, each split into sentences, with the title folded into the first one
passages = [
["Nineteen Eighty-Four\nNineteen Eighty-Four is a dystopian novel by English writer George Orwell.",
"It was published on 8 June 1949 by Secker & Warburg.",
"The story takes place in an imagined future."],
["Animal Farm\nAnimal Farm is a satirical allegorical novella by George Orwell.",
"It was first published in England on 17 August 1945."],
]
kept = []
for sentences in passages:
enc = tokenize_passage(tokenizer, query, sentences, max_seq_len=512)
with torch.no_grad():
logits = model(enc["input_ids"][None], enc["attention_mask"][None],
enc["sentence_ids"][None], len(sentences))
keep = logits[0].argmax(-1).tolist() # 1 = keep, 0 = drop (greedy, as in the paper)
kept += [s for s, k in zip(sentences, keep) if k == 1]
# Kept sentences in their original order; give this to the reader with the question
compressed_context = " ".join(kept)
print(compressed_context)
# Nineteen Eighty-Four
# Nineteen Eighty-Four is a dystopian novel by English writer George Orwell.
Any sentence splitter works; the training data was split with spaCy en_core_web_sm, with each title folded into its passage's first sentence as "{title}\n{sentence}". For throughput, load the model with SentenceCompressor.from_checkpoint(path, torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2") on a GPU and batch passages.
Evaluation
LEAN-base is compared with seven compressors on NQ, TriviaQA, HotpotQA, 2WikiMultihopQA and MuSiQue. QCE is the harmonic mean of answer-quality retention and compression rate; CES adds compression latency as a third term. Both are macro-averaged over the five benchmarks, and higher is better. Latency is the compressor's wall-clock time per query.
| Model | Params | Latency (ms) | QCE (EM) | QCE (F1) | CES (EM) | CES (F1) |
|---|---|---|---|---|---|---|
| Top-5 | ||||||
| CompAct | 7B | 3,106 | 0.939 | 0.940 | 0.481 | 0.481 |
| Refiner | 7B | 3,698 | 0.910 | 0.918 | 0.447 | 0.448 |
| LongLLMLingua | 7B | 3,181 | 0.603 | 0.600 | 0.400 | 0.399 |
| EXIT | 2B | 434 | 0.856 | 0.858 | 0.795 | 0.796 |
| RECOMP-Abs | 0.8B | 761 | 0.924 | 0.916 | 0.768 | 0.764 |
| Provence | 0.4B | 53 | 0.840 | 0.846 | 0.873 | 0.878 |
| RECOMP-Ext | 0.2B | 25 | 0.893 | 0.896 | 0.918 | 0.921 |
| nlpai-lab/LEAN-base | 0.1B | 5 | 0.916 | 0.923 | 0.941 | 0.946 |
| Top-20 | ||||||
| CompAct | 7B | 9,746 | 0.951 | 0.952 | 0.241 | 0.241 |
| Refiner | 7B | 16,200 | 0.901 | 0.907 | 0.162 | 0.163 |
| LongLLMLingua | 7B | 13,367 | 0.706 | 0.696 | 0.174 | 0.174 |
| EXIT | 2B | 1,758 | 0.894 | 0.900 | 0.600 | 0.602 |
| RECOMP-Abs | 0.8B | 799 | 0.927 | 0.931 | 0.763 | 0.764 |
| Provence | 0.4B | 213 | 0.880 | 0.884 | 0.860 | 0.863 |
| RECOMP-Ext | 0.2B | 101 | 0.862 | 0.887 | 0.875 | 0.893 |
| nlpai-lab/LEAN-base | 0.1B | 20 | 0.962 | 0.961 | 0.968 | 0.967 |
On 2WikiMultihopQA with a Llama-3.3-70B-Instruct reader (figure above), LEAN-base's EM rises from 27.6 to 28.5 as the retrieval depth grows from top-5 to top-20, while its compression rate stays among the highest and its latency the lowest.
License
LEAN-base is released under the MIT License. The encoder is initialized from ModernBERT-base (Apache 2.0).
Citation
@inproceedings{lean2027,
title = {LEAN: Lightweight Evidence Extraction for Advanced Context Compression through Goal-aligned Training},
author = {TBA},
booktitle = {Proceedings of the AAAI Conference on Artificial Intelligence},
year = {2027},
}
- Downloads last month
- -
Model tree for nlpai-lab/LEAN-base
Base model
answerdotai/ModernBERT-base