upload missing translate.py file
Browse files- translate.py +18 -0
translate.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ctranslate2
|
2 |
+
import sys
|
3 |
+
|
4 |
+
|
5 |
+
model = sys.argv[1]
|
6 |
+
file_name = sys.argv[2]
|
7 |
+
|
8 |
+
file = open(file_name, 'r')
|
9 |
+
|
10 |
+
translator = ctranslate2.Translator(model, device="cuda")
|
11 |
+
|
12 |
+
for line in file:
|
13 |
+
line = line.strip()
|
14 |
+
r = translator.translate_batch(
|
15 |
+
[line.split()], replace_unknowns=True, beam_size=5, batch_type='examples'
|
16 |
+
)
|
17 |
+
results =' '.join(r[0].hypotheses[0])
|
18 |
+
print(results)
|