October 2018
Intermediate to advanced
472 pages
10h 57m
English
Now that we've established our LSTM intuition and built the model, let's train it as follows:
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) acc, loss, _ = sess.run([model.accuracy, model.cost, model.optimizer], feed_dict = {model.X : batch_x, model.Y : train_onehot[i:i+batch_size]}) train_loss += loss train_acc += acc for i in range(0, (len(test_X) // batch_size) * batch_size, batch_size): ...Read now
Unlock full access