If you find this work is useful, please consider cite our paper:
@article{wang2024drt,
title={DRT: 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, 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-8B, DRT-7B and DRT-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, 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-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-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.