# RNN model with 3 hidden layers

In a paper, it mentioned: ANN, RNN, and LSTM NN are optimized to contain three hidden layers with 1000 hidden units in each layer.

I would like to model the RNN model in Keras. But my code fails in an error!

My code:

model=Sequential()
model.add(SimpleRNN(1000,input_shape=(320,15),activation='relu'))
model.add(SimpleRNN(1000))
model.add(SimpleRNN(1000))
model.add(Dense(1600))


Error:

    ValueError                                Traceback (most recent call last)
<ipython-input-49-ff01ce62eb30> in <module>()
1 model=Sequential()
2 model.add(SimpleRNN(1000,input_shape=(320,15),activation='relu'))
----> 3 model.add(SimpleRNN(1000))
4 model.add(SimpleRNN(1000))
5 model.add(Dense(1600))
.....
....
...
..
.

ValueError: Input 0 is incompatible with layer simple_rnn_2: expected ndim=3, found ndim=2


How can I code for the RNN model which is optimized to contain three hidden layers with 1000 hidden units in each layer?

Thank you so much

## 1 Answer

The shape should be 3d array --> (samples, timesteps, features)

It needs to add return_sequences=True in first two RNN layers.

model=Sequential()
model.add(SimpleRNN(1000,input_shape=(1,320*15),activation='relu', return_sequences=True))
model.add(SimpleRNN(1000, return_sequences=True))
model.add(SimpleRNN(1000))

• Why the input_shape is (1,320*15)? If he had 320 timesteps with 15 feature it should be (320,15). – Francesco Pegoraro Oct 2 '18 at 10:00
• It contains 1 timestep and 320*15 features. – user7194905 Oct 3 '18 at 11:46
• Wouldn't it be better if data was window-like? Where each timestep(row) has 15 features. This way the RNN will slide over timesteps. If the data is (1,320*15) there will be no sliding. It's literally as you said: "The shape should be 3d array --> (samples, timesteps, features)" – Francesco Pegoraro Oct 3 '18 at 12:41
• 320 is very large. Is it agreeable as the time step? It is an advantageous point. Thank you! – user7194905 Oct 4 '18 at 9:49