Skip to content

Instantly share code, notes, and snippets.

@gamingflexer
Created August 28, 2022 14:55
Show Gist options
  • Save gamingflexer/d90b802b328334c69e62ac0ecaf207d4 to your computer and use it in GitHub Desktop.
Save gamingflexer/d90b802b328334c69e62ac0ecaf207d4 to your computer and use it in GitHub Desktop.
NLLB FB 200 Language Translator
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
#for source and target lang check this - https://github.com/facebookresearch/flores/tree/main/flores200#languages-in-flores-200
def translation(text,src_lang,tgt_lang):
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length = 400)
return translator(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment