100% found this document useful (3 votes)
671 views

Full Deep Learning With Python Develop Deep Learning Models On Theano and TensorFLow Using Keras Jason Brownlee Ebook All Chapters

Deep

Uploaded by

cahuasdalev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
671 views

Full Deep Learning With Python Develop Deep Learning Models On Theano and TensorFLow Using Keras Jason Brownlee Ebook All Chapters

Deep

Uploaded by

cahuasdalev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Download the full version of the textbook now at textbookfull.

com

Deep Learning with Python Develop Deep


Learning Models on Theano and TensorFLow
Using Keras Jason Brownlee

https://textbookfull.com/product/deep-learning-
with-python-develop-deep-learning-models-on-
theano-and-tensorflow-using-keras-jason-brownlee/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Deep Learning for Natural Language Processing Develop Deep


Learning Models for Natural Language in Python Jason
Brownlee
https://textbookfull.com/product/deep-learning-for-natural-language-
processing-develop-deep-learning-models-for-natural-language-in-
python-jason-brownlee/
textbookfull.com

Deep Learning Projects Using TensorFlow 2: Neural Network


Development with Python and Keras 1st Edition Vinita
Silaparasetty
https://textbookfull.com/product/deep-learning-projects-using-
tensorflow-2-neural-network-development-with-python-and-keras-1st-
edition-vinita-silaparasetty/
textbookfull.com

Deep Learning with Applications Using Python Chatbots and


Face, Object, and Speech Recognition With TensorFlow and
Keras Springerlink (Online Service)
https://textbookfull.com/product/deep-learning-with-applications-
using-python-chatbots-and-face-object-and-speech-recognition-with-
tensorflow-and-keras-springerlink-online-service/
textbookfull.com

20 Principles of Productivity: Focus, Motivation,


Organization, Habit Building, Time Management, Apps,
Psychology, Goal Setting, Procrastination & More 2nd
Edition Genadinik
https://textbookfull.com/product/20-principles-of-productivity-focus-
motivation-organization-habit-building-time-management-apps-
psychology-goal-setting-procrastination-more-2nd-edition-genadinik/
textbookfull.com
Topological Geometrodynamics An Overview Matti Pitkänen

https://textbookfull.com/product/topological-geometrodynamics-an-
overview-matti-pitkanen/

textbookfull.com

Teaching secondary school mathematics research and


practice for the 21st century Geiger

https://textbookfull.com/product/teaching-secondary-school-
mathematics-research-and-practice-for-the-21st-century-geiger/

textbookfull.com

The Transnational Voices of Australia’s Migrant and


Minority Press Catherine Dewhirst

https://textbookfull.com/product/the-transnational-voices-of-
australias-migrant-and-minority-press-catherine-dewhirst/

textbookfull.com

Twists of fate : multiracial coalitions and minority


representation in the US House of Representatives 1st
Edition Tyson
https://textbookfull.com/product/twists-of-fate-multiracial-
coalitions-and-minority-representation-in-the-us-house-of-
representatives-1st-edition-tyson/
textbookfull.com

Flexible Engineering Toward Green Aircraft: CAE Tools for


Sustainable Mobility 1st Edition Marco Evangelos
Biancolini
https://textbookfull.com/product/flexible-engineering-toward-green-
aircraft-cae-tools-for-sustainable-mobility-1st-edition-marco-
evangelos-biancolini/
textbookfull.com
Childhood cancer a parent s guide to solid tumor cancers
Third Edition Keene

https://textbookfull.com/product/childhood-cancer-a-parent-s-guide-to-
solid-tumor-cancers-third-edition-keene/

textbookfull.com
   

��������������������������������
����������������������������
�����

��������������
Jason Brownlee

Deep Learning With Python


Develop Deep Learning Models On Theano And TensorFlow Using
Keras
i

Deep Learning With Python


Copyright 2016 Jason Brownlee. All Rights Reserved.

Edition: v1.7
Contents

Preface iii

I Introduction 1
1 Welcome 2
1.1 Deep Learning The Wrong Way . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Deep Learning With Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Book Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Requirements For This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 Your Outcomes From Reading This Book . . . . . . . . . . . . . . . . . . . . . . 7
1.6 What This Book is Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

II Background 10
2 Introduction to Theano 11
2.1 What is Theano? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 How to Install Theano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3 Simple Theano Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 Extensions and Wrappers for Theano . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5 More Theano Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3 Introduction to TensorFlow 15
3.1 What is TensorFlow? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 How to Install TensorFlow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Your First Examples in TensorFlow . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Simple TensorFlow Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 More Deep Learning Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4 Introduction to Keras 19
4.1 What is Keras? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 How to Install Keras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Theano and TensorFlow Backends for Keras . . . . . . . . . . . . . . . . . . . . 20

ii
iii

4.4 Build Deep Learning Models with Keras . . . . . . . . . . . . . . . . . . . . . . 21


4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5 Project: Develop Large Models on GPUs Cheaply In the Cloud 23


5.1 Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 Setup Your AWS Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.3 Launch Your Server Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.4 Login, Configure and Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.5 Build and Run Models on AWS . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.6 Close Your EC2 Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.7 Tips and Tricks for Using Keras on AWS . . . . . . . . . . . . . . . . . . . . . . 34
5.8 More Resources For Deep Learning on AWS . . . . . . . . . . . . . . . . . . . . 34
5.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

III Multilayer Perceptrons 36


6 Crash Course In Multilayer Perceptrons 37
6.1 Crash Course Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2 Multilayer Perceptrons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.3 Neurons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.4 Networks of Neurons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.5 Training Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

7 Develop Your First Neural Network With Keras 43


7.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2 Pima Indians Onset of Diabetes Dataset . . . . . . . . . . . . . . . . . . . . . . 44
7.3 Load Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.4 Define Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.5 Compile Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.6 Fit Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.7 Evaluate Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.8 Tie It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

8 Evaluate The Performance of Deep Learning Models 51


8.1 Empirically Evaluate Network Configurations . . . . . . . . . . . . . . . . . . . 51
8.2 Data Splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.3 Manual k-Fold Cross Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

9 Use Keras Models With Scikit-Learn For General Machine Learning 57


9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
9.2 Evaluate Models with Cross Validation . . . . . . . . . . . . . . . . . . . . . . . 58
9.3 Grid Search Deep Learning Model Parameters . . . . . . . . . . . . . . . . . . . 59
9.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
iv

10 Project: Multiclass Classification Of Flower Species 62


10.1 Iris Flowers Classification Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . 62
10.2 Import Classes and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.3 Initialize Random Number Generator . . . . . . . . . . . . . . . . . . . . . . . . 63
10.4 Load The Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.5 Encode The Output Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.6 Define The Neural Network Model . . . . . . . . . . . . . . . . . . . . . . . . . 65
10.7 Evaluate The Model with k-Fold Cross Validation . . . . . . . . . . . . . . . . . 65
10.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

11 Project: Binary Classification Of Sonar Returns 68


11.1 Sonar Object Classification Dataset . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.2 Baseline Neural Network Model Performance . . . . . . . . . . . . . . . . . . . . 69
11.3 Improve Performance With Data Preparation . . . . . . . . . . . . . . . . . . . 71
11.4 Tuning Layers and Neurons in The Model . . . . . . . . . . . . . . . . . . . . . 73
11.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

12 Project: Regression Of Boston House Prices 77


12.1 Boston House Price Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
12.2 Develop a Baseline Neural Network Model . . . . . . . . . . . . . . . . . . . . . 78
12.3 Lift Performance By Standardizing The Dataset . . . . . . . . . . . . . . . . . . 81
12.4 Tune The Neural Network Topology . . . . . . . . . . . . . . . . . . . . . . . . . 82
12.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

IV Advanced Multilayer Perceptrons and Keras 86


13 Save Your Models For Later With Serialization 87
13.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
13.2 Save Your Neural Network Model to JSON . . . . . . . . . . . . . . . . . . . . . 88
13.3 Save Your Neural Network Model to YAML . . . . . . . . . . . . . . . . . . . . 90
13.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

14 Keep The Best Models During Training With Checkpointing 93


14.1 Checkpointing Neural Network Models . . . . . . . . . . . . . . . . . . . . . . . 93
14.2 Checkpoint Neural Network Model Improvements . . . . . . . . . . . . . . . . . 94
14.3 Checkpoint Best Neural Network Model Only . . . . . . . . . . . . . . . . . . . 95
14.4 Loading a Saved Neural Network Model . . . . . . . . . . . . . . . . . . . . . . 96
14.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

15 Understand Model Behavior During Training By Plotting History 98


15.1 Access Model Training History in Keras . . . . . . . . . . . . . . . . . . . . . . 98
15.2 Visualize Model Training History in Keras . . . . . . . . . . . . . . . . . . . . . 99
15.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
v

16 Reduce Overfitting With Dropout Regularization 102


16.1 Dropout Regularization For Neural Networks . . . . . . . . . . . . . . . . . . . . 102
16.2 Dropout Regularization in Keras . . . . . . . . . . . . . . . . . . . . . . . . . . 103
16.3 Using Dropout on the Visible Layer . . . . . . . . . . . . . . . . . . . . . . . . . 104
16.4 Using Dropout on Hidden Layers . . . . . . . . . . . . . . . . . . . . . . . . . . 105
16.5 Tips For Using Dropout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
16.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

