forked from lavis-nlp/spert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spert.py
54 lines (38 loc) · 1.64 KB
/
spert.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse
from args import train_argparser, eval_argparser, predict_argparser
from config_reader import process_configs
from spert import input_reader
from spert.spert_trainer import SpERTTrainer
def _train():
arg_parser = train_argparser()
process_configs(target=__train, arg_parser=arg_parser)
def __train(run_args):
trainer = SpERTTrainer(run_args)
trainer.train(train_path=run_args.train_path, valid_path=run_args.valid_path,
types_path=run_args.types_path, input_reader_cls=input_reader.JsonInputReader)
def _eval():
arg_parser = eval_argparser()
process_configs(target=__eval, arg_parser=arg_parser)
def __eval(run_args):
trainer = SpERTTrainer(run_args)
trainer.eval(dataset_path=run_args.dataset_path, types_path=run_args.types_path,
input_reader_cls=input_reader.JsonInputReader)
def _predict():
arg_parser = predict_argparser()
process_configs(target=__predict, arg_parser=arg_parser)
def __predict(run_args):
trainer = SpERTTrainer(run_args)
trainer.predict(dataset_path=run_args.dataset_path, types_path=run_args.types_path,
input_reader_cls=input_reader.JsonPredictionInputReader)
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(add_help=False)
arg_parser.add_argument('mode', type=str, help="Mode: 'train' or 'eval'")
args, _ = arg_parser.parse_known_args()
if args.mode == 'train':
_train()
elif args.mode == 'eval':
_eval()
elif args.mode == 'predict':
_predict()
else:
raise Exception("Mode not in ['train', 'eval', 'predict'], e.g. 'python spert.py train ...'")