Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Deep Learning Cookbook

You're reading from  Python Deep Learning Cookbook

Product type Book
Published in Oct 2017
Publisher Packt
ISBN-13 9781787125193
Pages 330 pages
Edition 1st Edition
Languages
Author (1):
Indra den Bakker Indra den Bakker
Profile icon Indra den Bakker
Toc

Table of Contents (21) Chapters close

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Programming Environments, GPU Computing, Cloud Solutions, and Deep Learning Frameworks 2. Feed-Forward Neural Networks 3. Convolutional Neural Networks 4. Recurrent Neural Networks 5. Reinforcement Learning 6. Generative Adversarial Networks 7. Computer Vision 8. Natural Language Processing 9. Speech Recognition and Video Analysis 10. Time Series and Structured Data 11. Game Playing Agents and Robotics 12. Hyperparameter Selection, Tuning, and Neural Network Learning 13. Network Internals 14. Pretrained Models

Implementing bidirectional RNNs


Until now, we've considered the to flow in one direction through our network. However, sometimes it's beneficial to run the data through the network in both directions. We call such networks bidirectional RNNs. In the following example, we will implement the same LSTM network as we've implemented previously, but this time we will use a bidirectional RNN to classify the sentiment.

How to do it...

  1. Let's start with importing the libraries as follows:
import numpy as np

from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, 
Activation, Embedding, LSTM, Bidirectional
from keras.callbacks import EarlyStopping
from 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime