In the previous recipe, we implemented sentiment classification using LSTM in Keras. In this recipe, we will look at implementing the same thing but stack multiple LSTMs. Stacking multiple LSTMs is likely to capture more variation in the data and thus potentially a better accuracy.
Implementing stacked LSTM for sentiment classification
How to do it...
Stacked LSTM is implemented as follows (the code file is available as RNN_and_LSTM_sentiment_classification.ipynb in GitHub):
- The only change in the code we saw earlier will be to change the return_sequences parameter to true. This ensures that the first LSTM returns a sequence of output (as many output as the number of LSTM units), which can then be passed to another LSTM as...