Question Answering
Safetensors
English
modernbert
context-compression
extractive-compression
rag
File size: 10,891 Bytes
ac44320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4155bc
f6208f8
ac44320
 
 
 
f4155bc
ac44320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c31e1b
 
 
 
 
 
 
ac44320
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
138
139
---
tags:
- context-compression
- extractive-compression
- rag
- question-answering
language:
- en
base_model: answerdotai/ModernBERT-base
datasets:
- hotpotqa/hotpot_qa
- google-research-datasets/natural_questions
license: mit
---

[![GitHub](https://img.shields.io/badge/GitHub-LEAN-black.svg?logo=github)](https://github.com/dltmddbs100/LEAN)
[![arXiv](https://img.shields.io/badge/arXiv-2612.03679-B31B1B.svg)](https://arxiv.org/abs/2612.03679)
[![Conference](https://img.shields.io/badge/%F0%9F%87%A8%F0%9F%87%A6%20AAAI_2027-grey.svg?style=flat)](https://aaai.org/conference/aaai/aaai-27/)


# 鉁傦笍 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*](https://arxiv.org/abs/2612.03679). With 0.1B parameters, it compresses top-20 retrieved passages in **20 ms** per query and reaches **0.968** CES, the best quality鈥揷ompression鈥搇atency balance among eight compressors including 7B LLM-based ones.

<p align="center">
  <img src="assets/lean_2wiki_topk.png" width="100%" alt="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">
</p>

## 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](https://huggingface.co/answerdotai/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](https://github.com/dltmddbs100/LEAN), not in `transformers`. Run the snippet from the repository root:

```bash
git clone https://github.com/dltmddbs100/LEAN.git && cd LEAN
pip install torch transformers huggingface_hub
```

```python
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.

<div style="width: fit-content; max-width: 100%; margin: 0 auto;">
  <div style="overflow-x: auto;">
    <table cellpadding="6" style="margin: 0 auto; border-collapse: collapse; color: inherit; text-align: right; font-size: 0.85em; line-height: 1.6; font-variant-numeric: tabular-nums;">
      <thead>
        <tr style="border-bottom: 1px solid rgba(128, 128, 128, 0.35);"><th scope="col" style="text-align: left;">Model</th><th scope="col" style="text-align: left;">Params</th><th scope="col">Latency (ms)</th><th scope="col">QCE (EM)</th><th scope="col">QCE (F1)</th><th scope="col">CES (EM)</th><th scope="col">CES (F1)</th></tr>
      </thead>
      <tbody>
        <tr><th colspan="7" scope="rowgroup" style="padding: 16px 6px 6px; text-align: left; font-size: 0.8em; letter-spacing: 0.08em; text-transform: uppercase;">Top-5</th></tr>
        <tr><td style="text-align: left; white-space: nowrap;">CompAct</td><td style="text-align: left; white-space: nowrap;">7B</td><td>3,106</td><td><strong>0.939</strong></td><td><strong>0.940</strong></td><td>0.481</td><td>0.481</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">Refiner</td><td style="text-align: left; white-space: nowrap;">7B</td><td>3,698</td><td>0.910</td><td>0.918</td><td>0.447</td><td>0.448</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">LongLLMLingua</td><td style="text-align: left; white-space: nowrap;">7B</td><td>3,181</td><td>0.603</td><td>0.600</td><td>0.400</td><td>0.399</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">EXIT</td><td style="text-align: left; white-space: nowrap;">2B</td><td>434</td><td>0.856</td><td>0.858</td><td>0.795</td><td>0.796</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">RECOMP-Abs</td><td style="text-align: left; white-space: nowrap;">0.8B</td><td>761</td><td>0.924</td><td>0.916</td><td>0.768</td><td>0.764</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">Provence</td><td style="text-align: left; white-space: nowrap;">0.4B</td><td>53</td><td>0.840</td><td>0.846</td><td>0.873</td><td>0.878</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">RECOMP-Ext</td><td style="text-align: left; white-space: nowrap;">0.2B</td><td>25</td><td>0.893</td><td>0.896</td><td>0.918</td><td>0.921</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;"><strong><a href="https://huggingface.co/nlpai-lab/LEAN-base" style="color: #c9496b;">nlpai-lab/LEAN-base</a></strong></td><td style="text-align: left; white-space: nowrap;"><span style="color: #c9496b;">0.1B</span></td><td><span style="color: #c9496b;">5</span></td><td><span style="color: #c9496b;">0.916</span></td><td><span style="color: #c9496b;">0.923</span></td><td><strong style="color: #c9496b;">0.941</strong></td><td><strong style="color: #c9496b;">0.946</strong></td></tr>
      </tbody>
      <tbody style="border-top: 1px solid rgba(128, 128, 128, 0.25);">
        <tr><th colspan="7" scope="rowgroup" style="padding: 16px 6px 6px; text-align: left; font-size: 0.8em; letter-spacing: 0.08em; text-transform: uppercase;">Top-20</th></tr>
        <tr><td style="text-align: left; white-space: nowrap;">CompAct</td><td style="text-align: left; white-space: nowrap;">7B</td><td>9,746</td><td>0.951</td><td>0.952</td><td>0.241</td><td>0.241</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">Refiner</td><td style="text-align: left; white-space: nowrap;">7B</td><td>16,200</td><td>0.901</td><td>0.907</td><td>0.162</td><td>0.163</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">LongLLMLingua</td><td style="text-align: left; white-space: nowrap;">7B</td><td>13,367</td><td>0.706</td><td>0.696</td><td>0.174</td><td>0.174</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">EXIT</td><td style="text-align: left; white-space: nowrap;">2B</td><td>1,758</td><td>0.894</td><td>0.900</td><td>0.600</td><td>0.602</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">RECOMP-Abs</td><td style="text-align: left; white-space: nowrap;">0.8B</td><td>799</td><td>0.927</td><td>0.931</td><td>0.763</td><td>0.764</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">Provence</td><td style="text-align: left; white-space: nowrap;">0.4B</td><td>213</td><td>0.880</td><td>0.884</td><td>0.860</td><td>0.863</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;">RECOMP-Ext</td><td style="text-align: left; white-space: nowrap;">0.2B</td><td>101</td><td>0.862</td><td>0.887</td><td>0.875</td><td>0.893</td></tr>
        <tr><td style="text-align: left; white-space: nowrap;"><strong><a href="https://huggingface.co/nlpai-lab/LEAN-base" style="color: #c9496b;">nlpai-lab/LEAN-base</a></strong></td><td style="text-align: left; white-space: nowrap;"><span style="color: #c9496b;">0.1B</span></td><td><span style="color: #c9496b;">20</span></td><td><strong style="color: #c9496b;">0.962</strong></td><td><strong style="color: #c9496b;">0.961</strong></td><td><strong style="color: #c9496b;">0.968</strong></td><td><strong style="color: #c9496b;">0.967</strong></td></tr>
      </tbody>
    </table>
  </div>
</div>

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](https://github.com/dltmddbs100/LEAN/blob/main/LICENSE). The encoder is initialized from [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) (Apache 2.0).

## Citation

```bibtex
@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},
}
```