succ_translation_trainer_cpu / promp_translat.py
sdyy's picture
Create promp_translat.py
bb3938a verified
raw
history blame
686 Bytes
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)