Search⌘ K
AI Features

Project Creation: Part Two

Explore the process of building an RNN model for sentiment analysis on IMDB reviews. This lesson guides you through defining model architecture with embedding and RNN layers, compiling with appropriate loss functions and optimizers, and preparing data for model training. Gain practical skills to implement binary text classification using deep learning.

Create the model architecture

Now that we have our input in the format that our model will accept, we can create the model architecture. In this project, we are going to use a simple RNN model. But don’t worry, in later chapters, we will work with LSTMs too.

Let’s create the model architecture.

Python 3.5
from tensorflow.python.keras.layers import Embedding,SimpleRNN,Dense
from tensorflow.python.keras.models import Sequential
model = Sequential()
model.add(Embedding(10000,64))
model.add(SimpleRNN(32))
model.add(Dense(1,activation='sigmoid'))
print(model.summary())

Explanation:

  • On line 1 and line 2, we imported the package that is required for our model architecture.
  • On line 4, we created an object of sequential class. A sequential model is used for a plain stack of layers, where each layer has exactly one input tensor and one output tensor.
  • On line 5, we added the embedding layer with the appropriate parameters. Note that you must not change the value of 10,000, as this was the vocabulary size we
...