Translation
Transformers
PyTorch
nllb-moe
feature-extraction
How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
# Warning: Pipeline type "translation" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline

pipe = pipeline("translation", model="facebook/nllb-moe-54b")
# Load model directly
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-moe-54b")
model = AutoModel.from_pretrained("facebook/nllb-moe-54b", device_map="auto")
Quick Links

NLLB-MoE

This is the model card of NLLB-MoE variant.

  • Information about training algorithms, parameters, fairness constraints or other applied approaches, and features. The exact training algorithm, data and the strategies to handle data imbalances for high and low resource languages that were used to train NLLB-200 is described in the paper.
  • Paper or other resource for more information NLLB Team et al, No Language Left Behind: Scaling Human-Centered Machine Translation, Arxiv, 2022
  • License: CC-BY-NC
  • Where to send questions or comments about the model: https://github.com/facebookresearch/fairseq/issues

The NLLB model was presented in No Language Left Behind: Scaling Human-Centered Machine Translation by Marta R. Costa-jussร , James Cross, Onur ร‡elebi, Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, Anna Sun, Skyler Wang, Guillaume Wenzek, Al Youngblood, Bapi Akula, Loic Barrault, Gabriel Mejia Gonzalez, Prangthip Hansanti, John Hoffman, Semarley Jarrett, Kaushik Ram Sadagopan, Dirk Rowe, Shannon Spruit, Chau Tran, Pierre Andrews, Necip Fazil Ayan, Shruti Bhosale, Sergey Edunov, Angela Fan, Cynthia Gao, Vedanuj Goswami, Francisco Guzmรกn, Philipp Koehn, Alexandre Mourachko, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, and Jeff Wang.

Training:

  • The Expert Output Masking is used for training, which consists in droping the full contribution for some tokens. This corresponds to the following scheme: EOM

Generating with NLLB-MoE

The avalable checkpoints requires around 350GB of storage. Make sure to use accelerate if you do not have enough RAM on your machine.

While generating the target text set the forced_bos_token_id to the target language id. The following example shows how to translate English to French using the facebook/nllb-moe-54b model.

Note that we're using the BCP-47 code for French fra_Latn. See here for the list of all BCP-47 in the Flores 200 dataset.

>>> 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.",
]
Downloads last month
6,598
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Spaces using facebook/nllb-moe-54b 9

Paper for facebook/nllb-moe-54b