sdyy commited on
Commit
bb3938a
1 Parent(s): d3e9bcc

Create promp_translat.py

Browse files
Files changed (1) hide show
  1. promp_translat.py +18 -0
promp_translat.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import MarianMTModel, MarianTokenizer
2
+
3
+ # تحميل نموذج الترجمة
4
+ model_path = "/content/tst-translation/checkpoint-9"
5
+ model = MarianMTModel.from_pretrained(model_path)
6
+ tokenizer = MarianTokenizer.from_pretrained(model_path)
7
+
8
+ # الجملة التي تريد ترجمتها
9
+ sentence = "Others have dismissed him as a joke."
10
+
11
+ # تحويل الجملة إلى توكنات
12
+ inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True)
13
+
14
+ # الترجمة
15
+ translated = model.generate(**inputs)
16
+ translated_sentence = tokenizer.batch_decode(translated, skip_special_tokens=True)[0]
17
+
18
+ print("الجملة المترجمة:", translated_sentence)