Sentiment Analysis using an LSTM Neural Network

I found an excellent example of building a sentiment analysis prediction model using an LSTM neural network with Keras. The problem is to take the text of several thousand movie reviews from the IMDB Web site that have been marked as either good, bad, or neutral (by the star rating) and create a model that uses review text to predict if the review is good or bad (neutral reviews are thrown out).

The example code I found was on a blog site at I made a few minor changes so I could understand what each part of the code does.

In the abstract, the training data is

w1, w2, w3, . . . wn -> “good”
w1, w2, . . wm -> “bad”

Each w is a word in one or more sentences. An LSTM neural network is designed to handle problems like this where the input is a sequence of related data. The demo code uses the Keras library which is by far the simplest way to implement an LSTM network (at the expense of flexibility).

The demo data is 25,000 reviews marked as good or bad to be used for training, and 25,000 labeled reviews for testing. The demo code achieves 88.40% accuracy on the test items (22,100 correct and 2,900 wrong) which is quite good.

Even though the demo program is very short, conceptually here’s a lot going on. Very cool example.

The Cinerama Theater in downtown Seattle was built in 1963. In the late 1990s it was in shambles and scheduled for demolition. But very-rich-person Paul Allen did a complete renovation and the theater is now state-of-the-art. Hats off to him!

This entry was posted in Keras, Machine Learning. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s