Improve model card: update pipeline tag, add library name, and fix tags
#4
by
nielsr
HF Staff
- opened
README.md
CHANGED
@@ -1,21 +1,22 @@
|
|
1 |
---
|
2 |
-
|
|
|
3 |
language:
|
4 |
- en
|
5 |
- zh
|
6 |
-
|
7 |
-
|
|
|
8 |
tags:
|
9 |
-
- machine
|
10 |
- O1-like model
|
11 |
- Chat
|
12 |
-
pipeline_tag: text-generation
|
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 |
|
@@ -80,7 +81,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 +109,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,7 +157,8 @@ 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 |
tem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|
language:
|
5 |
- en
|
6 |
- zh
|
7 |
+
license: cc-by-nc-sa-4.0
|
8 |
+
pipeline_tag: translation
|
9 |
+
library_name: transformers
|
10 |
tags:
|
11 |
+
- machine translation
|
12 |
- O1-like model
|
13 |
- Chat
|
|
|
14 |
---
|
15 |
|
16 |
# DRT
|
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>   |    💻 <a href="https://github.com/krystalan/DRT-o1">Code</a>
|
20 |
|
21 |
</p>
|
22 |
|
|
|
81 |
### Model Prompts
|
82 |
During model inference, please use the following prompts:
|
83 |
- System prompt: `You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight.`
|
84 |
+
- User prompt: `Please translate the following text from English to Chinese:
|
85 |
+
[An English text]`
|
86 |
|
87 |
DRT models will first generate the thought and then provide the final translation, with the following format:
|
88 |
```
|
|
|
109 |
)
|
110 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
111 |
|
112 |
+
prompt = "Please translate the following text from English to Chinese:
|
113 |
+
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."
|
114 |
messages = [
|
115 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
116 |
{"role": "user", "content": prompt}
|
|
|
157 |
model=[model_name],
|
158 |
messages=[
|
159 |
{"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
|
160 |
+
{"role": "user", "content": "Please translate the following text from English to Chinese:
|
161 |
+
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."},
|
162 |
],
|
163 |
temperature=0.1,
|
164 |
top_p=0.8,
|
|
|
181 |
|
182 |
|
183 |
|
184 |
+
## Data
|
185 |
+
|
186 |
+
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.
|
187 |
+
|
188 |
+
|
189 |
+
# DeepTrans
|
190 |
+
|
191 |
+

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

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