-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
565 lines (445 loc) · 24.7 KB
/
train.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
'''Training script which can be used to train the model for the problems.'''
import tensorflow as tf
import os
import random
import matplotlib.pyplot as plt
import numpy as np
import hyperparms
import dataset
import model
import argparse
import seaborn as sns
import io
import warnings
from datetime import datetime
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras import backend as K
from tensorflow.keras.callbacks import ReduceLROnPlateau
from PIL import Image
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
tf.get_logger().setLevel('ERROR')
warnings.filterwarnings("ignore")
tf.autograph.set_verbosity(1)
class Train():
'''
This class gives us useful methods to train our model
Attributes:
optimizer: the optimizer that we want to use. Any one from tf.keras.optimizers
loss_function: Loss function to be used for training. Any one from tf.keras.losses
metric: List of metrics we want to test our model on . Any one from tf.keras.losses
train_data: Training data used for training our model
test_data: Test Data used for training our model
batch_size: The batch size for our dataset
learning_rate: The learning rate to be used for training
epochs: Number of epochs to train our model for
'''
def __init__(self, args, train_data, test_data, batch_size):
'''Initializes variables'''
self.args = args
self.seq_len = args.seq_length
self.optimizer = tf.keras.optimizers.get(args.optimizer)
self.loss_function = args.loss_function
self.metric = args.metric
self.train_dataset = train_data
self.test_dataset = test_data
self.batch_size = batch_size
self.learning_rate = args.learning_rate
self.epochs = args.epochs
self.problem_id = args.problem_id
self.config = hyperparms.Config(self.args.num_heads, self.args.num_layers, self.args.emb_dim, self.args.seq_length, self.args.vocab_size, self.args.head_size, self.args.pos_embedding, self.args.agg_method, self.args.pos_embedding_type)
def create_model(self):
'''Creates a Model object and returns it'''
config = self.config
if(config['agg_method'] == 'TOKEN'):
input_shape = (config['seq_length'] + 1)
else:
input_shape = (config['seq_length'])
input = Input(input_shape, dtype='int64')
op, att_scores = model._Model(config['emb_dim'], config['seq_length'], config['vocab_size'], config['pos_embedding'], config['num_heads'], config['head_size'], config['agg_method'], config['pos_embedding_type'], config['num_att_layers'])(input)
if(self.args.problem_id in [1,2,4,7]):
output = Dense(1)(op)
elif(self.args.problem_id in [5,6]):
output = Dense(2, activation='softmax')(op)
else:
output = Dense(config['vocab_size'], activation = 'softmax')(op)
att_model = Model(inputs = input, outputs=output)
print(att_model.summary())
return att_model
def get_lr_range(self, total_epoch = 3, show_plot = True):
'''
This method helps us to select a appropriate lr for our training
Using a custom call back , we train our model for 3 epochs and change the
learning rate after each batch update. At the end the plot will tell us the
learning rate range between which our loss was reducing.
'''
model = self.create_model()
lr = []
losses = []
class LrCallback(tf.keras.callbacks.Callback):
'''
Custom call back for getting our learning rate range
Attributes:
train_data: Training data used for training our model
batch_size: The batch size for our dataset
total_epoch: total epochs to runb our model
'''
def __init__(self,train_data,batch_size, total_epoch = 3):
'''Initilaizes variables'''
self.X_train = train_data
self.batch_size = batch_size
self.total_epoch = total_epoch
self._chief_worker_only = None
def on_train_begin(self, logs={}):
## on begin of training, we are creating a instance varible called history
## it is a dict with keys [loss, acc, val_loss, val_acc]
self.history={'loss': [],'acc': [],'val_loss': [],'val_acc': [],'AUC':[],'val_AUC':[]}
def on_epoch_end(self, epoch, logs={}):
pass
def on_batch_begin(self,batch,logs):
pass
def on_batch_end(self,batch,logs):
'''
Here we will try to find out our learning rate range
We will try to increase our learning rate slowly after each batch update,
and will store the loss after each batch along with the learning rate.
Plotting these two values will give us an idea about our learning rate
'''
'''getting loss after batch has ended'''
l = logs['loss']
'''getting the learning rate corresponding to the loss'''
lr.append(K.get_value(self.model.optimizer.lr))
losses.append(l)
'''we will start from small lr e-10 to e10 and check our plot for these values'''
start_lr = self.config['lr_range'][0]
end_lr = self.config['lr_range'][1]
'''Number of batch updates in each epoch'''
#step_size = (len(self.X_train) // self.batch_size)
step_size = len(self.X_train)
'''total batch updates across all epochs'''
iter = (self.total_epoch*step_size)
'''used to increase our lr exponentialy'''
LRmult = (end_lr/start_lr)**(1/iter)
'''calculating new lr'''
new_lr = K.get_value(self.model.optimizer.lr)*LRmult
'''setting new lr for our next batch'''
K.set_value(self.model.optimizer.lr, new_lr)
lr_callback = LrCallback(self.train_dataset, self.batch_size)
self.optimizer.learning_rate = self.config['lr_range'][0]
model = self.create_model()
model.compile(optimizer= self.optimizer, loss=self.loss_function, metrics = self.metric)
model.fit(self.train_dataset, epochs = self.total_epoch, validation_data = self.test_dataset, steps_per_epoch = len(self.train_dataset), callbacks=[lr_callback])
if(show_plot):
plt.plot(lr, losses)
plt.xscale("log")
plt.xlabel("Learning Rate (Log Scale)")
plt.ylabel("Loss")
plt.show()
return lr, losses
def train_model(self):
'''
This function trains our model using the parmeters defined in the class
and returns the loss values for each epoch
'''
class attPlotsCallback(tf.keras.callbacks.Callback):
def __init__(self, log_dir, test_data, problem_id, seq_len):
self.file_writer = tf.summary.create_file_writer(log_dir)
self.test_data = test_data
self.problem_id = problem_id
self.seq_len = seq_len
self.images = None
def plot_to_image(self, figure):
"""Converts the matplotlib plot specified by 'figure' to a PNG image and
returns it. The supplied figure is closed and inaccessible after this call."""
# Save the plot to a PNG in memory.
buf = io.BytesIO()
plt.savefig(buf, format='png')
# Closing the figure prevents it from being displayed directly inside
# the notebook.
plt.close(figure)
buf.seek(0)
# Convert PNG buffer to TF image
image = tf.image.decode_png(buf.getvalue(), channels=4)
# Add the batch dimension
image = tf.expand_dims(image, 0)
return image
def on_epoch_end(self, epoch, logs=None):
"""Runs metrics and histogram summaries at epoch end."""
def plot(axes, mat, data_point, problem_id, target=None):
axes.matshow(mat, cmap='viridis' )
if(problem_id == 1):
axes.set_title('epoch {} layer {}, head {}'.format(epoch, i, j))
axes.set_xticks(ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 3])
axes.set_yticks(ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 3])
axes.set_xticklabels([3,3])
axes.set_yticklabels([3,3])
elif(problem_id == 2):
axes.set_title('epoch {} layer {}, head {}'.format(epoch, i, j))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 2]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 2]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels([2 for i in x_ticks])
axes.set_yticklabels([2 for i in y_ticks])
elif(problem_id == 3):
axes.set_title('epoch {} layer {}, head {}'.format(epoch, i, j))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == target]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == target]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels([target for i in x_ticks])
axes.set_yticklabels([target for i in y_ticks])
elif(problem_id == 4):
axes.set_title('epoch {} layer {}, head {}'.format(epoch, i, j))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 1]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 1]
axes.set_xticks(ticks = [x_ticks[0],x_ticks[-1]])
axes.set_yticks(ticks = [y_ticks[0], y_ticks[-1]])
axes.set_xticklabels([1,1])
axes.set_yticklabels([1,1])
elif(problem_id == 7 or problem_id == 8 or problem_id == 5 or problem_id == 6):
axes.set_title('epoch {} layer {}, head {}'.format(epoch, i, j))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
x_labels = [_ for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels(x_labels)
axes.set_yticklabels(x_labels)
elif(problem_id == 9):
axes.set_title('Inference Plots prob_id {}\n'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
x_labels = [_ for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels(x_labels)
axes.set_yticklabels(x_labels)
data_point = None
for batch in self.test_data:
data_point = batch[0][:1]
target = batch[1].numpy()[0]
break
_ , att_scores = self.model.layers[1](data_point)
index = 0
fig, ax = plt.subplots(att_scores.shape[0], att_scores.shape[2], figsize=(16,16))
if(self.problem_id in [1,2,3,4,5,6,7,8,9]):
for i in range(att_scores.shape[0]):
for j in range(att_scores.shape[2]):
if (att_scores.shape[0] > 1 and att_scores.shape[2] > 1):
plot(ax[i][j], att_scores[i][0][j], data_point, self.problem_id, target)
elif(att_scores.shape[0] == 1 and att_scores.shape[2] > 1):
plot(ax[j], att_scores[i][0][j], data_point, self.problem_id, target)
elif(att_scores.shape[0] > 1 and att_scores.shape[2] == 1):
plot(ax[i], att_scores[i][0][j], data_point, self.problem_id, target)
else:
plot(ax, att_scores[i][0][j], data_point, self.problem_id, target)
if(self.images is not None):
self.images = tf.concat([self.images, self.plot_to_image(fig)], axis = 0)
else:
self.images = self.plot_to_image(fig)
with self.file_writer.as_default():
tf.summary.image("Training data", self.images, step=0, max_outputs = 500)
model = self.create_model()
logdir = self.config['log_dir']
checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
verbose=1)
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir = logdir, histogram_freq = 1)
att_plots = attPlotsCallback(logdir, self.test_dataset, self.problem_id, self.seq_len)
file_writer = tf.summary.create_file_writer(logdir)
self.optimizer.learning_rate = self.learning_rate
model.compile(optimizer= self.optimizer, loss=self.loss_function, metrics = self.metric)
history = model.fit(self.train_dataset, epochs = self.epochs, validation_data = self.test_dataset, steps_per_epoch = len(self.train_dataset), callbacks=[tensorboard_callback,
att_plots, cp_callback])
return model, history
class Test():
'''
This class helps us in testing our model.
The class helps in inferring a model and also plot the attention scores for our model
Attributes:
data_point: Test data points for which we want to test our model
model: trained model object which is used for inferenece and plotting attention scores
'''
def __init__(self, model, test_dataset, problem_id, seq_len):
''' Initializes the variables '''
self.model = model
self.test_dataset = test_dataset
self.problem_id = problem_id
self.seq_len = seq_len
def infer(self):
''' Gives prediction for the data points given by model '''
return self.model(self.data_point)
def scatter_plot(self):
predictions = []
actual = []
for b in self.test_dataset:
predictions.append(self.model.predict(b[0]))
actual.append(b[1])
predictions = tf.convert_to_tensor(predictions, dtype='float32')
actual = tf.convert_to_tensor(actual, dtype='float32')
predictions = tf.reshape(tf.squeeze(predictions), (tf.shape(predictions)[0]*tf.shape(predictions)[1],))
actual = tf.reshape(actual, tf.shape(actual)[0]*tf.shape(actual)[1])
plt.scatter(actual, predictions)
plt.xlabel('Actual')
plt.ylabel('Predictions')
plt.legend()
plt.savefig('scatter_plot.png')
def plot(self, axes, mat, data_point, problem_id, target=None):
axes.matshow(mat, cmap='viridis' )
if(problem_id == 1):
axes.set_title('Inference Plots prob_id {}'.format(problem_id))
axes.set_xticks(ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 3])
axes.set_yticks(ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 3])
axes.set_xticklabels([3,3])
axes.set_yticklabels([3,3])
elif(problem_id == 2):
axes.set_title('Inference Plots prob_id {}'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 2]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 2]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels([2 for i in x_ticks])
axes.set_yticklabels([2 for i in y_ticks])
elif(problem_id == 3):
axes.set_title('Inference Plots prob_id {}\n'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == target]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == target]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels([target for i in x_ticks])
axes.set_yticklabels([target for i in y_ticks])
elif(problem_id == 4):
axes.set_title('Inference Plots prob_id {}\n'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 1]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ == 1]
axes.set_xticks(ticks = [x_ticks[0],x_ticks[-1]])
axes.set_yticks(ticks = [y_ticks[0], y_ticks[-1]])
axes.set_xticklabels([1,1])
axes.set_yticklabels([1,1])
elif(problem_id == 7 or problem_id == 8 or problem_id == 5 or problem_id == 6):
axes.set_title('Inference Plots prob_id {}\n'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
x_labels = [_ for i,_ in enumerate(data_point[0].numpy()) if _ != 0]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels(x_labels)
axes.set_yticklabels(x_labels)
elif(problem_id == 9):
axes.set_title('Inference Plots prob_id {}\n'.format(problem_id))
x_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
y_ticks = [i for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
x_labels = [_ for i,_ in enumerate(data_point[0].numpy()) if _ != 11]
axes.set_xticks(ticks = x_ticks)
axes.set_yticks(ticks = y_ticks)
axes.set_xticklabels(x_labels)
axes.set_yticklabels(x_labels)
def attention_plots(self, layer=0, input_index=0):
'''
Plots heatmaps for our attention scores for a particular layer and input
layer: layer number for which we want to plot attention scores
input_index: input index for which we want to plot attention plots. In case of batch of inputs is sent
'''
data_point = None
for b in self.test_dataset:
num_points = len(b[0])
ind = random.randint(0,num_points-1)
data_point = b[0][ind]
target = b[1].numpy()[ind]
break
prediction = self.model(tf.expand_dims(data_point, axis=0))
_ , att_scores = self.model.layers[1](tf.expand_dims(data_point, axis=0))
if(self.problem_id in [1,2,4,7]):
print(f'Prediction: {prediction}')
else:
print(f'Prediction: {np.argmax(prediction[0])}')
layer_att_scores = att_scores[-1]
input_att_scores = layer_att_scores[input_index]
num_heads = input_att_scores.shape[0]
fig, ax = plt.subplots(1, num_heads, figsize=(16,16))
if(num_heads > 1):
for index,axes in enumerate(ax):
head_att_score = input_att_scores[index]
self.plot(axes, head_att_score, tf.expand_dims(data_point, axis=0), self.problem_id, target)
else:
self.plot(ax, input_att_scores[0], tf.expand_dims(data_point, axis=0), self.problem_id, target)
plt.savefig('infer.png')
def _train(args):
print(f"Training/Inference for problem id {args.problem_id}")
if(args.problem_id == 1):
dataset_ob = dataset.DistanceDataset()
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 2):
dataset_ob = dataset.CountRedTokenDataset(max_seq_length=args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 3):
vocab = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
dataset_ob = dataset.MaxTokenDataset(vocab = vocab, max_seq_length=args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 4):
dataset_ob = dataset.SeqLenDataset()
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 5):
vocab = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
dataset_ob = dataset.PalindromeDataset(vocab=vocab, max_seq_length=args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 6):
vocab = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
dataset_ob = dataset.SortedDataset(vocab=vocab,max_seq_length=args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 7):
vocab = list(range(10))
dataset_ob = dataset.SumDataset(vocab=vocab, max_seq_length = args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 8):
vocab = list(range(10))
dataset_ob = dataset.MaxDataset(vocab=vocab, max_seq_length = args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
elif(args.problem_id == 9):
vocab = list(range(10))
dataset_ob = dataset.MinDataset(vocab=vocab, max_seq_length = args.seq_length)
train_dataset, test_dataset = dataset_ob.gen_data()
if(args.training == 'true'):
train_ob = Train(args, train_dataset, test_dataset, 64)
model, history = train_ob.train_model()
else:
checkpoint_path = "training_" + str(1)+ "/cp.ckpt"
train_ob = Train(args, train_dataset, test_dataset, 64)
model = train_ob.create_model()
model.load_weights(checkpoint_path)
test_ob = Test(model, test_dataset, args.problem_id, args.seq_length)
test_ob.attention_plots()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--num_heads', type=int, default=1, help='Number of Attention Heads')
parser.add_argument('--num_layers', type=int, default=1, help='Number of Attention Layers')
parser.add_argument('--emb_dim', type=int, default=128, help='Embedding Dimensions')
parser.add_argument('--seq_length', type=int, default=512, help='input seq length')
parser.add_argument('--vocab_size', type=int, default=2, help='length of vocab for input')
parser.add_argument('--head_size', type=int, default=64, help='Size of the single dense layer head')
parser.add_argument('--pos_embedding', type=bool, default=True, help='Weather to use positional embedding or not')
parser.add_argument('--agg_method', type=str, default='TOKEN', help='Method used to feed into head. TOKEN Uses CLS token, SUM adds the output from attention')
parser.add_argument('--pos_embedding_type', type=str, default='SIN_COS', help='Which type of positional encoding to use. SIN_COS for alternating sin cos, RANDOM for random pos encodings')
parser.add_argument('--problem_id', type=int, default=1, help=''' Integer indicating which problem to solve?
Distance between 2 red tokens: 1
Count number of red tokens: 2
Find token that appears maximum time: 3
Compute sequence length: 4
Palindrome Sequence: 5
Sorted Sequence: 6
Sum: 7
MAx: 8
Min: 9
''')
parser.add_argument('--optimizer', type=str, default='adam', help='Which optimizer to use for training')
parser.add_argument('--loss_function', type=str, default='mean_squared_error', help='Which Loss Function to use for training')
parser.add_argument('--metric', type=str, default='mean_squared_error', help='Which metric to use for training')
parser.add_argument('--learning_rate', type=float, default=0.001, help='Which learning rate to use for training')
parser.add_argument('--epochs', type=int, default=15, help='Number of epochs to run for training')
parser.add_argument('--training', type=str, default='true', help='flag to train the model')
args = parser.parse_args()
_train(args)