Deep Learning with Python 1st Edition Nikhil Ketkar pdf download
Deep Learning with Python 1st Edition Nikhil Ketkar pdf download
Ketkar download
https://ebookmeta.com/product/deep-learning-with-python-1st-
edition-nikhil-ketkar/
https://ebookmeta.com/product/deep-learning-with-python-2nd-
edition-nikhil-ketkar/
https://ebookmeta.com/product/fundamentals-of-deep-learning-
nikhil-buduma/
https://ebookmeta.com/product/applied-deep-learning-with-
tensorflow-2-learn-to-implement-advanced-deep-learning-
techniques-with-python-2nd-edition-umberto-michelucci-2/
https://ebookmeta.com/product/oxford-textbook-of-palliative-care-
for-children-3rd-edition-richard-hain/
Business Law 11th Edition Andy Gibson
https://ebookmeta.com/product/business-law-11th-edition-andy-
gibson/
https://ebookmeta.com/product/algorithmic-game-theory-15th-
international-symposium-sagt-2022-colchester-uk-
september-12-15-2022-proceedings-panagiotis-kanellopoulos/
https://ebookmeta.com/product/savage-caress-savage-shifters-
book-4-1st-edition-milly-taiden-taiden-milly/
https://ebookmeta.com/product/the-indigenization-of-christianity-
in-china-ii-1st-edition-qi-duan/
Jojo Moolayil
Vancouver, BC, Canada
Apress Standard
Trademarked names, logos, and images may appear in this book. Rather
than use a trademark symbol with every occurrence of a trademarked
name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark. The use in this publication
of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of
opinion as to whether or not they are subject to proprietary rights.
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, express or implied, with respect to the material
contained herein or for any errors or omissions that may have been
made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
—Nikhil Ketkar
—Jojo Moolayil
Table of Contents
Chapter 1:Introduction to Machine Learning and Deep Learning
Defining Deep Learning
A Brief History
Advances in Related Fields
Prerequisites
The Approach Ahead
Installing the Required Libraries
The Concept of Machine Learning
Binary Classification
Regression
Generalization
Regularization
Summary
Chapter 2:Introduction to PyTorch
Why Do We Need a Deep Learning Framework?
What Is PyTorch?
Why PyTorch?
It All Starts with a Tensor
Creating Tensors
Tensor Munging Operations
Mathematical Operations
Element-Wise Mathematical Operations
Trigonometric Operations in Tensors
Comparison Operations for Tensors
Linear Algebraic Operations
Summary
Chapter 3:Feed-Forward Neural Networks
What Is a Neural Network?
Unit
The Overall Structure of a Neural Network
Expressing a Neural Network in Vector Form
Evaluating the Output of a Neural Network
Training a Neural Network
Deriving Cost Functions Using Maximum Likelihood
Binary Cross-Entropy
Cross-Entropy
Squared Error
Summary of Loss Functions
Types of Activation Functions
Linear Unit
Sigmoid Activation
Softmax Activation
Rectified Linear Unit
Hyperbolic Tangent
Backpropagation
Gradient Descent Variants
Gradient-Based Optimization Techniques
Practical Implementation with PyTorch
Summary
Chapter 4:Automatic Differentiation in Deep Learning
Numerical Differentiation
Symbolic Differentiation
Automatic Differentiation Fundamentals
Implementing Automatic Differentiation
Summary
Chapter 5:Training Deep Leaning Models
Performance Metrics
Classification Metrics
Regression Metrics
Data Procurement
Splitting Data for Training, Validation, and Testing
Establishing the Achievable Limit on the Error Rate
Establishing the Baseline with Standard Choices
Building an Automated, End-to-End Pipeline
Orchestration for Visibility
Analysis of Overfitting and Underfitting
Hyperparameter Tuning
Model Capacity
Regularizing the Model
Early Stopping
Norm Penalties
Dropout
A Practical Implementation in PyTorch
Interpreting the Business Outcomes for Deep Learning
Summary
Chapter 6:Convolutional Neural Networks
Convolution Operation
Pooling Operation
Convolution-Detector-Pooling Building Block
Stride
Padding
Batch Normalization
Filter
Filter Depth
Number of Filters
Summarizing key learnings from CNNs
Implementing a basic CNN using PyTorch
Implementing a larger CNN in PyTorch
CNN Thumb Rules
Summary
Chapter 7:Recurrent Neural Networks
Introduction to RNNs
Training RNNs
Bidirectional RNNs
Vanishing and Exploding Gradients
Gradient Clipping
Long Short-Term Memory
Practical Implementation
Summary
Chapter 8:Recent Advances in Deep Learning
Going Beyond Classification in Computer Vision
Object Detection
Image Segmentation
Pose Estimation
Generative Computer Vision
Natural Language Processing with Deep Learning
Transformer Models
Bidirectional Encoder Representations from Transformers
GrokNet
Additional Noteworthy Research
Concluding Thoughts
Index
About the Authors
Nikhil Ketkar
currently leads the Machine Learning
Platform team at Flipkart, India’s largest
ecommerce company. He received his
PhD from Washington State University.
Following that, he conducted
postdoctoral research at University of
North Carolina at Charlotte, which was
followed by a brief stint in high-
frequency trading at TransMarket in
Chicago. More recently, he led the data
mining team at Guavus, a startup doing
big data analytics in the telecom domain,
and Indix, a startup doing data science in the ecommerce domain. His
research interests include machine learning and graph theory.
Jojo Moolayil
is an artificial intelligence professional
and published author of three books on
machine learning, deep learning, and IoT.
He is currently working with Amazon
Web Services as a Research Scientist –
A.I. in their Vancouver, BC office.
In his current role with AWS, Jojo
works on researching and developing
large-scale A.I. solutions for combating
fraud and enriching the customer’s
payment experience in the cloud. He is
also actively involved as a technical
reviewer and AI consultant with leading
publishers and has reviewed over a
dozen books on machine learning, deep
learning, and business analytics.
You can reach Jojo at:
https://www.jojomoolayil.com/
https://www.linkedin.com/in/jojo62000
https://twitter.com/jojo62000
About the Technical Reviewers
Judy T. Raj
is a Google Certified Professional Cloud
Architect. She has great experience with
the three leading cloud platforms—
Amazon Web Services, Azure, and Google
Cloud Platform—and has co-authored a
book on Google Cloud Platform with
Packt Publications. She has also worked
with a wide range of technologies in
machine learning, data science,
blockchains, IoT, robotics, and mobile
and web app development. She is
currently a technical content engineer in
Loonycorn. Judy holds a degree in
computer science and engineering from Cochin University of Science
and Technology. A driven engineer fascinated with technology, she is a
passionate coder, a machine language enthusiast, and a blockchain
aficionado.
Manohar Swamynathan
is a data science practitioner and an avid
programmer, with more than 14 years of
experience in various data science-
related areas, including data
warehousing, business intelligence (BI),
analytical tool development, ad-hoc
analysis, predictive modeling, data
science product development,
consulting, formulating strategy, and
executing analytics programs. His career
has covered the life cycle of data across
multiple domains, such as US mortgage
banking, retail/ecommerce, insurance,
Exploring the Variety of Random
Documents with Different Content
CHAPTER XVI.
WATER ALWAYS TRYING TO BE LEVEL.
If you look at water in a bowl, you see that its surface is smooth
and level. If now you stir it about, you make it uneven. Watch it as it
becomes still and smooth again. There seems to be a kind of
struggle as all the particles of water take their places.
But you will ask me what I mean by the particles of water. We
suppose that water is made up of exceedingly fine balls. These balls
or particles are so round and smooth that they move among each
other very easily. This is the reason that water runs so readily, and
so soon becomes level when nothing is disturbing it. If the particles
were not so smooth, they would rub each other. They would not roll
over each other so freely as they do.
To make this plain, we will compare water to
small shot. If you put these into a bowl, they will The particles of
water compared
not lie level, as water does. Now what is the reason to shot.
that these round balls of lead do not act as the
smaller round balls of the water do? It is because
they are not as smooth. They can not roll over each other easily, for
they rub together. They can not in any way be made as smooth as
the particles of water are.
If you pour the shot from one bowl into another, they will run
somewhat as the water does; but they will not slip along as easily,
for they rub each other as they go, while there is almost no rubbing
among the particles of water.
The balls or particles of water are exceedingly
small. They are so small that no one has ever seen The particles of
water round and
them. How, then, you will ask, do we know that smooth.
they are round and smooth? We say that they are,
because we can not see how they could move
about among each other so easily if they were rough, or had corners
or points on them. You can not roll about blocks or nails as you can
roll shot; and the smoother the shot the more easily they will roll. So
then we know, from what we see in other things, that the particles
of water that roll so easily must be round, and must be smooth also.
If the particles of water were large enough for us to see them,
they would look to us, on the surface of still water, as a level layer of
little shot or round beads, and we should see them rolling about
among each other whenever there is the least motion of the water;
but, as we can not see the particles, the surface of the water looks
like smooth glass when they are all still.
As water moves so easily, it is almost always in motion. It is
moved by the wind, and is raised by it sometimes into very high
waves. It runs in the brooks and rivers.
In all its motions the water is always trying to be
level; and this is the only reason that water ever Why water runs.
runs. Water that is level will not run; it will be still.
But, when you disturb this level, it will run till it finds its level again.
I will make this plain to you. Suppose that you have a trough
stopped at both ends. Put some water in it as it lies on level ground.
The water is level in it, and is quiet. Now raise up one end of the
trough a little. The water is at once in motion. Why? Because you
have disturbed the level. The water runs from the end that you raise
toward the other end. Now hold the trough still a little time with the
end raised, and as soon as the water gets its level again, it will be as
still as it was before.
Suppose the trough is open at both ends, and
water is running in all the time at the raised end. It Brooks and rivers.
will keep running toward the lower end. It will be
all the time trying to get on a level, but never can. You see here the
reason that water runs in a brook or river. You can think of a brook
or a river as a trough with one end a little raised; and the water in it
is always, as we may say, running after a level, but never finds it.
The sea is to a river as a tub would be to the trough that pours its
water into it.
There is often great power in the water of a
running stream. It works a great deal of machinery The power of
running water.
in mills of various kinds; and, if the stream be
swollen with heavy rains, the water carries away
bridges, houses, etc. It does all this in trying to get on a level. If it
all could be made level in some way, as you see it in a bowl or a
pond, it would do no such violence.
Sometimes men build a dam across a river. This
is for the purpose of turning the water off one side Dams.
into a canal. The dam stops some of the water
running in the river, sometimes all of it. In doing this the water is
made about level just above the dam, and so is much more quiet
than it is any where else in the river.
Children often build mud dams, and the water that they stop is
very still because it is level. When the dams give way, how briskly
the water runs to try to get on a level again.
Water is always on the same level in the spout of
a coffee-pot that it is in the pot itself, as Pouring from a
coffee-pot.
represented in the first of these figures. If the
coffee-pot be turned up, as seen in the second
figure, the level is still preserved. If it be turned up a little more, the
liquid in the spout, in trying to be on a level with that in the pot,
runs out, as represented in the third figure.
You saw by what I told you in the latter part of the last chapter
that the great difference between a solid and a fluid is that the
particles of a solid are fastened tightly together, while those of a
fluid are not. If you should tie some people tightly together so that
they could not move away from each other at all, they would be like
the particles of a solid. If you moved them, you would move them all
together as you do a stick of wood, a lump of ice, or any thing else
that is solid. You can not move them, one one way, and another
another way, as you can the particles of water; but if they are all
pretty close together, and yet can move about among each other, as
you often see in a crowded company, they are like the particles of a
fluid. You can make your way among them just as you do among the
particles of water when you wade.
But you will ask, Are the particles of a solid really
tied together in any way? No; but there is Attraction of the
particles of solids
something that does the same thing to them as illustrated.
tying together would. It makes them stick together
very tight. We know not what it is, but we call it
attraction. We say that the particles of a solid attract each other very
much. This is really just what a child would mean by saying that
they stick together very close or very tight. Why they thus attract
each other, or how they do it, no one has ever yet found out.
It seems to be necessary that the particles
should be very near together to attract each other Experiment with
India-rubber and
as hard as they do in a solid. If a solid is divided in with bullets.
any way, you know that you can not make the two
parts stick close together again. The reason is that
you can not bring the particles near enough to each other to hold
together. This is commonly so, but not always. If you divide a piece
of India-rubber, making a smooth cut with a very sharp knife, you
can press the two parts together so as to make them adhere. Boys
often try the following experiment: A piece is cut off from two
bullets, and each cut place is scraped as smooth as it can be. The
two bullets are then pressed together at these smooth surfaces, and
they adhere so well that it takes considerable pulling to get them
apart. Here enough of the particles on the surfaces are brought near
enough together to hold on to each other, or to attract each other,
as it is commonly expressed.
The particles of solids, then, attract each other
very much, and it is this attraction that makes Drops of water.
them solid. But how is it with the particles of
liquids? Do they not attract each other? See that drop of water on a
window. Why is it in the shape of a drop? If the particles of water
did not attract each other they would be spread out on the glass.
They would not be in the shape of a drop. They do not attract each
other very much, but enough to keep them together in that shape.
But you can spoil that drop very easily. Put your finger on it, and it
is gone. It is all spread out now, partly on your finger and partly on
the glass. Why is this? It is because the particles attract each other
so little that they are easily separated.
Put your finger on a shot, and it remains shot
still. Why is it not gone like the round drop of Drops of water
and shot
water? Because its particles attract each other so compared.
much that they are not easily separated. A mere
touch will separate the particles of the drop of
water, and make them roll about any way; but you can not do this to
the shot without heating it very hot. You can melt it, and then it will
be, like the water, a liquid. Its particles now attract each other but
little, just as the particles of water do. And then, again, you can
freeze the water, and its particles attract each other like the particles
of the solid shot.
In some fluids the particles attract each other more strongly than
they do in others. And the more they attract each other, the better
they keep their drop shape. Pour a very little
quicksilver on a flat surface. See the round drops of Quicksilver.
it roll about! How well they keep their shape! If you
touch them you do not spoil them, as you do a drop of water when
you touch it. If you break one as you touch it, its parts make only so
many little drops or balls. Why is this? It is because the particles of
the quicksilver attract each other so much more than the particles of
water do. They are so attractive to each other that they are disposed
to keep together in little companies.
You sometimes see drops of water on the leaves
of plants more round and separate than you see Drops on leaves.
them on window-panes. They roll about like the
little balls of quicksilver. See the reason of this. The particles of the
drop like each other, as we may say, better than they do the leaf.
They are more ready to stick together than they are to stick to the
leaf, and so they roll about on it like little balls. As you see the drops
on the glass, they are not round, because the particles on one side
stick to the glass—that is, they are attracted by it; but the leaf does
not attract the particles so much as the glass does, for it lets them
keep together in a round form. There is a difference between
different leaves about this. On some, the drops of water act as they
do on the window-pane, and on others they do as I have just told
you; and then, on the same leaves, the drops act differently at
different times.
If you pour a little oil on water, you see the oil
floating in drops. This is for the same reason that Oil on water.
water stands in round drops on some leaves. The
water has no attraction for the oil, and so the particles of the oil hold
together in little companies on the surface of the water. It is
different when oil is spilled upon cloth or wood. It has so much
attraction for them that it mingles up with their fibres, instead of
forming into round companies as it does on the water.
Whenever there is a little of any liquid by itself, it
tends to take a round shape, as seen in the How shot are
quicksilver, and in the drops of water on windows made.
and leaves. We see a pretty example of this in the
manufacture of shot. Perhaps you have seen a shot
How shot are
tower. It is very high. All the shot that are made round.
drop from the top to the bottom. At the top they
have the melted lead. They pour it into a sort of
cullender—that is, a vessel with holes in it. These holes are quite
small. From each one of these holes come out, one after another,
drops of the melted lead. Each drop is round. It cools as it goes
down all this long distance in the air, and by the time that it gets to
the bottom of the tower, it is cold and solid. The shot all fall into a
tub of water, so that they may keep their round shape.
Now why is it that the shot are round? Simply because when they
begin to fall they are melted lead—that is, a fluid. Their particles are
disposed, therefore, to hold together in a round form, like the
particles of quicksilver, or of a drop of water.
Bullets are made by pouring the melted lead into
moulds. Think, now, why they can not be made in Bullets.
the same way that shot are. The reason is that
there are more particles in a bullet than can hold together in a round
shape while the lead is fluid. You can not have very large drops of
any fluid. The particles will hold together only in small companies.
There is one thing that you can do with soap-
bubbles which perhaps you have never thought of. Making soap-
bubbles roll.
You can make them roll on a table or on the floor
by blowing them along. The reason is that the
particles of soap and water mixed together hold on to each other, or
attract each other, better than the particles of water alone.
Questions.—What is the great difference between a
solid and a fluid? Give the comparison about a crowd. Do
we know what it is that fastens the particles of a solid
together? What is it called? What is said about the
particles being near together? Tell about the experiment
with the India-rubber and the lead. How do liquids differ
from solids in attraction? Why is water on a pane of glass
often in drops? Why is it that you can spoil a drop by a
touch? Tell how a shot differs from a drop of water. Is the
attraction between the particles alike in all fluids? Tell
about the quicksilver. Tell about the drops of water on
leaves. Tell about oil dropped upon water. How is it with
oil spilled upon cloth or wood? Describe shot-making. Why
are the shot round? How are bullets made? Why can not
they be made in the same way that shot are? What is said
about soap-bubbles?
CHAPTER XIX.
WATER IN THE AIR.
I have told you how water is in motion whenever it can be. It runs
whenever it can get a chance to do it; but it is in motion in another
way, which I will now tell you about.
You hang out a wet cloth to dry. When it is dry,
what has become of the water that was in it? It From what water
goes up into the
has gone somewhere. Where has it gone? It has air.
flown, like the birds, into the air; but it has gone so
quietly that nobody has seen it go. The little fine
particles of the water that I have told you about have mixed up with
the air, and are blown about with it every where. And so, when you
write, as the ink dries on the paper, the water in it flies off into the
air, leaving the dark part of the ink behind.
There is a great deal of water that is going up into the air in this
way all the time. It goes up from every thing that is wet. After a
shower, the ground, the stones, the houses, the trees, and plants
are all very wet, but in a little time they are dry again. Most of the
water on them has gone up in the air, and is mingled up with it. It
has mingled with it in such a way that you can not see it. The air is
generally as clear with all this water in it as it is when it is perfectly
dry. Even in a bright, clear day, there is a great deal of water mixed
up with the air.
But water goes up into the air not merely from things that appear
wet. You remember that, in Part First, I told you that water is all the
time going out from the pores of the leaves. A great deal of water is
furnished to the air in this way.
Then there is water going up from the skins of animals. Much
water goes from your skin into the air constantly, even when you
can not see that you are perspiring. You can prove this by putting
your arm into a glass jar, and holding it there some
time. The inside of the jar will become covered Experiment with
the arm and a
with the water that comes from the pores of the glass jar.
skin on your arm. This is like the experiment with
leaves noticed on page 77 of Part First.
There is water, too, coming out from the lungs of
animals and mixing with the air. It comes from Water in the
breath.
their lungs just as it does from the leaves, which
you know are the lungs of plants. You can see this
if you breathe upon a cold window. The moisture or water that is
breathed out with the air from the lungs gathers upon the glass. In
the morning you often see the panes of the windows in your
chamber very wet. All this water has come from your lungs as you
have slept. In a very cold day the water in your breath freezes upon
whatever is about your mouth. You see the water of the breath of a
horse frozen on the hairs about his mouth.
So you see water is going up into the air all the time from the
ground, the leaves, the animals, and indeed from every thing that is
at all moist. It goes up also in great quantities from seas, rivers,
lakes, etc. Water, then, is always moving. It runs and it flies. It flies
up into the air, and comes down again in the rain to run in the
streams. It is ever going its rounds, going up and coming down, and
none of it ever stays long in one place. The only way in which it can
be made to keep still is to shut it up. Let it be free, and it will soon
be gone, either by running or flying.
Commonly the water in the air is not seen, as I
have before told you; but sometimes you can see Water in the air
seen in fog.
it. You see it in the breath in a very cold day. The
cold air makes it look like smoke coming out of the
mouth. You see it, too, in the fog. When there is a fog there is a
great deal of water in the air. The reason that you can see it is that
the particles of water are not as finely divided up as when the air is
clear. They are in little companies, as we may say, but there are not
enough of them together to make drops. If they were in companies
large enough to make drops, they would fall to the ground—that is,
we should have a rain.
Sometimes the fog is every where; sometimes it
hangs only just over the water. If you are on a very A beautiful scene.
high hill, where you can look off and see a river in
the distance, you can sometimes see in the morning a line of fog
stretching along where the river is, while it is nowhere else. I once
saw a very singular and beautiful scene made by the fog. I had been
out on horseback in the night to visit a sick person. As I returned,
just before sunrise, I saw from a very high hill a thick fog over all
the river below. From the river arose high hills, irregular in their
shape, and on the sides of these hills were houses at different
heights. The lower houses were all so covered by this dense fog that
I could not see them, while those that stood high up on the hills I
could see as plainly as ever. It looked as if a sea had come in while I
was gone on my visit, and had filled up the valley where the river
ran, for the fog rose to the same height on the sides of all the hills.
Many of the houses stood upon the very edge of this sea. The scene
was so beautiful that I waited to see the sun rise upon it. As it rose,
it shone over the tops of the hills, and lighted up this sea of fog,
which it in a little time scattered by its heat.
Very thick fogs often hang over large cities, while
all around in the country the air may be perfectly Dense fogs often
hanging over
clear. London is often covered with such a fog. large cities.
Sometimes it has been so dense that people could
not see to do any business. It is related that the
fog over the city of Paris was once so thick that persons who went
about with torches often ran against each other, because even lights
could not be seen unless they were very near. And in Amsterdam, in
a fog in the year 1790, there were over two hundred persons
drowned by falling in the darkness into the canals which run through
every part of that singular city.
Questions.—What becomes of the water when a cloth is
dried? Tell about the drying of ink on the paper. Tell about
water’s going up in the air after a shower. Can you
commonly see the water that is in the air? Does water go
into the air from things that do not appear wet? What is
said about its going from the skins of animals? Tell about
the experiment with the glass jar. What is said about
water’s being breathed out from the lungs? In what ways
do you see this shown? What is said about water’s being
in constant motion? When there is a fog, why is it that you
see the water that is in the air? Tell what is said about
fogs. Tell about the fogs that hang over large cities.
CHAPTER XX.
CLOUDS.