Update README.md
Browse files
README.md
CHANGED
|
@@ -4,348 +4,73 @@ license: apache-2.0
|
|
| 4 |
license_link: https://huggingface.co/Qwen/Qwen3-32B/blob/main/LICENSE
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
---
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
<a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
|
| 10 |
-
<img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
|
| 11 |
-
</a>
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
- **Superior human preference alignment**, excelling in creative writing, role-playing, multi-turn dialogues, and instruction following, to deliver a more natural, engaging, and immersive conversational experience.
|
| 20 |
-
- **Expertise in agent capabilities**, enabling precise integration with external tools in both thinking and unthinking modes and achieving leading performance among open-source models in complex agent-based tasks.
|
| 21 |
-
- **Support of 100+ languages and dialects** with strong capabilities for **multilingual instruction following** and **translation**.
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
**Qwen3-32B** has the following features:
|
| 26 |
-
- Type: Causal Language Models
|
| 27 |
-
- Training Stage: Pretraining & Post-training
|
| 28 |
-
- Number of Parameters: 32.8B
|
| 29 |
-
- Number of Paramaters (Non-Embedding): 31.2B
|
| 30 |
-
- Number of Layers: 64
|
| 31 |
-
- Number of Attention Heads (GQA): 64 for Q and 8 for KV
|
| 32 |
-
- Context Length: 32,768 natively and [131,072 tokens with YaRN](#processing-long-texts).
|
| 33 |
-
|
| 34 |
-
For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3/), [GitHub](https://github.com/QwenLM/Qwen3), and [Documentation](https://qwen.readthedocs.io/en/latest/).
|
| 35 |
-
|
| 36 |
-
## Quickstart
|
| 37 |
-
|
| 38 |
-
The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
|
| 39 |
-
|
| 40 |
-
With `transformers<4.51.0`, you will encounter the following error:
|
| 41 |
-
```
|
| 42 |
-
KeyError: 'qwen3'
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
The following contains a code snippet illustrating how to use the model generate content based on given inputs.
|
| 46 |
-
```python
|
| 47 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 48 |
-
|
| 49 |
-
model_name = "Qwen/Qwen3-32B"
|
| 50 |
-
|
| 51 |
-
# load the tokenizer and the model
|
| 52 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 53 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 54 |
-
model_name,
|
| 55 |
-
torch_dtype="auto",
|
| 56 |
-
device_map="auto"
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
# prepare the model input
|
| 60 |
-
prompt = "Give me a short introduction to large language model."
|
| 61 |
-
messages = [
|
| 62 |
-
{"role": "user", "content": prompt}
|
| 63 |
-
]
|
| 64 |
-
text = tokenizer.apply_chat_template(
|
| 65 |
-
messages,
|
| 66 |
-
tokenize=False,
|
| 67 |
-
add_generation_prompt=True,
|
| 68 |
-
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
|
| 69 |
-
)
|
| 70 |
-
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 71 |
-
|
| 72 |
-
# conduct text completion
|
| 73 |
-
generated_ids = model.generate(
|
| 74 |
-
**model_inputs,
|
| 75 |
-
max_new_tokens=32768
|
| 76 |
-
)
|
| 77 |
-
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 78 |
-
|
| 79 |
-
# parsing thinking content
|
| 80 |
-
try:
|
| 81 |
-
# rindex finding 151668 (</think>)
|
| 82 |
-
index = len(output_ids) - output_ids[::-1].index(151668)
|
| 83 |
-
except ValueError:
|
| 84 |
-
index = 0
|
| 85 |
-
|
| 86 |
-
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
|
| 87 |
-
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
|
| 88 |
-
|
| 89 |
-
print("thinking content:", thinking_content)
|
| 90 |
-
print("content:", content)
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
|
| 94 |
-
- SGLang:
|
| 95 |
-
```shell
|
| 96 |
-
python -m sglang.launch_server --model-path Qwen/Qwen3-32B --reasoning-parser qwen3
|
| 97 |
-
```
|
| 98 |
-
- vLLM:
|
| 99 |
-
```shell
|
| 100 |
-
vllm serve Qwen/Qwen3-32B --enable-reasoning --reasoning-parser deepseek_r1
|
| 101 |
-
```
|
| 102 |
-
|
| 103 |
-
For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
|
| 104 |
-
|
| 105 |
-
## Switching Between Thinking and Non-Thinking Mode
|
| 106 |
-
|
| 107 |
-
> [!TIP]
|
| 108 |
-
> The `enable_thinking` switch is also available in APIs created by SGLang and vLLM.
|
| 109 |
-
> Please refer to our documentation for [SGLang](https://qwen.readthedocs.io/en/latest/deployment/sglang.html#thinking-non-thinking-modes) and [vLLM](https://qwen.readthedocs.io/en/latest/deployment/vllm.html#thinking-non-thinking-modes) users.
|
| 110 |
-
|
| 111 |
-
### `enable_thinking=True`
|
| 112 |
-
|
| 113 |
-
By default, Qwen3 has thinking capabilities enabled, similar to QwQ-32B. This means the model will use its reasoning abilities to enhance the quality of generated responses. For example, when explicitly setting `enable_thinking=True` or leaving it as the default value in `tokenizer.apply_chat_template`, the model will engage its thinking mode.
|
| 114 |
-
|
| 115 |
-
```python
|
| 116 |
-
text = tokenizer.apply_chat_template(
|
| 117 |
-
messages,
|
| 118 |
-
tokenize=False,
|
| 119 |
-
add_generation_prompt=True,
|
| 120 |
-
enable_thinking=True # True is the default value for enable_thinking
|
| 121 |
-
)
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
In this mode, the model will generate think content wrapped in a `<think>...</think>` block, followed by the final response.
|
| 125 |
-
|
| 126 |
-
> [!NOTE]
|
| 127 |
-
> For thinking mode, use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0` (the default setting in `generation_config.json`). **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
### `enable_thinking=False`
|
| 131 |
-
|
| 132 |
-
We provide a hard switch to strictly disable the model's thinking behavior, aligning its functionality with the previous Qwen2.5-Instruct models. This mode is particularly useful in scenarios where disabling thinking is essential for enhancing efficiency.
|
| 133 |
-
|
| 134 |
-
```python
|
| 135 |
-
text = tokenizer.apply_chat_template(
|
| 136 |
-
messages,
|
| 137 |
-
tokenize=False,
|
| 138 |
-
add_generation_prompt=True,
|
| 139 |
-
enable_thinking=False # Setting enable_thinking=False disables thinking mode
|
| 140 |
-
)
|
| 141 |
-
```
|
| 142 |
-
|
| 143 |
-
In this mode, the model will not generate any think content and will not include a `<think>...</think>` block.
|
| 144 |
-
|
| 145 |
-
> [!NOTE]
|
| 146 |
-
> For non-thinking mode, we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
|
| 147 |
-
|
| 148 |
-
### Advanced Usage: Switching Between Thinking and Non-Thinking Modes via User Input
|
| 149 |
-
|
| 150 |
-
We provide a soft switch mechanism that allows users to dynamically control the model's behavior when `enable_thinking=True`. Specifically, you can add `/think` and `/no_think` to user prompts or system messages to switch the model's thinking mode from turn to turn. The model will follow the most recent instruction in multi-turn conversations.
|
| 151 |
-
|
| 152 |
-
Here is an example of a multi-turn conversation:
|
| 153 |
-
|
| 154 |
-
```python
|
| 155 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 156 |
-
|
| 157 |
-
class QwenChatbot:
|
| 158 |
-
def __init__(self, model_name="Qwen/Qwen3-32B"):
|
| 159 |
-
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 160 |
-
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 161 |
-
self.history = []
|
| 162 |
-
|
| 163 |
-
def generate_response(self, user_input):
|
| 164 |
-
messages = self.history + [{"role": "user", "content": user_input}]
|
| 165 |
-
|
| 166 |
-
text = self.tokenizer.apply_chat_template(
|
| 167 |
-
messages,
|
| 168 |
-
tokenize=False,
|
| 169 |
-
add_generation_prompt=True
|
| 170 |
-
)
|
| 171 |
-
|
| 172 |
-
inputs = self.tokenizer(text, return_tensors="pt")
|
| 173 |
-
response_ids = self.model.generate(**inputs, max_new_tokens=32768)[0][len(inputs.input_ids[0]):].tolist()
|
| 174 |
-
response = self.tokenizer.decode(response_ids, skip_special_tokens=True)
|
| 175 |
-
|
| 176 |
-
# Update history
|
| 177 |
-
self.history.append({"role": "user", "content": user_input})
|
| 178 |
-
self.history.append({"role": "assistant", "content": response})
|
| 179 |
|
| 180 |
-
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
chatbot = QwenChatbot()
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
print(f"User: {user_input_1}")
|
| 189 |
-
response_1 = chatbot.generate_response(user_input_1)
|
| 190 |
-
print(f"Bot: {response_1}")
|
| 191 |
-
print("----------------------")
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
print(f"User: {user_input_2}")
|
| 196 |
-
response_2 = chatbot.generate_response(user_input_2)
|
| 197 |
-
print(f"Bot: {response_2}")
|
| 198 |
-
print("----------------------")
|
| 199 |
|
| 200 |
-
|
| 201 |
-
user_input_3 = "Really? /think"
|
| 202 |
-
print(f"User: {user_input_3}")
|
| 203 |
-
response_3 = chatbot.generate_response(user_input_3)
|
| 204 |
-
print(f"Bot: {response_3}")
|
| 205 |
-
```
|
| 206 |
|
| 207 |
-
>
|
| 208 |
-
|
| 209 |
-
>
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
|
| 212 |
|
| 213 |
-
|
| 214 |
|
| 215 |
-
To define the available tools, you can use the MCP configuration file, use the integrated tool of Qwen-Agent, or integrate other tools by yourself.
|
| 216 |
```python
|
| 217 |
-
from
|
| 218 |
-
|
| 219 |
-
# Define LLM
|
| 220 |
-
llm_cfg = {
|
| 221 |
-
'model': 'Qwen3-32B',
|
| 222 |
-
|
| 223 |
-
# Use the endpoint provided by Alibaba Model Studio:
|
| 224 |
-
# 'model_type': 'qwen_dashscope',
|
| 225 |
-
# 'api_key': os.getenv('DASHSCOPE_API_KEY'),
|
| 226 |
-
|
| 227 |
-
# Use a custom endpoint compatible with OpenAI API:
|
| 228 |
-
'model_server': 'http://localhost:8000/v1', # api_base
|
| 229 |
-
'api_key': 'EMPTY',
|
| 230 |
-
|
| 231 |
-
# Other parameters:
|
| 232 |
-
# 'generate_cfg': {
|
| 233 |
-
# # Add: When the response content is `<think>this is the thought</think>this is the answer;
|
| 234 |
-
# # Do not add: When the response has been separated by reasoning_content and content.
|
| 235 |
-
# 'thought_in_content': True,
|
| 236 |
-
# },
|
| 237 |
-
}
|
| 238 |
|
| 239 |
-
#
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
'time': {
|
| 243 |
-
'command': 'uvx',
|
| 244 |
-
'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
|
| 245 |
-
},
|
| 246 |
-
"fetch": {
|
| 247 |
-
"command": "uvx",
|
| 248 |
-
"args": ["mcp-server-fetch"]
|
| 249 |
-
}
|
| 250 |
-
}
|
| 251 |
-
},
|
| 252 |
-
'code_interpreter', # Built-in tools
|
| 253 |
-
]
|
| 254 |
|
| 255 |
-
|
| 256 |
-
bot = Assistant(llm=llm_cfg, function_list=tools)
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
pass
|
| 262 |
-
print(responses)
|
| 263 |
```
|
| 264 |
|
| 265 |
-
## Processing Long Texts
|
| 266 |
-
|
| 267 |
-
Qwen3 natively supports context lengths of up to 32,768 tokens. For conversations where the total length (including both input and output) significantly exceeds this limit, we recommend using RoPE scaling techniques to handle long texts effectively. We have validated the model's performance on context lengths of up to 131,072 tokens using the [YaRN](https://arxiv.org/abs/2309.00071) method.
|
| 268 |
-
|
| 269 |
-
YaRN is currently supported by several inference frameworks, e.g., `transformers` and `llama.cpp` for local use, `vllm` and `sglang` for deployment. In general, there are two approaches to enabling YaRN for supported frameworks:
|
| 270 |
-
|
| 271 |
-
- Modifying the model files:
|
| 272 |
-
In the `config.json` file, add the `rope_scaling` fields:
|
| 273 |
-
```json
|
| 274 |
-
{
|
| 275 |
-
...,
|
| 276 |
-
"rope_scaling": {
|
| 277 |
-
"rope_type": "yarn",
|
| 278 |
-
"factor": 4.0,
|
| 279 |
-
"original_max_position_embeddings": 32768
|
| 280 |
-
}
|
| 281 |
-
}
|
| 282 |
-
```
|
| 283 |
-
For `llama.cpp`, you need to regenerate the GGUF file after the modification.
|
| 284 |
-
|
| 285 |
-
- Passing command line arguments:
|
| 286 |
-
|
| 287 |
-
For `vllm`, you can use
|
| 288 |
-
```shell
|
| 289 |
-
vllm serve ... --rope-scaling '{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}' --max-model-len 131072
|
| 290 |
-
```
|
| 291 |
-
|
| 292 |
-
For `sglang`, you can use
|
| 293 |
-
```shell
|
| 294 |
-
python -m sglang.launch_server ... --json-model-override-args '{"rope_scaling":{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}}'
|
| 295 |
-
```
|
| 296 |
-
|
| 297 |
-
For `llama-server` from `llama.cpp`, you can use
|
| 298 |
-
```shell
|
| 299 |
-
llama-server ... --rope-scaling yarn --rope-scale 4 --yarn-orig-ctx 32768
|
| 300 |
-
```
|
| 301 |
-
|
| 302 |
-
> [!IMPORTANT]
|
| 303 |
-
> If you encounter the following warning
|
| 304 |
-
> ```
|
| 305 |
-
> Unrecognized keys in `rope_scaling` for 'rope_type'='yarn': {'original_max_position_embeddings'}
|
| 306 |
-
> ```
|
| 307 |
-
> please upgrade `transformers>=4.51.0`.
|
| 308 |
|
| 309 |
-
|
| 310 |
-
> All the notable open-source frameworks implement static YaRN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts.**
|
| 311 |
-
> We advise adding the `rope_scaling` configuration only when processing long contexts is required.
|
| 312 |
-
> It is also recommended to modify the `factor` as needed. For example, if the typical context length for your application is 65,536 tokens, it would be better to set `factor` as 2.0.
|
| 313 |
|
| 314 |
-
|
| 315 |
-
> The default `max_position_embeddings` in `config.json` is set to 40,960. This allocation includes reserving 32,768 tokens for outputs and 8,192 tokens for typical prompts, which is sufficient for most scenarios involving short text processing. If the average context length does not exceed 32,768 tokens, we do not recommend enabling YaRN in this scenario, as it may potentially degrade model performance.
|
| 316 |
|
| 317 |
-
|
| 318 |
-
> The endpoint provided by Alibaba Model Studio supports dynamic YaRN by default and no extra configuration is needed.
|
| 319 |
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
1. **Sampling Parameters**:
|
| 325 |
-
- For thinking mode (`enable_thinking=True`), use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`. **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions.
|
| 326 |
-
- For non-thinking mode (`enable_thinking=False`), we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`.
|
| 327 |
-
- For supported frameworks, you can adjust the `presence_penalty` parameter between 0 and 2 to reduce endless repetitions. However, using a higher value may occasionally result in language mixing and a slight decrease in model performance.
|
| 328 |
-
|
| 329 |
-
2. **Adequate Output Length**: We recommend using an output length of 32,768 tokens for most queries. For benchmarking on highly complex problems, such as those found in math and programming competitions, we suggest setting the max output length to 38,912 tokens. This provides the model with sufficient space to generate detailed and comprehensive responses, thereby enhancing its overall performance.
|
| 330 |
-
|
| 331 |
-
3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
|
| 332 |
-
- **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
|
| 333 |
-
- **Multiple-Choice Questions**: Add the following JSON structure to the prompt to standardize responses: "Please show your choice in the `answer` field with only the choice letter, e.g., `"answer": "C"`."
|
| 334 |
-
|
| 335 |
-
4. **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final output part and does not need to include the thinking content. It is implemented in the provided chat template in Jinja2. However, for frameworks that do not directly use the Jinja2 chat template, it is up to the developers to ensure that the best practice is followed.
|
| 336 |
-
|
| 337 |
-
### Citation
|
| 338 |
-
|
| 339 |
-
If you find our work helpful, feel free to give us a cite.
|
| 340 |
-
|
| 341 |
-
```
|
| 342 |
-
@misc{qwen3technicalreport,
|
| 343 |
-
title={Qwen3 Technical Report},
|
| 344 |
-
author={Qwen Team},
|
| 345 |
year={2025},
|
| 346 |
-
eprint={
|
| 347 |
archivePrefix={arXiv},
|
| 348 |
primaryClass={cs.CL},
|
| 349 |
-
url={https://arxiv.org/abs/
|
| 350 |
}
|
| 351 |
```
|
|
|
|
| 4 |
license_link: https://huggingface.co/Qwen/Qwen3-32B/blob/main/LICENSE
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
---
|
| 7 |
+
<div align="center">
|
| 8 |
|
| 9 |
+
# 🧩 ReForm: Reflective Autoformalization with Prospective Bounded Sequence Optimization
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
<a href="https://arxiv.org/pdf/2510.24592"><img src="https://img.shields.io/badge/Paper-arXiv-d63031?logo=arxiv&logoColor=white"></a>
|
| 12 |
+
<a href="https://huggingface.co/collections/GuoxinChen/reform"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Models-0984e3"></a>
|
| 13 |
+
<a href="https://github.com/Chen-GX/ReForm"><img src="https://img.shields.io/badge/GitHub-ReForm-black?logo=github"></a>
|
| 14 |
|
| 15 |
+
</div>
|
| 16 |
|
| 17 |
+
**ReForm** is a reflective **Autoformalization** framework that enables large language models to *generate → verify → refine* formal mathematical statements in an integrated self-corrective loop.
|
| 18 |
+
It introduces **Prospective Bounded Sequence Optimization (PBSO)** — a novel reinforcement learning algorithm designed for heterogeneous rewards at different sequence positions — enabling stable, reflective training and substantial gains in semantic fidelity.
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
## 🚀 Highlights
|
| 23 |
|
| 24 |
+
- 🪞 **Reflective Autoformalization Paradigm**
|
| 25 |
+
Turns single-pass translation into an iterative “generate–validate–refine” cycle, allowing the model to autonomously detect and correct semantic errors.
|
|
|
|
| 26 |
|
| 27 |
+
- ⚖️ **Prospective Bounded Sequence Optimization (PBSO)**
|
| 28 |
+
A reinforcement learning algorithm with position-specific rewards for both task accuracy and critique quality, ensuring stable and interpretable optimization.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
- 📈 **State-of-the-art Semantic Consistency**
|
| 31 |
+
ReForm achieves an **average +22.6pp improvement** over the strongest baseline across four formalization benchmarks (miniF2F, ProofNet, Putnam, and AIME 2025).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
<div align="center">
|
| 36 |
+
<img src="https://github.com/Chen-GX/ReForm/raw/main/images/benchmark_comparison.png" width="100%">
|
| 37 |
+
<br>
|
| 38 |
+
<sub><b>Figure:</b> ReForm consistently outperforms Goedel-V2 and Kimina-Autoformalizer on all benchmarks.</sub>
|
| 39 |
+
</div>
|
| 40 |
|
| 41 |
+
---
|
| 42 |
|
| 43 |
+
## 💡 Quick Start
|
| 44 |
|
|
|
|
| 45 |
```python
|
| 46 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
model_name = "GuoxinChen/ReForm-8B" # or "GuoxinChen/ReForm-32B"
|
| 49 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 50 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
prompt = "Think step by step to translate the mathematical problem in natural language to Lean 4, and verify the consistency.\nLet $a_1, a_2,\\cdots, a_n$ be real constants, $x$ a real variable, and $f(x)=\\cos(a_1+x)+\\frac{1}{2}\\cos(a_2+x)+\\frac{1}{4}\\cos(a_3+x)+\\cdots+\\frac{1}{2^{n-1}}\\cos(a_n+x).$ Given that $f(x_1)=f(x_2)=0,$ prove that $x_2-x_1=m\\pi$ for some integer $m.$"
|
|
|
|
| 53 |
|
| 54 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 55 |
+
outputs = model.generate(**inputs, max_new_tokens=32768)
|
| 56 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
|
|
|
|
|
| 57 |
```
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
More Details please refer to our [Github Repo](https://github.com/Chen-GX/ReForm).
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# 📚 Citation
|
|
|
|
| 63 |
|
| 64 |
+
If you find ReForm useful for your research, please cite:
|
|
|
|
| 65 |
|
| 66 |
+
```bibtex
|
| 67 |
+
@misc{chen2025reform,
|
| 68 |
+
title={ReForm: Reflective Autoformalization with Prospective Bounded Sequence Optimization},
|
| 69 |
+
author={Guoxin Chen and Jing Wu and Xinjie Chen and Wayne Xin Zhao and Ruihua Song and Chengxi Li and Kai Fan and Dayiheng Liu and Minpeng Liao},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
year={2025},
|
| 71 |
+
eprint={2510.24592},
|
| 72 |
archivePrefix={arXiv},
|
| 73 |
primaryClass={cs.CL},
|
| 74 |
+
url={https://arxiv.org/abs/2510.24592},
|
| 75 |
}
|
| 76 |
```
|