Add pipeline tag, library name, and paper/Github links

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +440 -3
README.md CHANGED
@@ -1,3 +1,440 @@
1
- ---
2
- license: cc-by-nc-sa-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ pipeline_tag: translation
4
+ library_name: transformers
5
+ ---
6
+
7
+ # Deep Reasoning Translation (DRT) Project
8
+
9
+ <p align="center">
10
+ 🤗 <a href="https://huggingface.co/Krystalan/DRT-7B">DRT-7B</a>&nbsp&nbsp | &nbsp&nbsp🤗 <a href="https://huggingface.co/Krystalan/DRT-8B">DRT-8B</a>&nbsp&nbsp | &nbsp&nbsp🤗 <a href="https://huggingface.co/Krystalan/DRT-14B">DRT-14B</a>&nbsp&nbsp | &nbsp&nbsp 🤗 <a href="https://huggingface.co/Krystalan/DeepTrans-7B">DeepTrans-7B</a> | &nbsp&nbsp 🤗 <a href="https://huggingface.co/Krystalan/ExTrans-7B">ExTrans-7B</a> | &nbsp&nbsp 🤗 <a href="https://huggingface.co/Krystalan/mExTrans-7B">mExTrans-7B</a>
11
+
12
+ </p>
13
+
14
+ This repository contains the resources for our work:
15
+ - [**ExTrans**: Multilingual Deep Reasoning Translation via Exemplar-Enhanced Reinforcement Learning](https://arxiv.org/abs/2505.12996) (arXiv preprint 2025) - [Code](https://github.com/dmis-lab/mExTrans)
16
+ - [**DeepTrans**: Deep Reasoning Translation via Reinforcement Learning](https://arxiv.org/abs/2504.10187) (arXiv preprint 2025) - [Code](https://github.com/dmis-lab/DeepTrans)
17
+ - [**DRT**: Deep Reasoning Translation via Long Chain-of-Thought](https://arxiv.org/abs/2412.17498) (ACL 2025 Findings) - [Code](https://github.com/dmis-lab/DRT)
18
+
19
+
20
+ Our exploration route is as follows:
21
+
22
+ ![](./images/exploration_route.png)
23
+
24
+ ### Updates:
25
+ - *2025.05.27*: We released the full data of our DRT work, including the synthesized thought contents and translations. Please refer to `data/MetaphorTrans_*.jsonl`
26
+ - *2025.05.19*: We released [ExTrans paper](https://arxiv.org/abs/2505.12996) with 🤗 <a href="https://huggingface.co/Krystalan/ExTrans-7B">ExTrans-7B</a> and 🤗 <a href="https://huggingface.co/Krystalan/mExTrans-7B">mExTrans-7B</a>. Check it out!
27
+ - *2025.05.16*: Our [DRT paper](https://arxiv.org/abs/2412.17498) is accepted to **ACL 2025 Findings**.
28
+ - *2025.04.14*: We released [DeepTrans paper](https://arxiv.org/abs/2504.10187) with 🤗 <a href="https://huggingface.co/Krystalan/DeepTrans-7B">DeepTrans-7B</a>. Check it out!
29
+ - *2024.12.31*: We updated [DRT paper](https://arxiv.org/abs/2412.17498) with more detals and analyses. Check it out!
30
+ - *2024.12.24*: We released [DRT paper](https://arxiv.org/abs/2412.17498) with 🤗 <a href="https://huggingface.co/Krystalan/DRT-7B">DRT-7B</a>, 🤗 <a href="https://huggingface.co/Krystalan/DRT-8B">DRT-8B</a> and 🤗 <a href="https://huggingface.co/Krystalan/DRT-14B">DRT-14B</a>. Check it out!
31
+
32
+
33
+ If you find this work is useful, please consider cite our paper:
34
+ ```
35
+ @article{wang2025extrans,
36
+ title={ExTrans: Multilingual Deep Reasoning Translation via Exemplar-Enhanced Reinforcement Learning},
37
+ author={Wang, Jiaan and Meng, Fandong and Zhou, Jie},
38
+ journal={arXiv preprint arXiv:2505.12996},
39
+ year={2025}
40
+ }
41
+ ```
42
+
43
+ ```
44
+ @article{wang2025deeptrans,
45
+ title={Deep Reasoning Translation via Reinforcement Learning},
46
+ author={Wang, Jiaan and Meng, Fandong and Zhou, Jie},
47
+ journal={arXiv preprint arXiv:2504.10187},
48
+ year={2025}
49
+ }
50
+ ```
51
+
52
+ ```
53
+ @article{wang2024drt,
54
+ title={DRT: Deep Reasoning Translation via Long Chain-of-Thought},
55
+ author={Wang, Jiaan and Meng, Fandong and Liang, Yunlong and Zhou, Jie},
56
+ journal={arXiv preprint arXiv:2412.17498},
57
+ year={2024}
58
+ }
59
+ ```
60
+
61
+ # Quick Links
62
+ - [DRT: Deep Reasoning Translation via Long Chain-of-Thought](#drt)
63
+ - [Introduction](#introduction)
64
+ - [Models](#models)
65
+ - [Model Access](#model-access)
66
+ - [Model Performance](#model-performance)
67
+ - [Model Prompts](#model-prompts)
68
+ - [Quickstart](#quickstart)
69
+ - [Translation Cases](#translation-cases)
70
+ - [Data (MetaphorTrans)](#data)
71
+ - [DeepTrans: Deep Reasoning Translation via Reinforcement Learning](#deeptrans)
72
+ - [Model Checkpoint](#model-checkpoint)
73
+ - [Inference](#inference)
74
+ - [ExTrans: Multilingual Deep Reasoning Translation via Exemplar-Enhanced Reinforcement Learning](#extrans)
75
+ - [ExTrans-7B inference](#inference-of-extrans)
76
+ - [mExTrans-7B inference](#inference-of-mextrans)
77
+ - [License](#license)
78
+
79
+ # DRT
80
+
81
+ ## Introduction
82
+
83
+ ![](./images/multi-agent-framework.png)
84
+
85
+
86
+
87
+ In this work, we introduce DRT, an attempt to bring the success of long thought reasoning to neural machine translation (MT). To this end,
88
+ - 🌟 We mine English sentences with similes or metaphors from existing literature books, which are suitable for translation via long thought.
89
+ - 🌟 We propose a designed multi-agent framework with three agents (i.e., a translator, an advisor and an evaluator) to synthesize the MT samples with long thought. There are 22,264 synthesized samples in total.
90
+ - 🌟 We train DRT-8B, DRT-7B and DRT-14B using Llama-3.1-8B-Instruct, Qwen2.5-7B-Instruct and Qwen2.5-14B-Instruct as backbones.
91
+
92
+ > Our goal is not to achieve competitive performance with OpenAI’s O1 in neural machine translation (MT). Instead, we explore technical routes to bring the success of long thought to MT. To this end, we introduce DRT, *a byproduct of our exploration*, and we hope it could facilitate the corresponding research in this direction.
93
+
94
+ ![](./images/data_case.png)
95
+
96
+
97
+ ## Models
98
+
99
+ ### Model Access
100
+
101
+ | | Backbone | Model Access |
102
+ | :--: | :--: | :--: |
103
+ | DRT-7B | 🤗 <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct">Qwen2.5-7B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/DRT-7B">DRT-7B</a> |
104
+ | DRT-8B | 🤗 <a href="https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct">Llama-3.1-8B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/DRT-8B">DRT-8B</a> |
105
+ | DRT-14B | 🤗 <a href="https://huggingface.co/Qwen/Qwen2.5-14B-Instruct">Qwen2.5-14B-Instruct</a> | 🤗 <a href="https://huggingface.co/Krystalan/DRT-14B">DRT-14B</a> |
106
+
107
+ ### Model Performance
108
+ | | GRF | CometKiwi | GRB | BLEU | CometScore |
109
+ | :--: | :--: | :--: | :--: | :--: | :--: |
110
+ | Llama-3.1-8B-Instruct | 79.25 | 70.14 | 73.30 | 18.55 | 74.58 |
111
+ | Qwen2.5-7B-Instruct | 81.53 | 70.36 | 77.92 | 27.02 | 76.78 |
112
+ | Qwen2.5-14B-Instruct | 84.74 | 72.01 | 80.85 | 30.23 | 78.84 |
113
+ | Marco-o1-7B | 82.41 | 71.62 | 77.50 | 29.48 | 77.41 |
114
+ | QwQ-32B-preview | 86.31 | 71.48 | 83.08 | 27.46 | 78.68 |
115
+ | DRT-8B | 84.49 | 70.85 | 80.80 | 32.67 | 78.81 |
116
+ | DRT-7B | 85.57 | 71.78 | 82.38 | 35.54 | 80.19 |
117
+ | DRT-14B | **87.19** | **72.11** | **83.20** | **36.46** | **80.64** |
118
+
119
+
120
+ ### Model Prompts
121
+ During model inference, please use the following prompts:
122
+ - System prompt: `You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight.`
123
+ - User prompt: `Please translate the following text from English to Chinese:
124
+ [An English text]`
125
+
126
+ DRT models will first generate the thought and then provide the final translation, with the following format:
127
+ ```
128
+ <thought>
129
+ [Reasoning process]
130
+ </thought>
131
+ <output>
132
+ [Final translation]
133
+ </output>
134
+ ```
135
+
136
+ ### Quickstart
137
+ - ⛷️ Huggingface Transformers:
138
+
139
+ ```python
140
+ from transformers import AutoModelForCausalLM, AutoTokenizer
141
+
142
+ model_name = "Krystalan/DRT-7B"
143
+
144
+ model = AutoModelForCausalLM.from_pretrained(
145
+ model_name,
146
+ torch_dtype="auto",
147
+ device_map="auto"
148
+ )
149
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
150
+
151
+ prompt = "Please translate the following text from English to Chinese:
152
+ 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."
153
+ messages = [
154
+ {"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
155
+ {"role": "user", "content": prompt}
156
+ ]
157
+ text = tokenizer.apply_chat_template(
158
+ messages,
159
+ tokenize=False,
160
+ add_generation_prompt=True
161
+ )
162
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
163
+
164
+ generated_ids = model.generate(
165
+ **model_inputs,
166
+ max_new_tokens=2048
167
+ )
168
+ generated_ids = [
169
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
170
+ ]
171
+
172
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
173
+ print(response)
174
+ ```
175
+
176
+ - ⛷️ vllm:
177
+
178
+ Deploying LLMs:
179
+ ```bash
180
+ python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
181
+ ```
182
+
183
+ Calling LLMs:
184
+ ```python
185
+ from openai import OpenAI
186
+ # Set OpenAI's API key and API base to use vLLM's API server.
187
+ openai_api_key = "EMPTY"
188
+ openai_api_base = "http://localhost:8000/v1"
189
+
190
+ client = OpenAI(
191
+ api_key=openai_api_key,
192
+ base_url=openai_api_base,
193
+ )
194
+
195
+ chat_response = client.chat.completions.create(
196
+ model=[model_name],
197
+ messages=[
198
+ {"role": "system", "content": "You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},
199
+ {"role": "user", "content": "Please translate the following text from English to Chinese:
200
+ 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."},
201
+ ],
202
+ temperature=0.1,
203
+ top_p=0.8,
204
+ max_tokens=2048,
205
+ extra_body={
206
+ "repetition_penalty": 1.05,
207
+ },
208
+ )
209
+ print("Chat response:", chat_response)
210
+ ```
211
+
212
+ ## Translation Cases
213
+
214
+ | Source Sentence | Qwen2.5-14B-Instruct | QwQ-32B-preview | DRT-14B |
215
+ | :--: | :--: | :--: | :--: |
216
+ |Women were weeping and children crying, and all were going as fast as seemingly lay in their power, looking behind now and then as if pursued by some deadly enemy. | 妇女在哭泣,孩子们在哀号,所有人都似乎在尽全力快速前行,不时回头张望,仿佛背后有某个致命的敌人在追赶。 | 妇女们哭泣着,孩子们哭喊着,每个人都在尽力加快脚步,不时回头张望,仿佛背后有致命的敌人在追击。 | 妇女悲泣,孩童哀号,众人疾奔,不时回首,仿佛有致命之敌在后紧追。 |
217
+ |Wait through this season of the rain Till suns of autumn dry the plain, Then shall thy giant foe, and all His host and realm, before thee fall. | 等待这雨季过去,直到秋日的阳光晒干原野,那时你的巨敌及其部众和王国都将倒在你面前。 | 忍过雨季漫长夜,待秋阳升空,晒干大地湿润色,那时,巨敌垮台,他的军队和王国,全在你脚下。 | 历尽这雨季,待秋日阳光驱散平原上的最后一丝湿润,那时,你那巨敌,连同他的军队与王国,都将匍匐在你脚下。 |
218
+ |And if their words had taken another turn...if he himself had been less fastidious about intruding on another man's secrets...it was cruel to think how thin a film had shut out rescue from all this guilt and misery. | 而如果他们的言辞转向了另一个方向……如果他自己对侵扰他人秘密不那么介意……想到正是那层薄薄的隔阂将救援拒之门外,使得这一切的罪恶和痛苦无法避免,真是残酷。 | 而且,假如他们的谈话走向不同……假如他自己不对干涉他人私事如此谨慎……那时他会意识到,只要一层薄薄的屏障就阻隔了救援,使得所有这些罪恶和痛苦无法解脱,这真是残忍。 | 若他们的言辞稍作转变……若他本人不那么介意侵入他人的心扉……想到这层薄薄的隔阂竟将所有内疚与痛苦隔离于救援之外,实为残忍。 |
219
+ |This cold officer upon a monument, who dropped epithets unconcernedly down, would be finer as a dead man, he thought. | 他认为,这个站在纪念碑上的冷漠官员,若死了会更好,他不带任何感情地抛下了一些称呼。 | 这个冷冰冰的官员站在纪念碑上,毫不在意地抛下一些称号,他想,如果作为一个死人会更出色。 | 纪念碑上的冷淡官员,漫不经心地吟咏那些修饰语,他心想,若化为亡者,或许更显尊贵。 |
220
+
221
+
222
+ ## Data
223
+
224
+ 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.
225
+
226
+
227
+ # DeepTrans
228
+
229
+ ![](./images/deeptrans-reward-framework.png)
230
+
231
+ 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.
232
+
233
+ ## Model Checkpoint
234
+
235
+ | | Backbone | Model Access |
236
+ | :--: | :--: | :--: |
237
+ | 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> |
238
+
239
+ ## Inference
240
+
241
+ - Huggingface Transformers
242
+ ```python
243
+ from transformers import AutoModelForCausalLM, AutoTokenizer
244
+
245
+ model_name = "Krystalan/DeepTrans-7B"
246
+
247
+ model = AutoModelForCausalLM.from_pretrained(
248
+ model_name,
249
+ torch_dtype="auto",
250
+ device_map="auto"
251
+ )
252
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
253
+
254
+ prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
255
+ <think>
256
+ [思考过程]
257
+ </think>[翻译结果]
258
+
259
+ 在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
260
+ 现在请你翻译以下这句英语:
261
+ " + "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."
262
+
263
+ messages = [
264
+ {"role": "user", "content": prompt}
265
+ ]
266
+ text = tokenizer.apply_chat_template(
267
+ messages,
268
+ tokenize=False,
269
+ add_generation_prompt=True
270
+ )
271
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
272
+
273
+ generated_ids = model.generate(
274
+ **model_inputs,
275
+ max_new_tokens=2048
276
+ )
277
+ generated_ids = [
278
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
279
+ ]
280
+
281
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
282
+ print(response)
283
+ ```
284
+
285
+ - VLLM:
286
+ deploying LLMs:
287
+ ```bash
288
+ python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
289
+ ```
290
+
291
+ calling LLMs:
292
+ ```python
293
+ from openai import OpenAI
294
+ # Set OpenAI's API key and API base to use vLLM's API server.
295
+ openai_api_key = "EMPTY"
296
+ openai_api_base = "http://localhost:8000/v1"
297
+
298
+ client = OpenAI(
299
+ api_key=openai_api_key,
300
+ base_url=openai_api_base,
301
+ )
302
+
303
+ prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
304
+ <think>
305
+ [思考过程]
306
+ </think>[翻译结果]
307
+
308
+ 在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
309
+ 现在请你翻译以下这句英语:
310
+ " + "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."
311
+
312
+ chat_response = client.chat.completions.create(
313
+ model=[model_name],
314
+ messages=[
315
+ {"role": "user", "content": prompt},
316
+ ],
317
+ temperature=0.1,
318
+ top_p=0.8,
319
+ max_tokens=2048,
320
+ extra_body={
321
+ "repetition_penalty": 1.05,
322
+ },
323
+ )
324
+ print("Chat response:", chat_response)
325
+ ```
326
+
327
+ # ExTrans
328
+
329
+ ![](./images/extrans-reward-framework.png)
330
+
331
+ 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.
332
+
333
+ 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.
334
+
335
+ The model checkpoints can be accessed from the following links:
336
+ | | Backbone | Model Access |
337
+ | :--: | :--: | :--: |
338
+ | 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> |
339
+ | 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> |
340
+
341
+
342
+ ## Inference of ExTrans
343
+
344
+ deploying LLMs:
345
+ ```bash
346
+ python3 -m vllm.entrypoints.openai.api_server --model [model_ckpt] --served-model-name [model_name]
347
+ ```
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
+ prompt = "你是一个翻译专家,擅长将英文翻译成中文。你在翻译过程中非常擅长思考,会先进行思考再给出翻译结果。你的输出格式为:
362
+ <think>
363
+ [思考过程]
364
+ </think>[翻译结果]
365
+
366
+ 在你思考完之后,也就是</think>之后,你会给出最终的翻译即“[翻译结果]”,且[翻译结果]中不需要给出任何解释和描述,只需要提供英文的翻译结果。
367
+ 现在请你翻译以下这句英语:
368
+ " + "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."
369
+
370
+ chat_response = client.chat.completions.create(
371
+ model=[model_name],
372
+ messages=[
373
+ {"role": "user", "content": prompt},
374
+ ],
375
+ temperature=0.1,
376
+ top_p=0.8,
377
+ max_tokens=2048,
378
+ extra_body={
379
+ "repetition_penalty": 1.05,
380
+ },
381
+ )
382
+ print("Chat response:", chat_response)
383
+ ```
384
+
385
+ ## Inference of mExTrans
386
+
387
+ calling LLMs:
388
+ ```python
389
+ from openai import OpenAI
390
+ # Set OpenAI's API key and API base to use vLLM's API server.
391
+ openai_api_key = "EMPTY"
392
+ openai_api_base = "http://localhost:8000/v1"
393
+
394
+ client = OpenAI(
395
+ api_key=openai_api_key,
396
+ base_url=openai_api_base,
397
+ )
398
+
399
+ lang2des = {
400
+ "ar": "阿拉伯语", # Arabic
401
+ "cs": "捷克语", # Czech
402
+ "de": "德语", # German
403
+ "en": "英语", # English
404
+ "es": "西班牙语", # Spanish
405
+ "fr": "法语", # French
406
+ "it": "意大利语", # Italian
407
+ "ja": "日语", # Japanese
408
+ "ko": "韩语", # Korean
409
+ "ru": "俄语", # Russian
410
+ "zh": "中文" # Chinese
411
+ }
412
+
413
+ current_src_lang = lang2des["en"] # set the source language
414
+ current_trg_lang = lang2des["zh"] # set the target language
415
+
416
+ 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
417
+
418
+ TRANS_PROMPT = "你是一个翻译专家,擅长将{current_src}翻译成{current_trg}。你在翻译过程中非常擅长思考,会先用中文进行思考再给出翻译结果。在你思考完之后,也就是</think>之后,你会给出最终的翻译,且最终的翻译结果中不需要给出任何解释和描述,只需要提供翻译结果。
419
+ 现在请你翻译以下这句{current_src}:
420
+ {current_sent}"
421
+
422
+ chat_response = client.chat.completions.create(
423
+ model=[model_name],
424
+ messages=[
425
+ {"role": "user", "content": TRANS_PROMPT.format(current_src=current_src_lang, current_trg=current_trg_lang, current_sent=current_sent)},
426
+ ],
427
+ temperature=0.1,
428
+ top_p=0.8,
429
+ max_tokens=2048,
430
+ extra_body={
431
+ "repetition_penalty": 1.05,
432
+ },
433
+ )
434
+ print("Chat response:", chat_response)
435
+ ```
436
+
437
+ Note that, the prompt of mExTrans is slightly different from that of ExTrans.
438
+
439
+ # License
440
+ This work is licensed under cc-by-nc-sa-4.0