Simple RNN in TensorFlow
The workflow to define and train a simple RNN in TensorFlow is as follows:
- Define the hyper-parameters for the model:
state_size = 4 n_epochs = 100 n_timesteps = n_x learning_rate = 0.1
The new hyper-parameter here is the state_size
. The state_size
represents the number of weight vectors of an RNN cell.
- Define the placeholders for X and Y parameters for the model. The shape of X placeholder is
(batch_size, number_of_input_timesteps, number_of_inputs)
and the shape of Y placeholder is(batch_size, number_of_output_timesteps, number_of_outputs)
. Forbatch_size
, we useNone
so that we can input the batch of any size later.
X_p = tf.placeholder(tf.float32, [None, n_timesteps, n_x_vars], name='X_p') Y_p = tf.placeholder(tf.float32, [None, n_timesteps, n_y_vars], name='Y_p')
- Transform the input placeholder
X_p
into a list of tensors of length equal to the number of time steps, which isn_x
or 1 in this example:
# make a list of tensors of length n_timesteps rnn_inputs...