-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.py
30 lines (22 loc) · 1.01 KB
/
main.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
import csv
import argparse
from trainer import Trainer
from utils import load_dataset, make_iter, Params
def main(config):
params = Params('config/params.json')
if config.mode == 'train':
train_data, valid_data = load_dataset(config.mode)
train_iter, valid_iter = make_iter(params.batch_size, config.mode,
train_data=train_data, valid_data=valid_data)
trainer = Trainer(params, config.mode, train_iter=train_iter, valid_iter=valid_iter)
trainer.train()
else:
test_data = load_dataset(config.mode)
test_iter = make_iter(params.batch_size, config.mode, test_data=test_data)
trainer = Trainer(params, config.mode, test_iter=test_iter)
trainer.inference()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Transformer Neural Machine Translation')
parser.add_argument('--mode', type=str, default='train', choices=['train', 'test'])
args = parser.parse_args()
main(args)