In this project, we are going to make a Recurrent Neural Network
In the other words, the aim of this project is to classify the user movie reviews into positive and negative reviews. we are going to use Recurrent Neural Network using Keras to solve this problem
let’s get our environment ready with the libraries we’ll need and then import the data!
from keras.preprocessing import sequence from keras.models import Sequential from keras.layers import Dense from keras.layers import Embedding from keras.layers import LSTM from keras.datasets import imdb
Now let’s importing train and test set of the data. In addition, we are going to limit the data to the 20000 most popular words in the IMDB dataset.
(X_train, y_train) , (X_test, y_test) = imdb.load_data(num_words=20000)
So now we have a bunch of movie reviews that have been converted into vectors of words represented by
In the next step, We are going to break out the training set and test set and watch the first 80 words of reviews for training and test phase.
X_train = sequence.pad_sequences(X_train,maxlen=80) X_test = sequence.pad_sequences(X_test,maxlen=80)
Initialising the RNN
model = Sequential()
In the next step, We have to convert the input data into dense vectors of fixed size that’s better suited for a neural network.
Adding the first LSTM layer and some Dropout regularisation to prevent the overfitting of our model
model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2))
Adding the output layer
Compiling the RNN
model.compile(optimizer = 'adam', loss = 'binary_crossentropy',metrics=['accuracy'])
Let’s see the train score and train accuracy of our model
score, acc = model.evaluate(X_train,y_train,batch_size=32) print('Train Score : ', score) print('Train Accuracy : ', acc)
Now Let’s see the Test Score and Test accuracy of our model
score, acc = model.evaluate(X_test,y_test,batch_size=32) print('Test Score : ', score) print('Test Accuracy : ', acc)
You may have heard the world is made up of atoms and molecules, but it’s really made up of stories.