-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
98 lines (58 loc) · 3.17 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 13 14:24:16 2018
@author: piesauce
"""
import tensorflow as tf
import json
from utils import Data
from CharCNN1 import CharCNN1
from CharCNN2 import CharCNN2
from CharTCN import CharTCN
tf.flags.DEFINE_string("m", "CharCNN1", "Select between models CharCNN1, CharCNN2, and CharTCN")
FLAGS = tf.flags.FLAGS
FLAGS._parse_flags()
if __name__ == "__main__":
config = json.load(open("config.json"))
train_data = Data(path=config["data"]["train_path"],
input_size=config["data"]["input_size"],
vocab=config["data"]["vocab"],
num_classes=config["data"]["num_classes"])
X_train, y_train = train_data.load()
dev_data = Data(path=config["data"]["dev_path"],
input_size=config["data"]["input_size"],
vocab=config["data"]["vocab"],
num_classes=config["data"]["num_classes"])
X_dev, y_dev = dev_data.load()
if FLAGS.m == "CharCNN1":
m = CharCNN1(input_size=config["data"]["input_size"],
vocab_size=config["data"]["vocab_size"],
embedding_size=config["data"]["embedding_size"],
num_classes=config["data"]["num_classes"],
conv_layers=config["cnn1"]["conv_layers"],
fc_layers=config["cnn1"]["fc_layers"],
optim_alg=config["cnn1"]["optim_alg"],
loss_fnc=config["cnn1"]["loss_fnc"],
drop_prob=config["cnn1"]["drop_prob"])
elif FLAGS.m == "cnn2":
m = CharCNN2(input_size=config["data"]["input_size"],
vocab_size=config["data"]["vocab_size"],
embedding_size=config["data"]["embedding_size"],
num_classes=config["data"]["num_classes"],
conv_layers=config["cnn2"]["conv_layers"],
fc_layers=config["cnn2"]["fc_layers"],
optim_alg=config["cnn2"]["optim_alg"],
loss_fnc=config["cnn2"]["loss_fnc"],
drop_prob=config["cnn2"]["drop_prob"])
else:
m = CharTCN(input_size=config["data"]["input_size"],
vocab_size=config["data"]["vocab_size"],
embedding_size=config["data"]["embedding_size"],
num_classes=config["data"]["num_classes"],
conv_layers=config["cnn3"]["conv_layers"],
fc_layers=config["cnn3"]["fc_layers"],
optim_alg=config["cnn3"]["optim_alg"],
loss_fnc=config["cnn3"]["loss_fnc"],
drop_prob=config["cnn3"]["drop_prob"],
m.train(X_train=X_train, y_train=y_train, X_dev=X_dev, y_dev=y_dev,
epochs=config["params"]["epochs"], batch_size=config["params"]["batch_size"])