Supreeth commited on
Commit
abd59df
Β·
verified Β·
1 Parent(s): 11c6f0f

Enrich model card with examples and training details

Browse files
Files changed (1) hide show
  1. README.md +133 -56
README.md CHANGED
@@ -16,82 +16,144 @@ library_name: transformers
16
  pipeline_tag: text-generation
17
  ---
18
 
19
- # SearchLM NL2BM25 β€” GRPO v2 Shaped Reward (Qwen2.5-3B-Instruct)
20
 
21
- The best-performing SearchLM checkpoint. Trained via GRPO with a shaped reward
22
- that eliminates the keyword-bag gaming observed in [GRPO v1](Supreeth/searchlm-nl2bm25-grpo).
23
 
24
- See the [SearchLM collection](https://huggingface.co/collections/Supreeth/searchlm) for all checkpoints
25
- and the [v2 analysis report](https://github.com/SupreethRao99/searchLM/blob/main/REWARD_HACKING_REPORT_V2.md)
26
- for full benchmark results and behavioral analysis.
 
 
 
 
27
 
28
  ## What it does
29
 
30
- Given a natural language query, the model reasons step-by-step about key concepts,
31
- synonyms, and boolean structure, then emits a Tantivy boolean search query:
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ```
34
- Input: Do Cholesterol Statin Drugs Cause Breast Cancer?
35
 
36
- Output:
 
37
  <reasoning>
38
- Key concepts: (1) cholesterol-lowering statin drugs β€” synonyms: statin, HMG-CoA reductase
39
- inhibitor, simvastatin, atorvastatin; (2) causal relationship β€” cause, risk, association,
40
- induce; (3) breast cancer β€” "breast cancer", "breast carcinoma", "breast neoplasm".
41
- Connect with AND; expand synonyms with OR.
42
  </reasoning>
43
- <query>(statin OR "HMG-CoA reductase inhibitor" OR simvastatin OR atorvastatin) AND
44
- (cause OR risk OR association OR induce) AND ("breast cancer" OR "breast carcinoma")</query>
45
  ```
46
 
 
 
 
 
 
47
  ## How v2 eliminated reward hacking
48
 
49
- The v1 reward (`0.6 Γ— NDCG@10 + 0.4 Γ— MRR`) was gameable with keyword bags on small corpora.
50
- v2 uses a shaped reward with three anti-gaming mechanisms:
 
51
 
 
 
 
 
 
 
 
52
  ```
53
- base = 0.6 Γ— max(0, NDCG@10 βˆ’ keyword_baseline) + 0.4 Γ— MRR
54
- shaped = complexity_mult Γ— base + 0.15 Γ— min(reasoning_tokens / 100, 1.0)
55
- reward = 0.0 if len(query.split()) < 3 else shaped
56
 
57
- where:
58
- keyword_baseline = NDCG@10 of naive noun-extraction (precomputed per query)
59
- complexity_mult = 1.0 with boolean operators, 0.5 without
60
- ```
 
 
61
 
62
- 1. **Keyword baseline delta** β€” must beat noun-extraction to earn NDCG credit
63
- 2. **Hard length gate** β€” queries < 3 tokens β†’ reward = 0.0
64
- 3. **Reasoning depth bonus** β€” up to +0.15 for substantive reasoning blocks
65
 
66
- ## Benchmark (test split, NDCG@10)
 
 
 
 
 
 
67
 
68
- | Dataset | Base | SFT v1 | GRPO v1 | SFT v2 | **GRPO v2** |
69
- |---------|------|--------|--------|--------|------------|
70
- | NFCorpus | 0.455 | 0.441 | 0.556 | 0.466 | **0.577** |
71
- | SciFact | 0.386 | 0.273 | 0.608 | 0.358 | **0.657** |
72
 
73
- ## Behavioral comparison vs GRPO v1
74
 
75
- | Dimension | GRPO v1 | GRPO v2 |
76
  |-----------|---------|---------|
77
- | Mean completion length | 6 tokens | **147 tokens** |
78
- | Boolean operator usage | 0% | ~35% |
79
- | `frac_reward_zero_std` (early training) | 90–96% | **0%** |
80
- | Reasoning block | empty | substantive |
 
 
 
 
 
 
 
 
81
 
82
  ## Training Details
83
 
84
  | Setting | Value |
85
  |---------|-------|
86
  | Base model | [searchlm-nl2bm25-sft-v2](Supreeth/searchlm-nl2bm25-sft-v2) |
87
- | Method | GRPO (TRL + vLLM colocate) |
88
- | Reward | Shaped (baseline delta + complexity mult + reasoning bonus) |
89
- | Training datasets | NFCorpus + SciFact + FiQA (3K queries, 57K docs) |
 
90
  | Epochs | 1 |
91
- | `num_generations` | 8 |
92
- | Steps | 2,879 |
93
- | Hardware | NVIDIA H100 80 GB (~3h 3m) |
 
 
 
 
 
 
94
  | Final mean reward | ~0.29 |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  ## Usage
97
 
@@ -105,7 +167,8 @@ model = AutoModelForCausalLM.from_pretrained(
105
  )
106
  tokenizer = AutoTokenizer.from_pretrained("Supreeth/searchlm-nl2bm25-grpo-v2")
107
 
108
- SYSTEM_PROMPT = """You are an expert information retrieval specialist. Convert the natural language query into a Tantivy boolean search query.
 
109
 
110
  Output format (strictly follow this):
111
  <reasoning>
@@ -124,18 +187,32 @@ outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sampl
124
  print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
125
  ```
126
 
 
 
127
  ## Tantivy Boolean Syntax
128
 
129
- | Construct | Syntax |
130
- |-----------|--------|
131
- | Single term | `cancer` |
132
- | Exact phrase | `"bone density"` |
133
- | AND | `vitamin AND calcium` |
134
- | OR | `cancer OR tumor OR malignancy` |
135
- | NOT | `NOT review` |
136
- | Grouping | `(cat OR feline) AND behavior` |
137
- | Field scope | `title:"machine learning"` |
138
- | Boost | `cancer^2 OR tumor` |
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  ## Citation
141
 
 
16
  pipeline_tag: text-generation
17
  ---
18
 
19
+ # SearchLM NL2BM25 β€” GRPO v2 Shaped Reward βœ… (Qwen2.5-3B-Instruct)
20
 
21
+ **Part of the [SearchLM collection](https://huggingface.co/collections/Supreeth/searchlm) Β· [GitHub](https://github.com/SupreethRao99/searchLM)**
 
22
 
23
+ The best-performing SearchLM checkpoint. Trained via GRPO with a shaped reward that
24
+ eliminated the specification gaming found in [GRPO v1](Supreeth/searchlm-nl2bm25-grpo) while simultaneously
25
+ improving retrieval quality. Achieves **NDCG@10 = 0.577** on NFCorpus and **0.657** on SciFact.
26
+
27
+ > **Pipeline position:** `base β†’ SFT v1 β†’ GRPO v1 (⚠️) β†’ SFT v2 β†’ `**`GRPO v2 βœ…`**
28
+
29
+ ---
30
 
31
  ## What it does
32
 
33
+ The model reasons step-by-step about key concepts, synonym expansion, and boolean structure,
34
+ then emits a Tantivy-compatible boolean search query:
35
 
36
+ **Input:** `Do Cholesterol Statin Drugs Cause Breast Cancer?`
37
+
38
+ **Output:**
39
+ ```
40
+ <reasoning>
41
+ Key concepts:
42
+ 1. Statin drugs β€” synonyms: statin, "HMG-CoA reductase inhibitor", simvastatin,
43
+ atorvastatin, lovastatin, pravastatin
44
+ 2. Causal relationship β€” cause, risk, association, induce, "increase risk"
45
+ 3. Breast cancer β€” "breast cancer", "breast carcinoma", "breast neoplasm"
46
+
47
+ Strategy: AND the three concept groups; use OR to expand synonyms within each.
48
+ Phrase-quote multi-word terms; keep AND chains short to avoid zero-result queries.
49
+ </reasoning>
50
+ <query>(statin OR "HMG-CoA reductase inhibitor" OR simvastatin OR atorvastatin OR lovastatin)
51
+ AND (cause OR risk OR association OR induce)
52
+ AND ("breast cancer" OR "breast carcinoma" OR "breast neoplasm")</query>
53
  ```
 
54
 
55
+ Compare to [GRPO v1](Supreeth/searchlm-nl2bm25-grpo)'s output for the same query:
56
+ ```
57
  <reasoning>
 
 
 
 
58
  </reasoning>
59
+ <query>Cholesterol Statin Breast Cancer</query>
 
60
  ```
61
 
62
+ GRPO v2 generates 147-token completions with substantive reasoning; GRPO v1 generated 5-token
63
+ keyword bags with empty reasoning blocks.
64
+
65
+ ---
66
+
67
  ## How v2 eliminated reward hacking
68
 
69
+ The v1 reward (`0.6 Γ— NDCG@10 + 0.4 Γ— MRR`) was gameable with keyword bags on small corpora
70
+ because BM25 recall on 3–5K doc indexes is high for distinctive nouns. Three mechanisms
71
+ closed this gap in v2:
72
 
73
+ ```python
74
+ # v2 reward function
75
+ base = 0.6 * max(0, ndcg_at_10 - keyword_baseline_ndcg) # must beat noun-extraction
76
+ + 0.4 * mrr
77
+ shaped = complexity_mult * base # 1.0 with boolean ops, 0.5 without
78
+ + 0.15 * min(reasoning_tokens / 100, 1.0) # up to +0.15 reasoning bonus
79
+ reward = 0.0 if len(query.split()) < 3 else shaped # hard gate: β‰₯3 tokens required
80
  ```
 
 
 
81
 
82
+ | Mechanism | Effect |
83
+ |-----------|--------|
84
+ | Keyword baseline delta | Model earns zero NDCG credit for matching naive noun-extraction |
85
+ | Hard length gate | Single/double-word queries unconditionally return 0.0 |
86
+ | Reasoning depth bonus | Up to +0.15 reward for β‰₯100-token reasoning blocks |
87
+ | Complexity multiplier | Queries without boolean operators earn half credit |
88
 
89
+ ---
90
+
91
+ ## All SearchLM checkpoints
92
 
93
+ | Model | NFCorpus NDCG@10 | SciFact NDCG@10 | Mean tokens | Boolean ops |
94
+ |-------|-----------------|----------------|-------------|-------------|
95
+ | base (Qwen2.5-3B-Instruct) | 0.455 | 0.386 | 120 | ~20% |
96
+ | [SFT v1](https://huggingface.co/Supreeth/searchlm-nl2bm25-sft) | 0.441 | 0.273 | 95 | ~80% |
97
+ | [GRPO v1](https://huggingface.co/Supreeth/searchlm-nl2bm25-grpo) ⚠️ | 0.556 | 0.608 | **5–7** | **0%** |
98
+ | [SFT v2](https://huggingface.co/Supreeth/searchlm-nl2bm25-sft-v2) | 0.466 | 0.358 | 109 | ~65% |
99
+ | [**GRPO v2**](https://huggingface.co/Supreeth/searchlm-nl2bm25-grpo-v2) βœ… | **0.577** | **0.657** | 147 | ~35% |
100
 
101
+ Evaluated on BEIR test splits (NFCorpus: 323 queries, SciFact: 300 queries).
102
+
103
+ ---
 
104
 
105
+ ## Behavioral comparison (GRPO v1 vs GRPO v2)
106
 
107
+ | Dimension | [GRPO v1](Supreeth/searchlm-nl2bm25-grpo) ⚠️ | **GRPO v2** βœ… |
108
  |-----------|---------|---------|
109
+ | NFCorpus NDCG@10 | 0.556 | **0.577** (+0.021) |
110
+ | SciFact NDCG@10 | 0.608 | **0.657** (+0.049) |
111
+ | Mean completion length | **5–7 tokens** | 147 tokens |
112
+ | Boolean operator usage | **0%** | ~35% |
113
+ | Phrase usage | **0%** | ~25% |
114
+ | `frac_reward_zero_std` (step 1) | **90–96%** | 0.0% |
115
+ | `frac_reward_zero_std` (final) | **90–96%** | ~61% |
116
+ | Reasoning block | **empty** | substantive |
117
+
118
+ The shaped reward did not sacrifice performance to eliminate gaming β€” it improved both.
119
+
120
+ ---
121
 
122
  ## Training Details
123
 
124
  | Setting | Value |
125
  |---------|-------|
126
  | Base model | [searchlm-nl2bm25-sft-v2](Supreeth/searchlm-nl2bm25-sft-v2) |
127
+ | Method | GRPO (TRL GRPOTrainer + vLLM colocate, single H100) |
128
+ | Reward | Shaped: `complexity_mult Γ— (0.6 Γ— Ξ”NDCG + 0.4 Γ— MRR) + 0.15 Γ— reasoning_depth` |
129
+ | Training datasets | NFCorpus + SciFact + FiQA-2018 (3K queries, 57,638 docs) |
130
+ | `num_generations` | 8 (was 2 in v1) |
131
  | Epochs | 1 |
132
+ | Steps | 2,879 (~3.3s/step) |
133
+ | Batch size | 2 (+ 8 grad accum = effective 16) |
134
+ | Learning rate | 1e-6 |
135
+ | vLLM GPU utilisation | 0.30 (24 GB KV cache) |
136
+ | Max new tokens | 1,024 |
137
+ | Gradient checkpointing | yes |
138
+ | Hardware | NVIDIA H100 80 GB |
139
+ | Training time | ~3h 3m |
140
+ | Final train loss | 0.0012 |
141
  | Final mean reward | ~0.29 |
142
+ | W&B run | `supreethrao/searchlm/runs/9x1tg52j` |
143
+
144
+ ### Why these hyperparameters
145
+
146
+ **`num_generations=8`**: v1 used 2, leading to 90-96% of groups having zero within-group
147
+ reward variance (no gradient signal). With 8 completions, variance emerged from step 1.
148
+
149
+ **`vllm_gpu_memory_utilization=0.30`**: On H100 80GB, Adam fp32 optimizer states for a 3B
150
+ model require ~24 GB. At 0.45 utilisation, vLLM reserved 36 GB and Adam states OOM'd. 0.30
151
+ leaves 56 GB for the training stack.
152
+
153
+ **`torch_compile=False`**: Compiled backward pass materialised fp32 FFN intermediate buffers
154
+ (~90 MB each) that eager + gradient checkpointing avoids, causing OOM at batch_size=4.
155
+
156
+ ---
157
 
158
  ## Usage
159
 
 
167
  )
168
  tokenizer = AutoTokenizer.from_pretrained("Supreeth/searchlm-nl2bm25-grpo-v2")
169
 
170
+ SYSTEM_PROMPT = """You are an expert information retrieval specialist. Convert the \
171
+ natural language query into a Tantivy boolean search query.
172
 
173
  Output format (strictly follow this):
174
  <reasoning>
 
187
  print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
188
  ```
189
 
190
+ ---
191
+
192
  ## Tantivy Boolean Syntax
193
 
194
+ [Tantivy](https://github.com/quickwit-oss/tantivy) is a full-text search engine library.
195
+ The model targets its query language:
196
+
197
+ | Construct | Syntax | Example |
198
+ |-----------|--------|---------|
199
+ | Single term | `word` | `cancer` |
200
+ | Exact phrase | `"phrase"` | `"bone density"` |
201
+ | AND | `A AND B` | `vitamin AND calcium` |
202
+ | OR | `A OR B` | `cancer OR tumor OR malignancy` |
203
+ | NOT | `NOT A` | `NOT review` |
204
+ | Grouping | `(A OR B)` | `(cat OR feline) AND behavior` |
205
+ | Field scope | `field:term` | `title:"machine learning"` |
206
+ | Boost | `term^N` | `cancer^2 OR tumor` |
207
+
208
+ ---
209
+
210
+ ## Related resources
211
+
212
+ - **Code:** [SupreethRao99/searchLM](https://github.com/SupreethRao99/searchLM)
213
+ - **Analysis:** [Full five-checkpoint comparison report](https://github.com/SupreethRao99/searchLM/blob/main/REWARD_HACKING_REPORT_V2.md)
214
+ - **Dataset:** [Supreeth/nl2bm25-sft](https://huggingface.co/datasets/Supreeth/nl2bm25-sft)
215
+ - **Collection:** [SearchLM collection](https://huggingface.co/collections/Supreeth/searchlm)
216
 
217
  ## Citation
218