🚀 NLLB-MoE
NLLB-MoE是一个强大的多语言翻译模型,它致力于消除语言障碍,实现跨语言的高效交流,为全球不同语言的用户提供了便捷的翻译解决方案。
🚀 快速开始
NLLB模型在论文 No Language Left Behind: Scaling Human-Centered Machine Translation 中被提出,作者包括Marta R. Costa - jussà、James Cross、Onur Çelebi等众多研究人员。
✨ 主要特性
- 多语言支持:支持多种语言,涵盖了如ace、acm、acq等众多语言代码对应的语言,具体语言详情可参考
language_details
字段。
- 特定训练算法:采用Expert Output Masking进行训练,通过丢弃某些标记的全部贡献来优化模型。
- 多指标评估:使用bleu、spbleu、chrf++等指标进行评估。
📦 安装指南
可用的检查点大约需要350GB的存储空间。如果你的机器内存不足,请确保使用 accelerate
。
💻 使用示例
基础用法
以下示例展示了如何使用 facebook/nllb-moe-54b 模型将英语翻译成法语。注意,这里使用的是法语的BCP - 47代码 fra_Latn
。所有Flores 200数据集中的BCP - 47代码列表可参考 此处。
>>> from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-moe-54b")
>>> model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-moe-54b")
>>> batched_input = [
'We now have 4-month-old mice that are non-diabetic that used to be diabetic," he added.',
"Dr. Ehud Ur, professor of medicine at Dalhousie University in Halifax, Nova Scotia and chair of the clinical and scientific division of the Canadian Diabetes Association cautioned that the research is still in its early days."
"Like some other experts, he is skeptical about whether diabetes can be cured, noting that these findings have no relevance to people who already have Type 1 diabetes."
"On Monday, Sara Danius, permanent secretary of the Nobel Committee for Literature at the Swedish Academy, publicly announced during a radio program on Sveriges Radio in Sweden the committee, unable to reach Bob Dylan directly about winning the 2016 Nobel Prize in Literature, had abandoned its efforts to reach him.",
'Danius said, "Right now we are doing nothing. I have called and sent emails to his closest collaborator and received very friendly replies. For now, that is certainly enough."',
"Previously, Ring's CEO, Jamie Siminoff, remarked the company started when his doorbell wasn't audible from his shop in his garage.",
]
>>> inputs = tokenizer(article, return_tensors="pt", padding = True)
>>> translated_tokens = model.generate(
... **inputs, forced_bos_token_id=tokenizer.lang_code_to_id["fra_Latn"]
... )
>>> tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)
['"Nous avons maintenant des souris de 4 mois non diabétiques qui étaient diabétiques", a-t-il ajouté.',
"Le docteur Ehud Ur, professeur de médecine à l'université Dalhousie, à Halifax, en Nouvelle-Écosse, et président de la division clinique et scientifique de l'Association canadienne du diabète, prévient que la recherche n'en est qu'à ses débuts.",
"Comme d'autres spécialistes, il est sceptique quant à la guérison du diabète, notant que ces résultats ne sont pas pertinents pour les personnes atteintes de diabète de type 1.",
"Lundi, Sara Danius, secrétaire permanente du Comité Nobel de littérature à l'Académie suédoise, a annoncé publiquement lors d'une émission de radio sur Sveriges Radio en Suède que le comité, incapable de contacter Bob Dylan directement au sujet du prix Nobel de littérature 2016, avait abandonné ses efforts pour le joindre.",
"Danius a déclaré: \"Pour le moment, nous ne faisons rien. J'ai appelé et envoyé des courriels à son plus proche collaborateur et j'ai reçu des réponses très amicales. Pour l'instant, c'est certainement suffisant\".",
"Auparavant, le PDG de Ring, Jamie Siminoff, a fait remarquer que la société avait commencé lorsque sa sonnette n'était pas audible depuis son magasin dans son garage.",
"Il a construit une sonnette WiFi, il a dit.",
]
📚 详细文档
- 训练算法:使用Expert Output Masking进行训练,即丢弃某些标记的全部贡献。具体方案如下:

- 更多信息资源:可参考论文NLLB Team et al, No Language Left Behind: Scaling Human-Centered Machine Translation, Arxiv, 2022。
- 许可证:CC - BY - NC
- 问题反馈:如有关于该模型的问题或建议,请访问 此处。
📄 许可证
本模型采用CC - BY - NC - 4.0许可证。
信息表格
属性 |
详情 |
支持语言 |
ace、acm、acq等众多语言 |
数据集 |
flores - 200 |
评估指标 |
bleu、spbleu、chrf++ |
许可证 |
CC - BY - NC - 4.0 |
常用提示信息
⚠️ 重要提示
生成目标文本时,请将 forced_bos_token_id
设置为目标语言的ID。
💡 使用建议
如果你的机器内存不足,请使用 accelerate
来运行模型。