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 https://machinelearningmastery.com/sequence-classification-lstm-recurrent-neural-networks-python-keras/. I made a few minor changes so I could understand what each part of the code does.
Update: I discovered that the original source of the program was from the Keras source code documentation examples at: https://github.com/keras-team/keras/blob/master/examples/imdb_lstm.py
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!