Example use for translation

#6
by mikahail42 - opened

It will be better to add example use for translation:

model_name = 'Helsinki-NLP/opus-mt-ru-en'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

ru_text = 'привет, мир!'
input_ids = tokenizer.encode(text, return_tensors="pt")
output_ids = model.generate(input_ids, max_new_tokens=100)
en_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print(en_text) # Hello, world!

This comment has been hidden

Thank you for this! One small edit, the 5th line should be input_ids = tokenizer.encode(ru_text, return_tensors="pt")

Sign up or log in to comment