I am trying to create a 2-layer simple RNN model with Keras in which I can directly feed data into the first layer. As I understand it, cells in an RNN are fully connected with their input with the standard Keras layer. For example, if I define an input with 4 features and 1 timestep, connected to a SimpleRNN with 4 cells as follows:
from tensorflow import keras
from tensorflow.keras import layers
model = keras.models.Sequential()
model.add(layers.Input(shape=(1, 4)))
model.add(layers.SimpleRNN(4, use_bias=False, return_sequences=True))
model.summary()
I will get:
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
simple_rnn (SimpleRNN) (None, 1, 4) 32
=================================================================
Total params: 32
Trainable params: 32
Non-trainable params: 0
_________________________________________________________________
Which makes sense. There are 4x4 recurrent connections in the SimpleRNN, and 4x4 connections between the input and the 4 RNN cells, so we get 32 trainable params (ignoring bias terms).
However, I would like to structure my network so that each input feature is connected to only one cell in the RNN, as in the diagram below:
Is there any way to do this in Keras? For example removing specific connections between layers?
