|
from transformers import MarianMTModel, MarianTokenizer |
|
|
|
|
|
model_path = "/content/tst-translation/checkpoint-9" |
|
model = MarianMTModel.from_pretrained(model_path) |
|
tokenizer = MarianTokenizer.from_pretrained(model_path) |
|
|
|
|
|
sentence = "Others have dismissed him as a joke." |
|
|
|
|
|
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True) |
|
|
|
|
|
translated = model.generate(**inputs) |
|
translated_sentence = tokenizer.batch_decode(translated, skip_special_tokens=True)[0] |
|
|
|
print("الجملة المترجمة:", translated_sentence) |
|
|