How to do it...

  1. 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
  1. 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)))
  1. 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 ...

Get Python Deep Learning Cookbook now with O’Reilly online learning.

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