

from transformers import MarianMTModel, MarianTokenizer
src_text = [
     ">>fr<< this is a sentence in english that we want to translate to french",
     ">>pt<< This should go to portuguese",
     ">>es<< And this to Spanish",
 ]
model_name = "Helsinki-NLP/opus-mt-en-ROMANCE"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
translated = model.generate(**tokenizer(src_text, return_tensors="pt", padding=True))
tgt_text = [tokenizer.decode(t, skip_special_tokens=True) for t in translated]
["c'est une phrase en anglais que nous voulons traduire en français", 
 'Isto deve ir para o português.',
 'Y esto al español']