Working example, check notebook :
import tensorflow as tf from tensorflow.models.rnn import rnn, rnn_cell print(tf.__version__) #> 0.8.0 batch_size = 2 output_size = input_size = 2 seq_len = 10 num_units = 2 cell = rnn_cell.BasicLSTMCell(num_units) inputs = [tf.placeholder(tf.float32, shape=[batch_size,input_size ]) for _ in xrange(seq_len)] result = [tf.placeholder(tf.float32, shape=[batch_size,output_size]) for _ in xrange(seq_len)] W_o = tf.Variable(tf.random_normal([num_units,input_size], stddev=0.01)) b_o = tf.Variable(tf.random_normal([input_size], stddev=0.01)) outputs, states = rnn.rnn(cell, inputs, dtype=tf.float32) losses = [] for i in xrange(seq_len): final_transformed_val = tf.matmul(outputs[i],W_o) + b_o losses.append(tf.squared_difference(result[i],final_transformed_val)) losses = tf.reshape(tf.concat(1, losses), [-1, seq_len]) cost = tf.reduce_mean(losses)
To see this in action, you can feed the chart in a hacker way:
import matplotlib.pyplot as plt import numpy as np step = tf.train.AdamOptimizer(learning_rate=0.01).minimize(cost) sess = tf.InteractiveSession() sess.run(tf.initialize_all_variables()) costs = []

As a beginner with tensor flow, I have yet to find a unified way / best way to handle RNN, but as mentioned above, I am sure this is not recommended. Liked your script as a very nice introduction, thanks for the snippets. In addition, wrg is happening before the scan implementation and the convenience of RNN-tuple-friendly , so be careful
source share