🚀 ALMA(高級基於語言模型的翻譯器)
ALMA(Advanced Language Model-based trAnslator)是一個基於大語言模型(LLM)的翻譯模型,採用了全新的翻譯模型範式:先在單語數據上進行微調,再使用高質量的平行數據進一步優化。這種兩步微調過程確保了強大的翻譯性能。更多詳細信息請參考我們的論文。
@misc{xu2023paradigm,
title={A Paradigm Shift in Machine Translation: Boosting Translation Performance of Large Language Models},
author={Haoran Xu and Young Jin Kim and Amr Sharaf and Hany Hassan Awadalla},
year={2023},
eprint={2309.11674},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
ALMA - R(全新發布!) ALMA - R 基於 ALMA 模型構建,與 ALMA 中使用的監督微調不同,它使用我們提出的對比偏好優化(CPO) 進行進一步的 LoRA 微調。CPO 微調需要我們的[三元組偏好數據](https://huggingface.co/datasets/haoranxu/ALMA - R - Preference)進行偏好學習。現在,ALMA - R 的性能可以媲美甚至超越 GPT - 4 或 WMT 獲勝者!
@misc{xu2024contrastive,
title={Contrastive Preference Optimization: Pushing the Boundaries of LLM Performance in Machine Translation},
author={Haoran Xu and Amr Sharaf and Yunmo Chen and Weiting Tan and Lingfeng Shen and Benjamin Van Durme and Kenton Murray and Young Jin Kim},
year={2024},
eprint={2401.08417},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
✨ 主要特性
模型發佈
我們發佈了論文中介紹的六個翻譯模型:
- ALMA - 7B:在 200 億單語詞元上對 LLaMA - 2 - 7B 進行全量權重微調,然後在人工編寫的平行數據上進行全量權重微調。
- ALMA - 7B - LoRA:在 200 億單語詞元上對 LLaMA - 2 - 7B 進行全量權重微調,然後在人工編寫的平行數據上進行LoRA微調。
- ALMA - 7B - R(全新發布!):在 ALMA - 7B - LoRA 的基礎上,使用對比偏好優化進行進一步的 LoRA 微調。
- ALMA - 13B:在 120 億單語詞元上對 LLaMA - 2 - 7B 進行全量權重微調,然後在人工編寫的平行數據上進行全量權重微調。
- ALMA - 13B - LoRA(我們的最佳系統):在 120 億單語詞元上對 LLaMA - 2 - 7B 進行全量權重微調,然後在人工編寫的平行數據上進行LoRA微調。
- ALMA - 13B - R(全新發布!):在 ALMA - 13B - LoRA 的基礎上,使用對比偏好優化進行進一步的 LoRA 微調。
模型檢查點已在 Hugging Face 上發佈:
模型 |
基礎模型鏈接 |
LoRA 鏈接 |
ALMA - 7B |
[haoranxu/ALMA - 7B](https://huggingface.co/haoranxu/ALMA - 7B) |
- |
ALMA - 7B - LoRA |
[haoranxu/ALMA - 7B - Pretrain](https://huggingface.co/haoranxu/ALMA - 7B - Pretrain) |
[haoranxu/ALMA - 7B - Pretrain - LoRA](https://huggingface.co/haoranxu/ALMA - 7B - Pretrain - LoRA) |
ALMA - 7B - R(全新發布!) |
[haoranxu/ALMA - 7B - R (LoRA merged)](https://huggingface.co/haoranxu/ALMA - 7B - R) |
- |
ALMA - 13B |
[haoranxu/ALMA - 13B](https://huggingface.co/haoranxu/ALMA - 13B) |
- |
ALMA - 13B - LoRA |
[haoranxu/ALMA - 13B - Pretrain](https://huggingface.co/haoranxu/ALMA - 13B - Pretrain) |
[haoranxu/ALMA - 13B - Pretrain - LoRA](https://huggingface.co/haoranxu/ALMA - 13B - Pretrain - LoRA) |
ALMA - 13B - R(全新發布!) |
[haoranxu/ALMA - 13B - R (LoRA merged)](https://huggingface.co/haoranxu/ALMA - 13B - R) |
- |
⚠️ 重要提示
請注意,ALMA - 7B - Pretrain
和 ALMA - 13B - Pretrain
不是翻譯模型。它們僅經歷了第一階段的單語微調(7B 模型為 200 億詞元,13B 模型為 120 億詞元),應與它們的 LoRA 模型結合使用。
數據集發佈
ALMA 和 ALMA - R 使用的數據集也已在 Hugging Face 上發佈(全新發布!)
數據集 |
訓練/驗證集 |
測試集 |
人工編寫的平行數據(ALMA) |
[訓練和驗證集](https://huggingface.co/datasets/haoranxu/ALMA - Human - Parallel) |
[WMT'22](https://huggingface.co/datasets/haoranxu/WMT22 - Test) |
三元組偏好數據 |
[訓練集](https://huggingface.co/datasets/haoranxu/ALMA - R - Preference) |
[WMT'22](https://huggingface.co/datasets/haoranxu/WMT22 - Test) 和 [WMT'23](https://huggingface.co/datasets/haoranxu/WMT23 - Test) |
🚀 快速開始
以下是使用 ALMA - 13B - LoRA 系統進行翻譯的快速入門示例,將“我愛機器翻譯。”翻譯成英語:
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM
from transformers import LlamaTokenizer
model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-Pretrain", torch_dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(model, "haoranxu/ALMA-13B-Pretrain-LoRA")
tokenizer = LlamaTokenizer.from_pretrained("haoranxu/ALMA-13B-Pretrain", padding_side='left')
prompt="Translate this from Chinese to English:\nChinese: 我愛機器翻譯。\nEnglish:"
input_ids = tokenizer(prompt, return_tensors="pt", padding=True, max_length=40, truncation=True).input_ids.cuda()
with torch.no_grad():
generated_ids = model.generate(input_ids=input_ids, num_beams=5, max_new_tokens=20, do_sample=True, temperature=0.6, top_p=0.9)
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
print(outputs)
更多詳細信息請參考我們的 GitHub 倉庫。
📄 許可證
本項目採用 MIT 許可證。