17 Lift Performance With Learning Rate Schedules 108


17.1 Learning Rate Schedule For Training Models . . . . . . . . . . . . . . . . . . . . 108
17.2 Ionosphere Classification Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . 109
17.3 Time-Based Learning Rate Schedule . . . . . . . . . . . . . . . . . . . . . . . . 109
17.4 Drop-Based Learning Rate Schedule . . . . . . . . . . . . . . . . . . . . . . . . . 112
17.5 Tips for Using Learning Rate Schedules . . . . . . . . . . . . . . . . . . . . . . . 114
17.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

V Convolutional Neural Networks 115


18 Crash Course In Convolutional Neural Networks 116
18.1 The Case for Convolutional Neural Networks . . . . . . . . . . . . . . . . . . . . 116
18.2 Building Blocks of Convolutional Neural Networks . . . . . . . . . . . . . . . . . 117
18.3 Convolutional Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
18.4 Pooling Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
18.5 Fully Connected Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
18.6 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
18.7 Convolutional Neural Networks Best Practices . . . . . . . . . . . . . . . . . . . 119
18.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

19 Project: Handwritten Digit Recognition 121


19.1 Handwritten Digit Recognition Dataset . . . . . . . . . . . . . . . . . . . . . . . 121
19.2 Loading the MNIST dataset in Keras . . . . . . . . . . . . . . . . . . . . . . . . 122
19.3 Baseline Model with Multilayer Perceptrons . . . . . . . . . . . . . . . . . . . . 123
19.4 Simple Convolutional Neural Network for MNIST . . . . . . . . . . . . . . . . . 127
19.5 Larger Convolutional Neural Network for MNIST . . . . . . . . . . . . . . . . . 131
19.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

20 Improve Model Performance With Image Augmentation 135


20.1 Keras Image Augmentation API . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
20.2 Point of Comparison for Image Augmentation . . . . . . . . . . . . . . . . . . . 136
20.3 Feature Standardization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
20.4 ZCA Whitening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
20.5 Random Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
20.6 Random Shifts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
20.7 Random Flips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
20.8 Saving Augmented Images to File . . . . . . . . . . . . . . . . . . . . . . . . . . 145
20.9 Tips For Augmenting Image Data with Keras . . . . . . . . . . . . . . . . . . . 147
vi

20.10Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

21 Project Object Recognition in Photographs 148


21.1 Photograph Object Recognition Dataset . . . . . . . . . . . . . . . . . . . . . . 148
21.2 Loading The CIFAR-10 Dataset in Keras . . . . . . . . . . . . . . . . . . . . . . 149
21.3 Simple CNN for CIFAR-10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
21.4 Larger CNN for CIFAR-10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
21.5 Extensions To Improve Model Performance . . . . . . . . . . . . . . . . . . . . . 157
21.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

22 Project: Predict Sentiment From Movie Reviews 159


22.1 Movie Review Sentiment Classification Dataset . . . . . . . . . . . . . . . . . . 159
22.2 Load the IMDB Dataset With Keras . . . . . . . . . . . . . . . . . . . . . . . . 160
22.3 Word Embeddings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
22.4 Simple Multilayer Perceptron Model . . . . . . . . . . . . . . . . . . . . . . . . 163
22.5 One-Dimensional Convolutional Neural Network . . . . . . . . . . . . . . . . . . 165
22.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

VI Recurrent Neural Networks 169


23 Crash Course In Recurrent Neural Networks 170
23.1 Support For Sequences in Neural Networks . . . . . . . . . . . . . . . . . . . . . 170
23.2 Recurrent Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
23.3 Long Short-Term Memory Networks . . . . . . . . . . . . . . . . . . . . . . . . . 172
23.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

24 Time Series Prediction with Multilayer Perceptrons 174


24.1 Problem Description: Time Series Prediction . . . . . . . . . . . . . . . . . . . . 174
24.2 Multilayer Perceptron Regression . . . . . . . . . . . . . . . . . . . . . . . . . . 176
24.3 Multilayer Perceptron Using the Window Method . . . . . . . . . . . . . . . . . 181
24.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

25 Time Series Prediction with LSTM Recurrent Neural Networks 185


25.1 LSTM Network For Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
25.2 LSTM For Regression Using the Window Method . . . . . . . . . . . . . . . . . 189
25.3 LSTM For Regression with Time Steps . . . . . . . . . . . . . . . . . . . . . . . 191
25.4 LSTM With Memory Between Batches . . . . . . . . . . . . . . . . . . . . . . . 194
25.5 Stacked LSTMs With Memory Between Batches . . . . . . . . . . . . . . . . . . 197
25.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

26 Project: Sequence Classification of Movie Reviews 201


26.1 Simple LSTM for Sequence Classification . . . . . . . . . . . . . . . . . . . . . . 201
26.2 LSTM For Sequence Classification With Dropout . . . . . . . . . . . . . . . . . 203
26.3 LSTM and CNN For Sequence Classification . . . . . . . . . . . . . . . . . . . . 206
26.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
vii

27 Understanding Stateful LSTM Recurrent Neural Networks 209


27.1 Problem Description: Learn the Alphabet . . . . . . . . . . . . . . . . . . . . . 209
27.2 LSTM for Learning One-Char to One-Char Mapping . . . . . . . . . . . . . . . 211
27.3 LSTM for a Feature Window to One-Char Mapping . . . . . . . . . . . . . . . . 214
27.4 LSTM for a Time Step Window to One-Char Mapping . . . . . . . . . . . . . . 216
27.5 LSTM State Maintained Between Samples Within A Batch . . . . . . . . . . . . 218
27.6 Stateful LSTM for a One-Char to One-Char Mapping . . . . . . . . . . . . . . . 221
27.7 LSTM with Variable Length Input to One-Char Output . . . . . . . . . . . . . . 224
27.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

28 Project: Text Generation With Alice in Wonderland 228


28.1 Problem Description: Text Generation . . . . . . . . . . . . . . . . . . . . . . . 228
28.2 Develop a Small LSTM Recurrent Neural Network . . . . . . . . . . . . . . . . . 229
28.3 Generating Text with an LSTM Network . . . . . . . . . . . . . . . . . . . . . . 234
28.4 Larger LSTM Recurrent Neural Network . . . . . . . . . . . . . . . . . . . . . . 237
28.5 Extension Ideas to Improve the Model . . . . . . . . . . . . . . . . . . . . . . . 240
28.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

VII Conclusions 242


29 How Far You Have Come 243

30 Getting More Help 244


30.1 Artificial Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
30.2 Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
30.3 Python Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
30.4 Keras Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Preface

Deep learning is a fascinating field. Artificial neural networks have been around for a long time,
but something special has happened in recent years. The mixture of new faster hardware, new
techniques and highly optimized open source libraries allow very large networks to be created
with frightening ease.
This new wave of much larger and much deeper neural networks are also impressively skillful
on a range of problems. I have watched over recent years as they tackle and handily become
state-of-the-art across a range of difficult problem domains. Not least object recognition, speech
recognition, sentiment classification, translation and more.
When a technique comes a long that does so well on such a broad set of problems, you have
to pay attention. The problem is where do you start with deep learning? I created this book
because I thought that there was no gentle way for Python machine learning practitioners to
quickly get started developing deep learning models.
In developing the lessons in this book, I chose the best of breed Python deep learning library
called Keras that abstracted away all of the complexity, ruthlessly leaving you an API containing
only what you need to know to efficiently develop and evaluate neural network models.
This is the guide that I wish I had when I started apply deep learning to machine learning
problems. I hope that you find it useful on your own projects and have as much fun applying
deep learning as I did in creating this book for you.

Jason Brownlee
Melbourne, Australia
2016

viii
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Part I

Introduction

1
Chapter 1

Welcome

Welcome to Deep Learning With Python. This book is your guide to deep learning in Python.
You will discover the Keras Python library for deep learning and how to use it to develop and
evaluate deep learning models. In this book you will discover the techniques, recipes and skills
in deep learning that you can then bring to your own machine learning projects.
Deep learning does have a lot of fascinating math under the covers, but you do not need
to know it to be able to pick it up as a tool and wield it on important projects and deliver
real value. From the applied perspective, deep learning is quite a shallow field and a motivated
developer can quickly pick it up and start making very real and impactful contributions. This is
my goal for you and this book is your ticket to that outcome.

1.1 Deep Learning The Wrong Way


If you ask a deep learning practitioner how to get started with neural networks and deep learning,
what do they say? They say things like

You must have a strong foundation in linear algebra.

You must have a deep knowledge of traditional neural network techniques.

You really must know about probability and statistics.

You should really have a deep knowledge of machine learning.

You probably need to be a PhD in computer science.

You probably need 10 years of experience as a machine learning developer.

You can see that the “common sense” advice means that it is not until after you have
completed years of study and experience that you are ready to actually start developing and
evaluating machine learning model for your machine learning projects.
I think this advice is dead wrong.

2
1.2. Deep Learning With Python 3

1.2 Deep Learning With Python


