Movie Review Sentiment Analysis

Photo by Matheus Rocha on Dribbble

I am sure at least once in our lives every one of us watched a movie just by totally depending on the reviews. This whole process of reading quite a good number of reviews and then analyzing and categorizing them as positive, negative, or average can be tiresome and time-consuming.

What if we make our deep learning model get that done for us! Interesting right!! Let’s get to work.

This time I am training the neural nets so that at the end of the whole process my model should be able to predict ‘what is what review’. Just make sure you are working on TensorFlow 2.x.

For the foremost steps, we will import the necessary libraries and we will also do some data exploration this time.

While loading our dataset, we need to divide our dataset into train, test, and validation too. Moving onto preprocessing part, we will be checking out how our data looks and perform some basic to intermediate text preprocessing on the text like removing punctuations and special characters, etc. so that our text is good enough to build the required model on. I personally had a great time working on this.

Moving onto our deep learning model, I have trained this very simple and easy-to-understand Bi-directional sequential model.

The structure of our sequential model would be somewhat like this:

and for compilation of the model, I have used: optimizer =”adam”, loss =”Sparse_categorical_crossentropy”, and metrics = [“accuracy”].

Check this video out if loss functions confuse you.

I have trained my model keeping epochs value as 20. You can really, play around with this for better accuracy or even less loss. In my case, I got 77.16% training accuracy and 78.14% validation accuracy using above mentioned parameters. That’s pretty cool no!

After training and saving the model, it is a good practice to visualize the results of our model. I have attached the model accuracy and model loss graph you can have a look at.


Now, it’s prediction time! It’s been a lot of work I would rather advise saving the predictions in a csv file to make it easy and neat to understand.

Platform: cAInvas

Code: Here

Author: Bhavyaa Sharma