The model was initially fine-tuned on an English-centric parallel data from TowerBlocks.
The model can perform translations between supported languages, with limited translation capabilities between non-English languages.
The model is also used to synthesize preference data for subsequent x2x optimization.
Out-of-Scope Use
The model is not guaranteed to perform for languages other than the 10 languages it supports.
Although the model is trained on natural language instructions related to translation tasks, its ability to follow instructions and the accuracy of results for tasks beyond translation cannot be guaranteed.
Bias, Risks, and Limitations
Llama-2-7b-MT-SFT has not been aligned to human preferences, so the model may generate problematic outputs (e.g., hallucinations, harmful content, or false statements).
How to Get Started with the Model
Here's how you can run the model with Huggingface Transformers:
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
23MODEL_PATH ="double7/Llama-2-7b-MT-SFT"45tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)6model = AutoModelForCausalLM.from_pretrained(7 MODEL_PATH, device_map="auto", torch_dtype="auto"8)910src_lang ="German"11trg_lang ="Chinese"12src_text ="Filmkarriere Collinges Filmdebüt in Die kleinen Füchse von 1941 brachte ihr eine Nominierung für den Academy Award als beste Nebendarstellerin ein."1314prompt =f"Translate the following text from {src_lang} into {trg_lang}:\n{src_lang}: {src_text}\n{trg_lang}:"1516# We use the tokenizer’s chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating17messages =[18{"role":"user","content": prompt},19]2021input_text = tokenizer.apply_chat_template(22 messages, tokenize=False, add_generation_prompt=True23)2425inputs = tokenizer(input_text, return_tensors="pt").to(model.device)2627outputs = model.generate(**inputs, do_sample=False, max_new_tokens=256)28output_text = tokenizer.batch_decode(outputs, skip_special_tokens=False)[0]29print(output_text)30# <s><|im_start|> user31# Translate the following text from German into Chinese:32# German: Filmkarriere Collinges Filmdebüt in Die kleinen Füchse von 1941 brachte ihr eine Nominierung für den Academy Award als beste Nebendarstellerin ein.33# Chinese:<|im_end|> 34# <|im_start|> assistant35# Collinge 的电影生涯,她的电影处女作是 1941 年的《小狐狸》,获得了她的奥斯卡最佳女配角提名。<|im_end|>36
Translation Instructions
Following TowerInstruct, we use diverse translation instructions in training, you can use natural language to describe translation requests, such as:
python
1prompt1 =f"Translate the following text from {src_lang} into {trg_lang}:\n{src_lang}: {src_text}\n{trg_lang}:"23prompt1 =f"Please provide a translation from {src_lang} to {trg_lang} for the following text:\n{src_text}\nTarget:",45prompt2 =f"Translate this {src_lang} text into {trg_lang}:\nSource: {src_text}\nTranslation:",
We use prompt1 for the evaluation.
Prompt Format
Llama-2-7b-MT-SFT was trained using the ChatML prompt templates without any system prompts. An example follows below: