Skip to content

Instantly share code, notes, and snippets.

Created March 26, 2019 10:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chricke/d04cd2b230c907cbbe6335bd6c000eea to your computer and use it in GitHub Desktop.
Train the neural network
batches = get_batches(int_text, batch_size, seq_length)
with tf.Session(graph=train_graph) as sess:
for epoch_i in range(num_epochs):
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, _ =[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(
# Save Model
saver = tf.train.Saver(), 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