recurrent-neural-network

What is num_units in tensorflow BasicLSTMCell?

◇◆丶佛笑我妖孽 提交于 2019-11-28 02:49:13
In MNIST LSTM examples, I don't understand what "hidden layer" means. Is it the imaginary-layer formed when you represent an unrolled RNN over time? Why is the num_units = 128 in most cases ? I know I should read colah's blog in detail to understand this, but, before that, I just want to get some code working with a sample time series data I have. nobar The number of hidden units is a direct representation of the learning capacity of a neural network -- it reflects the number of learned parameters . The value 128 was likely selected arbitrarily or empirically. You can change that value

Keras functional API: Combine CNN model with a RNN to to look at sequences of images

本秂侑毒 提交于 2019-11-28 00:44:22
问题 So i was stuck with a question on how to combine a CNN with a RNN in Keras. While posting the question someone pointed me out that this is the correct way to approach the problem. Apparently i just overlooked something in the original code, which made me answer my own question. The original problem is as follows: How do you create a model in Keras that has sequences of images as the input, with a CNN 'looking' at each individual image and the sequence of the CNN output being fed into a RNN?

Stateful LSTM: When to reset states?

拟墨画扇 提交于 2019-11-27 21:56:10
问题 Given X with dimensions (m samples, n sequences, and k features) , and y labels with dimensions (m samples, 0/1) : Suppose I want to train a stateful LSTM (going by keras definition, where "stateful = True" means that cell states are not reset between sequences per sample -- please correct me if I'm wrong!), are states supposed to be reset on a per epoch basis or per sample basis? Example: for e in epoch: for m in X.shape[0]: #for each sample for n in X.shape[1]: #for each sequence #train_on

Tensorflow: How to pass output from previous time-step as input to next timestep

旧巷老猫 提交于 2019-11-27 21:31:00
It is a duplicate of this question How can I feed last output y(t-1) as input for generating y(t) in tensorflow RNN? I want to pass the output of RNN at time-step T as the input at time-step T+1. input_RNN(T+1) = output_RNN(T) As per the documentation, the tf.nn.rnn as well as tf.nn.dynamic_rnn functions explicitly take the complete input to all time-steps. I checked the seq2seq example at https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/seq2seq.py It uses a loop and calls the cell(input,state) function. The cell can be lstm or gru or any other rnn cell. I checked the

Understanding stateful LSTM

守給你的承諾、 提交于 2019-11-27 20:41:08
I'm going through this tutorial on RNNs/LSTMs and I'm having quite a hard time understanding stateful LSTMs. My questions are as follows : 1. Training batching size In the Keras docs on RNNs , I found out that the hidden state of the sample in i -th position within the batch will be fed as input hidden state for the sample in i -th position in the next batch. Does that mean that if we want to pass the hidden state from sample to sample we have to use batches of size 1 and therefore perform online gradient descent? Is there a way to pass the hidden state within a batch of size >1 and perform

TimeDistributed(Dense) vs Dense in Keras - Same number of parameters

喜欢而已 提交于 2019-11-27 20:09:47
I'm building a model that converts a string to another string using recurrent layers (GRUs). I have tried both a Dense and a TimeDistributed(Dense) layer as the last-but-one layer, but I don't understand the difference between the two when using return_sequences=True, especially as they seem to have the same number of parameters. My simplified model is the following: InputSize = 15 MaxLen = 64 HiddenSize = 16 inputs = keras.layers.Input(shape=(MaxLen, InputSize)) x = keras.layers.recurrent.GRU(HiddenSize, return_sequences=True)(inputs) x = keras.layers.TimeDistributed(keras.layers.Dense

Difference between bidirectional_dynamic_rnn and stack_bidirectional_dynamic_rnn in Tensorflow

穿精又带淫゛_ 提交于 2019-11-27 18:32:53
问题 I am building a dynamic RNN network with stacking multiple LSTMs. I see there are 2 options # cells_fw and cells_bw are list of cells eg LSTM cells stacked_cell_fw = tf.contrib.rnn.MultiRNNCell(cells_fw) stacked_cell_bw = tf.contrib.rnn.MultiRNNCell(cells_bw) output = tf.nn.bidirectional_dynamic_rnn( stacked_cell_fw, stacked_cell_bw, INPUT, sequence_length=LENGTHS, dtype=tf.float32) vs output = tf.contrib.rnn.stack_bidirectional_dynamic_rnn(cells_fw, cells_bw, INPUT, sequence_length=LENGTHS,

What is the equivalent of tf.nn.rnn in new versions of TensorFlow?

馋奶兔 提交于 2019-11-27 18:01:36
问题 I used to create the RNN network, in version 0.8 of TensorFlow, using: from tensorflow.python.ops import rnn # Define a lstm cell with tensorflow lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0) # Get lstm cell output outputs, states = rnn.rnn(cell=lstm_cell, inputs=x, dtype=tf.float32) rnn.rnn() is not available anymore, and it sounds it has been moved to tf.contrib . What is the exact code to create RNN network out of a BasicLSTMCell ? Or, in the case that I have an stacked

Is RNN initial state reset for subsequent mini-batches?

泪湿孤枕 提交于 2019-11-27 17:45:16
Could someone please clarify whether the initial state of the RNN in TF is reset for subsequent mini-batches, or the last state of the previous mini-batch is used as mentioned in Ilya Sutskever et al., ICLR 2015 ? danijar The tf.nn.dynamic_rnn() or tf.nn.rnn() operations allow to specify the initial state of the RNN using the initial_state parameter. If you don't specify this parameter, the hidden states will be initialized to zero vectors at the beginning of each training batch. In TensorFlow, you can wrap tensors in tf.Variable() to keep their values in the graph between multiple session

Error when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)

℡╲_俬逩灬. 提交于 2019-11-27 13:59:49
My input is simply a csv file with 339732 rows and two columns : the first being 29 feature values, i.e. X the second being a binary label value, i.e. Y I am trying to train my data on a stacked LSTM model: data_dim = 29 timesteps = 8 num_classes = 2 model = Sequential() model.add(LSTM(30, return_sequences=True, input_shape=(timesteps, data_dim))) # returns a sequence of vectors of dimension 30 model.add(LSTM(30, return_sequences=True)) # returns a sequence of vectors of dimension 30 model.add(LSTM(30)) # return a single vector of dimension 30 model.add(Dense(1, activation='softmax')) model