October 2018
Intermediate to advanced
472 pages
10h 57m
English
Now that we have our model architecture defined, let's train our model. We begin with a TensorFlow graph initialization and execute the training steps as follows:
tf.reset_default_graph()sess = tf.InteractiveSession()model = Model(size_layer,num_layers,embedded_size,vocabulary_size+4,dimension_output,learning_rate)sess.run(tf.global_variables_initializer())EARLY_STOPPING, CURRENT_CHECKPOINT, CURRENT_ACC, EPOCH = 5, 0, 0, 0while True: lasttime = time.time() if CURRENT_CHECKPOINT == EARLY_STOPPING: print('break epoch:%d\n'%(EPOCH)) break train_acc, train_loss, test_acc, test_loss = 0, 0, 0, 0 for i in range(0, (len(train_X) // batch_size) * batch_size, batch_size): batch_x = str_idx(train_X[i:i+batch_size],dictionary,maxlen) ...Read now
Unlock full access