Train the neural network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batches = get_batches(int_text, batch_size, seq_length) | |
with tf.Session(graph=train_graph) as sess: | |
sess.run(tf.global_variables_initializer()) | |
for epoch_i in range(num_epochs): | |
state = sess.run(initial_state, {input_text: batches[0][0]}) | |
for batch_i, (x, y) in enumerate(batches): | |
feed = { | |
input_text: x, | |
targets: y, | |
initial_state: state, | |
lr: learning_rate} | |
train_loss, state, _ = sess.run([cost, final_state, train_op], feed) | |
# Show every <show_every_n_batches> batches | |
if (epoch_i * len(batches) + batch_i) % show_every_n_batches == 0: | |
print('Epoch {:>3} Batch {:>4}/{} train_loss = {:.3f}'.format( | |
epoch_i, | |
batch_i, | |
len(batches), | |
train_loss)) | |
# Save Model | |
saver = tf.train.Saver() | |
saver.save(sess, save_dir) | |
print('Model Trained and Saved') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment