Text Generation
Transformers
Safetensors
English
qwen2
information-retrieval
boolean-search
NL2BM25
GRPO
RLVR
tantivy
BEIR
searchlm
conversational
text-generation-inference
Instructions to use Supreeth/searchlm-nl2bm25-grpo-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Supreeth/searchlm-nl2bm25-grpo-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Supreeth/searchlm-nl2bm25-grpo-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Supreeth/searchlm-nl2bm25-grpo-v2") model = AutoModelForCausalLM.from_pretrained("Supreeth/searchlm-nl2bm25-grpo-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Supreeth/searchlm-nl2bm25-grpo-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Supreeth/searchlm-nl2bm25-grpo-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Supreeth/searchlm-nl2bm25-grpo-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Supreeth/searchlm-nl2bm25-grpo-v2
- SGLang
How to use Supreeth/searchlm-nl2bm25-grpo-v2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Supreeth/searchlm-nl2bm25-grpo-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Supreeth/searchlm-nl2bm25-grpo-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Supreeth/searchlm-nl2bm25-grpo-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Supreeth/searchlm-nl2bm25-grpo-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Supreeth/searchlm-nl2bm25-grpo-v2 with Docker Model Runner:
docker model run hf.co/Supreeth/searchlm-nl2bm25-grpo-v2
Enrich model card with examples and training details
Browse files
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 |
-
|
| 22 |
-
that eliminates the keyword-bag gaming observed in [GRPO v1](Supreeth/searchlm-nl2bm25-grpo).
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
## What it does
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
```
|
| 34 |
-
Input: Do Cholesterol Statin Drugs Cause Breast Cancer?
|
| 35 |
|
| 36 |
-
|
|
|
|
| 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>
|
| 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 |
-
|
|
|
|
| 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 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
| SciFact | 0.386 | 0.273 | 0.608 | 0.358 | **0.657** |
|
| 72 |
|
| 73 |
-
## Behavioral comparison vs GRPO
|
| 74 |
|
| 75 |
-
| Dimension | GRPO v1 | GRPO v2 |
|
| 76 |
|-----------|---------|---------|
|
| 77 |
-
|
|
| 78 |
-
|
|
| 79 |
-
|
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 (
|
| 89 |
-
| Training datasets | NFCorpus + SciFact + FiQA (3K queries,
|
|
|
|
| 90 |
| Epochs | 1 |
|
| 91 |
-
|
|
| 92 |
-
|
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 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 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
| 133 |
-
|
|
| 134 |
-
|
|
| 135 |
-
|
|
| 136 |
-
|
|
| 137 |
-
|
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|