🚀 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中使用的監督微調不同,它使用我們提出的對比偏好優化(Contrastive Preference Optimization,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、ALMA - 7B - LoRA、ALMA - 7B - R、ALMA - 13B、ALMA - 13B - LoRA和ALMA - 13B - R等多種模型,滿足不同需求。
- 性能卓越:ALMA - R通過對比偏好優化進一步提升性能,可與GPT - 4或WMT獲勝模型相媲美。
📦 安裝指南
文檔未提供具體安裝步驟,可跳過此章節。
💻 使用示例
基礎用法
以下是使用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)
📚 詳細文檔
模型發佈
我們發佈了論文中介紹的六個翻譯模型:
- 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) |
🔧 技術細節
文檔未提供具體技術實現細節,可跳過此章節。
📄 許可證
本項目採用MIT許可證。