Keras Deep Learning Cookbook
eBook - ePub

Keras Deep Learning Cookbook

Over 30 recipes for implementing deep neural networks in Python

Rajdeep Dua, Manpreet Singh Ghotra

  1. 252 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Keras Deep Learning Cookbook

Over 30 recipes for implementing deep neural networks in Python

Rajdeep Dua, Manpreet Singh Ghotra

Book details
Book preview
Table of contents
Citations

About This Book

Leverage the power of deep learning and Keras to develop smarter and more efficient data models

Key Features

  • Understand different neural networks and their implementation using Keras
  • Explore recipes for training and fine-tuning your neural network models
  • Put your deep learning knowledge to practice with real-world use-cases, tips, and tricks

Book Description

Keras has quickly emerged as a popular deep learning library. Written in Python, it allows you to train convolutional as well as recurrent neural networks with speed and accuracy.

The Keras Deep Learning Cookbook shows you how to tackle different problems encountered while training efficient deep learning models, with the help of the popular Keras library. Starting with installing and setting up Keras, the book demonstrates how you can perform deep learning with Keras in the TensorFlow. From loading data to fitting and evaluating your model for optimal performance, you will work through a step-by-step process to tackle every possible problem faced while training deep models. You will implement convolutional and recurrent neural networks, adversarial networks, and more with the help of this handy guide. In addition to this, you will learn how to train these models for real-world image and language processing tasks.

By the end of this book, you will have a practical, hands-on understanding of how you can leverage the power of Python and Keras to perform effective deep learning

What you will learn

  • Install and configure Keras in TensorFlow
  • Master neural network programming using the Keras library
  • Understand the different Keras layers
  • Use Keras to implement simple feed-forward neural networks, CNNs and RNNs
  • Work with various datasets and models used for image and text classification
  • Develop text summarization and reinforcement learning models using Keras

Who this book is for

Keras Deep Learning Cookbook is for you if you are a data scientist or machine learning expert who wants to find practical solutions to common problems encountered while training deep learning models. A basic understanding of Python and some experience in machine learning and neural networks is required for this book.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Keras Deep Learning Cookbook an online PDF/ePUB?
Yes, you can access Keras Deep Learning Cookbook by Rajdeep Dua, Manpreet Singh Ghotra in PDF and/or ePUB format, as well as other popular books in Informatique & Réseaux de neurones. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788623087

Recurrent Neural Networks

In this chapter, we will cover the following recipes:
  • Simple RNNs for time series data
  • LSTM networks for time series data
  • LSTM memory example time series forecasting with LSTM
  • Sequence to sequence learning for the same length output with LSTM

Introduction

In this chapter, we will learn various recipes on how to create recurrent neural networks (RNNs) using Keras. First, we will understand the need for RNN. We will start with the simple RNNs followed by long short-term memory (LSTM) RNNs (these networks remember the state over a long period of time because of special gates in the cell).

The need for RNNs

Traditional neural networks cannot remember their past interactions, and that is a significant shortcoming. RNNs address this issue. They are networks with loops in them, allowing information to persist. RNNs have loops. In the next diagram, a chunk of the neural network, A, looks at some input, xt, and outputs a value, ht. A loop in the network allows information to be passed from one step of the network to the next.
This diagram shows what a neural network looks like:

Simple RNNs for time series data

In this recipe, we will learn how to use a simple RNN implementation of Keras to predict sales based on a historical dataset.
RNNs are a class of artificial neural network where connections between nodes of the network form a directed graph along a sequence. This topology allows it to exhibit dynamic temporal behavior for input of the time sequence type. Unlike feedforward neural networks, RNNs can use their internal state (also called memory) to process sequences of inputs. This makes them suitable for tasks such as unsegmented, connected handwriting recognition or speech recognition.
A simple RNN is implemented as part of the keras.layers.SimpleRNN class as follows:
keras.layers.SimpleRNN(units, activation='tanh', 
use_bias=True,
kernel_initializer='glorot_uniform',
recurrent_initializer='orthogonal',
bias_initializer='zeros',
kernel_regularizer=None,
recurrent_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
recurrent_constraint=None,
bias_constraint=None,
dropout=0.0,
recurrent_dropout=0.0,
return_sequences=False,
return_state=False,
go_backwards=False,
stateful=False,
unroll=False)
A simple RNN is a fully-connected RNN where the output is to be fed back to the input. We will be using a simple RNN for time series prediction.

Getting ready

The dataset is in this file: sales-of-shampoo-over-a-three-ye.csv. It has two columns, the first for months and the second for sales figures for each month, as follows:
"Month","Sales of shampoo over a three year period"
"1-01",266.0
"1-02",145.9
"1-03",183.1
"1-04",119.3
"1-05",180.3
"1-06",168.5
"1-07",231.8
First, we need to import the relevant classes, as follows:
from pandas import read_csv
from matplotlib import pyplot
from pandas import datetime

Loading the dataset

  1. We define a parser to convert YY to YYYY, shown as follow:
def parser(x):
return datetime.strptime('200' + x, '%Y-%m')
  1. Next, call the read_csv function of pandas to load a .csv file into a pandas DataFrame.
Notice the data parser being used is the function defined previously.
  1. The next read_csv function is called in the next code:
series = read_csv('sales-of-shampoo-over-a-three-ye.csv', header=0, parse_dates=[0], index_col=0, 
squeeze=True, date_parser=parser)
  1. Once the series is loaded, let's summarize the first few rows:
print(series.head())
The output of the preceding code is as follows:
Month
2001-01-01 266.0
2001-02-01 145.9
2001-03-01 183.1
2001-04-01 119.3
2001-05-01 180.3
  1. Next, let's print the line plot using the pyplot library:
series.plot()
pyplot.show()
The...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Keras Installation
  7. Working with Keras Datasets and Models
  8. Data Preprocessing, Optimization, and Visualization
  9. Classification Using Different Keras Layers
  10. Implementing Convolutional Neural Networks
  11. Generative Adversarial Networks
  12. Recurrent Neural Networks
  13. Natural Language Processing Using Keras Models
  14. Text Summarization Using Keras Models
  15. Reinforcement Learning
  16. Other Books You May Enjoy
Citation styles for Keras Deep Learning Cookbook

APA 6 Citation

Dua, R., & Ghotra, M. S. (2018). Keras Deep Learning Cookbook (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/835429/keras-deep-learning-cookbook-over-30-recipes-for-implementing-deep-neural-networks-in-python-pdf (Original work published 2018)

Chicago Citation

Dua, Rajdeep, and Manpreet Singh Ghotra. (2018) 2018. Keras Deep Learning Cookbook. 1st ed. Packt Publishing. https://www.perlego.com/book/835429/keras-deep-learning-cookbook-over-30-recipes-for-implementing-deep-neural-networks-in-python-pdf.

Harvard Citation

Dua, R. and Ghotra, M. S. (2018) Keras Deep Learning Cookbook. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/835429/keras-deep-learning-cookbook-over-30-recipes-for-implementing-deep-neural-networks-in-python-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Dua, Rajdeep, and Manpreet Singh Ghotra. Keras Deep Learning Cookbook. 1st ed. Packt Publishing, 2018. Web. 14 Oct. 2022.