Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,163 @@
|
|
1 |
-
|
2 |
-
library_name: transformers
|
3 |
-
tags: []
|
4 |
-
---
|
5 |
-
|
6 |
-
# Model Card for Model ID
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
## Model Details
|
13 |
-
|
14 |
-
### Model Description
|
15 |
-
|
16 |
-
<!-- Provide a longer summary of what this model is. -->
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
-
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
-
|
28 |
-
### Model Sources [optional]
|
29 |
-
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
## Uses
|
37 |
-
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
-
### Direct Use
|
41 |
-
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
-
|
76 |
-
## Training Details
|
77 |
-
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
|
|
|
|
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
|
171 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
176 |
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
|
180 |
|
181 |
-
|
182 |
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
|
187 |
-
|
188 |
|
189 |
-
##
|
190 |
|
191 |
-
[
|
|
|
|
|
|
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
|
197 |
-
|
198 |
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Qwen2.5‑3B Search‑R1‑Multiturn (reproduce)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
> **Author · Seungyoun Shin**
|
4 |
+
> 🤗 Model Hub: [https://huggingface.co/Seungyoun/qwen2.5-3b-it\_searchR1-like-multiturn](https://huggingface.co/Seungyoun/qwen2.5-3b-it_searchR1-like-multiturn)
|
5 |
|
6 |
+
A faithful re‑implementation of the *Search‑R1* on **Qwen 2.5‑3B**, trained purely on the Wikipedia‑based Search‑R1 corpus (HotpotQA train split) with GRPO via the open‑source [VERL](https://github.com/volcengine/verl) framework.
|
7 |
|
8 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
## 🚀 Quick start
|
11 |
+
|
12 |
+
|
13 |
+
### Full inference script (Using duck-duck-go)
|
14 |
+
|
15 |
+
Below is the exact script used in our experiments—drop it next to the model weights and run.
|
16 |
+
|
17 |
+
```python
|
18 |
+
#!/usr/bin/env python3
|
19 |
+
"""
|
20 |
+
Minimal **multi‑turn tool‑calling** demo for the Qwen2.5‑3B Search‑R1 model
|
21 |
+
|
22 |
+
Highlights
|
23 |
+
-----------
|
24 |
+
* Presents the `search` function schema via `tools=[…]` so the model emits JSON calls.
|
25 |
+
* Detects `<tool_call>` → parses `{name:"search", arguments:{query_list:[…]}}` and runs DuckDuckGo.
|
26 |
+
* Streams results back in `<tool_response>` until an `<answer>` block appears.
|
27 |
+
"""
|
28 |
+
from __future__ import annotations
|
29 |
+
import json, re, sys
|
30 |
+
from typing import List
|
31 |
+
import torch
|
32 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
33 |
+
from duckduckgo_search import DDGS
|
34 |
+
|
35 |
+
DEFAULT_SYSTEM_CONTENT = "You are a helpful and harmless assistant."
|
36 |
+
DEFAULT_USER_CONTENT_PREFIX = (
|
37 |
+
"Answer the given question. You must conduct reasoning inside <think> and "
|
38 |
+
"</think> first every time you get new information. After reasoning, if you "
|
39 |
+
"find you lack some knowledge, you can call a search engine by <tool_call> "
|
40 |
+
"query </tool_call> and it will return the top searched results between "
|
41 |
+
"<tool_response> and </tool_response>. You can search as many times as your "
|
42 |
+
"want. If you find no further external knowledge needed, you can directly "
|
43 |
+
"provide the answer inside <answer> and </answer>, without detailed "
|
44 |
+
"illustrations. For example, <answer> Beijing </answer>. Question: "
|
45 |
+
)
|
46 |
+
MODEL_NAME = "Seungyoun/qwen2.5-3b-it_searchR1-like-multiturn"
|
47 |
+
MAX_TURNS, MAX_RESPONSE_TOKENS = 4, 512
|
48 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
49 |
+
|
50 |
+
SEARCH_SCHEMA = {
|
51 |
+
"type": "function",
|
52 |
+
"function": {
|
53 |
+
"name": "search",
|
54 |
+
"description": "DuckDuckGo web search",
|
55 |
+
"parameters": {
|
56 |
+
"type": "object",
|
57 |
+
"properties": {
|
58 |
+
"query_list": {
|
59 |
+
"type": "array",
|
60 |
+
"items": {"type": "string"},
|
61 |
+
"description": "Fully‑formed semantic queries."
|
62 |
+
}
|
63 |
+
},
|
64 |
+
"required": ["query_list"],
|
65 |
+
},
|
66 |
+
},
|
67 |
+
}
|
68 |
+
|
69 |
+
def create_prompt(q: str) -> List[dict]:
|
70 |
+
return [
|
71 |
+
{"role": "system", "content": DEFAULT_SYSTEM_CONTENT},
|
72 |
+
{"role": "user", "content": DEFAULT_USER_CONTENT_PREFIX + q},
|
73 |
+
]
|
74 |
+
|
75 |
+
def ddg_search(query: str, k: int = 5) -> str:
|
76 |
+
with DDGS() as ddgs:
|
77 |
+
hits = list(ddgs.text(query, safesearch="moderate", max_results=k))
|
78 |
+
return "\n".join(f"{i+1}. {h['title']} – {h['body']} ({h['href']})" for i,h in enumerate(hits))
|
79 |
+
|
80 |
+
def extract_queries(raw: str) -> List[str]:
|
81 |
+
try:
|
82 |
+
payload = json.loads(raw)
|
83 |
+
if payload.get("name") == "search":
|
84 |
+
return payload.get("arguments", {}).get("query_list", [])
|
85 |
+
except json.JSONDecodeError:
|
86 |
+
pass
|
87 |
+
return [raw]
|
88 |
+
|
89 |
+
def main() -> None:
|
90 |
+
q = sys.argv[1] if len(sys.argv) > 1 else "How is the weather in Seoul?"
|
91 |
+
tok = AutoTokenizer.from_pretrained(MODEL_NAME, padding_side="left")
|
92 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16, device_map="auto")
|
93 |
+
msgs = create_prompt(q)
|
94 |
+
history = tok.apply_chat_template(msgs, tools=[SEARCH_SCHEMA], add_generation_prompt=True, tokenize=False)
|
95 |
+
pattern = re.compile(r"<tool_call>\s*(.*?)\s*</tool_call>", re.S)
|
96 |
+
for turn in range(MAX_TURNS):
|
97 |
+
enc = tok(history, return_tensors="pt").to(DEVICE)
|
98 |
+
out = model.generate(**enc, max_new_tokens=MAX_RESPONSE_TOKENS, temperature=0.7, do_sample=True)
|
99 |
+
new = tok.decode(out[0][enc.input_ids.shape[1]:], skip_special_tokens=True)
|
100 |
+
print(f"\n===== Assistant (turn {turn+1}) =====\n{new}\n")
|
101 |
+
history += new
|
102 |
+
m = pattern.search(new)
|
103 |
+
if not m: break
|
104 |
+
results = "\n---\n".join(ddg_search(q,5) for q in extract_queries(m.group(1)))
|
105 |
+
history += f"<tool_response>\n{results}\n</tool_response>"
|
106 |
+
|
107 |
+
if __name__ == "__main__":
|
108 |
+
main()
|
109 |
+
```
|
110 |
|
111 |
+
---
|
112 |
|
113 |
+
## 🧠 Reasoning style
|
114 |
|
115 |
+
```
|
116 |
+
<think> … chain‑of‑thought … </think>
|
117 |
+
<tool_call>{"name":"search", "arguments":{"query_list":["…"]}}</tool_call>
|
118 |
+
<tool_response>
|
119 |
+
1. web result
|
120 |
+
…
|
121 |
+
</tool_response>
|
122 |
+
<answer> final concise answer </answer>
|
123 |
+
```
|
124 |
|
125 |
+
---
|
126 |
|
127 |
+
## 📊 Evaluation (Pass@1)
|
128 |
|
129 |
+
| Dataset | Original Search‑R1 (Qwen2.5‑3B) | **This work** |
|
130 |
+
| --------- | ------------------------------- | ------------- |
|
131 |
+
| NQ | 0.397 | **0.406** |
|
132 |
+
| TriviaQA | 0.565 | **0.582** |
|
133 |
+
| PopQA | 0.391 | **0.420** |
|
134 |
+
| HotpotQA | 0.331 | **0.338** |
|
135 |
+
| 2Wiki | 0.310 | **0.332** |
|
136 |
+
| Musique | **0.124** | 0.111 |
|
137 |
+
| Bamboogle | 0.232 | **0.296** |
|
138 |
|
|
|
139 |
|
140 |
+
---
|
141 |
|
142 |
+
## 🤝 Acknowledgements
|
143 |
|
144 |
+
* [Qwen LM](https://github.com/QwenLM) for the base model.
|
145 |
+
* [Search‑R1 authors](https://github.com/PeterGriffinJin/Search-R1) for the dataset & baseline.
|
146 |
+
* [Volcengine **VERL**](https://github.com/volcengine/verl) for the GRPO training toolkit.
|
147 |
+
* HuggingFace for the open ecosystem.
|
148 |
|
149 |
+
---
|
150 |
|
151 |
+
## 📄 License & citation
|
152 |
|
153 |
+
Code is released under **MIT**; model weights under the original **Qwen open‑source license**.
|
154 |
|
155 |
+
```bibtex
|
156 |
+
@misc{shin2025qwen25_searchr1_multiturn,
|
157 |
+
author = {Seungyoun Shin},
|
158 |
+
title = {Qwen2.5-3B Search-R1-Multiturn (reproduce)},
|
159 |
+
year = 2025,
|
160 |
+
howpublished = {HuggingFace Model Hub},
|
161 |
+
url = {https://huggingface.co/Seungyoun/qwen2.5-3b-it_searchR1-like-multiturn}
|
162 |
+
}
|
163 |
+
```
|