These are chat archives for arita37/tensorflow

27th
Mar 2017
Andre Pemmelaar
@Andy-P
Mar 27 2017 03:04

I have a question regarding the use of tf.nn.dynamic_rnn.

I have a numpy array of size x_shape = (50, 30, 10),
where the
batch size = 50,
max length of series (max_time) = 30
input vector of length = 10.

I'm getting an error of TypeError: 'Tensor' object is not iterable.

According to the documatation:
If time_major == False (default), this must be a Tensor of shape: [batch_size, max_time, ...], or a nested tuple of such elements.

How should I format my input if not an array of rank three e.g. [50, 30, 10]? Perhaps a list of 30 elements each of which each element is a vector of length 10?

Jongyeol Yang
@didw
Mar 27 2017 05:24
I have implemented LSTM for simple mnist data. I hope it can helpful to understand hot to implement LSTM in tensorflow.
https://github.com/didw/tensorflow_lstm_mnist
Andre Pemmelaar
@Andy-P
Mar 27 2017 06:25
@didw Thanks. I'm studying it now.
Andre Pemmelaar
@Andy-P
Mar 27 2017 08:42

@didw Your example is quite helpful, but in your case you're only interested in the last state so you use

    w1 = tf.Variable(tf.random_normal([h_size, n_classes]))
    b1 = tf.Variable(tf.random_normal([n_classes]))
    outputs, states = tf.nn.dynamic_rnn(lstm_cell, self.X, initial_state=init_state)
    self.pred = tf.matmul(outputs[:,-1], w1) + b1 

with outputs[:,-1]
How should I modify this is I am interested in it at every step?

Jongyeol Yang
@didw
Mar 27 2017 08:44
I think tf.matmul(outputs, w1)+b1 would be worked.
Andre Pemmelaar
@Andy-P
Mar 27 2017 08:48
@didw tf.matmul(outputs, w1)+b1 generates the following error when use a sequence with 3 steps and batch size 5 (I have only one category as it is a regression)
  ValueError: Shape must be rank 2 but is rank 3 for 'MatMul' (op: 'MatMul') with input shapes: [5,3,32], [32,1]
Jongyeol Yang
@didw
Mar 27 2017 08:51
You should change dimension rank 3 to rank 2 before multiply it. Use outputs = tf.reshape(outputs, [-1, 32])
Andre Pemmelaar
@Andy-P
Mar 27 2017 09:03
@didw Won't that get rid of the batch dimension? I need it to results in a [5, 3] for 5 batches of length 3 each, no?
Jongyeol Yang
@didw
Mar 27 2017 09:13
You can also make original shape using tf.reshape after multiplication.