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 model with binary_crossentropy as the loss function since we were solving a binary classification problem. We used the adam optimizer for this. Then, we trained our model on the training dataset. In step 4, we evaluated the test accuracy of our model to see how our model performed on the test data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset