Prediction of Movie Opinions

In this project, we are going to make a Recurrent Neural Network for understanding the reviews of the users and extract the meaningful information behind them to figure out whether the user liked the movie or not.

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 integer and a binary sentiment classification for extracting the opinion of the user which indicates whether the user liked the movie or not.

Also Read:  Prediction of Aliens Vs. Predators

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)

.

Building RNN

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.

model.add(Embedding(20000, 128))

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

model.add(Dense(1, activation='sigmoid'))

Compiling the RNN

model.compile(optimizer = 'adam', loss = 'binary_crossentropy',metrics=['accuracy'])

.

Evaluation

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)
3007cookie-checkPrediction of Movie Opinions

Leave a Reply

Your email address will not be published.