Sentiment Analysis using LSTM

Sentiment Analysis: the process of computationally identifying and categorizing opinions expressed in a piece of text, especially in order to
determine whether the writer’s attitude towards a particular topic, product, etc. is positive, negative, or neutral.

Suppose you have a collection of e-mail messages from users of your product or service. You don’t have time to read every message
so you want to programmatically determine if the tone of each message is positive (“great service”) or negative (“you guys are terrible”).
This is an example of sentiment analysis. In this article I show you how to get started with sentiment analysis using the Keras code library.


To run deep learning we can use google co-lab using python, they are providing the ram and disc space to achieve the basic problems.

The Dataset Preparation

The datasets that can be downloaded from this Sentiment.csv, Remove the unwanted columns, I am using ‘text’,’sentiment’ columns as a datasets.

sentiment data

Required Libraries



using Tokenizer to vectorize and convert text into Sequences so the Network can deal with it as input.

Build LSTM Model

Long short-term memory is an artificial recurrent neural network architecture used in the field of deep learning.
Unlike standard feedforward neural networks, LSTM has feedback connections.
It never keeps the entire data like standard recurrent neural network, lstm keeps short-term memory of data.

Train Model

To Train the model, have to use epochs,batch size to train the model.
epochs are iteration.
batch_size is data size for each iteration.


keras with python is the better way to achieve the deep
learning concepts. I have followed kaggle blogs and datasets.

CTO @ Preline,Inc