I am trying to implement an LSTM based speech recognizer. So far, I could configure bidirectional LSTM (I think it works like bidirectional LSTM), following the example in the Merge layer. Now I want to try it with another bidirectional LSTM layer, which makes it a deep bidirectional LSTM. But I canβt understand how to connect the output of the previously merged two layers into the second set of LSTM layers. I do not know if this is possible with Keras. Hope someone can help me with this.
The code for a single-page bidirectional LSTM is as follows
left = Sequential() left.add(LSTM(output_dim=hidden_units, init='uniform', inner_init='uniform', forget_bias_init='one', return_sequences=True, activation='tanh', inner_activation='sigmoid', input_shape=(99, 13))) right = Sequential() right.add(LSTM(output_dim=hidden_units, init='uniform', inner_init='uniform', forget_bias_init='one', return_sequences=True, activation='tanh', inner_activation='sigmoid', input_shape=(99, 13), go_backwards=True)) model = Sequential() model.add(Merge([left, right], mode='sum')) model.add(TimeDistributedDense(nb_classes)) model.add(Activation('softmax')) sgd = SGD(lr=0.1, decay=1e-5, momentum=0.9, nesterov=True) model.compile(loss='categorical_crossentropy', optimizer=sgd) print("Train...") model.fit([X_train, X_train], Y_train, batch_size=1, nb_epoch=nb_epoches, validation_data=([X_test, X_test], Y_test), verbose=1, show_accuracy=True)
The sizes of my x and y values ββare as follows.
(100, 'train sequences') (20, 'test sequences') ('X_train shape:', (100, 99, 13)) ('X_test shape:', (20, 99, 13)) ('y_train shape:', (100, 99, 11)) ('y_test shape:', (20, 99, 11))