The approach taken with this book and with all of Machine Learning Mastery is to flip the
traditional approach. If you are interested in deep learning, start by developing and evaluating
deep learning models. Then if you discover you really like it or have a knack for it, later you
can step deeper and deeper into the background and theory, as you need it in order to serve
you in developing better and more valuable results. This book is your ticket to jumping in and
making a ruckus with deep learning.
I have used many of the top deep learning platforms and libraries and I chose what I think
is the best-of-breed platform for getting started and very quickly developing powerful and even
state-of-the-art deep learning models in the Keras deep learning library for Python. Unlike R,
Python is a fully featured programming language allowing you to use the same libraries and
code for model development as you can use in production. Unlike Java, Python has the SciPy
stack for scientific computing and scikit-learn which is a professional grade machine library.
There are two top numerical platforms for developing deep learning models, they are Theano
developed by the University of Montreal and TensorFlow developed at Google. Both were
developed for use in Python and both can be leveraged by the super simple to use Keras library.
Keras wraps the numerical computing complexity of Theano and TensorFlow providing a concise
API that we will use to develop our own neural network and deep learning models.
You will develop your own and perhaps your first neural network and deep learning models
while working through this book, and you will have the skills to bring this amazing new
technology to your own projects. It is going to be a fun journey and I can’t wait to start.

1.3 Book Organization


This book is broken down into three parts.

Lessons where you learn about specific features of neural network models and or how to
use specific aspects of the Keras API.

Projects where you will pull together multiple lessons into an end-to-end project and
deliver a result, providing a template your your own projects.

Recipes where you can copy and paste the standalone code into your own project,
including all of the code presented in this book.

1.3.1 Lessons and Projects


Lessons are discrete and are focused on one topic, designed for you to complete in one sitting.
You can take as long as you need, from 20 minutes if you are racing through, to hours if you
want to experiment with the code or ideas and improve upon the presented results. Your lessons
are divided into five parts:

Background.

Multilayer Perceptrons.

Advanced Multilayer Perceptrons and Keras.


1.3. Book Organization 4

Convolutional Neural Networks.


Recurrent Neural Networks.

1.3.2 Part 2: Background


In this part you will learn about the Theano, TensorFlow and Keras libraries that lay the
foundation for your deep learning journey and about how you can leverage very cheap Amazon
Web Service computing in order to develop and evaluate your own large models in the cloud.
This part of the book includes the following lessons:
Introduction to the Theano Numerical Library.
Introduction to the TensorFlow Numerical Library.
Introduction to the Keras Deep Learning Library.
The lessons will introduce you to the important foundational libraries that you need to
install and use on your workstation. This is taken one step further in a project that shows how
you can cheaply harness GPU cloud computing to develop and evaluate very large deep learning
models.
Project: Develop Large Models on GPUs Cheaply In the Cloud.
At the end of this part you will be ready to start developing models in Keras on your
workstation or in the cloud.

1.3.3 Part 3: Multilayer Perceptrons


In this part you will learn about feedforward neural networks that may be deep or not and how
to expertly develop your own networks and evaluate them efficiently using Keras. This part of
the book includes the following lessons:
Crash Course In Multilayer Perceptrons.
Develop Your First Neural Network With Keras.
Evaluate The Performance of Deep Learning Models.
Use Keras Models With Scikit-Learn For General Machine Learning.
These important lessons are tied together with three foundation projects. These projects
demonstrate how you can quickly and efficiently develop neural network models for tabular
data and provide project templates that you can use on your own regression and classification
machine learning problems. These projects include:
Project: Multiclass Classification Problem.
Project: Binary Classification Problem.
Project: Regression Problem.
At the end of this part you will be ready to discover the finer points of deep learning using
the Keras API.
1.3. Book Organization 5

1.3.4 Part 4: Advanced Multilayer Perceptrons


In this part you will learn about some of the more finer points of the Keras library and API for
practical machine learning projects and some of the more important developments in applied
neural networks that you need to know in order to deliver world class results. This part of the
book includes the following lessons:

Save Your Models For Later With Network Serialization.

Keep The Best Models During Training With Checkpointing.

Understand Model Behavior During Training By Plotting History.

Reduce Overfitting With Dropout Regularization.

Lift Performance With Learning Rate Schedules.

At the end of this part you will know how to confidently wield Keras on your own machine
learning projects with a focus of the finer points of investigating model performance, persisting
models for later use and gaining lifts in performance over baseline models.

1.3.5 Part 5: Convolutional Neural Networks


In this part you will receive a crash course in the dominant model for computer vision machine
learning problems and some natural language problems and how you can best exploit the
capabilities of the Keras API for your own projects. This part of the book includes the following
lessons:

Crash Course In Convolutional Neural Networks.

Improve Model Performance With Image Augmentation.

The best way to learn about this impressive type of neural network model is to apply it.
You will work through three larger projects and apply CNN to image data for object recognition
and text data for sentiment classification.

Project: Handwritten Digit Recognition.

Project: Object Recognition in Photographs.

Project: Movie Review Sentiment Classification.

After completing the lessons and projects in this part you will have the skills and the
confidence of complete and working templates and recipes to tackle your own deep learning
projects using convolutional neural networks.
1.4. Requirements For This Book 6

1.3.6 Part 6: Recurrent Neural Networks


In this part you will receive a crash course in the dominant model for data with a sequence or
time component and how you can best exploit the capabilities of the Keras API for your own
projects. This part of the book includes the following lessons:

Crash Course In Recurrent Neural Networks.

Multilayer Perceptron Models for Time Series Problems.

LSTM Models for Time Series Problems.

Understanding State in LSTM Models for Sequence Prediction.

The best way to learn about this complex type of neural network model is to apply it.
You will work through two larger projects and apply RNN to sequence classification and text
generation.

Project: Sequence Classification of Movie Reviews.

Project: Text Generation With Alice in Wonderland.

After completing the lessons and projects in this part you will have the skills and the
confidence of complete and working templates and recipes to tackle your own deep learning
projects using recurrent neural networks.

1.3.7 Conclusions
The book concludes with some resources that you can use to learn more information about a
specific topic or find help if you need it as you start to develop and evaluate your own deep
learning models.

1.3.8 Recipes
Building up a catalog of code recipes is an important part of your deep learning journey. Each
time you learn about a new technique or new problem type, you should write up a short code
recipe that demonstrates it. This will give you a starting point to use on your next deep learning
or machine learning project.
As part of this book you will receive a catalog of deep learning recipes. This includes recipes
for all of the lessons presented in this book, as well as the complete code for all of the projects.
You are strongly encouraged to add to and build upon this catalog of recipes as you expand
your use and knowledge of deep learning in Python.

1.4 Requirements For This Book


1.4.1 Python and SciPy
You do not need to be a Python expert, but it would be helpful if you knew how to install and
setup Python and SciPy. The lessons and projects assume that you have a Python and SciPy
1.5. Your Outcomes From Reading This Book 7

environment available. This may be on your workstation or laptop, it may be in a VM or a


Docker instance that you run, or it may be a server instance that you can configure in the cloud
as taught in Part II of this book.
Technical Requirements: The technical requirements for the code and tutorials in this
book are as follows:

Python version 2 or 3 installed. This book was developed using Python version 2.7.11.

SciPy and NumPy installed. This book was developed with SciPy version 0.17.0 and
NumPy version 1.11.0.

Matplotlib installed. This book was developed with Matplotlib version 1.5.1.

Pandas installed. This book was developed with Pandas version 0.18.0.

scikit-learn installed. This book was developed with scikit-learn 0.17.1.

You do not need to match the version exactly, but if you are having problems running a
specific code example, please ensure that you update to the same or higher version as the library
specified. You will be guided as to how to install the deep learning libraries Theano, TensorFlow
and Keras in Part II of the book.

1.4.2 Machine Learning


You do not need to be a machine learning expert, but it would be helpful if you knew how to
navigate a small machine learning problem using scikit-learn. Basic concepts like cross validation
and one hot encoding used in lessons and projects are described, but only briefly. There are
resources to go into these topics in more detail at the end of the book, but some knowledge of
these areas might make things easier for you.

1.4.3 Deep Learning


You do not need to know the math and theory of deep learning algorithms, but it would be
helpful to have some basic idea of the field. You will get a crash course in neural network
terminology and models, but we will not go into much detail. Again, there will be resources for
more information at the end of the book, but it might be helpful if you can start with some
idea about neural networks.
Note: All tutorials can be completed on standard workstation hardware with a CPU. A
GPU is not required. Some tutorials later in the book can be sped up significantly by running
on the GPU and a suggestion is provided to consider using GPU hardware at the beginning of
those sections. You can access GPU hardware easily and cheaply in the cloud and a step-by-step
procedure is taught on how to do this in Chapter 5.

1.5 Your Outcomes From Reading This Book


This book will lead you from being a developer who is interested in deep learning with Python
to a developer who has the resources and capabilities to work through a new dataset end-to-end
using Python and develop accurate deep learning models. Specifically, you will know:
1.6. What This Book is Not 8

How to develop and evaluate neural network models end-to-end.

How to use more advanced techniques required for developing state-of-the-art deep learning
models.

How to build larger models for image and text data.

How to use advanced image augmentation techniques in order to lift model performance.

How to get help with deep learning in Python.

From here you can start to dive into the specifics of the functions, techniques and algorithms
used with the goal of learning how to use them better in order to deliver more accurate predictive
models, more reliably in less time. There are a few ways you can read this book. You can dip
into the lessons and projects as your need or interests motivate you. Alternatively, you can
work through the book end-to-end and take advantage of how the lessons and projects build in
complexity and range. I recommend the latter approach.
To get the very most from this book, I recommend taking each lesson and project and build
upon them. Attempt to improve the results, apply the method to a similar but di↵erent problem,
and so on. Write up what you tried or learned and share it on your blog, social media or send
me an email at [email protected]. This book is really what you make of it
and by putting in a little extra, you can quickly become a true force in applied deep learning.

