- Let's start with importing the libraries as follows:
import numpy as npfrom keras.preprocessing import sequencefrom keras.models import Sequentialfrom keras.layers import Dense, Dropout, Activation, Embedding, LSTM, Bidirectionalfrom keras.callbacks import EarlyStoppingfrom keras.datasets import imdb
- We will be using the IMDB dataset from Keras; load the data with the following code:
n_words = 1000(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=n_words)print('Train seq: {}'.format(len(X_train)))print('Test seq: {}'.format(len(X_train)))
- Let's print an example output of the training and test data:
print('Train example: \n{}'.format(X_train[0]))print('\nTest example: \n{}'.format(X_test[0]))# Note: the ...