2024.12.23: We released our model checkpoints. 🤗 DRT-o1-7B and 🤗 DRT-o1-14B.
If you find this work is useful, please consider cite our paper:
@article{wang2024drt,
title={DRT-o1: Optimized Deep Reasoning Translation via Long Chain-of-Thought},
author={Wang, Jiaan and Meng, Fandong and Liang, Yunlong and Zhou, Jie},
journal={arXiv preprint arXiv:2412.17498},
year={2024}
}
In this work, we introduce DRT-o1, an attempt to bring the success of long thought reasoning to neural machine translation (MT). To this end,
🌟 We mine English sentences with similes or metaphors from existing literature books, which are suitable for translation via long thought.
🌟 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.
🌟 We train DRT-o1-8B, DRT-o1-7B and DRT-o1-14B using Llama-3.1-8B-Instruct, Qwen2.5-7B-Instruct and Qwen2.5-14B-Instruct as backbones.
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-o1, a byproduct of our exploration, and we hope it could facilitate the corresponding research in this direction.
1from transformers import AutoModelForCausalLM, AutoTokenizer
23model_name ="Krystalan/DRT-o1-7B"45model = AutoModelForCausalLM.from_pretrained(6 model_name,7 torch_dtype="auto",8 device_map="auto"9)10tokenizer = AutoTokenizer.from_pretrained(model_name)1112prompt ="Please translate the following text from English to Chinese:\nThe 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."13messages =[14{"role":"system","content":"You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},15{"role":"user","content": prompt}16]17text = tokenizer.apply_chat_template(18 messages,19 tokenize=False,20 add_generation_prompt=True21)22model_inputs = tokenizer([text], return_tensors="pt").to(model.device)2324generated_ids = model.generate(25**model_inputs,26 max_new_tokens=204827)28generated_ids =[29 output_ids[len(input_ids):]for input_ids, output_ids inzip(model_inputs.input_ids, generated_ids)30]3132response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]33print(response)
1from openai import OpenAI
2# Set OpenAI's API key and API base to use vLLM's API server.3openai_api_key ="EMPTY"4openai_api_base ="http://localhost:8000/v1"56client = OpenAI(7 api_key=openai_api_key,8 base_url=openai_api_base,9)1011chat_response = client.chat.completions.create(12 model=[model_name],13 messages=[14{"role":"system","content":"You are a philosopher skilled in deep thinking, accustomed to exploring complex problems with profound insight."},15{"role":"user","content":"Please translate the following text from English to Chinese:\nThe 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."},16],17 temperature=0.1,18 top_p=0.8,19 max_tokens=2048,20 extra_body={21"repetition_penalty":1.05,22},23)24print("Chat response:", chat_response)
Translation Cases
Source Sentence
Qwen2.5-14B-Instruct
QwQ-32B-preview
DRT-o1-14B
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.
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.
This cold officer upon a monument, who dropped epithets unconcernedly down, would be finer as a dead man, he thought.
他认为,这个站在纪念碑上的冷漠官员,若死了会更好,他不带任何感情地抛下了一些称呼。
这个冷冰冰的官员站在纪念碑上,毫不在意地抛下一些称号,他想,如果作为一个死人会更出色。
纪念碑上的冷淡官员,漫不经心地吟咏那些修饰语,他心想,若化为亡者,或许更显尊贵。
Data
We release the testing set of our work, please refer to data/test.jsonl, where en indicates the English source sentences, and zh denotes the corresponding Chinese translation.
We will release the long-thought MT data as well as the data collection codes soon!