🚀 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许可证。