1.6 What This Book is Not


This book solves a specific problem of getting you, a developer, up to speed applying deep
learning to your own machine learning projects in Python. As such, this book was not intended
to be everything to everyone and it is very important to calibrate your expectations. Specifically:

This is not a deep learning textbook. We will not be getting into the basic theory
of artificial neural networks or deep learning algorithms. You are also expected to have
some familiarity with machine learning basics, or be able to pick them up yourself.

This is not an algorithm book. We will not be working through the details of how
specific deep learning algorithms work. You are expected to have some basic knowledge of
deep learning algorithms or how to pick up this knowledge yourself.

This is not a Python programming book. We will not be spending a lot of time on
Python syntax and programming (e.g. basic programming tasks in Python). You are
expected to already be familiar with Python or a developer who can pick up a new C-like
language relatively quickly.

You can still get a lot out of this book if you are weak in one or two of these areas, but you
may struggle picking up the language or require some more explanation of the techniques. If
this is the case, see the Getting More Help chapter at the end of the book and seek out a good
companion reference text.
1.7. Summary 9

1.7 Summary
It is a special time right now. The tools for applied deep learning have never been so good.
The pace of change with neural networks and deep learning feels like it has never been so fast,
spurred by the amazing results that the methods are showing in such a broad range of fields.
This is the start of your journey into deep learning and I am excited for you. Take your time,
have fun and I’m so excited to see where you can take this amazing new technology.

1.7.1 Next
Let’s dive in. Next up is Part II where you will take a whirlwind tour of the foundation libraries
for deep learning in Python, namely the numerical libraries Theano and TensorFlow and the
library you will be using throughout this book called Keras.
Part II

Background

10
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 2

Introduction to Theano

Theano is a Python library for fast numerical computation that can be run on the CPU or GPU.
It is a key foundational library for deep learning in Python that you can use directly to create
deep learning models. After completing this lesson, you will know:

About the Theano library for Python.

How a very simple symbolic expression can be defined, compiled and calculated.

Where you can learn more about Theano.

Let’s get started.

2.1 What is Theano?


Theano is an open source project released under the BSD license and was developed by the LISA
(now MILA1 ) group at the University of Montreal, Quebec, Canada (home of Yoshua Bengio).
It is named after a Greek mathematician. At it’s heart Theano is a compiler for mathematical
expressions in Python. It knows how to take your structures and turn them into very efficient
code that uses NumPy, efficient native libraries like BLAS and native code to run as fast as
possible on CPUs or GPUs.
It uses a host of clever code optimizations to squeeze as much performance as possible from
your hardware. If you are into the nitty-gritty of mathematical optimizations in code, check out
this interesting list2 . The actual syntax of Theano expressions is symbolic, which can be o↵
putting to beginners. Specifically, expression are defined in the abstract sense, compiled and
later actually used to make calculations.
Theano was specifically designed to handle the types of computation required for large
neural network algorithms used in deep learning. It was one of the first libraries of its kind
(development started in 2007) and is considered an industry standard for deep learning research
and development.
1
http://mila.umontreal.ca/
2
http://deeplearning.net/software/theano/optimizations.html#optimizations

11
2.2. How to Install Theano 12

2.2 How to Install Theano


Theano provides extensive installation instructions for the major operating systems: Windows,
OS X and Linux. Read the Installing Theano guide for your platform3 . Theano assumes a
working Python 2 or Python 3 environment with SciPy. There are ways to make the installation
easier, such as using Anaconda4 to quickly setup Python and SciPy on your machine as well
as using Docker images. With a working Python and SciPy environment, it is relatively
straightforward to install Theano using pip, for example:
sudo pip install Theano

Listing 2.1: Install Theano with pip.


New releases of Theano may be announced and you will want to update to get any bug fixes
and efficiency improvements. You can upgrade Theano using pip as follows:
sudo pip install --upgrade --no-deps theano

Listing 2.2: Upgrade Theano with pip.


You may want to use the bleeding edge version of Theano checked directly out of GitHub.
This may be required for some wrapper libraries that make use of bleeding edge API changes.
You can install Theano directly from a GitHub checkout as follows:
sudo pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git

Listing 2.3: Upgrade Theano with pip from GitHub.


You are now ready to run Theano on your CPU, which is just fine for the development of
small models. Large models may run slowly on the CPU. If you have a Nvidia GPU, you may
want to look into configuring Theano to use your GPU. There is a wealth of documentation of
the Theano homepage for further configuring the library.

Theano v0.8.2is the latest at the time of writing and is used in this book.

2.3 Simple Theano Example


In this section we demonstrate a simple Python script that gives you a flavor of Theano. In this
example we define two symbolic floating point variables a and b. We define an expression that
uses these variables (c = a + b). We then compile this symbolic expression into a function using
Theano that we can use later. Finally, we use our compiled expression by plugging in some real
values and performing the calculation using efficient compiled Theano code under the covers.
# Example of Theano library
import theano
from theano import tensor
# declare two symbolic floating-point scalars
a = tensor.dscalar()
b = tensor.dscalar()
3
http://deeplearning.net/software/theano/install.html
4
https://www.continuum.io/downloads
2.4. Extensions and Wrappers for Theano 13

# create a simple symbolic expression


c = a + b
# convert the expression into a callable object that takes (a,b) and computes c
f = theano.function([a,b], c)
# bind 1.5 to a , 2.5 to b , and evaluate c
result = f(1.5, 2.5)
print(result)

Listing 2.4: Example of Symbolic Arithmetic with Theano.


Running the example prints the output 4, which matches our expectation that 1.5 + 2.5 = 4.0.
This is a useful example as it gives you a flavor for how a symbolic expression can be defined,
compiled and used. Although we have only performed a basic introduction of adding 2 and 2,
you can see how pre-defining computation to be compiled for efficiency may be scaled up to
large vector and matrix operations required for deep learning.

2.4 Extensions and Wrappers for Theano


If you are new to deep learning you do not have to use Theano directly. In fact, you are highly
encouraged to use one of many popular Python projects that make Theano a lot easier to use
for deep learning. These projects provide data structures and behaviors in Python, specifically
designed to quickly and reliably create deep learning models whilst ensuring that fast and
efficient models are created and executed by Theano under the covers. The amount of Theano
syntax exposed by the libraries varies.
Keras is a wrapper library that hides Theano completely and provides a very simple API to
work with to create deep learning models. It hides Theano so well, that it can in fact run as a
wrapper for another popular foundation framework called TensorFlow (discussed next).

2.5 More Theano Resources


Looking for some more resources on Theano? Take a look at some of the following.

Theano Official Homepage


http://deeplearning.net/software/theano/

Theano GitHub Repository


https://github.com/Theano/Theano/

Theano: A CPU and GPU Math Compiler in Python (2010)


http://www.iro.umontreal.ca/~lisa/pointeurs/theano_scipy2010.pdf

List of Libraries Built on Theano


https://github.com/Theano/Theano/wiki/Related-projects

List of Theano configuration options


http://deeplearning.net/software/theano/library/config.html
2.6. Summary 14

2.6 Summary
In this lesson you discovered the Theano Python library for efficient numerical computation.
You learned:

Theano is a foundation library used for deep learning research and development.

Deep learning models can be developed directly in Theano if desired.

The development and evaluation of deep learning models is easier with wrapper libraries
like Keras.

2.6.1 Next
You now know about the Theano library for numerical computation in Python. In the next
lesson you will discover the TensorFlow library released by Google that attempts to o↵er the
same capabilities.
Chapter 3

Introduction to TensorFlow

TensorFlow is a Python library for fast numerical computing created and released by Google.
It is a foundation library that can be used to create deep learning models directly or by using
wrapper libraries that simplify the process built on top of TensorFlow. After completing this
lesson you will know:

About the TensorFlow library for Python.

How to define, compile and evaluate a simple symbolic expression in TensorFlow.

Where to go to get more information on the Library.

Let’s get started.


Note: TensorFlow is not easily supported on Windows at the time of writing. It may be
possible to get TensorFlow working on windows with Docker. TensorFlow is not required to
complete the rest of this book, and if you are on the Windows platform you can skip this lesson.

3.1 What is TensorFlow?


TensorFlow is an open source library for fast numerical computing. It was created and is
maintained by Google and released under the Apache 2.0 open source license. The API is
nominally for the Python programming language, although there is access to the underlying
C++ API. Unlike other numerical libraries intended for use in Deep Learning like Theano,
TensorFlow was designed for use both in research and development and in production systems,
not least RankBrain in Google search1 and the fun DeepDream project2 . It can run on single
CPU systems, GPUs as well as mobile devices and large scale distributed systems of hundreds
of machines.

3.2 How to Install TensorFlow


Installation of TensorFlow is straightforward if you already have a Python SciPy environment.
TensorFlow works with Python 2.7 and Python 3.3+. With a working Python and SciPy
1
https://en.wikipedia.org/wiki/RankBrain
2
https://en.wikipedia.org/wiki/DeepDream

