File size: 646 Bytes
18d0ab4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import ctranslate2
import sys


model = sys.argv[1]
file_name = sys.argv[2]

file = open(file_name, 'r')

translator = ctranslate2.Translator(model, device="cuda")
#translator = ctranslate2.Translator(model, device="cpu")

for line in file:  
    line = line.strip()
    #line = line.split()
   # r = translator.translate_batch([line], beam_size=5, batch_type='examples')
    r = translator.translate_batch(
            [line.split()], replace_unknowns=True,  beam_size=5, batch_type='examples'
        )
    results =' '.join(r[0].hypotheses[0]) 
   # results =' '.join(r[0][0]['tokens'])

#   print(results[0].hypotheses[0])
    print(results)