How it works...
Before building the model, we need to prepare the data. You can refer to the Sentiment classification using RNNs section of this chapter if you want to learn more about the data preprocessing part.
In step 1, we instantiated a Keras sequential model. In step 2, we added layers to the sequential model. First, we added an embedding layer, which reduced the dimensionality of the input feature space. Then, we added a simple RNN in a bidirectional wrapper with merge_mode equal to concat. Merge mode defines how to combine outputs of the forward and backward RNNs. Other modes include sum, mul, ave, and NULL. Finally, we added a dense layer with one hidden unit and used sigmoid as the activation function.
In step 3, we compiled the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access