How to implement deep bidirectional LSTM with Keras?

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)) 
+8
deep-learning keras lstm
source share
3 answers

Well, I got an answer to a question posted on Keras questions. I hope this will be useful for anyone looking for such an approach. How to implement deep bidirectional -LSTM

+14
source share

You can use keras.layers.wrappers.Bidirectional . Here you can refer to the official guide, https://keras.io/layers/wrappers/#bidirectional

+1
source share

BiLSTM development is now easier. The new Bidirectional class is added according to the official doc here: https://www.tensorflow.org/api_docs/python/tf/keras/layers/Bipirectional

For learning outcomes and full code

0
source share

All Articles