-
Notifications
You must be signed in to change notification settings - Fork 17
/
translate.py
executable file
·36 lines (28 loc) · 970 Bytes
/
translate.py
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
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import configargparse
from onmt.utils.logging import init_logger
from onmt.translate.translator import build_translator
import onmt.opts as opts
def main(opt):
translator = build_translator(opt, report_score=True)
translator.translate(
knl=opt.knl,
src=opt.src,
tgt=opt.tgt,
src_dir=opt.src_dir,
batch_size=opt.batch_size,
attn_debug=opt.attn_debug
)
if __name__ == "__main__":
parser = configargparse.ArgumentParser(
description='translate.py',
config_file_parser_class=configargparse.YAMLConfigFileParser,
formatter_class=configargparse.ArgumentDefaultsHelpFormatter)
opts.config_opts(parser)
opts.add_md_help_argument(parser)
opts.translate_opts(parser)
opt = parser.parse_args()
logger = init_logger(opt.log_file)
main(opt)