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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.