🚀 NLLB - MoE
NLLB - MoE 是一款在機器翻譯領域表現出色的模型。它支持眾多語言,通過升級相關組件提升了加載速度,雖推理速度較慢,但仍是當前開源機器翻譯的前沿模型。
🚀 快速開始
此模型的運行需將 bitsandbytes
升級到最新版本,並安裝 hf transformers
的這個拉取請求:https://github.com/huggingface/transformers/pull/26037。它僅需 37GB 的顯存,加載時間從 15 分鐘縮短至約 20 秒,不過推理速度較慢。
✨ 主要特性
- 多語言支持:支持眾多語言,包括 ace、acm、acq 等多種語言。
- 訓練優化:採用 Expert Output Masking 進行訓練,通過丟棄某些標記的全部貢獻來優化模型。
- 前沿成果:是當前開源機器翻譯領域的前沿模型。
📦 安裝指南
要使用此模型,需將 bitsandbytes
升級到最新版本,並安裝 hf transformers
的這個拉取請求:https://github.com/huggingface/transformers/pull/26037。
💻 使用示例
基礎用法
以下示例展示瞭如何使用 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(batched_input, 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 進行訓練,該方法通過丟棄某些標記的全部貢獻來優化模型訓練過程。
- 資源需求:模型運行需要將
bitsandbytes
升級到最新版本,並安裝 hf transformers
的特定拉取請求。運行時需要 37GB 的 VRAM,加載時間約 20 秒。可用的檢查點大約需要 350GB 的存儲空間。
📄 許可證
本模型使用的許可證為 CC - BY - NC - 4.0。
補充信息
屬性 |
詳情 |
支持語言 |
ace、acm、acq 等眾多語言 |
數據集 |
flores - 200 |
評估指標 |
bleu、spbleu、chrf++ |
推理功能 |
不可用 |
訓練算法 |
Expert Output Masking |
論文引用 |
NLLB Team et al, No Language Left Behind: Scaling Human - Centered Machine Translation, Arxiv, 2022 |
問題反饋地址 |
https://github.com/facebookresearch/fairseq/issues |