How can I run the model in python?
#11
by
Sohaib36
- opened
How can I run the model ?
Check this link: https://huggingface.co/docs/transformers/model_doc/marian
from transformers import MarianMTModel, MarianTokenizer
src_text = [
"你好。",
"今天天气非常棒!",
"心情好是最重要的。",
]
model_name = "Helsinki-NLP/opus-mt-zh-en"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
translated = model.generate(**tokenizer(src_text, return_tensors="pt", padding=True))
res = [tokenizer.decode(t, skip_special_tokens=True) for t in translated]
print(res)
the result is:
['Hello.', "It's a beautiful day!", 'Good moods are the most important.']