Question Answering
Safetensors
English
modernbert
context-compression
extractive-compression
rag

GitHub arXiv Conference

✂️ LEAN-large

LEAN-large 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. It follows the training recipe of LEAN-base with a ModernBERT-large encoder.

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).
  • 395M parameters: a ModernBERT-large 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-large")
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

The results reported in the paper use LEAN-base; see its model card for the comparison with baseline compressors.

License

LEAN-large is released under the MIT License. The encoder is initialized from ModernBERT-large (Apache 2.0).

Citation

@inproceedings{lean2027,
  title         = {LEAN: Lightweight Evidence Extraction for Advanced Context Compression through Goal-aligned Training},
  author        = {Seungyoon Lee and Seongtae Hong and Sungbin Han and Jungseob Lee and Chanjun Park and Heuiseok Lim},
  booktitle     = {Proceedings of the AAAI Conference on Artificial Intelligence},
  year          = {2027},
  eprint        = {2612.03679},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CL},
}
Downloads last month
49
Safetensors
Model size
0.4B 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-large

Finetuned
(445)
this model

Datasets used to train nlpai-lab/LEAN-large

Paper for nlpai-lab/LEAN-large