To understand how RNN is implemented in Keras, let's implement the airline-tweet sentiment classification exercise that we performed in the Chapter 10, Text Analysis Using Word Vectors chapter.
Implementing RNN for sentiment classification
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):
- Import the relevant packages and dataset:
from keras.layers import Dense, Activation
from keras.layers.recurrent import SimpleRNN
from keras.models import Sequential
from keras.utils import to_categorical
from keras.layers.embeddings import Embedding
from sklearn.cross_validation import train_test_split
import numpy as np
import nltk
from nltk.corpus...