Improve model card: Update pipeline tag, add library_name, fix tag typo, and add GitHub link
#2
by
nielsr
HF Staff
- opened
README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
- zh
|
| 6 |
-
|
| 7 |
-
|
| 8 |
tags:
|
| 9 |
-
- machine
|
| 10 |
- O1-like model
|
| 11 |
- Chat
|
| 12 |
-
|
| 13 |
---
|
| 14 |
|
| 15 |
-
# DRT
|
| 16 |
|
| 17 |
<p align="center">
|
| 18 |
🤗 <a href="https://huggingface.co/Krystalan/DRT-7B">DRT-7B</a>   |   🤗 <a href="https://huggingface.co/Krystalan/DRT-8B">DRT-8B</a>   |   🤗 <a href="https://huggingface.co/Krystalan/DRT-14B">DRT-14B</a>   |    📑 <a href="https://arxiv.org/abs/2412.17498">Paper</a>
|
| 19 |
-
|
| 20 |
</p>
|
| 21 |
|
| 22 |
-
This repository contains the resources for our paper ["DRT: Deep Reasoning Translation via Long Chain-of-Thought"](https://arxiv.org/abs/2412.17498)
|
| 23 |
-
|
| 24 |
|
| 25 |
If you find this work is useful, please consider cite our paper:
|
| 26 |
```
|
|
@@ -80,7 +80,8 @@ In this work, we introduce DRT, an attempt to bring the success of long thought
|
|
| 80 |
### Model Prompts
|
| 81 |
During model inference, please use the following prompts:
|
| 82 |
- System prompt: `You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight.`
|
| 83 |
-
- User prompt: `Please translate the following text from English to Chinese
|
|
|
|
| 84 |
|
| 85 |
DRT models will first generate the thought and then provide the final translation, with the following format:
|
| 86 |
```
|
|
@@ -107,7 +108,8 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 107 |
)
|
| 108 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 109 |
|
| 110 |
-
prompt = "Please translate the following text from English to Chinese
|
|
|
|
| 111 |
messages = [
|
| 112 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
| 113 |
{"role": "user", "content": prompt}
|
|
@@ -154,8 +156,9 @@ chat_response = client.chat.completions.create(
|
|
| 154 |
model=[model_name],
|
| 155 |
messages=[
|
| 156 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
| 157 |
-
{"role": "user", "content": "Please translate the following text from English to Chinese
|
| 158 |
-
|
|
|
|
| 159 |
temperature=0.1,
|
| 160 |
top_p=0.8,
|
| 161 |
max_tokens=2048,
|
|
@@ -176,9 +179,222 @@ print("Chat response:", chat_response)
|
|
| 176 |
|This cold officer upon a monument, who dropped epithets unconcernedly down, would be finer as a dead man, he thought. | 他认为,这个站在纪念碑上的冷漠官员,若死了会更好,他不带任何感情地抛下了一些称呼。 | 这个冷冰冰的官员站在纪念碑上,毫不在意地抛下一些称号,他想,如果作为一个死人会更出色。 | 纪念碑上的冷淡官员,漫不经心地吟咏那些修饰语,他心想,若化为亡者,或许更显尊贵。 |
|
| 177 |
|
| 178 |
|
|
|
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
- Chat
|
| 13 |
+
library_name: transformers
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# DRT: Deep Reasoning Translation via Long Chain-of-Thought
|
| 17 |
|
| 18 |
<p align="center">
|
| 19 |
🤗 <a href="https://huggingface.co/Krystalan/DRT-7B">DRT-7B</a>   |   🤗 <a href="https://huggingface.co/Krystalan/DRT-8B">DRT-8B</a>   |   🤗 <a href="https://huggingface.co/Krystalan/DRT-14B">DRT-14B</a>   |    📑 <a href="https://arxiv.org/abs/2412.17498">Paper</a>
|
|
|
|
| 20 |
</p>
|
| 21 |
|
| 22 |
+
This repository contains the resources for our paper ["DRT: Deep Reasoning Translation via Long Chain-of-Thought"](https://arxiv.org/abs/2412.17498).
|
| 23 |
+
The code is available on GitHub: [https://github.com/krystalan/DRT-o1](https://github.com/krystalan/DRT-o1)
|
| 24 |
|
| 25 |
If you find this work is useful, please consider cite our paper:
|
| 26 |
```
|
|
|
|
| 80 |
### Model Prompts
|
| 81 |
During model inference, please use the following prompts:
|
| 82 |
- System prompt: `You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight.`
|
| 83 |
+
- User prompt: `Please translate the following text from English to Chinese:
|
| 84 |
+
[An English text]`
|
| 85 |
|
| 86 |
DRT models will first generate the thought and then provide the final translation, with the following format:
|
| 87 |
```
|
|
|
|
| 108 |
)
|
| 109 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 110 |
|
| 111 |
+
prompt = "Please translate the following text from English to Chinese:
|
| 112 |
+
The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
| 113 |
messages = [
|
| 114 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
| 115 |
{"role": "user", "content": prompt}
|
|
|
|
| 156 |
model=[model_name],
|
| 157 |
messages=[
|
| 158 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
| 159 |
+
{"role": "user", "content": "Please translate the following text from English to Chinese:
|
| 160 |
+
The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."},
|
| 161 |
+
],\
|
| 162 |
temperature=0.1,
|
| 163 |
top_p=0.8,
|
| 164 |
max_tokens=2048,
|
|
|
|
| 179 |
|This cold officer upon a monument, who dropped epithets unconcernedly down, would be finer as a dead man, he thought. | 他认为,这个站在纪念碑上的冷漠官员,若死了会更好,他不带任何感情地抛下了一些称呼。 | 这个冷冰冰的官员站在纪念碑上,毫不在意地抛下一些称号,他想,如果作为一个死人会更出色。 | 纪念碑上的冷淡官员,漫不经心地吟咏那些修饰语,他心想,若化为亡者,或许更显尊贵。 |
|
| 180 |
|
| 181 |
|
| 182 |
+
## Data
|
| 183 |
|
| 184 |
+
We release the synthesized data (named ```MetaphorTrans```), please refer to `data/MetaphorTrans_*.jsonl`, where `text` and `trans` denote the source English sentences and the target Chinese translations, respectively. `thought` indicates the thought content for MT.
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
# DeepTrans
|
| 188 |
+
|
| 189 |
+

|
| 190 |
+
|
| 191 |
+
In this work, we propose DeepTrans-7B, which aims at enhancing the free translation ability of deep reasoning LLMs via RL. To this end, we use DeepSeek-v3 (671B) as the reward model, and design scoring criteria on both translations and thought process.
|
| 192 |
+
|
| 193 |
+
## Model Checkpoint
|
| 194 |
+
|
| 195 |
+
| | Backbone | Model Access |
|
| 196 |
+
| :--: | :--: | :--: |
|
| 197 |
+
| DeepTrans-7B | 🤗 <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct">Qwen2.5-7B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/DeepTrans-7B">DeepTrans-7B</a> |
|
| 198 |
+
|
| 199 |
+
## Inference
|
| 200 |
+
|
| 201 |
+
- Huggingface Transformers
|
| 202 |
+
```python
|
| 203 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 204 |
+
|
| 205 |
+
model_name = "Krystalan/DeepTrans-7B"
|
| 206 |
+
|
| 207 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 208 |
+
model_name,
|
| 209 |
+
torch_dtype="auto",
|
| 210 |
+
device_map="auto"
|
| 211 |
+
)
|
| 212 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 213 |
+
|
| 214 |
+
prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
|
| 215 |
+
<think>
|
| 216 |
+
[思考过程]
|
| 217 |
+
</think>[翻译结果]
|
| 218 |
+
|
| 219 |
+
在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
|
| 220 |
+
现在请你翻译以下这句英语:
|
| 221 |
+
" + "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
| 222 |
+
|
| 223 |
+
messages = [
|
| 224 |
+
{"role": "user", "content": prompt}
|
| 225 |
+
]
|
| 226 |
+
text = tokenizer.apply_chat_template(
|
| 227 |
+
messages,
|
| 228 |
+
tokenize=False,
|
| 229 |
+
add_generation_prompt=True
|
| 230 |
+
)
|
| 231 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 232 |
+
|
| 233 |
+
generated_ids = model.generate(
|
| 234 |
+
**model_inputs,
|
| 235 |
+
max_new_tokens=2048
|
| 236 |
+
)
|
| 237 |
+
generated_ids = [
|
| 238 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 239 |
+
]
|
| 240 |
+
|
| 241 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 242 |
+
print(response)
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
- VLLM:
|
| 246 |
+
deploying LLMs:
|
| 247 |
+
```bash
|
| 248 |
+
python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
calling LLMs:
|
| 252 |
+
```python
|
| 253 |
+
from openai import OpenAI
|
| 254 |
+
# Set OpenAI's API key and API base to use vLLM's API server.
|
| 255 |
+
openai_api_key = "EMPTY"
|
| 256 |
+
openai_api_base = "http://localhost:8000/v1"
|
| 257 |
+
|
| 258 |
+
client = OpenAI(
|
| 259 |
+
api_key=openai_api_key,
|
| 260 |
+
base_url=openai_api_base,
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
|
| 264 |
+
<think>
|
| 265 |
+
[思考过程]
|
| 266 |
+
</think>[翻译结果]
|
| 267 |
+
|
| 268 |
+
在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
|
| 269 |
+
现在请你翻译以下这句英语:
|
| 270 |
+
" + "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
| 271 |
+
|
| 272 |
+
chat_response = client.chat.completions.create(
|
| 273 |
+
model=[model_name],
|
| 274 |
+
messages=[
|
| 275 |
+
{"role": "user", "content": prompt},
|
| 276 |
+
],
|
| 277 |
+
temperature=0.1,
|
| 278 |
+
top_p=0.8,
|
| 279 |
+
max_tokens=2048,
|
| 280 |
+
extra_body={
|
| 281 |
+
"repetition_penalty": 1.05,
|
| 282 |
+
},
|
| 283 |
+
)
|
| 284 |
+
print("Chat response:", chat_response)
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
# ExTrans
|
| 288 |
+
|
| 289 |
+

|
| 290 |
+
|
| 291 |
+
In this work, we propose ExTrans-7B, which aims at enhancing the free translation ability of deep reasoning LLMs via **exemplar-enhanced** RL. In detail, for each training MT sample, we use DeepSeek-R1 (671B) to generate a exemplar translation, and compare the translation results of the policy model with the exemplar translations to provide rewards for the policy model.
|
| 292 |
+
|
| 293 |
+
Moreover, we extend ExTrans-7B from English-to-Chinese translation into **multilingual settings** with 11 languages, *e.g.*, Chinese, English, Arabic, Czech, German, Spanish, French, Italian, Japanese, Russian and Korean.
|
| 294 |
+
|
| 295 |
+
The model checkpoints can be accessed from the following links:
|
| 296 |
+
| | Backbone | Model Access |
|
| 297 |
+
| :--: | :--: | :--: |
|
| 298 |
+
| ExTrans-7B | 🤗 <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct">Qwen2.5-7B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/ExTrans-7B">ExTrans-7B</a> |
|
| 299 |
+
| mExTrans-7B | 🤗 <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct">Qwen2.5-7B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/mExTrans-7B">mExTrans-7B</a> |
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
## Inference of ExTrans
|
| 303 |
+
|
| 304 |
+
deploying LLMs:
|
| 305 |
+
```bash
|
| 306 |
+
python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
calling LLMs:
|
| 310 |
+
```python
|
| 311 |
+
from openai import OpenAI
|
| 312 |
+
# Set OpenAI's API key and API base to use vLLM's API server.
|
| 313 |
+
openai_api_key = "EMPTY"
|
| 314 |
+
openai_api_base = "http://localhost:8000/v1"
|
| 315 |
+
|
| 316 |
+
client = OpenAI(
|
| 317 |
+
api_key=openai_api_key,
|
| 318 |
+
base_url=openai_api_base,
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
|
| 322 |
+
<think>
|
| 323 |
+
[思考过程]
|
| 324 |
+
</think>[翻译结果]
|
| 325 |
+
|
| 326 |
+
在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
|
| 327 |
+
现在请你翻译以下这句英语:
|
| 328 |
+
" + "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap."
|
| 329 |
+
|
| 330 |
+
chat_response = client.chat.completions.create(
|
| 331 |
+
model=[model_name],
|
| 332 |
+
messages=[
|
| 333 |
+
{"role": "user", "content": prompt},
|
| 334 |
+
],
|
| 335 |
+
temperature=0.1,
|
| 336 |
+
top_p=0.8,
|
| 337 |
+
max_tokens=2048,
|
| 338 |
+
extra_body={
|
| 339 |
+
"repetition_penalty": 1.05,
|
| 340 |
+
},
|
| 341 |
+
)
|
| 342 |
+
print("Chat response:", chat_response)
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
## Inference of mExTrans
|
| 346 |
+
|
| 347 |
+
calling LLMs:
|
| 348 |
+
```python
|
| 349 |
+
from openai import OpenAI
|
| 350 |
+
# Set OpenAI's API key and API base to use vLLM's API server.
|
| 351 |
+
openai_api_key = "EMPTY"
|
| 352 |
+
openai_api_base = "http://localhost:8000/v1"
|
| 353 |
|
| 354 |
+
client = OpenAI(
|
| 355 |
+
api_key=openai_api_key,
|
| 356 |
+
base_url=openai_api_base,
|
| 357 |
+
)
|
| 358 |
|
| 359 |
+
lang2des = {
|
| 360 |
+
"ar": "阿拉伯语", # Arabic
|
| 361 |
+
"cs": "捷克语", # Czech
|
| 362 |
+
"de": "德语", # German
|
| 363 |
+
"en": "英语", # English
|
| 364 |
+
"es": "西班牙语", # Spanish
|
| 365 |
+
"fr": "法语", # French
|
| 366 |
+
"it": "意大利语", # Italian
|
| 367 |
+
"ja": "日语", # Japanese
|
| 368 |
+
"ko": "韩语", # Korean
|
| 369 |
+
"ru": "俄语", # Russian
|
| 370 |
+
"zh": "中文" # Chinese
|
| 371 |
+
}
|
| 372 |
|
| 373 |
+
current_src_lang = lang2des["en"] # set the source language
|
| 374 |
+
current_trg_lang = lang2des["zh"] # set the target language
|
| 375 |
+
|
| 376 |
+
current_sent = "The mother, with her feet propped up on a stool, seemed to be trying to get to the bottom of that answer, whose feminine profundity had struck her all of a heap." # the source sentence to be translated
|
| 377 |
+
|
| 378 |
+
TRANS_PROMPT = "你是一个翻译专家,擅长将{current_src}翻译成{current_trg}。你在翻译过程中非常擅长思考,会先用中文进行思考再给出翻译结果。在你思考完之后,也就是</think>之后,你会给出最终的翻译,且最终的翻译结果中不需要给出任何解释和描述,只需要提供翻译结果。
|
| 379 |
+
现在请你翻译以下这句{current_src}:
|
| 380 |
+
{current_sent}"
|
| 381 |
+
|
| 382 |
+
chat_response = client.chat.completions.create(
|
| 383 |
+
model=[model_name],
|
| 384 |
+
messages=[
|
| 385 |
+
{"role": "user", "content": TRANS_PROMPT.format(current_src=current_src_lang, current_trg=current_trg_lang, current_sent=current_sent)},
|
| 386 |
+
],
|
| 387 |
+
temperature=0.1,
|
| 388 |
+
top_p=0.8,
|
| 389 |
+
max_tokens=2048,
|
| 390 |
+
extra_body={
|
| 391 |
+
"repetition_penalty": 1.05,
|
| 392 |
+
},
|
| 393 |
+
)
|
| 394 |
+
print("Chat response:", chat_response)
|
| 395 |
+
```
|
| 396 |
+
|
| 397 |
+
Note that, the prompt of mExTrans is slightly different from that of ExTrans.
|
| 398 |
+
|
| 399 |
+
## License
|
| 400 |
+
This work is licensed under cc-by-nc-sa-4.0
|