How to do it...

The task would be performed as follows (the code file is available as RNN_and_LSTM_sentiment_classification.ipynb in GitHub):

  1. Import the relevant packages and dataset:
from keras.layers import Dense, Activationfrom keras.layers.recurrent import SimpleRNNfrom keras.models import Sequentialfrom keras.utils import to_categoricalfrom keras.layers.embeddings import Embeddingfrom sklearn.cross_validation import train_test_splitimport numpy as npimport nltkfrom nltk.corpus import stopwordsimport reimport pandas as pddata=pd.read_csv('https://www.dropbox.com/s/8yq0edd4q908xqw/airline_sentiment.csv')data.head()
  1. Preprocess the text to remove punctuation, normalize all words to lowercase, and remove the stopwords, as follows:
import ...

Get Neural Networks with Keras Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.