It's my first time I work with Bidirectional layers, but I don't find any examples with the use of the functional API from Keras. mask_mastrix is a tensor with shape (samples, timesteps) with binary values True / False.
with strategy.scope():
input_tensor = Input(shape=(timesteps, features))
enc = Bidirectional(LSTM(timesteps * 2, activation = 'tanh', return_sequences = True))(input_tensor, mask=mask_matrix)
enc = Bidirectional(LSTM(timesteps * 1.5, activation = 'tanh', return_sequences = False))(enc)
decode1 = RepeatVector(timesteps)(enc)
decode1 = Bidirectional(LSTM(200, activation = 'tanh', return_sequences = True))(decode1)
decode1 = Bidirectional(LSTM(timesteps, activation = 'tanh', return_sequences = True))(decode1)
decode1 = TimeDistributed(Dense(8, activation="softmax"), name="dec1")(decode1)
decode2 = RepeatVector(timesteps)(enc)
decode2 = Bidirectional(LSTM(timesteps, activation = 'tanh', return_sequences = True))(decode2)
decode2 = TimeDistributed(Dense(2, activation = "tanh"), name="dec2")(decode2)
new_model = Model(inputs=input_tensor, outputs = [decode1, decode2])
new_model.compile(loss={"dec1":"categorical_crossentropy", "dec2":'mse'}, optimizer='adam')
plot_model(new_model, to_file='model.png')
I get the following error:
Dimension value must be integer or None or have an __index__ method, got value '1932.0' with type '<class 'float'>'
I have two questions about this:
- What caused the problem and how to solve it?
- How does the mask value works when you use Bidirectional layers? Because from my understanding, this layer creates two LSTMs with: first with the forward sequence and the second with the backward sequence (to get the whole context). Does the mask argument also gets reversed?
Thanks in advance!