How to do it...

  1. To start, we load the necessary libraries for the script:
import os 
import re 
import string 
import requests 
import numpy as np 
import collections 
import random 
import pickle 
import matplotlib.pyplot as plt 
import tensorflow as tf 
  1. Next, we start a graph session and set the RNN parameters:
sess = tf.Session()# Set RNN Parameters 
min_word_freq = 5 
rnn_size = 128 
epochs = 10 
batch_size = 100 
learning_rate = 0.001 
training_seq_len = 50  
embedding_size = rnn_size 
save_every = 500 
eval_every = 50 
prime_texts = ['thou art more', 'to be or not to', 'wherefore art thou'] 
  1. We set up the data and model folders and filenames, along with declaring punctuation to be removed. We will want to keep hyphens and apostrophes because Shakespeare ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.