15
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Plain
Parochial Sermons, preached in the Parish
Church of Bolton-le-Moors
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: Plain Parochial Sermons, preached in the Parish Church of


Bolton-le-Moors

Author: James Slade

Release date: May 25, 2020 [eBook #62223]

Language: English

Credits: Transcribed from the 1831 C. J. G. and F. Rivington edition


by David Price

*** START OF THE PROJECT GUTENBERG EBOOK PLAIN


PAROCHIAL SERMONS, PREACHED IN THE PARISH CHURCH OF
BOLTON-LE-MOORS ***
Transcribed from the 1831 C. J. G. and F. Rivington edition by David
Price, [email protected]

PLAIN
PAROCHIAL SERMONS,

PREACHED IN

THE PARISH CHURCH OF BOLTON-LE-MOORS,


BY THE
REV. JAMES SLADE, M.A.,
VICAR OF BOLTON, AND PREBENDARY OF CHESTER.

London:
C. J. G. AND F. RIVINGTON, ST. PAUL’S CHURCH YARD.

1831.

BOLTON:
PRINTED BY J. GARDNER.

TO THE CONGREGATION
OF THE PARISH CHURCH OF BOLTON,
THESE SERMONS
ARE INSCRIBED AND DEDICATED,
WITH AFFECTIONATE REGARD,
BY THEIR PASTOR AND FRIEND,
J. S.
ADVERTISEMENT.

The author has been repeatedly urged to print a volume of his


Parochial Sermons; and perhaps he owes some apology to those
friends, whose kind advice, on this head, has been for years
neglected. He was apprehensive, that the interest, excited by his
discourses from the pulpit, would not be adequately revived by their
appearance in print; or at most, that they would be impressive only
upon those who had heard them: and he moreover thought, that the
christian world was already provided with more than a sufficiency of
such publications. However, whether these opinions be well founded
or not, he has been at length prevailed upon to defer to the wishes
and judgment of others.
It is almost needless to observe, that the Sermons were written
without any, the most distant, view to publication; they pretend to
nothing, but the simple and earnest inculcation of christian principle
and practice; and as this is the author’s sole object, so does he pour
forth his humble prayer, that what, by God’s help, he has planted
and watered, may, by God’s blessing, be increased to the glory of
His own great name, and the edification of His Church.
CONTENTS.

SERMON I.
AWAKE THOU THAT SLEEPEST AND ARISE FROM THE DEAD.

Ephesians v. 14.—Wherefore He saith, Awake thou that sleepest, Page


and arise from the dead, and Christ shall give thee light. 1
[Preached January 10th, 1830, 1st Epiph., [vii] and at Chester
Cathedral, August 1st, in the same year.]
SERMON II.
THE UNSEARCHABLE RICHES OF CHRIST.

Ephesians iii. 8.—The unsearchable riches of Christ. 20


[Preached January 9th, 1831, 1st Epiph.]
SERMON III.
THE DESTRUCTION OF THE FLOOD.

Genesis vi. 7.—It repented the Lord, that He had made man 38
upon the earth and it grieved Him at His heart; and the Lord
said, I will destroy man, whom I have created, from the face
of the earth.
[Preached February 6th, 1825, Sexag.]
SERMON IV.
THE PRESERVATION FROM THE FLOOD.

Genesis vi. 8.—Noah found grace in the eyes of the Lord. 56


[Preached February 13th, 1825.]
SERMON V.
DO THIS GREAT WICKEDNESS AND SIN AGAINST GOD,

Genesis xxxix. 9.—How then can I do this great wickedness and 76


sin against God?
[Preached March 6th, 1825, 3rd Lent.]
SERMON VI.
ON THE JOURNEY TO EMMAUS.

Luke xxiv. 32.—And they said one to another, Did not our heart 95
burn within us, while He talked with us by the way, and while
He opened to us the Scriptures?
[Preached April 13th, 1828, 1st Easter, and at Chester
Cathedral July 12th, 1829.]
SERMON VII.
IF THEY HEAR NOT MOSES AND THE PROPHETS.

Luke xvi. 31.—If they hear not Moses and the Prophets, neither 114
will they be persuaded, though one rose from the dead.
[Preached June 1st, 1823, 1st Trin.]
SERMON VIII.
PERFECT LOVE CASTETH OUT FEAR.

1 John iv. 18,—There is no fear in love, but perfect love casteth 134
out fear: because fear hath torment; he that feareth is not
made perfect in love.
[Preached June 16th, 1822, 2nd Trin.]
SERMON IX.
HUMBLE YOURSELVES UNDER THE MIGHTY HAND OF GOD.

1 Peter v. 6.—Humble yourselves under the mighty hand of 154


God, that He may exalt you in due time.
[Preached June 19th, 1825, 3rd Trin.]
SERMON X.
THOU ART THE MAN.
2 Samuel xii. 7.—And Nathan said to David, Thou art the man. 172
[Preached July 14th, 1822, 6th Trin., and at Chester Cathedral
July 6th 1823.]
SERMON XI.
THE WAY OF THE LORD EQUAL.

Ezekiel xviii. 25.—Ye say, the way of the Lord is not equal. 189
Hear now, O house of Israel; is not My ways equal? are not
your ways unequal?
[Preached October 10th, 1824, 17th Trin.]
SERMON XII.
THE NEW MAN.

Ephesians iv. 24.—That ye put on the new man, which after God 209
is created in righteousness and true holiness.
[Preached October 13th, 1822, 19th Trin.]
SERMON XIII.
THE WEDDING GARMENT.

Matthew xxii. 2.—The kingdom of heaven is like unto a certain 230


king which made a marriage for his son.
[Preached October 31st, 1824, 20th Trin.]
SERMON XIV.
WALK WORTHY OF THE LORD, BE FRUITFUL AND INCREASING.

Colossians i. 10.—That ye might walk worthy of the Lord unto 252


all pleasing, being fruitful in every good work, and increasing
in the knowledge of God.
[Preached November 9th, 1823, 24th Trin. and at Chester
Cathedral, August 20th, 1826.]
SERMON XV.
THE WORD OF THE LORD PRECIOUS.

1 Samuel iii. 1.—The word of the Lord was precious in those 271
days; there was no open vision.
[Preached December 9th, 1827. 2nd Advent]
SERMON XVI.
DISTINCTIONS TO BE MADE ON THE DAY OF JUDGMENT.

Matthew xxiv. 40.—The one shall be taken and the other left. 290
[Preached December 12th, 1824, 3rd Advent.]
SERMON XVII.
GOD MADE MAN UPRIGHT; MAN MAKES HIMSELF MISERABLE.

Eccles. vii. 29.—Lo, this only have I found, that God hath made 310
man upright, but they have sought out many inventions.
[Preached August, 1828, and at Chester Cathedral, June 28th,
1829.]
SERMON XVIII.
THE KNOWLEDGE OF GOD REVEALED TO THEM THAT FEAR HIM.

Psalm xxv. 14.—The secret of the Lord is with them that fear 329
Him; and He will shew them His covenant.
[Preached November 19th, 1826, and at Chester Cathedral,
July 29th, 1827.]
SERMON XIX.
RESIST THE BEGINNINGS OF EVIL TEMPTATION.

Proverbs iv. 14, 15.—Enter not into the path of the wicked, and 349
go not in the way of evil men. Avoid it, pass not by it, turn
from it, and pass away.
[Preached October 10th, 1830.]
SERMON XX.
THE LOVE OF CHRIST FOR THOSE WHO DO THE WILL OF GOD.

Mark iii. 35.—Whosoever shall do the will of God, the same is 366
My brother and My sister and mother.
[Preached February 3rd, 1828.]
SERMON XXI.
ON SEEKING OUT THE WORKS OF THE LORD AND PRAISING HIM.
Psalm cxi. 1, 2.—I will give thanks unto the Lord with my whole 385
heart; in the assembly of the upright and in the congregation.
The works of the Lord are great, sought out of all them that
have pleasure therein.
[Preached November 23rd, 1828.]
SERMON XXII.
DILIGENCE AND PERSEVERANCE IN THE CHRISTIAN RACE.

Philipp. iii. 13, 14.—Brethren, I count not myself to have 404


apprehended; but this one thing I do, forgetting those things
which are behind, and reaching forth unto those things which
are before, I press toward the mark for the prize of the high
calling of God in Christ Jesus.
[Preached March 28th, 1830, and at Chester Cathedral,
September 5th, in the same year.]
SERMON I.
AWAKE THOU THAT SLEEPEST.

Ephesians v. 14.
Wherefore, he saith, Awake, thou that sleepest, and arise from
the dead, and Christ shall give thee light.

In this chapter the Apostle has been reminding his Ephesian converts
of the state in which they were, before they had received and
obeyed the call of the gospel. The people of Ephesus were highly
endowed, in the world’s estimation, not only with riches, but also
with talent and learning, and refinement; with all the arts and
ornaments of civilized life. And yet, how does St. Paul describe them
in the 8th verse? “Ye were sometimes darkness;” how in the 12th?
“For it is a shame even to speak of those things which are done of
them in secret.”
Here, you observe, we have a remarkable declaration from the
mouth of an Apostle, that a people, however talented and learned,
were still wrapt in the mantle of darkness, with regard to their real
good and happiness; with regard to their religious and moral
condition. Whatever nature had done for them, to whatever
eminence they had been raised by art or industry, they were left far
short of the object which it concerned them most to attain—an
acquaintance with God, a knowledge and practice of His law; a
peace with Him and with their own consciences. So far were they
from this, that their characters were stained with the most debasing
vices; their secret sins were too abominable even to be mentioned.
Thus we see how little the instructions and advantages of this world
have to do with reforming the conduct, or amending the depraved
heart of man. And what was true in this instance, is true in all;
there is no teaching, there are no rules of prudence, no maxims
however wise, no manners however polished, that can cleanse the
heart of its natural unrighteousness, and curb its natural propensity
to evil: give what you may, educate as you may, man, if left to his
own wisdom and strength, will remain what he is by fallen nature, a
weak, a wayward, and a wicked being; an enemy to holiness and to
God. There may be a shew of wisdom “falsely so called;” there may
be a refined conversation and a polished outside; but there will
always be uncleanness remaining within. The evil principles may
wear a dazzling veil, and the vices may be clothed in fashionable
garments, but they will be evil principles and vices still.
There is but one means by which the darkness of nature can be
scattered, and that is by the light of God’s truth; but one means by
which the evil spirit of the natural man can be cast out, and that is
by the Spirit of God. The blessed Jesus came into the world to
reclaim and redeem it from the grossness in which it was sunk; to
open a new scene of things; to impart a new life; to banish the thick
cloud of error and of sin, in which the world hopelessly and
irrecoverably lay; and to raise it to the knowledge and service, the
favour and blessing of an offended God. This is the description of
the happy effects which the gospel is intended and fitted to produce;
“the people that walked in darkness have seen a great light; they
that dwell in the land of the shadow of death, upon them hath the
light shined.” [4] All, without the gospel, are in this miserable
condition, whatever they may think of themselves: all who sincerely
embrace it, are enlightened and happy, however poor and humble,
and of whatever else they may be ignorant.
Poor and humble did I say? It is to them, that this light is the most
easily, and frequently, and effectually communicated. The
prosperous and the great too often resemble the wealthy Ephesians,
“having the understanding darkened, being alienated from the life of
God through the ignorance that is in them, because of the blindness
of their heart;” [5] revelling in the self-sufficiency of their earthly
comforts, proud of their acquirements, fond of their own way, they
disdain to be taught the humbling truths of the gospel from a fellow-
creature like themselves: and often has the minister of the gospel to
be thankful to his Lord and Master, that, when he finds his message
rejected and despised by his wealthier hearers, it still makes its way
into the hearts of some of the poor: grieved he is indeed, that those,
who ought to know it best and love it most, should be so deluded by
worldly vanities and follies, as to continue, amidst all their
advantages of education, in spiritual darkness and death; set against
the messenger, because hating the truth of his message: yet, is it a
comfort to him, sincere and unspeakable, that he meets with more
success among the ignorant, as they are called, and the children of
the poor: that there he finds wisdom, “the wisdom which is from
above;” and there he finds friends among the friends of God.
It was so in the Apostle’s day; and with some bright exceptions, it
has been the same in every day: “For ye see your calling, brethren,
how that not many wise men after the flesh, not many mighty, not
many noble are called; but God hath chosen the foolish things of the
world to confound the wise; and God hath chosen the weak things
of the world, to confound the things that are mighty: and base
things of the world, and things which are despised hath God chosen;
yea, and things which are not, to bring to nought things that are:
that no flesh should glory in his presence.” [7]
All these observations have been made, to connect and explain the
first word of the text, wherefore; “wherefore, he saith, awake thou
that sleepest and arise from the dead, and Christ shall give thee
light.” Inasmuch as it is impossible for thee to know and to please
God, to attain unto holiness and happiness, to save thy soul, by the
light of nature, (for nature is in fact, of itself and for such a purpose,
no light at all,) turn to the way, which is opened to thee by the
shining of the Sun of Righteousness; to that one way, which is
opened alike for all mankind, rich and poor, learned and unlearned;
turn to thy Redeemer, in humble faith and hearty desire, and “He
shall give thee light:” learn of Him and He shall teach thee all that
thou needest to know: seek of Him, and He shall guide thee into all
righteousness and truth; lean on Him, and He shall support thee,
through all the course of thy earthly pilgrimage; and conduct thee in
peace and safety to thy journey’s end.
“Wherefore, he saith;” there is no particular passage in the Old
Testament, in which these words of the text are found; but they
seem to allude to several expressions of similar import, in the
prophecy of Isaiah. In the 26th chapter, there is a passage which
describes the deliverance of God’s people from a state of
degradation, both political and spiritual, under the figure of a
resurrection from the dead: “Thy dead men shall live, together with
my dead body shall they arise. Awake and sing, ye that dwell in
dust; for thy dew is as the dew of herbs, and the earth shall cast out
the dead.” [8] And again, in the 52nd chapter: “Awake, awake, put
on thy strength, O Zion; put on thy beautiful garments, O Jerusalem,
the Holy city; for henceforth there shall no more come in to thee the
uncircumcised and the unclean; shake thyself from the dust; arise
and sit down, O Jerusalem: loose thyself from the bands of thy neck,
O captive daughter of Zion: for thus saith the Lord, ye have sold
yourselves for nought; and ye shall be redeemed without money:”
[9a]
a powerful call upon the Jewish people to cast away their
transgressions, through which they had been brought into a state of
grievous captivity, and to throw themselves on the Lord’s mercy, and
return to the Lord’s service, that He might break their bonds
asunder, and visit them with His salvation. One more passage there
is, to which the Apostle clearly alludes, in the opening of the 60th
chapter: “Arise, shine, for thy light is come, and the glory of the Lord
is risen upon thee. For behold, the darkness shall cover the earth,
and gross darkness the people: but the Lord shall arise upon thee,
and his glory shall be seen upon thee.” [9b] Here the prophet foretels
the glorious dawn of gospel light, and calls upon the Church to arise
and behold it, shining from afar; to behold it with the eye of faith; to
look forward to that Saviour, that great “fountain for sin and
uncleanness,” which the law and the prophets did all with one voice
proclaim. The prophet adds, “And the gentiles shall come to thy
light, and kings to the brightness of thy rising.” The first coming of
the gentile world was visible in the footsteps of the wise men, who
came “from the east to Jerusalem,” [10] to worship the infant Jesus:
and ever since our Lord’s return to the heavens, the gospel has been
preached to all nations; and accepted, more or less, by the kings
and potentates of the earth.
And, as the prophet called on the people of old, to awake and arise
and turn to the coming light, so St. Paul invited and animated his
converts and their brethren, to awake and behold the glory of the
Lord, after it had been fully revealed to the dark and sinful world;
and so do the ministers of Christ, in every age, call upon their
hearers to arouse from their benighted and lost condition, and let
this light shine upon their understandings and hearts, and direct
them in the way of life and salvation. For grieved are we to say, that
notwithstanding these bright beams of grace and truth have been so
long pouring forth their splendour upon the earth, yet are there
many dark corners; and many eyes awfully closed against the light:
and still more grieved are we to say, that even in the land where
these beams have shone brightest, even in this land, vast numbers
yet remain total strangers to their enlightening influence and
converting power: numbers who have had the benefit of being
educated under the gospel, who have witnessed its happy effects;
who have seen what it has done for their relations, or friends, or
neighbours, have yet ungratefully and disdainfully turned away from
the heavenly light, and “walked on still in darkness;” have sided with
the world and Satan and sin, and resisted the salvation of their
souls.
O, that they could be brought, O for the grace of God’s Holy Spirit to
bring them, to listen to the warning words of that merciful Saviour,
to whom, if they now continue to despise Him, they will one day lift
up their hands in vain: these are His words, “if the light that is in
thee be darkness, how great is that darkness.” [12] If, after all the
gracious offers of pardon and life, which thy Redeemer has made
thee, by His own mouth, and the mouth of His messengers, thou still
choosest unforgiveness and death, going on in the heedlessness of
thy impenitent heart, and wantoning in sin, how dreadful is thy
condition! how infinitely more dreadful, than if the voice of mercy
had never sounded in thine ears. Be convinced: let the love of thy
Saviour work upon thee; let the love of thine own immortal soul
move thee to fly unto Him, the great, the only, the everlasting
Redeemer. Leave thy way of misery and ruin, and turn to Him for
comfort and deliverance. Turn, while thou hast the power; the night
is fast coming. Thou knowest not how many more sabbaths, how
many more invitations and warnings, will be vouchsafed: many thou
hast had already; enough of them thou hast already slighted. Come,
ye that are strong, for the strong are often laid low; come, ye that
are young, for the young are not always spared; come, ye aged, for
your hour of trial must be nearly run out. Come all, while ye may, to
the Lamb of God, for acceptance and for blessing: there is no safety,
and no hope in any other: and no hope in Him, when the door is
once shut; “we pray you, in Christ’s stead, be ye reconciled to God.”
[13]

The text says, “Awake thou that sleepest;” it means, awake from the
sleep of sin; and very fitly is the state of the sinner compared to a
state of sleep: he is quite insensible of his true, his awful condition;
he fears not, perceives not, the doom that is awaiting him. Satan
has bound up his senses; the eyes of his understanding are closed,
and his knowledge of good and evil is utterly prevented. He is to
the spiritual world, what the sleeping man is to the natural,
unconscious of what is going forward to his advantage or his injury.
Speak to him of mercy, he hears not: “sing him one of the songs of
Sion,” it is all in vain: speak to him of divine wrath, of eternal
punishment; to what purpose, while his ear is closed? The whispers
of conscience, the counsel of friends, “the tongues of men or of
angels,” are alike unprofitable, while a deep sleep is cast upon the
soul.
And there is a further resemblance: the sinner dreams, of happiness
arising from worldly prosperity, from plenty and pleasure: and as the
brain of a poor or disconsolate man, in a state of sleep, is often filled
with ideas of such things, and he awakes and finds them sadly
untrue; awakes from his pleasant dreaming to his state of drudgery
and discomfort; so is the sinner often constrained to feel and
confess, that his notions of happiness were no better than a dream;
that they were unsubstantial and unreal, promising much and
bringing little: still he is unconvinced; pursues his course of trifling,
his disappointed dreamings, till at length he awakes in another
world, and thoroughly perceives the wretchedness of his condition,
which it is then too late, impossible to change. From this dreadful,
fatal sleep of sin, the gospel is designed to rouse us: and I pray God,
that our conscience may be effectually alarmed and awakened; that
we may be alive and active in perceiving and following “the things
that belong unto our peace!”
The text says further, “Arise from the dead;” from the death of sin;
from the state of misery and ruin, in which ye insensibly lie. Here is
another significant figure: the impenitent sinner is not only plunged
into a condition of helpless wretchedness, but he has no energy to
recover from it, no quickening or effectual desire of better things; no
more perception of spiritual interests, of heavenly objects, than a
corpse has of the natural world. When once the breath has left the
body, the busiest scenes of earth can affect it no longer; nothing can
“charm the dull cold ear of death:” when the breath of a divine life is
not in the soul, when the new-creating spirit of God is not received
and cherished, the beauty of holiness and the all-important interests
of a spiritual and eternal world produce no effect upon the forlorn
understanding and the deserted heart: no representations of
spiritual truth can move the heavy ear of a besotted and determined
sinner; none, while he is resolved, so to remain: not even the voice
of the Son of God, “charm He never so wisely.” Till the heart be
moved to repentance, till, the faculties of the soul are recovered
from the fascination of stupor and sin, no living impression can be
made, even with all the force that truth can carry. How often do we
find this to be the case! how often does the sinner acknowledge the
justice, the certainty, the necessity of what is urged upon him, but
without any alteration in his character; without any effectual or
lasting alteration. His heart is unchanged: the slave of sin; dead in
sin; not alive or open to the force of truth, to the doctrines of
righteousness or salvation.
Infatuated sinner! thine own conscience accuses thee; thou believest
that there will be a world to come, a world of recompence, and yet
thou turnest not to prepare for it; pray, when thou fearest; pray,
when thou thinkest of these things; cry earnestly to thy Saviour, that
he may deliver thee from this “gall of bitterness and this bond of
iniquity;” pray for the convincing, converting, life-giving Spirit, that
He may “set thine heart at liberty” from the thraldom of sin; and
thus enable thee to listen to the call of the gospel, and turn thy feet
in earnest to the Redeemer of thy soul. For if thou listenest and
turnest not, “dead thou art while thou livest;” and when thou diest,
eternally dead; dead to all comfort and happiness for ever; dead in a
world of woe.
But if we will (and God grant that we all may) awake and arise,
“Christ will assuredly give us light:” “He is the true light, which
lighteth every man that cometh into the world;” [18] ready to shine
upon every soul, to lighten it in darkness and quicken it in death.
Believe in Him, and live in Him, and the clouds of ignorance shall be
scattered away; and the drowsiness of the soul shall be cast off; and
the cold heart of the natural man shall be warm with life again. In
the midst of this world’s temptations and trials, troubles and
perplexities, we shall see our way clear, our way to the heavenly
Jerusalem; a brightness, the brightness of God’s presence, will be
resting upon our souls; the world sees it not, but we shall see and
enjoy it every hour: dark things will be made light, and “crooked
things will be made straight, and the rough places plain:” we shall
be living above the world, for “our life will be hid with Christ in God:”
[19]
cheerful we shall be when nature is sad: inspirited when nature is
languishing; full of praises and thanksgivings when nature is
mourning.
Say, Christian people, have ye never seen the triumph of faith over
nature’s weakness and Satan’s power? have ye never, in the hour of
trial, witnessed that the Saviour was near? never observed the
fainting spirit animated and sustained? never beheld the closing eye,
of the dying saint, beaming with heavenly fire; and the pale features
lighted up with the smile of satisfaction and composure and peace?
If ye have not, the dying Christian will shew you these things—go to
his bed, and learn the lesson; go, and catch the hope, that “Christ
will give you light.”
SERMON II.
THE UNSEARCHABLE RICHES OF CHRIST.

Eph. iii 8.
The unsearchable riches of Christ.

There is no passage, in the whole range of Scripture, in which the


benefits and blessings of the gospel are more strikingly and fully
represented, than by these few words: it is elsewhere described as
the “pearl of great price,” as “the treasure that fadeth not away,” as
“the true riches;” but here, as if in addition to the former
descriptions, it is called, under the direction of the Holy Spirit, “the
unsearchable riches of Christ:” impossible for men, impossible for
angels to search out and discover its full excellency and value. The
more it is examined, and the more it is experimentally known, the
more is the believer convinced of the propriety and truth of this
description; without a deep enquiry indeed, without a vital
experience of its blessedness, it is not for any one to understand
even the nature of its transcendent riches; to the world at large they
are known only by name: but the sincere Christian, who makes them
his own, is brought to admire their inexhaustible fulness; and to
perceive, how utterly they extend beyond his comprehension, how
highly they are removed above his loftiest thoughts and his most
ardent imagination: “eye hath not seen, nor ear heard, neither have
entered into the heart of man the things which God hath prepared
for them that love him.” [21] They lie entirely out of the reach of the
natural man; and even the spiritual man does but imperfectly
understand them.
These unsearchable riches it was the province of St. Paul especially
to declare unto the gentile world, that is, unto the world at large,
when the offer of them had been rejected by the Jewish nation: in
consequence of which blessed communication to the gentiles, the
knowledge of them was conveyed, in process of time, to our
favoured land.
Many learned persons have believed, that St. Paul himself preached
in this island; of this, however, there is no certain evidence; it is
enough for us to know, that we are partakers of the benefit of his
preaching, that the sound of the gospel, which he sent “forth into all
lands,” has long ago reached us; and that we are now in the full
enjoyment of this inestimable privilege. He declares, in the chapter,
before us, that Jesus Christ, by express revelation, made known to
him the great mystery, the unfathomable purpose of His mercy;
“which in other ages was not made known unto the sons of men, as
it is now revealed unto the holy Apostles and Prophets by the Spirit:
that the Gentiles should be fellow-heirs, and of the same body, and
partakers of His promise in Christ by the gospel.” Unto me, he says,
“who am less than the least of all saints, is this grace given, that I
should preach among the Gentiles the unsearchable riches of Christ.
And to make all men see what is the fellowship of the mystery,
which, from the beginning of the world, hath been hid in God, who
created all things by Jesus Christ.” [23]
You perceive here the object of the Apostle’s preaching; it was, that
all mankind, we among the number, might be brought acquainted
with the glorious scheme of eternal redemption, and be made
partakers of its unspeakable blessings. And is there a heart so cold,
as not to beat with gratitude, in the remembrance of such mercy; as
not to take an interest in such a testimony of divine love? If we
knew no particulars respecting it, the very announcement and
promise of an infinite treasure, of a treasure in the mansions of
eternity, were sufficient to awaken our most profound attention: it
often does so, when carried by the missionary to the heathen and
the stranger; they, who never heard before the good tidings of
salvation, are arrested by the voice of the messenger, and hang
upon his lips with a longing anxiety, and receive his message to the
comfort of their souls: and can we remain unmoved by such
considerations; we, who know the purport of the heavenly message;
we, who profess to believe that it is sent for our everlasting salvation
from sin and death; to reconcile us to an offended God, to deliver us
from the intolerable bondage of Satan, to make us happy while we
live, happy when we die, happy for ever in another world, in the
kingdom of heaven? Though the mercy is too great to be
adequately understood, though “the love of Christ passeth
knowledge,” shall this prevent us from contemplation and enquiry?
shall we not rather, on this very account, entertain a more fervent
desire to understand and know, of this mystery of goodness, all that
is possible to be known? Whoever, indeed, has not this desire,
cannot take any lively interest in the revelation which he professes
to believe, cannot have sincerely embraced it; knowing, as he does,
the subject and purpose of the gospel, he is in a worse situation
than many an ignorant heathen; his heart more hard and
unimpressible; his eyes more closed against the light; his affections
more difficult to be roused and engaged. May the Lord touch the
heart of all such heedless professors; or the very publicans and
sinners, the darkest and most despised of the earth, will “enter into
the kingdom of heaven before them.”
Hoping that we all are deeply concerned in this important matter,
that we do place a most exalted value on the riches of Christ, and
earnestly desire to partake of them, I beg that we may enter
together, with humble minds and spiritual desires, into some
examination of their nature and excellency; and enquire in what
respects, and for what reasons, they are unsearchable.
1. In the first place, what is the foundation of all our blessedness
and all our hope, as the redeemed and adopted children of God; as
brought from a state of enmity and rebellion, into favour with Him;
as having any claim upon His mercy; any prospect of recovering our
lost happiness, of saving our souls alive? What, I say, is the
foundation on which we expect these marvellous acts of grace? It
is, that the everlasting Son of God left “the glory which he had with
the Father before the world was,” [26a] and “took upon Him the form
of a servant,” [26b] the nature of man: it is, that the “Word, who in
the beginning was with God and was God,” “was made flesh” and
came and “dwelt among us, full of grace and truth.” [26c] Here then,
in the very outset, is unsearchable mercy; the immensity of the
divine Redeemer’s condescension and love! Who can search, who
can understand it? “It is higher than heaven, what canst thou
know” of it? Admire thou mayest, and adore and love; but it is
beyond the stretch of thy created powers to conceive, beyond the
capacity of any creature. The great truth is revealed and the work is
accomplished; and here thou must leave it, in humble faith and
overwhelming emotion.
2. We may consider, in the next place, the preciousness, the value,
the efficacy of the incarnation and sufferings of our Redeemer. All
the attributes of the Godhead are perfect and infinite; His holiness
and justice, as well as His mercy. Man, by transgression, fell into a
state of unholiness; his nature became corrupt; his understanding
debased, his affections and passions and desires all sinful; as such
he could not possibly be accepted or blest by the infinitely holy God,
by Him “who is of purer eyes than to behold iniquity:” he became, to
borrow the language of men, vile and hateful in God’s sight; he
resembled Satan and the wicked spirits, who fell, for their
transgression, from the heavens. And so, with regard to justice; the
infinitely just God could not, without some means of atonement or
satisfaction, shew favour to a disobedient, offending, rebellious
creature; it was contrary to His essential character and nature so to
do: nor can we form any true idea of the value of that sacrifice, on
the part of another, which could be held sufficient to reconcile the
great Jehovah to a creature “laden with iniquity:” the displeasure
being infinite, the distance and separation between God and His
creatures infinite, the sacrifice must be infinite also, and exceeding
the bounds of our comprehension. And yet, strange to say, though
the means of the sinner’s re-admission, to the favour and blessing of
a holy and just God, must of necessity be beyond our powers of
conception, there are persons, who object to the Christian doctrine
of the atonement, solely on the ground of its being
incomprehensible. But we, my brethren, “have not so learned
Christ;” we are ready to bow with thankfulness to the revelation of
the great Jehovah, by whose unsearchable wisdom and mercy the
plan of our redemption was formed: we are ready to acknowledge
with reverence, that “great is the mystery of godliness; God was
manifest in the flesh.” [29a]
3. Intimately connected with this consideration is the recollection of
God’s exceeding love towards us, in that “while we were yet sinners
Christ died for us.” [29b] In our very state of guilt and rebellion it
was, that He came into the world; that He did and suffered so much,
“to seek and to save that which was lost.” Suppose that man had
never transgressed; and that God had sent an angel, to shew him
the way to a happier and higher condition, than that in which he was
created: this would have been an act of free and undeserved mercy;
but that He should have sent His beloved Son, to “suffer for sins, the
just for the unjust,” [29c] to be born and to tabernacle in a world of
guilt and sorrow; to be exposed to rejection and scorn, to indignity
and cruelty; to endure the conflicts of Satan and the bitterest
agonies of death; this was indeed an act of love, surpassing the
bounds of thought; a mystery of goodness “into which angels desire
to look,” but cannot penetrate. Every believing soul must be
overpowered by such a contemplation; must be lost in wonder, love,
and praise.
4. Nor can we learn the manner or degree, in which our merciful
Lord is at this moment bestowing blessings upon His Church, and
upon every individual believer. When He ascended up to heaven, His
work of mediation was not finished; He then took upon Him the
office of interceding for His people in all ages: presenting their
prayers, and desires, and all their services, for acceptance at the
throne of grace; pleading His merits for them; observing all their
necessities and wants; and sending His holy spirit and His holy
angels, to minister to their infirmities: not a wounded spirit, but He
is still ready to bind up and heal; not a sigh from a contrite heart,
but He knows and answers; not a child of ignorance, but He is
willing to instruct; not a returning prodigal, but He meets; not a
prayer or thanksgiving, not a godly thought or wish, of a sincere
worshipper and pious servant, but He accepts and blesses: He is
ever with us, though unseen; with us by His providence and grace;
“about our bed and about our path;” pouring his benefits upon us,
temporal, and spiritual: yea upon all His people, at every moment of
time, throughout the whole world. We are lost in this mystery of
mercy—we can but believe, and gratefully apply the benefit to our
souls.
5. And what are the privileges of Christ’s redeemed people? What
their present state, what their glorious inheritance? How
unsearchable both the one and the other! The humble believer, the
repenting sinner, the sincere and faithful servant derives, from the
fountain of mercy which is opened unto him, a perpetual stream of
increasing satisfaction and delight; he finds, that “there is no end
thereof;” that it is a fountain, which he never can fathom. The
sense of pardon and reconciliation with God affords a comfort to his
soul, which flows the more abundantly, the longer he dwells upon it;
as he journies onward in the way of salvation, his hopes are more
enlivened, and his fears more calmed; even when he began to walk
with his God, he felt that all around him was joy, and deemed his
recompence in this life amply sufficient; but, at every step he
advances in communion with his God and Saviour, he perceives more
and more that “His ways are ways of pleasantness and all His paths
are peace;” [32] and this experience will be enlarged the longer he
lives, even beyond his present anticipation. The word of God has
fresh stores for him every day; of knowledge, of comfort, and of
grace: the Spirit of God has fresh supplies; to succour his infirmities,
to elevate him in prayer and meditation, to guide him in perplexity,
to strengthen him in trial, to console him in trouble and affliction, to
raise him above the world, and place his affections in heaven. Thus
will his joy in the Lord increase, till he comes to the end of his
pilgrimage: and, in the end, the riches of redeeming love will be
infinitely enhanced: who shall number or declare them? Which of us
can now understand the preciousness of a Christian’s hope, the
comfort of a Christian’s peace, at that hour, when his soul is
struggling for departure? Who can now enter, as the dying man
does, into the vast difference between the bright hope of being
saved, and the gloomy fear of being lost; between the prospect of
being for ever with the Lord, and the dismal foreboding of the
terrors of the evil one? We have now but a slight conception of the
feelings and views, in that momentous hour; but we shall one day
know: God grant that the knowledge may be peace!
And if we die in peace, then shall we be more than ever convinced
of the truth of the text; we shall then perceive, how little we
comprehended, in our mortal state, of the blessedness of the saints
at rest, of “the rest that remaineth for the people of God.” And, at
the resurrection, other scenes will follow, with more abundant
tokens of confirmation: who can conceive the happiness of rising
with the just; of hearing with joy the trumpet of the archangel; of
beholding, with an eye of rapture, the beaming of that glorious
morn; of meeting the smile of a compassionate Judge and Saviour;
of being called to His right hand, “come, ye blessed of my father,
inherit the kingdom prepared for you from the foundation of the
world:” [34a] what mind on earth is equal to these things?
And then will succeed the consummation of our felicity, “the new
heavens and the new earth, wherein dwelleth righteousness;” [34b]
the enjoyment of the presence of God and the Lamb; the personal
sharing of the service, the honour, and the delight of angels and
archangels, through all eternity. Of this we cannot pretend to form
an estimate in our mortal condition; while the veil is hanging before
our eyes; the holy Spirit, by many a sublime image, lifts our
imagination as high as it can be carried; but still, the representation
must be feeble, when compared with the glorious reality; after all
that has been said, if we arrive at the heavenly city, the appearance
will be new, the happiness new to us all. Unsearchable it is now,
unsearchable it will be then; a wonder of love that will never be
satisfied, a mansion of glory that will never be completely surveyed.
But we shall doubtless behold, on seeing “face to face,” more of the
fulness of the riches of Christ; shall penetrate further into that
mystery of divine love, which planned the merciful work of our
redemption before the foundation of the world; shall see more of the
meetness of the Saviour’s sufferings; of His mighty conquest over sin
and death; of the greatness of His kingdom and the “majesty of His
glory.” We shall then see and admire that now invisible bond, by
which the whole company of the Lord’s servants and people,
heavenly and earthly, have been sustained and kept together: how
men below, and saints at rest, and angels in heaven, have been
bound in spiritual union, through all the ages of time; how the vast
multitude of holy creatures in the universe have felt a common
interest and benefit in their blessed Lord. [36] When they are all
assembled together in adoration round His throne, we shall know
more of this endearing bond; it will then be manifest, and be
perfected for ever.
I need not attempt to go further; certainly none of us will deny the
unsearchableness of the riches of Christ. Certainly every one of us is
ready to exclaim, O that I may be partaker of them; all this world,
nay, a thousand worlds are nothing in comparison. These riches are
now offered to you: they are waiting your acceptance; receive them
with all your heart, and they are yours; you do not expect them to
be forced upon you; you do not expect this happy portion without
choosing it, without prayer and without striving for it; ask earnestly,
seek diligently, and it shall be yours; your inexhaustible treasure, in
time and to eternity.

You might also like