Skip to content

Instantly share code, notes, and snippets.

@ArthurZucker
Last active April 28, 2023 12:51
Show Gist options
  • Save ArthurZucker/62656a3a143b1e709bc44e8293b2543b to your computer and use it in GitHub Desktop.
Save ArthurZucker/62656a3a143b1e709bc44e8293b2543b to your computer and use it in GitHub Desktop.
nllb_moe_gist
>>> from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-moe-54b")
>>> model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-moe-54b", device_map = "auto")
>>> article = "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")
>>> translated_tokens = model.generate(**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["fra_Latn"], max_length=50)
>>> tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
"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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment