The task would be performed as follows (the code file is available as RNN_and_LSTM_sentiment_classification.ipynb in GitHub):
- 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()
- Preprocess the text to remove punctuation, normalize all words to lowercase, and remove the stopwords, as follows:
import ...