GitHub arXiv Conference

✂️ 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.

EM, compression rate and compression latency of LEAN-base and seven baseline compressors on 2WikiMultihopQA as the number of retrieved passages grows from 5 to 20

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.

ModelParamsLatency (ms)QCE (EM)QCE (F1)CES (EM)CES (F1)
Top-5
CompAct7B3,1060.9390.9400.4810.481
Refiner7B3,6980.9100.9180.4470.448
LongLLMLingua7B3,1810.6030.6000.4000.399
EXIT2B4340.8560.8580.7950.796
RECOMP-Abs0.8B7610.9240.9160.7680.764
Provence0.4B530.8400.8460.8730.878
RECOMP-Ext0.2B250.8930.8960.9180.921
nlpai-lab/LEAN-base0.1B50.9160.9230.9410.946
Top-20
CompAct7B9,7460.9510.9520.2410.241
Refiner7B16,2000.9010.9070.1620.163
LongLLMLingua7B13,3670.7060.6960.1740.174
EXIT2B1,7580.8940.9000.6000.602
RECOMP-Abs0.8B7990.9270.9310.7630.764
Provence0.4B2130.8800.8840.8600.863
RECOMP-Ext0.2B1010.8620.8870.8750.893
nlpai-lab/LEAN-base0.1B200.9620.9610.9680.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
-
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for nlpai-lab/LEAN-base

Finetuned
(1,646)
this model

Datasets used to train nlpai-lab/LEAN-base