🚀 [ALMA-R:基於對比偏好優化的機器翻譯模型]
ALMA-R 是在 ALMA 模型 的基礎上進一步發展而來。與 ALMA 採用的監督微調不同,ALMA-R 通過我們提出的 對比偏好優化(Contrastive Preference Optimization,CPO) 進行 LoRA 微調。CPO 微調需要使用我們的 三元組偏好數據 進行偏好學習。目前,ALMA-R 在性能上已經能夠與 GPT - 4 或 WMT 獲勝模型相媲美,甚至超越它們!
📄 許可證
本項目採用 MIT 許可證。
📚 引用信息
@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}
}
@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 - 7B
- ALMA - 7B - LoRA
- ALMA - 7B - R(新!):在 ALMA - 7B - LoRA 的基礎上,通過對比偏好優化進行進一步的 LoRA 微調。
- ALMA - 13B
- ALMA - 13B - 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 - R)進行翻譯的快速入門示例,將“我愛機器翻譯。”翻譯成英語:
import torch
from transformers import AutoModelForCausalLM
from transformers import AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-R", torch_dtype=torch.float16, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("haoranxu/ALMA-13B-R", 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 倉庫 中查找更多詳細信息。