-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_model.py
204 lines (157 loc) · 6.88 KB
/
base_model.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import argparse
import os
from model.model_manager import ModelManager
DEFAULT_BATCH_SIZE = 32
DEFAULT_PERFORM_SHUFFLE = True
DEFAULT_NUM_EPOCHS = 10000
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def bool_arguments(value):
return True if int(value) == 1 else False
def create_argument_parser():
parser = argparse.ArgumentParser()
parser.add_argument('-tr',
'--train-file',
type=str,
help='The location of the train file',
required=True)
parser.add_argument('-v',
'--validation-file',
type=str,
help='The location of the validation file',
required=True)
parser.add_argument('-ts',
'--test-file',
type=str,
help='The location of the test file',
required=True)
parser.add_argument('-sm',
'--saved-model-folder',
type=str,
help='Location to search/save models. The model name variable will be used for searching') # noqa
parser.add_argument('-shs',
'--should-save',
type=bool_arguments,
help='If the model should be saved')
parser.add_argument('-nt',
'--num-train',
type=int,
help='Number of training examples')
parser.add_argument('-nv',
'--num-validation',
type=int,
help='Number of validation examples')
parser.add_argument('-nte',
'--num-test',
type=int,
help='Number of test examples')
parser.add_argument('-uv',
'--use-validation',
type=bool_arguments,
help='If the model should provide accuracy measurements using validation set') # noqa
parser.add_argument('-umd',
'--use-mc-dropout',
type=bool_arguments,
help='If we will evaluate the model using MC Dropout')
parser.add_argument('-gd',
'--graphs-dir',
type=str,
help='The location of the graphs dir')
parser.add_argument('-mn',
'--model-name',
type=str,
help='The model name that will be used to save tensorboard information')
parser.add_argument('-td',
'--tensorboard-dir',
type=str,
help='Directory to save tensorboard information')
parser.add_argument('-ef',
'--embedding-file',
type=str,
help='The path of the embedding file')
parser.add_argument('-ekl',
'--embedding-pickle',
type=str,
help='The path of embedding matrix pickle file')
parser.add_argument('-lr',
'--learning-rate',
type=float,
help='The learning rate to use during training')
parser.add_argument('-bs',
'--batch-size',
type=int,
default=DEFAULT_BATCH_SIZE,
help='The batch size used for stochastic gradient descent')
parser.add_argument('-np',
'--num-epochs',
type=int,
default=DEFAULT_NUM_EPOCHS,
help='Number of epochs to train the model')
parser.add_argument('-ps',
'--perform-shuffle',
type=bool_arguments,
default=DEFAULT_PERFORM_SHUFFLE,
help='If the dataset should be shuffled before using it')
parser.add_argument('-es',
'--embed-size',
type=int,
help='The embedding size of the embedding matrix')
parser.add_argument('-nu',
'--num-units',
type=int,
help='The number of hidden units in the Recurrent layer')
parser.add_argument('-nc',
'--num-classes',
type=int,
help='The number of classification classes')
parser.add_argument('-lid',
'--recurrent-input-dropout',
type=float,
help='Dropout value for inputs in the network')
parser.add_argument('-lod',
'--recurrent-output-dropout',
type=float,
help='Dropout value for Recurrent output')
parser.add_argument('-lsd',
'--recurrent-state-dropout',
type=float,
help='Dropout value for recurrent state (variational dropout)')
parser.add_argument('-ed',
'--embedding-dropout',
type=float,
help='Dropout value for embedding layer')
parser.add_argument('-cp',
'--clip-gradients',
type=bool_arguments,
help='If gradient clipping should be performed')
parser.add_argument('-mxn',
'--max-norm',
type=int,
help='The max norm to clip the gradients, if --clip-gradients=True')
parser.add_argument('-wd',
'--weight-decay',
type=float,
help='Weight Decay value for L2 regularizer')
parser.add_argument('-bw',
'--bucket-width',
type=int,
help='The width use to define a bucket id for a given movie review')
parser.add_argument('-nb',
'--num-buckets',
type=int,
help='The maximum number of buckets allowed')
parser.add_argument('-ut',
'--use-test',
type=bool_arguments,
help='Define if the model should check accuracy on test dataset')
parser.add_argument('-sg',
'--save-graph',
type=bool_arguments,
help='Define if an accuracy graph should be saved')
return parser
def main():
parser = create_argument_parser()
user_args = vars(parser.parse_args())
model_manager = ModelManager(user_args)
model_manager.run_model()
if __name__ == '__main__':
main()