Deep Learning with PyTorch
Vishnu Subramanian
BIRMINGHAM - MUMBAI
"QSBDUJDBMBQQSPBDIUPCVJMEJOHOFVSBMOFUXPSLNPEFMT
VTJOH 1Z5PSDI
Deep Learning with PyTorch
Copyright a 2018 Packt Publishing
First published: February 2018
Production reference: 1210218
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78862-433-6
XXXQBDLUQVCDPN
Foreword
I have been working with Vishnu Subramanian for the last few years. Vishnu comes across
as a passionate techno-analytical expert who has the rigor one requires to achieve
excellence. His points of view on big data/machine learning/AI are well informed and carry
his own analysis and appreciation of the landscape of problems and solutions. Having
known him closely, I'm glad to be writing this foreword in my capacity as the CEO of
Affine.
Increased success through deep learning solutions for our Fortune 500 clients clearly
necessitates quick prototyping. PyTorch (a year-old deep learning framework) allows rapid
prototyping for analytical projects without worrying too much about the complexity of the
framework. This leads to an augmentation of the best of human capabilities with
frameworks that can help deliver solutions faster. As an entrepreneur delivering advanced
analytical solutions, building this capability in my teams happens to be the primary
objective for me. In this book, Vishnu takes you through the fundamentals of building deep
learning solutions using PyTorch while helping you build a mindset geared towards
modern deep learning techniques.
The first half of the book introduces several fundamental building blocks of deep learning
and PyTorch. It also covers key concepts such as overfitting, underfitting, and techniques
that helps us deal with them.
In the second half of the book, Vishnu covers advanced concepts such as CNN, RNN, and
LSTM transfer learning using pre-convoluted features, and one-dimensional convolutions,
along with real-world examples of how these techniques can be applied. The last two
chapters introduce you to modern deep learning architectures such as Inception, ResNet,
DenseNet model and ensembling, and generative networks such as style transfer, GAN,
and language modeling.
With all the practical examples covered and with solid explanations, this is one of the best
books for readers who want to become proficient in deep learning. The rate at which
technology evolves is unparalleled today. To a reader looking forward towards developing
mature deep learning solutions, I would like to point that the right framework also drives
the right mindset.
To all those reading through this book, happy exploring new horizons!
Wishing Vishnu and this book a roaring success, which they both deserve.
Manas Agarwal
CEO, Co-Founder of Affine Analytics,
Bengaluru, India
Preface
1
Chapter 1: Getting Started with Deep Learning Using PyTorch
6
Artificial intelligence
7
The history of AI
7
Machine learning
8
Examples of machine learning in real life
9
Deep learning
9
Applications of deep learning
10
Hype associated with deep learning
12
The history of deep learning
13
Why now?
13
Hardware availability
13
Data and algorithms
15
Deep learning frameworks
15
PyTorch
16
Summary
17
Chapter 2: Building Blocks of Neural Networks
18
Installing PyTorch
18
Our first neural network
19
Data preparation
20
Scalar (0-D tensors)
21
Vectors (1-D tensors)
21
Matrix (2-D tensors)
21
3-D tensors
22
Slicing tensors
23
4-D tensors
26
5-D tensors
26
Tensors on GPU
27
Variables
28
Creating data for our neural network
30
Creating learnable parameters
30
Contents