Uh oh!
There was an error while loading. Please reload this page.
forked from tech-srl/code2seq
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2seq.py
More file actions
Latest commit
50 lines (44 loc) · 1.97 KB
/
Copy pathcode2seq.py
File metadata and controls
50 lines (44 loc) · 1.97 KB
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
fromargparseimportArgumentParser
importnumpyasnp
importtensorflowastf
fromconfigimportConfig
frominteractive_predictimportInteractivePredictor
frommodelimportModel
if__name__=='__main__':
parser=ArgumentParser()
parser.add_argument("-d", "--data", dest="data_path",
help="path to preprocessed dataset", required=False)
parser.add_argument("-te", "--test", dest="test_path",
help="path to test file", metavar="FILE", required=False)
parser.add_argument("-s", "--save_prefix", dest="save_path_prefix",
help="path to save file", metavar="FILE", required=False)
parser.add_argument("-l", "--load", dest="load_path",
help="path to saved file", metavar="FILE", required=False)
parser.add_argument('--release', action='store_true',
help='if specified and loading a trained model, release the loaded model for a smaller model '
'size.')
parser.add_argument('--predict', action='store_true')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--seed', type=int, default=239)
args=parser.parse_args()
np.random.seed(args.seed)
tf.set_random_seed(args.seed)
ifargs.debug:
config=Config.get_debug_config(args)
else:
config=Config.get_default_config(args)
model=Model(config)
print('Created model')
ifconfig.TRAIN_PATH:
model.train()
ifconfig.TEST_PATHandnotargs.data_path:
results, precision, recall, f1, rouge=model.evaluate()
print('Accuracy: '+str(results))
print('Precision: '+str(precision) +', recall: '+str(recall) +', F1: '+str(f1))
print('Rouge: ', rouge)
ifargs.predict:
predictor=InteractivePredictor(config, model)
predictor.predict()
ifargs.releaseandargs.load_path:
model.evaluate(release=True)
model.close_session()