DL UNIT 1 To UNIT 3 Lecture Notes
DL UNIT 1 To UNIT 3 Lecture Notes
DEEP LEARNING
LECTURE NOTES
R20
lO M oAR cPSD |270 42294
U n it –
1
Fundamentals of Deep Learning: A rtificia l In te llig e n c e , H is to ry
o f M a c h in e le a rn in g : P ro b a b ilis tic M o d e lin g , E a rly N e u ra l
N e tw o rk s , K e rn e l M e th o d s , D e c is io n T re e s , R a n d o m fo re s ts
a n d G ra d ie n t B o o s tin g M a c h in e s , F u n d a m e n ta ls o f M a c h in e
L e a rn in g : F o u r B ra n c h e s o f M a c h in e L e a rn in g , E v a lu a tin g
M a c h in e le a rn in g M o d e ls , O ve rfittin g a n d U n d e rfittin g .
3. N a tu ra l L an g u a g e P ro c es s in g ( N L P ): N L P is a fie ld o f A I th a t d e a ls w ith th e
in ter a c tio n b e tw e e n c o m p u te r s an d h u m a n la n g u a g e . D e e p lea r nin g te c h niq u e s ,
s u c h a s re c u rre n t n e u ra ln e tw o rk s (R N N s ) a n d tra n s fo rm e r m o d e ls , a re u s e d in
N L P ta s k s lik e m ac h in e tr an s la tio n , s e n tim e n t an a ly s is , la n g u a g e g e n e ra tio n ,
a n d q u e s tio n -a n s w e rin g s ys te m s .
4. C o m p u te r V is io n : D e ep le a rn in g h a s re vo lutio n ize d c o m p u te r v is io n ta s k s , s u c h
a s im a g e c la s s ific atio n , o b je c t d e te c tio n , a n d im ag e s e g m e n ta tio n . A I a lg o r ith m s ,
in c lud in g C N N s a n d d e e p c o n v o lu tio n a l g e n e ra tiv e a d ve rs a ria l n e tw o r k s (D C G A N s ),
e n a b le m a c h in e s to p e rc e ive a n d u n d e r s ta n d v is u a l d a ta w ith re m a rk a b le a c c u ra c y .
5. R e in fo rc e m e n t L e a rn in g : R e inf o rc e m e nt le a rn in g is a b ra n c h o f A I c o n c e r ne d
w ith tra in in g a g e n ts to m a k e d e c is io n s in a n en v iro n m e n t to m a x im ize r ew a rd s .
D e e p re in fo r c e m e n t le a rn in g
lO M oAR cPSD |270 42294
c o m b in e s d e e p le a rn in g a nd re in fo rc e m e n t le a rn in g te c h n iq ue s , e n a b lin g a g e n ts to
le a rn d ire c tly fro m ra w s e n s o r y inp u t a n d a c h ie v e im p re s s ive p e rfo rm a n c e in
c o m p le x ta s ks , s u c h a s g am e p la yin g a n d ro b o tic s .
6. A u to n o m o u s S y s te m s : D e e p le a rn in g , a lo n g w ith A I p rin c ip le s , is a k e y
c o m p o n e n t in th e d e v e lo p m e n t o f a u to n o m o us s ys te m s . T h e s e s y s te m s , s u c h a s
s e lf- d r iving c ar s a n d a u to n o m o u s d r o n e s , re ly o n d e e p le a rn in g alg o rith m s to
p er c e iv e th e e n vir o n m e n t, in te rp re t s e n s o r d a ta , a nd m ak e r ea l- tim e d e c is io n s .
1 . E a rly F o u n d a tio n s ( 19 5 0 s - 1 9 6 0 s ) :
- In the 1 95 0 s, A rth u r S a m u e l d ev e lo p e d th e c o n c e p t o f m ac h in e le a rn in g b y
c re a tin g p ro g ra m s th a t c o u ld im p ro ve th e ir p e rfo rm a n c e over tim e th r o u g h
e x p er ie n c e , s p e c ific a lly in th e d o m a in o fg am e- p la yin g , s uc h a s c h ec k e rs .
2 . S ym b o lic A I a n d E x p e rt S y s te m s ( 19 6 0 s - 1 9 8 0 s ):
- M a c h in e le a rn in g to o k a b a c k s e a t a s ru le - b a s e d s ys te m s d o m in a te d th e fie ld ,
w ith p ro je c ts lik e D E N D R A L ( a s ys te m f o r m o le c u la r b io lo g y ) a n d M Y C IN ( a s y s te m
fo r d iag n o s in g b a c te ria lin fe c tio n s ) g a in in g a tte n tio n .
3 . C o n n e c tio n is m a n d N e u ra l N e tw o rk s ( 1 9 8 0 s - 1 9 9 0 s ) :
- T h e fie ld s a w th e e m e rg e n c e o f e n s e m b le m e th o d s , s uc h a s R a n d o m
F o re s ts a n d B o o s ting ,w h ic h c o m b in e d m u ltip le m o d e ls to im p ro ve p e r fo rm a n c e .
5 . B ig D a ta a n d D e e p L e a rn in g ( 2 0 1 0 s - p re s e n t):
- D e e p le a rn in g , s p e c if ic a lly C o n vo lu tio n a l N e u ra l N e tw o rk s ( C N N s ) a n d
R e c u rr en t N e u ra lN e tw o r k s (R N N s ), a c h ie ve d re m a rk a b le s u c c e s s in c o m p u te r
v is io n, s p e e c h re c o g n itio n , an d n a tu ra l la n g u a g e p ro c e s s in g .
- D e e p le a rn in g fra m e w o r k s lik e T e n s o rF lo w a n d P y T o rc h g a in e d
w id e s p re a d a d o p tio n ,m a k in g it e a s ie r fo r re s e a rc h e rs a n d p r a c titio n e rs to
b uild a n d tr a in d e e p ne u ra l n e tw o r k s .
Probabilistic Modeling:
P r o b a b ilis tic m o d e lin g is a n a p p ro a c h to m o d e lin g a n d a n a ly zin g d a ta th a t
in c o rp o ra te s u nc e rta in ty a n d p ro b a b ility th e o ry . It a llo w s u s to re a s o n a n d m a k e
p re d ic tio n s in s itu a tio n s w h e re th e re is in he r en t va ria b ility o r n o is e in th e d a ta . In
p ro b a b ilis tic m o d e lin g , w e re p re s e n t u n c er ta in q u a n titie s a s p ro b a b ility d is tr ib u tio n s
a n d u s e s ta tis tic a l in fe re n c e te c h n iq u e s to le a rn a nd m a k e in fe r en c e s fro m th e
a v ailab le d a ta .
2. B a ye s ia n In fe re n c e : B a y e s ia n in f er e nc e is a fu n d a m e n ta l a p p ro a c h in
p ro b a b ilis tic m o d e lin g th a t a llo w s u s to u p d a te o u r b e lie fs a b o u t u n c e rta in va ria b le s
b as e d o n o b s e rv e d d a ta . It c o m b in e s p rio r k n o w le d g e o r b e lie fs (e x p r e s s ed a s p rio r
d is trib u tio n s ) w ith o b s er ve d d a ta to o b ta in p o s te rio r d is trib utio n s , w h ic h re p re s e n t
o ur u p d ate d b e lie fs .
6. A p p lic a tio n s : P ro b a b ilis tic m o d e lin g fin d s a p p lic a tio n s in va rio u s fie ld s ,
in c lud in g fin a n c e , h e a lth c a r e, n a tu ra l la n g u a g e p ro c es s in g , c o m p u te r vis io n , a n d
m o re . It is u s e d fo r tas k s s u c h a s ris k a s s e s s m e n t, fra u d d e te c tio n ,
re c o m m e n d a tio n s y s te m s , s e n tim e n t a n aly s is , im a g e re c o g n itio n , a n d p re d ic tive
m o d e lin g .
2. P e rc e p tr o n ( 19 5 7 ) : D e ve lo p e d b y F ra n k R o s en b latt, th e p er c e p tro n w a s o ne o f
th e e a rlie s t fo r m s o f a le a rn ing a lg o rith m fo r n e u ra l ne tw o rk s . It c o n s is te d o f a s ing le
la ye r o f inte rc o nn e c te d a rtif ic ial n e u ro n s ( M c C u llo c h - P itts n e u ro n s ) th a t c o u ld le a rn
to c la s s if y inp u ts into tw o c la s s e s . T h e p e rc e p tr o n le a rn in g ru le a d ju s te d th e
c o n n e c tio n w e ig h ts b a s e d o n e rr o rs m a d e d u rin g tr a in in g .
lO M oAR cPSD |270 42294
Kernal Methods:
K e rn e l m e th o d s a re a fa m ily o f m a c hin e lea r nin g te c h n iq u e s th a t o p e ra te in a
h ig h - d im e n s io n a lfe a tu re s p a c e im p lic itly th ro u g h a k e rn e l fu n c tio n . T h e y a re
p a rtic u la rly u s e fu l fo r s o lv in g c o m p le x n o n lin e a r p ro b le m s w h ile p re s e rv in g the
c o m p uta tio n a l e ff ic ien c y o f lin e a r m e th o d s . K e rn e l m e th o d s h a ve ap p lic a tio ns in
v a rio u s fie ld s , in c lud in g c la s s ific a tio n , re g re s s io n , d im e n s io n a lity re d u c tio n , a n d
a n o m aly d e te c tio n .
H e r e a re s o m e k e y a s p e c ts o f k e rn e l m e th o d s :
3. S u p p o r t V e c to r M a c h in e s (S V M ) : S V M is a w id e ly u s e d k er n el- b a s ed a lg o rith m
lO M oAR cPSD |270 42294
4. K e rn e l P C A : K e rn e l P rin c ip a l C o m p o n e n t A n a lys is (P C A ) is a n e x te n s io n o f
tra d itio n a l P C A th at u s e s k e rn e l fu n c tio n s to p e rfo rm n o n lin e a r d im e n s io na lity
re d u c tio n . It c a p tu re s n o n lin e a rn re la tio n s h ip s in th e d a ta b y m a p p in g it to a
h ig h - d im e n s io n a l fe a tu re s p a c e a n d c o m p u tin g p r in c ip a l c o m p o ne n ts in tha t
s p ac e .
lO M oAR cPSD |270 42294
6. K e rn e l- b a s e d C lu s te rin g : K e rn e l m e th o d s c a n a ls o b e a p p lie d to c lu s te r in g
a lg o rith m s , s u c h a s K er n el K - m e a n s a n d S p e c tra l C lu s te rin g . T h es e m e th o d s u s e
k e rn e l fu n c tio n s to m e a s u re s im ila rity o r d is s im ila rity b e tw e e n d a ta p o in ts an d g r o u p
th e m into c lu s te rs .
K e rn e l m e th o d s h a ve s ev e ra l a d v a n ta g e s , in c lu d in g th e ir a b ility to h a n d le
n o n lin e a r re latio n s h ip s , th e ir m a th e m a tic al e le g an c e , a n d th e ir in te rp re ta b ility.
H o w e v e r, th e y m a y f ac e c ha lle n g e s w ith s c a la b ility a n d h yp e rp a ra m e te r s e le c tio n .
N e v e rth e le s s , k er n el m eth o d s h av e h a d a s ig n ific a n t im p ac t o n th e fie ld o f m a c hin e
le a rn in g , p ro v id in g p o w er fu l to o ls f o r s o lvin g a w id e r a ng e o f p ro b le m s .
Decision Trees:
Node. D e c is io n no d e s a re u s e d to m a k e a n y d e c is io n a n d h a ve m u ltip le
b ra n c h e s , w h e re a s L e a f n o d e s a re th e o u tp u t o f tho s e d e c is io n s a n d d o n o t
c o n ta in a n y fu rth e r b ra n c h e s .
T h e d e c is io n s o r th e te s t a re p e rfo rm ed o n th e b a s is o f fe a tu re s o f th e g ive n
d a ta s e t.
Algorithm
Step-1: Begin the tree with the root node, says S, which contains the complete
dataset.
Step-2: Find the best attribute in the dataset using Attribute Selection Measure
(ASM).
Step-3: Divide the S into subsets that contains possible values for the best attributes.
Step-4: Generate the decision tree node, which contains the best attribute.
Step-5: Recursively make new decision trees using the subsets of the dataset
created in step -3. Continue this process until a stage is reached where you
cannot further classify the nodes and called the final node as a leaf node.
lO M oAR cPSD |270 42294
Random Forest:
Random Forest is an ensemble learning method that combines multiple decision trees to
make predictions or classifications. It is a powerful and widely used algorithm known for
its robustness and ability to handle complex datasets. Random Forest overcomes the
limitations ofindividual decision trees by reducing overfitting and improving generalization.
Here are the key characteristics and concepts of Random Forest:
2. Random Sampling: Random Forest uses two types of random sampling. The first
type is random sampling with replacement, also known as bootstrap sampling. It
creates multiple bootstrap samples by randomly selecting data points from the training
dataset, allowing somedata points to be present in multiple subsets. The second type is
random feature selection, where only a subset of features is considered for splitting at
each node of the decision tree.
3. Voting for Predictions: Random Forest employs a majority voting scheme for
classification tasks and averaging for regression tasks. Each decision tree in the
ensemble makes an individualprediction, and the class with the most votes or the
average of the predicted values is chosen asthe final prediction.
Here are the key characteristics and concepts of Gradient Boosting Machines:
1. Boosting: GBMs belong to the boosting family of algorithms, where weak models are
sequentially trained to correct the mistakes of the previous models. Each subsequent model in
the ensemble focuseson reducing the errors made by the previous models, leading to an
ensemble with improved overall predictive performance.
3. Weak Learners: GBMs use weak learners as building blocks, typically decision trees with a
small depth(often referred to as "shallow trees" or "decision stumps"). These weak learners are
simple models thatmake predictions slightly better than random guessing. They are usually
shallow to prevent overfitting and to focus on capturing the specific patterns missed by previous
models.
4. Residuals: In GBMs, the subsequent weak learners are trained to predict the residuals (the
differencesbetween the true values and the predictions of the ensemble so far). By focusing on
the residuals, the subsequent models are designed to correct the errors made by the previous
models and improve the overall prediction accuracy.
5. Learning Rate: GBMs introduce a learning rate parameter that controls the contribution of
each weak learner to the ensemble. A smaller learning rate makes the learning process more
conservative, slowingdown the convergence but potentially improving the generalization ability.
7. Feature Importance: GBMs can provide estimates of feature importance based on how
frequently andeffectively they are used in the ensemble. This information helps identify the most
informative featuresfor the task.
Machine learning is a subset of AI, which enables the machine to automatically learn
from data, improve performance from past experiences, and make predictions.
M a c h in e le ar n in g c o n ta ins a s e t o f a lg o rith m s tha t w o rk o n a h u g e a m o u n t o f d a ta .
D a ta is f ed to th e s e a lg o rith m s to tra in th e m , a nd o n th e b a s is o f tra in ing , th e y b u ild
th e m o d e l & p e rfo r m a s p e c ific ta s k .
T h es e M L a lg o rith m s h e lp to s o lv e d if fe re n t b u s in e s s p ro b le m s lik e R e g re s s io n ,
C la s s ific a tio n ,F o re c a s tin g , C lu s te r in g , a n d A s s o c ia tio n s , etc .
1 . S u p e rvis ed M a c h in e L e a rn in g
2 . U n s u p e rv is e d M a c hin e Le a rn in g
lO M oAR cPSD |270 42294
3 . S e m i- S u p e rv is e d M a c h in e L e a rn in g
lO M oAR cPSD |270 42294
4 . R e in fo rc e m e n t L e a rn in g
L e t's u n d e rs ta n d s u p e rv is e d le a rn in g w ith a n e x a m p le . S u p p o s e w e h a ve a n in p u t
d ata s et o f c ats a n d d o g im a g e s . S o , firs t, w e w ill p ro vid e th e tra in in g to th e m a c h in e
to u n d er s ta n d th e im a g e s , s u c h a s th e shape & size of the tail of cat and dog, Shape
of eyes, colour, height (dogs are taller, cats are smaller), etc. A fte r c o m p le tio n o f
tra in in g , w e in p ut th e p ic tu re o f a c a t a n d a s k th e m a c hin e to id e n tify th e o b je c t a n d
p re d ic t th e o u tp u t. N o w , th e m a c h in e is w e ll tr ain e d , s o it w ill c h e c k a ll th e fe a tu re s
o f th e o b je c t, s u c h a s h e ig h t, s h a p e , c o lo u r, e ye s , e a rs , ta il, e tc ., an d fin d th a t it's a
c at. S o , it w ill p u t it in th e C a t c a te g o ry . T h is is th e p ro c e s s o f h o w th e m a c h in e
id e n tifies th e o b je c ts in S up e rvis e d L e a rn in g .
The main goal of the supervised learning technique is to map the input variable(x)
with the output variable(y). S o m e r ea l- w o rld a p p lic a tio ns o f s u p e rv is e d le a rn in g a re
Risk Assessment, Fraud Detection, Spam filtering, e tc .
C a te g orie s o f S u pe rvise d M a ch in e Le a rn in g
S u p e rvis e d m a c h in e le a rn in g c a n b e c la s s ifie d in to tw o typ e s o f p ro b le m s , w h ic h a re
g ive n b e lo w :
Classification
lO M oAR cPSD |270 42294
Regression
lO M oAR cPSD |270 42294
S o m e p o p u la r R e g re s s io n a lg o r ith m s a re g ive n b e lo w :
A d va n ta g e s a n d D isa d va n ta g e s of S u p e rvis e d Le a rn in g
Advantages:
S in c e s u p e rv is e d le a rn in g w o rk w ith th e la b e lle d d a ta s e t s o w e c a n h av e a n
e x a c t id e a a b o u t th e c la s s e s o f o b je c ts .
T h e s e a lg o rithm s ar e n o t a b le to s o lv e c o m p le x ta s k s .
It m a y p re d ic t th e w ro n g o u tp u t if th e te s t d a ta is d iffe re n t f ro m th e tra in in g d a ta .
Image Segmentation:
lO M oAR cPSD |270 42294
Medical Diagnosis:
Supervised algorithms are also used in the medical field for diagnosis
purposes. It is done by using medical images and past labelled data with
labels for disease conditions. With such a process, the machine can identify a
disease for the new patients.
Fraud Detection - S u p er vis e d Le a rn in g c la s s ific a tio n a lg o rith m s a re us e d fo r
id e n tify in g fra u d tr an s a c tio n s , fr a ud c u s to m e rs , e tc . It is d o n e b y u s in g h is to r ic
Spam detection - In s p a m d ete c tio n & filte rin g , c la s s ific a tio n a lg o rith m s a re
u s e d . T h e s e alg o rith m s c la s s if y a n e m a il a s s p a m o r n o t s p a m . T h e s p a m
e m a ils a re s e nt to th e s p a m fo ld e r .
p as s w o rd s , vo ic e c o m m a n d s , e tc .
The main aim of the unsupervised learning algorithm is to group or categories the
unsorted dataset according to the similarities, patterns, and differences. M a c h in e s
a re in s tru c ted to find th e h id d e n p a tte rn s fro m th e in p ut d a ta s e t.
L e t's ta k e a n e x a m p le to u n d e rs tan d it m o re p re c io u s ly ; s u p p o s e th e re is a b a s k et o f
fr uit im a g e s , an d w e in p u t it in to th e m a c h in e le a rn in g m o d e l. T h e im a g e s a re to ta lly
u n k n o w n to th e m o d e l, a n d th e ta s k o f th e m a c h in e is to fin d th e p a tte rn s a n d
c a te g o r ie s o f th e o b je c ts .
C a te g orie s o f U n su p e rv is e d M a c h in e L e a rn in g
lO M oAR cPSD |270 42294
U n s u p e rv is e d L e a rn in g c a n b e fu r th e r c la s s ifie d in to tw o ty p e s , w h ic h a re g ive n b e lo w :
Clustering
Association
1) C lus te ring
T h e c lu s te rin g te c hn iq u e is u s e d w h e n w e w a n t to fin d th e in h e re n t g ro u p s fro m th e
d a ta . It is a w a y to g ro u p th e o b jec ts in to a c lu s te r s u c h th a t th e o b je c ts w ith the
m o s t s im ilar itie s re m a in in
lO M oAR cPSD |270 42294
S o m e o f th e p o p u la r c lu s te ring a lg o rith m s a re g iv en b e lo w :
T h e s e a lg o rith m s c a n b e u s e d fo r c o m p lic a te d ta s k s c o m p a r ed to th e
T h e o u tp u t o f a n u n s u p e rv is e d a lg o rith m c a n b e le s s a c c u ra te a s th e
p rio r .
u n la b e lle d d a ta s e t th a t d o e s n o t m a p w ith th e o u tp u t.
u n s u p e rv is e d le ar n in g , w h ic h c a n id e n tif y u n u s u a l d a ta p o in ts w ith in th e
3 . S e m i- S u p e rvis e d Le a rnin g
Semi-Supervised learning is a type of Machine Learning algorithm that lies between
Supervised and Unsupervised machine learning . It re p re s e n ts th e in te rm e d ia te
g ro u n d b etw e e n S u p er vis e d ( W ith L a b e lle d tra in in g d a ta ) a n d U n s u p e rv is e d le a rn in g
( w ith n o la b e lled tra in in g d a ta ) a lg o r ith m s a n d u s e s th e c o m b in a tio n o f la b e lle d a n d
u n la b e le d d a ta s e ts d ur in g th e tra in in g p er io d .
Alth o u g h S e m i- s u p e rv is e d le a rn in g is th e m id d le g ro u n d b e tw e e n s u p e rv is e d an d
u n s u p e rv is e d le a rn in g a n d o p e ra te s o n th e d a ta th a t c o ns is ts o f a fe w la b e ls , it
m o s tly c o n s is ts o f u n la b e le d d a ta . A s la b e ls a re c o s tly, b u t fo r c o rp o ra te p u rp o s e s ,
th e y m ay h a ve fe w la b e ls . It is c o m p lete ly d iffe re n t fro m s u p e rv is e d an d
u n s u p e rv is e d le a rn in g a s th ey a re b a s e d o n th e p re s e nc e & ab s e n c e o f la b e ls .
A d va n ta g e s a n d d isa d va n ta g e s of S e m i- s u pe rvise d L e a rn in g
Advantages:
It is s im p le a n d e a s y to u n d er s ta n d th e a lg o rith m .
It is h ig h ly e ffic ie n t.
lO M oAR cPSD |270 42294
It is u s e d to s o lv e d ra w b a c k s o f S up e rvis e d a n d U n s u p e rv is e d L e ar n in g
a lg o rith m s .
Disadvantages:
W e c a n n o t a p p ly th e s e a lg o rith m s to n e tw o rk - le ve l d a ta .
lO M oAR cPSD |270 42294
A c c u ra c y is lo w .
4 . R e in fo rc e m e nt Le a rnin g
Reinforcement learning works on a feedback-based process, in which an AI agent
(A software component) automatically explore its surrounding by hitting & trail,
taking action, learning from experiences, and improving its performance. A g e n t g e ts
re w a rd e d fo r e a c h g o o d ac tio n a n d g e t p u n is h e d f o r e a c h b a d a c tio n ; h e n c e th e
g o a l o f re in fo rc e m e n t le a rn in g a g e n t is to m a x im ize th e r e w a rd s .
In re in fo rc e m e n t le a rn in g , th e re is no la b e lle d d a ta lik e s u p e rv is e d le a rn in g , a n d
a g en ts le ar n fro m th e ir e x p e rie n c e s o n ly.
T he r e in fo rc e m e n t le a rn in g p ro c e s s is s im ila r to a hu m a n b e in g ; fo r e x a m p le , a c h ild
le a rn s v a rio u s th in g s by e x p e rie n c e s in h is d a y - to - d a y life . A n e x a m p le of
re in f o rc em en t le a rn in g is to p la y a g a m e , w h e re th e G a m e is th e e n viro n m e n t,
m o ve s o f a n a g e n t a t e a c h s te p d e fin e s ta tes , a n d th e g o a l o f th e a g e n t is to g e t a
h ig h s c o re . A g e n t re c e ive s fe e d b a c k in te rm s o f p u n is h m e n t a n d re w a rd s .
C a te g orie s o f R e in force m e n t Le a rn in g
R e in fo rc e m e n t le a rn in g is c a te g o riz e d m a inly in to tw o ty p e s o f m e th o d s / a lg o rith m s :
a d d in g s o m e th in g . It e n h a n c e s th e s tre n g th o f th e b e h a v io r o f the a g e n t a n d
p o s itive ly im p a c ts it.
s u p e r -h u m a n p e r fo rm a n c e . S o m e p o p u la r g a m e s th a t u s e R L a lg o r ith m s a re
lO M oAR cPSD |270 42294
A lp h aG O a n d A lp h a G O Z e ro .
R e s o u rc e
M a n a g em en
t:
to u s e R L in c o m p u te r to au to m a tic a lly le a rn an d s c h e d u le re s o ur c e s to w a it
fo r d iffe re n t jo b s in o rd e r to m in im iz e a ve ra g e jo b s lo w d o w n .
R o b o tic s :
in d u s tria l a n d m a n u fa c tu rin g a re a , a n d th e s e ro b o ts a re m ad e m o re p o w e r fu l
v is io n o f b u ild in g in tellig e n t ro b o ts u s in g A I a n d M a c h in e le a rn in g te c h n o lo g y .
Text M in in g
w ith th e h e lp o f R e in fo rc e m e n t L e a rn in g b y S a le s fo r c e c o m p a n y .
A d va n ta g e s a n d D isa d va n ta g e s of R e in fo rc em e n t L e a rn in g
Advantages
s o lv e d b y g e n e ra l te c h n iq u e s .
T h e le a rn ing m o d e l o f R L is s im ila r to th e le a rn in g o f hu m a n b e in g s ; h e n c e
m o s t a c c u ra te re s u lts c a n b e fo u n d .
H e lp s in a c h ie v in g lo ng te rm re s u lts .
Disadvantage
R L a lg o r ith m s a re n o t p re fe rr e d fo r s im p le p ro b le m s .
H e r e a re s o m e fu n d a m e n ta l c o n c e p ts o f m a c h in e le a rn in g
3. S u p e rvis ed L e a rn in g : In s up e rvis e d le a rn in g , th e g o a l is to le a rn a m a p p in g
fu n c tio n th a t c a n p re d ic t th e o u tp ut v ar ia b le g iv en th e inp u t v a ria b le s . T h e tra in in g
d ata c o n s is ts o f la b e le d e x a m p les , w h e re b o th th e in p u t a nd th e d e s ire d o u tp u t a re
k n o w n . S u p e rvis e d le a rn in g a lg o rithm s inc lu d e re g re s s io n (p re d ic tin g c o n tinu o u s
v a lu e s ) a n d c la s s ific a tio n ( p re d ic tin g c a te g o ric a l va lu e s ).
4. U n s u p e rv is e d L e a rn in g : In u n s u p e rv is e d le a rn in g , th e g o a l is to d is c o v e r
p atte rn s o r s tru c tu r es in th e d a ta w ith o u t e x p lic it la b e ls o r ta r g e t va ria b le s .
U n s u p e rv is e d le a rn in g a lg o rith m s in c lu d e c lu s te rin g (g ro u p in g s im ila r d a ta p o in ts
to g e th e r) a n d d im e n s io n a lity re d u c tio n (re d u c in g th e n u m b e r o f in p u t va riab le s w h ile
p re s e rvin g im p o rtan t in fo r m a tio n ) .
a c h ie ve a m o d e l th a t c a n g e n e ra liz e w e ll.
1. Overfitting:
O v e rfittin g o c c u rs w h e n a m o d e l le a rn s th e tra in ing d a ta to o w e ll, c a p tu rin g n o is e
a n d ra n d o m va ria tio n s th a t a r e s p e c ific to th e tra in in g s e t b u t d o n o t e x is t in th e
u n d e rly in g p o p u la tio n o r th e te s t d ata . S ig n s o f o ve rfittin g in c lu d e:
- T h e m o d e l is e x c e s s iv e ly c o m p le x a nd h a s to o m an y p a r am ete rs , w h ic h a llo w s
it to m e m o rize the tra in in g e x a m p le s in s tea d o f le ar n in g th e u nd e rlying p atte rn s .
2. Underfitting:
U n d e rfittin g o c c u rs w h e n a m o d e l is to o s im p le to c a p tu re th e u n d e r ly in g p a tte rn s in
th e d a ta . It fa ils to le a rn th e im p o r ta n t re la tio n s h ip s b e tw e e n th e in p u t fe a tu re s a n d
lO M oAR cPSD |270 42294
- T h e m o d e l is to o s im p le a n d d o e s n o t c a p tu re th e c o m p le x itie s o f th e d a ta .
lO M oAR cPSD |270 42294
- In c re a s e th e c o m p le x ity o f th e m o d e l b y a d d in g m o re p a ra m e te rs o r u s in g
m o re s o p h is tic a te d a lg o rith m s .
- C o lle c t m o re re le va n t fe a tu re s o r c re a te n e w fe a tu re s th a t p r o v id e m o re
in f o rm a tio n to th e m o d e l.
U N IT 2
lO M oAR cPSD |270 42294
H is to ry o f C o m p u te r V is io n
C o m p u te r v is io n is a te c hn iq u e th a t e x tra c ts in fo rm a tio n fr o m v is u a l d a ta , s u c h a s
im a g e s a n d v id e o s . A lth o u g h c o m p u te r v is io n w o r k s s im ila rly to h u m a n e ye s w ith
b r ain w o rk , th is is p ro b a b ly o n e o f th e b ig g e s t o p en q u e s tio n s fo r IT p ro fe s s io n a ls :
H o w d o e s th e h u m a n b ra in o p e ra te a n d s o lve vis u a l o b je c t re c o g n itio n ?
n o w a c c u ra te ly d e te c t w h e th e r th e im a g e c o n ta in s a d o g o r n o t fo r ea c h in p ut im a g e
lO M oAR cPSD |270 42294
A lth o u g h c o m p u te r v is io n h a s b e e n u tilize d in s o m an y f ie ld s , th e re a re a fe w
c o m m o n ta s k s fo r c o m p u te r vis io n s y s te m s . T h e s e ta s k s a re g ive n b e lo w :
re s p e c t to the im a g e .
lO M oAR cPSD |270 42294
o Facial recognition: C o m p u te r v is io n h a s e n a b le d m a c h in e s to d e te c t fa c e
im a g e s o f p e o p le to v e rify th e ir id en tity . In itia lly , th e m a c h in e s a re g ive n in p u t
d ata im a g e s in w h ic h c o m p u te r vis io n a lg o rith m s d e te c t fa c ial fe a tu re s a n d
c o m p a r e th e m w ith d a ta b a s es o f fa k e p ro f ile s . P o p u la r s o c ia l m e d ia p la tf o rm s
lik e F a c e b o o k a ls o u s e fa c ial r e c o g n itio n to d e te c t a n d ta g u s e rs . F u rth e r,
v a rio u s g o v e rn m e n t s p y ag e n c ie s a re e m p lo yin g th is fe a tu re to id e n tify
c rim in a ls in vid e o fe e d s .
o Healthcare and Medicine: C o m p u ter vis io n h as p la ye d a n im p o r ta n t ro le in the
h e a lth c a re and m e d ic in e in d u s try . T ra d itio na l a p p r o a c h e s fo r e va lu a tin g
c an c e ro u s tu m o rs ar e tim e - c o n s u m in g a n d h a v e le s s ac c u ra te p re d ic tio n s ,
w h e re a s c o m p ute r v is io n tec h n o lo g y p r o vid e s fa s te r a n d m o re a c c u ra te
c he m o th e ra p y re s p o n s e a s s e s s m e n ts ; d o c to rs c a n id e n tify c a n c e r p a tie n ts
w h o n e e d f a s te r s u rg er y w ith life - s a vin g p re c is io n .
o Self-driving vehicles: C o m p u te r vis io n te c h n o lo g y h a s a ls o c o n trib u te d to its
ro le in s e lf - d rivin g ve h ic le s to m a k e s e n s e o f th e ir s u rro u n d in g s b y c a p tu rin g
v id e o fro m d iffe re n t an g les a r o u n d th e c a r a nd th e n in tro d u c in g it in to th e
s o ftw ar e . T h is h e lp s to d e te c t o the r c a rs a n d o b je c ts , re a d tra ff ic s ig n a ls ,
p ed e s tria n p a th s , e tc . , a nd s a fe ly d riv e its p a s s e n g e rs to th e ir d e s tin a tio n .
o Optical character recognition (OCR)
O p tic a l c h a ra c te r r ec o g n itio n h e lp s u s e x tr ac t p rinte d o r h a n d w ritte n te x t fro m
v is u a l d a ta s u c h a s im a g e s . F u rth e r, it a ls o e n a b le s u s to e x tra c t te x t fro m
d o c u m e n ts lik e in v o ic e s , b ills , a rtic le s , e tc .
o Machine inspection: C o m p u te r v is io n is vita l in p ro vid in g a n im a g e - b a s e d
a u to m a tic ins p e c tio n . It d e te c ts a m a c h in e 's d e fe c ts , fe a tu re s , an d fu n c tio n a l
fla w s , d e te rm in e s in s p e c tio n g o a ls , c h o o s e s lig h tin g a n d m a te ria l- h a n d lin g
te c h n iq u e s , a n d o th e r irre g ula ritie s in m a n u fa c tu re d p ro d u c ts .
o Retail (e.g., automated checkouts): C o m p u te r vis io n is a ls o b e in g
im p le m e n te d in th e re ta il ind u s trie s to tra c k p ro d u c ts , s h e lve s , w a g e s , re c o rd
p ro d u c t m o ve m e n ts in to th e s to re , e tc . T h is A I- b a s e d c o m p u te r v is io n
te c h n iq u e a u to m a tic a lly c h a rg e s th e c u s to m e r fo r th e m a rk e d p ro d u c ts u p o n
c he c k o u t fro m th e re ta il s to re s .
o 3D model building: 3 D m o d e l b u ild in g o r 3 D m o d eling is a te c h n iq u e to
g en e ra te a 3 D d ig ita l re p re s e n ta tio n o f a n y o b je c t o r s u rfa c e u s in g the
s o ftw ar e . In th is field a ls o , c o m p u te r v is io n p la y s its ro le in c o n s tru c tin g 3 D
c o m p u ter m o d e ls fr o m e x is tin g o b je c ts . F u rth er m o re , 3 D m o d e lin g ha s a
v a rie ty o f a p p lic atio n s in va rio u s p la c e s , s u c h a s R o b o tic s , A u to n o m o u s
d rivin g , 3 D tra c k in g , 3 D s c e n e re c o n s tru c tio n , an d A R /V R .
lO M oAR cPSD |270 42294
H u m a n la n g u ag e is a c o m p lex a n d d yn a m ic s ys te m o f c o m m u n ic a tio n u s e d b y
h um an s to e x p re s s th o u g h ts , id e a s , a n d e m o tio n s . H u m a n la n g u a g e s e x is t in th re e
fie ld s – s p e e c h ,
H u m a n la ng u a g e is a c o m p le x a n d s o p h is tic a te d s ys te m o f c o m m u n ic a tio n us e d b y
h um an s to c o n v e y th o u g h ts , id e a s , e m o tio n s , an d in fo rm a tio n . It is o n e o f th e
d e fin in g c h a ra c te ris tic s o f o ur s p e c ie s a n d p la y s a c e n tr a l r o le in o ur a b ility to
c o m m u nic a te , le a rn , a n d in te ra c t w ith o n e an o th e r.
le v e l, th er e is a
d is tin c t p a tter n o f o rg a n iza tio n .
5 . Semanticity: L a n g u a g e c o n ve y s m e a n in g th ro u g h w o rd s a n d th e w a y the y a re
a rra n g e d in
s e nte n c e s . W o rd s h a ve s p e c ific m e a nin g s , a n d th e c o m b in a tio n o f w o r d s in a
s e nte n c e c a n c r e ate
c o m p le x m ea n ing s .
6 . Cultural Transmission: L a n g u a g e is le a rn e d a n d tra n s m itte d fro m o n e g e n e ra tio n to
th e n ex t
th ro u g h c u ltu ra l an d s o c ia l inte ra c tio n s . C h ild re n a c q u ire la n g u a g e b y
e x p o s u re to th e
la n g u a g e (s ) s p o k e n in th e ir e n v iro n m e n t.
lO M oAR cPSD |270 42294
M a ch ine la ng u a g e
M a c h in e la ng u a g e , o fte n re fe rr ed to a s m ac h in e c o d e, is a lo w - le ve l p ro g ra m m in g
la n g u a g e th a t is d ire c tly un d e rs to o d and ex e c u te d by a c o m p u ter 's c e n tra l
p r o c e s s in g u n it (C P U ) . It is th e lo w e s t- le v e l re p re s e n ta tio n o f a p r o g r a m a n d is
co m po se d o f b in a ry d ig its (0 s a n d 1s ) th a t c o rre s p o n d to s p e c ific m a c h in e
in s tr uc tio n s .
K e y c h a ra c te ris tic s o f m a c h in e la n g ua g e in c lu d e :
N a tu ra l L a n g u a g e P ro c e s s in g (N L P ) is a s u b f ie ld o f a rtific ia l in te llig e n c e th a t d e a ls
w ith th e in te ra c tio n b e tw e e n c o m p u te rs a n d h u m a n s in n a tu ra l la ng u a g e . It
in v o lve s th e us e o f c o m p u ta tio n a l te c h n iq u e s to p ro c e s s a n d a n a lyz e n a tu ra l
la n g u a g e d a ta , s u c h as te x t a n d s p e e c h , w ith th e g o a l o f u n d e rs ta n d in g th e
m e a n in g b e h in d th e la n g u a g e .
S o m e c o m m o n te c h niq u e s u s e d in N L P in c lu d e :
1 . Tokenization: th e p ro c e s s o f b re a k in g te x t in to in d ivid u a l w o rd s o r p h ra s e s .
2 . Part-of-speech tagging: th e p ro c e s s o f la b e lin g e a c h w o rd in a
s e n te n c e w ith its g ra m m a tic a l p a rt o f s p e ec h .
3 . Named entity recognition: th e p r o c e s s o f id e n tify in g a n d c a te g o riz in g n a m e d
e n titie s , s u c h a s p e o p le , p la c e s , a n d o rg an iza tio n s , in te x t.
4 . Sentiment analysis: th e p ro c e s s o f d e te rm in in g th e s e n tim e nt o f a p ie c e o f
te x t, s u c h a s w h e th e r it is p o s itive , n e g a tive , o r n e utra l.
5 . Machine translation: th e p ro c e s s o f a u to m atic a lly tr an s la tin g te x t f ro m o n e
la n g u a g e to a n o th e r.
6 . Text classification: th e p ro c e s s o f c ate g o r izing te x t in to p re d e fin e d c a te g o rie s o r
to p ic s .
lO M oAR cPSD |270 42294
Speech Recognition:
lO M oAR cPSD |270 42294
● F irs t, th e c o m p u te r m u s t c o m p re h e n d th e m e a n in g o f e a c h w o r d . It tr ie s to f ig u re
o u t w h e th e r the w o rd is a n o u n o r a v e rb , w h e th e r it’ s in th e p a s t o r p re s e n t
te n s e , a n d s o o n . T h is is c a lle d P a rt- o f- S p e e c h ta g g in g ( P O S ) .
● A le x ic o n (a vo c a b u la ry ) an d a s e t o f g ra m m a tic a l ru le s a r e a ls o b u ilt in to N L P
s ys te m s . T he m o s t d iffic u lt p a rt o f N L P is u n d e rs ta n d in g .
● T h e m a c h ine s h o u ld b e a b le to g ra s p w h a t y o u s a id b y th e c o n c lu s io n o f th e
p r o c e s s . T he r e a re s e ve ra l c h a lle n g e s in ac c o m p lis h in g th is w h e n c o n s id er in g
p r o b le m s s u c h a s w o rd s h a v in g s e ve r al m e a n in g s ( p o ly s e m y) o r d if fe re n t w o rd s
h a vin g s im ila r m e a n in g s ( s yn o n ym y ), b u t d ev e lo p e r s e n c o d e ru le s in to th eir N L U
s ys te m s a n d tra in th e m to le a rn to a p p ly th e ru le s c o rre c tly.
it c o m e s in th e fo rm o f lo n g d o c u m e n ts o r a rtic le s . N L P is u s e d to d e c ip h e r th e
m e a n in g o f th e d a ta a n d th e n p ro v id e s s h o rte r s um m a rie s o f th e d a ta s o th a t
h u m a n s c a n c o m p r e he n d it m o re q u ic k ly .
lO M oAR cPSD |270 42294
The typical Artificial Neural Network looks something like the given figure.
lO M oAR cPSD |270 42294
lO M oAR cPSD |270 42294
D e n d rite s f ro m B io lo g ic a l N e u ra l N e tw o rk re p re s e n t in p u ts in A rtif ic ia l N e u ra l
N e tw o rk s , c elln uc le u s re p re s e n ts N o d e s , s yn a p s e r e p re s e n ts W eig h ts , an d A x o n
re p re s e n ts O u tp u t.
D e n d rite s In p u ts
C e ll n u c le u s N o des
S yn a p s e W e ig h ts
A xon O u tp u t
T h e re a re a ro u n d 10 0 0 b illio n n e u ro n s in th e h u m a n b ra in . E a c h n e u ro n ha s a n
as s o c iatio n p o in t s o m e w he r e in th e ra n g e o f 1 ,0 0 0 a n d 1 0 0 ,0 0 0 . In th e h u m a n b ra in ,
d a ta is s to re d in s u c h a m a n n er a s to b e d is trib u te d , an d w e c a n e x tra c t m o re th a n
o n e p ie c e o f th is d a ta w h e n n e c e s s a ry f ro m o u r m e m o ry p a ra lle lly . W e c a n s a y th a t
th e h u m a n b ra in is m a d e u p o f in c re d ib ly a m a z in g p a ra lle l p r o c e s s o rs .
W e c a n u n d e rs ta n d th e a rtific ia l n e u ra l n e tw o r k w ith a n e x a m p le , c o ns id e r a n
ex a m p le o f a d ig ita l lo g ic g a te th a t ta k e s a n in p ut a n d g iv e s a n o u tp u t. "O R " g a te ,
w h ic h ta k e s tw o in p u ts . If o ne o r b o th th e in p u ts a re " O n ," th en w e g e t " O n " in o u tp u t.
If b o th th e in p u ts a re "O f f," th e n w e g e t " O ff" in o u tp u t. H e re th e o u tp u t d e p e n d s
up o n in p ut. O u r b ra in d o e s n o t p er fo rm th e s a m e ta s k . T h e o u tp u ts to in p u ts
re la tio n s h ip k e e p c h a n g in g b e c a us e o f th e n e ur o n s in o u r b ra in , w h ic h a re " le a rn ing ."
T o u n d er s ta n d th e c o n c e p t o f th e a rc h ite c tu re o f a n a rtific ia l n e u ra l n e tw o rk , w e
ha v e to u n d e rs ta n d w h a t a n e u ra l n e tw o rk c o n s is ts o f. In o rd e r to d e fin e a n e u ra l
ne tw o rk th a t c o ns is ts o f a lar g e n u m b e r o f a rtific ia l n e u ro n s , w h ic h a re te rm ed u n its
ar ra n g e d in a s e q u e n c e o f la ye rs . L e ts u s lo o k a t v ar io u s typ e s o f la ye rs a v a ila b le in
an a rtific ia l n e u ra l n e tw o rk .
lO M oAR cPSD |270 42294
Input Layer:
A s th e n a m e s u g g e s ts , it a c c e p ts in p u ts in s e v e ra l d iff e re n t f o rm a ts p ro v id e d b y th e
p r o g r am m e r.
Hidden Layer:
Output Layer:
T h e a rtific ia l n e ur a l n e tw o rk ta k e s in p u t a n d c o m p u te s th e w e ig hte d s u m o f th e
in p u ts a n d in c lu d es a b ia s . T h is c o m p u ta tio n is r e p re s e n te d in the fo rm o f a transfer
function.
Sigmoid Function
Tanh Function
● Equation :-
● Value Range :- - 1 to + 1
● Nature :- n o n - lin e a r
● Uses :- U s u ally u s e d in h id d e n la ye rs o f a n e u ra l n e tw o rk a s it’ s va lu e s lie s
b e tw e e n -1 to1 h e n c e th e m e a n fo r th e h id d e n la ye r c o m e s o u t b e 0 o r ve ry
c lo s e to it, h e n c e h e lp s
in b y b rin g ing m e a n c lo s e to 0 . T h is m a k e s le a rn in g fo r th e n e x t
la ye r m u c h e a s ie r.
lO M oAR cPSD |270 42294
RELU Function
Softmax Function
● Nature :- n o n - lin e a r
● Uses :- U s u ally u s e d w h e n try in g to h a n d le m u ltip le c la s s e s . th e s o f tm a x
fu n c tio n w a s c o m m o n ly f o u n d in the o u tp u t lay e r o f im a g e c la s s ific a tio n
p r o b le m s .T h e s o ftm a x fu n c tio n
lO M oAR cPSD |270 42294
w o u ld s q u e e ze th e o u tp u ts fo r e a c h c la s s b e tw e e n 0 a n d 1 a n d w o u ld a ls o d ivid e b y
th e s u m o f th e o u tp u ts .
● Output:- T h e s o ftm a x f u nc tio n is id e a lly us e d in th e o u tp u t la ye r o f th e c la s s ifie r
w h e re w e a re a c tu a lly try in g to a tta in th e p ro b a b ilitie s to d e fin e th e c la s s o f e a c h
in p u t.
● T h e b a s ic ru le o f th u m b is if yo u re a lly d o n ’ t k n o w w h a t a c tiv a tio n fu n c tio n to
u s e , th e n s im p ly u s e a s it is a g e n e ra l a c tiv atio n fu n c tio n in h id d e n la y e rs
a n d is u s e d in m o s tc a s e s the s e d a ys .
● If y o u r o u tp u t is fo r b in a ry c la s s ific a tio n th e n , is ve ry n a tu ra l
c h o ic e fo r o u tp u t la ye r .
● If yo ur o u tp u t is f o r m u lti- c la s s c la s s ific a tio n th e n , S o f tm a x is v er y u s ef u l to
p r ed ic t th e p ro b a b ilitie s o f e a c h c la s s e s .
A d e e p n e u ra l n e tw o rk (D N N ) is a n A N N w ith m u ltip le h id d e n la ye r s b e tw e e n th e
in p u t a n d o u tp u t la ye r s
T ra in in g d e e p n eu r al n e tw o r k s is a c ru c ia l s te p in th e f ie ld o f d e e p le a rn in g , e n a b ling
th e s e n e tw o rk s to lea r n fro m d a ta a n d m a k e p re d ic tio n s o r d e c is io n s . B e lo w a re th e
k e y s te p s a n d c o n c e p ts in vo lv e d in tra in in g d e e p n e tw o rk s :
1 . Data Collection and Preparation:
● G ath er a d a ta s e t th a t is re p r e s en tative o f th e p ro b le m yo u w a n t to s o lve . T h is
d a ta s h o uld b e d iv id ed in to tra in in g , va lid a tio n , a n d tes t s e ts .
● P re p ro c e s s th e d a ta b y n o rm a liz in g , s c a lin g , a n d a u g m e n tin g it a s
n e e d e d . D a ta p re p r o c e s s in g h e lp s e n s u re th a t th e n e tw o r k c a n le a rn
e ffe c tive ly .
2 . Model Architecture:
● C h o o s e a n ap p ro p ria te n e u ra l n e tw o rk a rc h ite c tu re fo r yo u r p ro b le m . T h is
m a y in vo lv e s e le c tin g th e ty p e o f la y e rs (e .g ., c o n v o lu tio n a l, r e c u rre n t, fu lly
c o n ne c te d ) a n d ar ra n g in g th e m in a m e a n in g f u l w a y.
● D e te rm in e th e n um b e r o f n e u ro n s o r u n its in e a c h la y e r, th e a c tiva tio n
fu n c tio n s to u s e ,a n d a n y o th e r a rc h ite c tu ra l d eta ils .
3 . Loss Function:
● S e le c t a n a p p r o p r ia te lo s s fu n c tio n ( a ls o k n o w n a s a c o s t o r o b je c tive
fu n c tio n ) th a t q u a n tifie s the d iffe r en c e b e tw e e n th e m o d e l's p r e d ic tio ns a n d
th e a c tu a l tar g e t v a lu e s . T h e c h o ic e o f lo s s fu n c tio n d e p e n d s o n th e p ro b le m
(e . g ., m e a n s q u a re d e rr o r fo r re g re s s io n ,
c ro s s - e n tro p y fo r c la s s ific a tio n ) .
4 . Optimizer:
● C h o o s e a n o p tim iz a tio n a lg o rithm (o p tim iz er ) th a t w ill a d ju s t the m o d e l's
w e ig h ts a n d b ia s es to m in im iz e th e lo s s fu n c tio n . C o m m o n o p tim iz er s
in c lu d e s to c h a s tic g ra d ie n t d e s c e n t ( S G D ) , A d am , R M S p ro p , a n d o th er s .
● S e t h y p e rp a ra m e te rs fo r th e o p tim ize r , s u c h as th e le a rn in g ra te a n d
m o m e n tu m .
5 . Training Loop:
● Ite ra te th ro u g h th e tra in ing d a ta s et in b a tc h e s . F o r ea c h b a tc h :
lO M oAR cPSD |270 42294
● F o rw a r d p a s s : C o m p ute p re d ic tio n s fo r th e in p ut d a ta .
● C o m p u te th e lo s s u s in g th e c h o s e n lo s s fu n c tio n a n d th e tru e la b e ls .
lO M oAR cPSD |270 42294
● B a c k w a rd p as s ( b a c k p ro p a g a tio n ) : C o m p u te g ra d ie nts o f th e lo s s
w ith re s p e c t to th e m o d e l's p a ra m e te rs .
● U p d a te th e m o d e l's p a ra m e te rs u s in g th e o p tim ize r.
6 . Validation:
● P e rio d ic a lly e v a lua te the m o d e l's p e rfo rm a n c e o n a s e p a ra te va lid a tio n
d a ta s e t. T his h e lp s m o n ito r th e m o d e l's p ro g re s s a n d d ete c t o v e rfittin g ( w h en
th e m o d e l p e rfo r m s w e ll o n th e tra in in g d ata b u t n o t o n u ns e e n d ata ).
● A d ju s t h yp e rp a ra m e te rs o r s to p tra in in g if th e v a lid a tio n p e rf o rm a n c e d o e s
n o t im p ro ve o r s ta r ts to d e g ra d e .
7 . Hyperparameter Tuning:
● E x p e rim e n t w ith d if fe re n t h y p e rp a r am ete rs , in c lu d in g le a rn in g ra te s , b atc h
s iz es , n e tw o r k a rc hite c tur e s , a n d re g u la riz a tio n te c h niq u e s (e . g ., d ro p o u t, L 2
re g u la riz a tio n ) to f in d th e
b e s t c o m b in a tio n fo r yo u r p ro b le m .
8 . Regularization:
● A p p ly r e g u la riza tio n te c h n iq u e s to p re ve n t o v e rfittin g . T h e s e te c hn iq u e s
in c lu d e d ro p o u t,
w e ig h t d e c a y ( L 2 re g u la riz atio n ) , a n d e a rly s to p p in g .
9. Data Augmentation:
● A u g m en t th e tra in in g d a ta b y a p p lying ra n d o m tra n s fo rm a tio n s (e .g ., ro ta tio n s ,
flip s ,
c ro p s ) to in c re a s e th e d ive rs ity o f th e tra in in g s am p le s a nd im p ro ve
g e n e ra liz a tio n .
10 . Monitoring and Logging:
● K e ep tra c k o f tra in in g p ro g re s s b y m o n ito rin g m etric s lik e lo s s a n d a c c u ra c y.
● L o g r e le v a n t in fo rm a tio n , s u c h a s tra in in g a n d va lid a tio n p er fo rm a n c e ,
h yp e rp a ra m e te rs ,
a n d m o d e l c h e c k p o in ts , fo r fu tu re re fe re n c e .
11 . Testing :
● A fte r tra in in g , e va lu a te th e fin a l m o d el o n a s e p a ra te te s t d ata s e t th a t it h a s
n e ve r s e e n
b e fo re to as s e s s its g e n e ra liza tio n p e rfo rm a n c e .
12 . Deployment:
● O n c e s a tis fie d w ith th e m o d e l's p e rfo rm a n c e , d e p lo y it fo r m a k in g p re d ic tio n s
o n n ew ,
u n s e en d a ta in a p r o d u c tio n e n v iro nm en t.
lO M oAR cPSD |270 42294
Example
Input values
X 1= 0 .0
5
X 2 = 0 .1
0
Initial weight
W 1 = 0 . 15 w 5 = 0 .4 0
W 2 = 0 .2 0
w 6 = 0 .4 5
W 3 = 0 .2 5
w 7 = 0 .5 0
W 4 = 0 .3 0
w 8 = 0 . 55
lO M oAR cPSD |270 42294
Bias Values
b 1 = 0 .3 5 b 2 = 0 .6 0
Target Values
T1= 0.01
T 2 = 0 .9
9
N o w , w e firs t c alc u la te th e va lu e s o f H 1 a nd H 2 b y a f o rw a rd p a s s .
lO M oAR cPSD |270 42294
Forward Pass
T o find th e v a lue o f H 1 w e f irs t m u ltip ly th e in p u t va lu e fro m th e
w e ig h ts a s H 1 = x 1 × w 1+ x 2 × w 2 + b 1
H 1= 0 .0 5 × 0 .15 + 0 .10 × 0 .2 0 + 0 .3 5
H1=0.3775
W e w ill c a lc u la te th e v a lu e o f H 2 in th e s a m e w a y a s H 1
H 2 = x 1× w 3 + x 2 × w 4 + b 1 H 2= 0 . 0 5 × 0 .2 5 + 0 .10 ×
0 .3 0 + 0 .3 5
H2=0.3925
T o c a lc u la te th e f in a l re s u lt o f H 2 , w e p e rfo rm ed th e s ig m o id f u nc tio n a s
N o w , w e c a lc u la te th e v a lu e s o f y1 a n d y2 in th e s a m e w a y a s w e c a lc u la te th e H 1 a n d
H2.
y1 = H 1× w 5 + H 2 × w 6 + b 2 y1 = 0 .5 9 32 6 9 9 92 ×
0 .4 0 + 0 .5 96 8 8 4 3 7 8 × 0 .4 5+ 0 .60
y1=1.10590597
W e w ill c a lc u la te th e va lu e o f y 2 in th e s am e w a y as y1
y2 = H 1 × w 7 + H 2 × w 8 + b 2 y2 = 0 .5 9 3 26 9 9 9 2 ×
0 .5 0 + 0 .5 9 6 8 8 4 37 8 × 0 .5 5+ 0 .60
y2=1.2249214
O u r ta rg e t v a lu es a re 0 .0 1 a n d 0 .9 9 . O u r y 1 a nd y 2 v a lu e is n o t m a tc h e d w ith o u r
ta rg e t va lu e s T 1 a n d T 2 .
S o , th e to ta l e rro r is
lO M oAR cPSD |270 42294
N o w , w e w ill b a c k p r o p a g a te th is e rr o r to u p d a te th e w e ig h ts u s ing a b a c k w a rd p a s s .
W e p e rfo r m b a c kw a rd p ro c e s s s o firs t c o n s id e r th e la s t w e ig h t w 5 a s
P u ttin g th e v a lu e o f e -y in e q u a tio n ( 5 )
w5new=0.35
lO M oAR cPSD |270 42294
891648
w6new=4086
66186
lO M oAR cPSD |270 42294
w7new=0.5113012
70
w8new=0.5613701
21
N o w , w e w ill b a c k p ro p a g a te to o u r hid d en la y e r a n d u p d a te th e w e ig ht w 1 , w 2 , w 3 ,
a n d w 4 a s w e h a ve d o n e w ith w 5 , w 6 , w 7 , a n d w 8 w e ig h ts .
W e w ill c a lc u la te th e e rr o r a t w 1 a s
W e a g a in S p lit b o th b e c a u s e th e re is n o a n y y1 a n d y 2 te rm in E 1 a n d E 2 .
W e s p litit a s
( 19 ) a s F ro m e q u a tio n ( 18 )
F r o m e q u a tio n (8 )
F r o m e q u a tio n (1 9 )
lO M oAR cPSD |270 42294
F r o m e q u a tio n (2 1 )
lO M oAR cPSD |270 42294
N o w fro m e q u a tio n (1 6 ) a n d (1 7 )
P u t th e va lu e o f in e q ua tio n ( 15 ) a s
lO M oAR cPSD |270 42294
W e h a ve w e ne e d to fig u re o u t as
w1new=0.1497
80716
w2new=0.199
56143
w3new=0.249
75114
w4new=0.299
lO M oAR cPSD |270 42294
50229
W e h av e u p d a te d all th e w e ig h ts . W e fo u nd th e e rr o r 0 .2 9 8 3 7 1 10 9 o n th e n e tw o rk
w h e n w e fe d fo rw a rd th e 0 . 0 5 a n d 0 .1 in p u ts . In th e f irs t r o u n d o f B a c k p ro p a g a tio n ,
th e to ta l e rro r is d o w n to 0 .2 9 10 2 7 9 2 4 . A fte r r ep e a tin g th is p ro c e s s 1 0 ,0 0 0 , th e to ta l
e rro r is d o w n to 0 . 0 0 0 0 3 5 1 0 8 5 . A t th is p o in t, th e o u tp u ts n e u ro n s g e n e ra te
0 . 15 9 1 2 19 6 0 a nd 0 .9 8 4 0 6 5 7 3 4 i. e ., n e a rb y o u r ta rg e t va lu e w h en w e fe e d fo r w a rd
th e 0 .0 5 a n d 0 .1
lO M oAR cPSD |270 42294
Im p ro vin g D e e p N e tw o rk s
H e re a re a fe w m e th o d s th at c a n b e u s ed to a v o id o v e rfittin g d u rin g N e u ra l N e tw o r k
hyperparameter tuning:
S e v e ra l a p p ro a c h e s c a n b e us e d to p er fo rm h yp er p a ra m e te r tu n in g o n n e u ra l
n e tw o rk s , in c lu d in g
Grid Search
Random Search
Bayesian Optimization
Gradient Descent
R e g u la riza tio n
R e g u la riz a tio n in d e e p n e u ra l n e tw o rk s is a s e t o f te c h n iq u e s u s e d to p r ev e n t
o v e rfittin g , w h ic h o c c u rs w he n a m o d e l le a rn s to fit th e tra in in g d a ta ve ry c lo s e ly
b u t p e rfo r m s p o o rly o n u n s e e n d a ta . R eg u lar iza tio n m e th o d s a im to e n c o u ra g e
th e m o d e l to g e n e ra liz e b e tte r b y ad d ing c o n s tra in ts o r p e n a ltie s to th e lo s s
fu n c tio n , w h ic h d is c o u ra g e s th e m o d e l fro m le a rn ing c o m p le x p a tte rn s th a t m a y
n o t b e re p re s e n ta tiv e o f th e tru e u n d e rlyin g re la tio n s hip s in th e d a ta .
So m e c o m m o n r e g u la riz atio n te c h n iq ue s u s ed in d e e p n e u ra l n e tw o r k s :
4. E a rly S to p p in g :
• E a rly s to p p in g is a s im p le b u t e ffe c tiv e re g u la riza tio n te c h n iq u e . It
in v o lve s m o n ito rin g th e m o d e l's p e r fo rm a n c e o n a va lid a tio n d a ta s e t d u rin g
tra inin g . If th e p e r fo rm a n c e s ta rts to d e g ra d e ( in d ic a tin g o v e rfittin g ) , tra in in g is
s to p p e d e a rly to p re ve n t th e m o d e l fro m
le a rn in g n o is e in th e d a ta .
5. D a ta A u g m e n ta tio n :
• D a ta au g m e n ta tio n in v o lve s c re a tin g n e w tra in in g e x a m p le s b y
a p p lyin g ra n d o m tra n s fo rm a tio n s (e .g ., ro ta tio ns , flip s , c ro p s ) to th e e x is tin g
tra inin g d a ta . T h is in c re a s e s
th e d ive rs ity o f th e tra in in g s e t a n d h e lp s th e m o d e l g e n er a lize b e tte r.
6. W e ig h t C o n s tra in ts :
• Y o u c a n a p p ly c o ns tra in ts to th e w e ig h ts o f th e n e u ra l n etw o rk to
lim it the ir va lu e s . F o r e x a m p le , yo u c a n u s e th e m a x - n o rm c o n s tra in t, w h ic h
lim its th e m a g nitu d e o f w e ig ht
ve c to r s . T h is c a n h e lp p re v e nt w eig h ts fro m g ro w in g e x c e s s ive ly d u rin g tra in in g .
7. N o is e In je c tio n :
• A d d in g n o is e to th e in p u t d a ta o r to th e a c tiv atio n s o f n e u ro n s
d u rin g tra in in g c a n a c t a s a fo rm o f re g u la riza tio n . N o is e c a n h elp th e m o d e l
b e c o m e m o re ro b u s t to v a ria tio n s in th e
d a ta .
8. D ro p C o n n e c t:
• S im ila r to d r o p o u t, D ro p C o n n ec t ra n d o m ly s e ts a fr ac tio n o f
w e ig h ts to ze ro d u rin g e a ch fo rw a rd and ba c kw a rd pa ss. H o w e ve r, in
D ro p C o n n e c t, w e ig h ts th em s elv e s , n o t n e u ro n s ,
a re d ro p p e d .
9. E n s e m b le M e th o d s :
• C o m b in in g th e p re d ic tio n s o f m u ltip le n e u ra l n etw o rk s ( e n s e m b le
le a rn in g ) c a n le a d to im p ro v ed p e rfo rm a n c e a n d a c t a s a fo rm o f re g ula riza tio n .
T e c h n iq u e s lik e b a g g in g an d
b o o s tin g c a n b e a p p lie d to n e u ra l n e tw o r k s .
10. A d ve rs a ria l T ra in in g :
• T r a in in g th e m od el on a d ve rs a ria l e x a m p le s g e n e ra te d by
p e rtu rb in g th e inp u t d a ta c a n
m a k e th e n e tw o r k m o re ro b us t to s m a ll p e rtu rb a tio ns a n d im p ro ve g en e ra liz a tio n .
lOM oA RcP SD| 27042 294
U N IT -III
Neural Networks: Anatomy of Neural Network, Introduction to Keras: Keras, TensorFlow,
Theano and CNTK, Setting up Deep Learning Workstation, Classifying Movie Reviews:
BinaryClassification, Classifying newswires: Multiclass Classification.
The , w h ic h d e fin e s th e fe e d b ac k s ig n a l
u s e d f o r le a rn in g T h e , w h ic h d e te rm in e s ho w
le a rn in g p ro c e e d s
T h e fu n d a m e n ta l d a ta s tru c tu re in n e u ra l n e tw o rk s is th e
A la y e r is a d a ta - p ro c es s in g m o d u le th a t ta k e s a s in p ut o n e o r m o re te n s o r s a n d
th a t o u tp u ts o n e o r m o re te n s o rs . S o m e la y e rs a re s ta tele s s , b u t m o re fre q u e n tly
la ye rs ha v e a s ta te .
D iffe re n t la ye rs a re a p p ro p ria te fo r d iffe re n t te n s o r fo rm ats a n d d iffe re n t ty p e s o f d a ta
p r o c e s s in g .
F o r in s ta nc e , s im p le v e c to r d a ta , s to re d in 2 D te n s o r s o f s ha p e ( s a m p le s , fe a tu re s ) ,
is o fte n p ro c e s s e d b y la ye rs , a ls o c a lled or
lOM oA RcP SD| 27042 294
la y e rs ( th e D e n s e c la s s in K e ra s ). S e q ue n c e d a ta , s to re d in 3 D ten s o rs o f
s h a p e ( s a m p le s , tim e s te p s , fe a tu re s ) , is typ ic a lly p ro c e s s e d b y la y e rs s u c h
a s a n L S T M la y er . Im a g e d a ta , s to r ed in 4 D te ns o rs , is us u a lly p ro c e s s e d b y 2 D
c o n vo lu tio n la y e rs (C o nv 2 D ) .
B u ild ing d e e p - le a rn in g m o d e ls in K e ra s is d o n e b y c lip p in g to g e th e r c o m p a tib le
la ye rs to f o rm u s e fu ld ata - tra n s fo rm a tio n p ip e lin e s .
C o n s id e r th e fo llo w in g e x am p le
A d e e p - le a rn in g m o d e l is a d ire c te d , a c y c lic g r ap h o f la ye rs . T h e m o s t c o m m o n
in s ta n c e is a lin ea r s ta c k o f la ye rs , m a p p in g a s in g le in p ut to a s in g le o u tp u t.
B u t a s y o u m o ve fo rw a rd , y o u ’ ll b e ex p o s e d to a m u c h b ro a d e r v ar ie ty o f
n e tw o rk to p o lo g ie s . S o m e c o m m o n o n e s in c lu d e th e fo llo w in g :
o Tw o -b ra n ch n e tw o rk s
o M u ltih ea d n etw orks
o In ce ption block s
● — D e te rm ine s ho w the n etw ork w ill be u pda te d ba sed on th e loss fun ction .
3 .2 . IN TR O DU CTION T O KER A S
O v e rview o f K e ra s
d iffic u lt to u n d er s ta n d fo r c re a tin g ne u ra l n e tw o r ks .
K e ra s is b a s e d o n m in im a l s tru c tu re th a t p ro v id es a c le a n a n d e a s y w a y to c re a te
d e e p le a rn in g m o d e ls b a s e d o n T e n s o rF lo w o r T he a n o . K e ra s is d es ig n e d to q u ic k ly
d e fin e d e e p le a rn in g m o d e ls . W e ll, K e ra s is a n o p tim a l c h o ic e fo r d e e p le a rn in g
a p p lic a tio n s .
F e a tu r es
B e n e fits
K e ra s :
T e n s o rF lo w :
T e n s o rF lo w is a n o p e n - s o u rc e m ac h in e le a rn in g fra m e w o rk d e v elo p e d b y G o o g le
B ra in . It p ro v id e s a c o m p re h e n s iv e e c o s y s te m o f to o ls , lib ra rie s , a n d re s o u rc es fo r
b u ild in g a nd d ep lo y in g m a c h in e le a rn in g m o d e ls . T e n s o rF lo w in c lu d e s a lo w - le v el A P I
th a t a llo w s u s e rs to d e f in e a n d e x e c u te c o m p u ta tio n a l g ra p h s , a s w e ll a s a h ig h - lev e l
A P I c a lle d T e n so rF lo w K e ra s , w hic h in te g ra te s s ea m le s s ly w ith K e ra s . In fa c t, s in c e
T e n s o rF lo w 2 .0 , K e ra s h a s b e c o m e th e o ffic ia l h ig h - le ve l A P I fo r b u ild in g m o d e ls in
T e n s o rF lo w .
Thea no :
C N T K (M ic ro s o ft C o g nitiv e T o o lk it) :
I a s s u m e th a t y o u alre a d y h av e U b un tu o n yo u r c o m p ute r. If n o t th e n p le a s e in s ta ll
th e la te s t v e rs io n o f U b u ntu . T h is is th e m o s t fa m o u s o p e n - s o u rc e A lth o u g h it is
p o s s ib le to r u n d e e p lea r nin g K e ra s m o d e ls o n W in d o w s , it is n o t re c o m m e n d e d .
A n o th e r p re r eq u is ite fo r r un n in g d e e p lea r nin g m o d e ls is a g o o d q u a lity G P U . I w ill
a d v is e y o u to h a ve a n N V ID IA G P U in y o u r c o m p u te r fo r s a tis f ac to r y p e rfo rm a n c e . It
is a n e c e s s a ry c o n d itio n n o t m u s t th o u g h . B e c au s e ru n n in g s e q u e n c e p ro c e s s in g
u s in g re c u rre n t n e u ra l n e tw o rk a n d im a g e p ro c e s s in g th ro u g h c o n vo lu tio n a l n e u ra l
m o d e ls in C P U is a d iffic ult p ro p o s itio n .
S u c h m o d e ls m a y ta k e h o u rs to g ive re s u lts w h e n ru n w ith C P U . W h e re a s a m o d e rn
N V ID IA G P U w ill ta k e m e re ly 5 - 10 m in u te s to c o m p le te th e m o d e ls . In c a s e if y o u a re
n o t inte re s te d to in ve s t fo r G P U a n a lte rn a tiv e is u s in g c lo u d s e rv ic e fo r c o m p u tin g
p a y in g h o u rly re n t.
H o w e v e r, in lo n g r u n, th is u s in g this s e rvic e m a y c o s t yo u m o re tha n u p g ra d in g y o u r
lo c a l s y s te m . S o , m y s u g g e s tio n w ill b e if yo u a re s e rio u s a b o u t d e e p le a rn ing a n d
w is h to c o n tin u e w ith ev e n m o d e ra te u s e , g o fo r a g o o d w o rk s ta tio n s e t u p .
$ s ud o ap t- g e t u p d a te
$ s u d o a p t- g e t - -a s s u m e - y e s u p g ra d e
It c re a te d a b ig p ro b le m a s I w a s c lu e le s s a b o u t w h y it is h a p p e n in g . In m y o ld
c o m p u te r , I ha v e u s e d it n o . o f tim e s w itho u t a ny is s u e . A fte r s c o u rin g th e in te rn e t fo r
s e ve ra l h o u rs I g o t th e s o lu tio n . T h is h a s to d o w ith th e P y th o n v e rs io n in s ta lle d in
yo u r c o m p u te r .
If yo u a re a ls o fa c in g th e p ro b le m (m o s t lik e ly if u s in g a n e w c o m p u te r) th e n firs t
c h e c k th e p y th o n v e rs io n w ith th is c o m m a n d .
$ ls /b in /p yth o n*
# In s ta llin g P yth o n 3
$ s u d o a p t- g e t in s ta ll p yth o n 3 - p ip p y th o n 3 - d ev
p y th o n - y a m l
R u n th e fo llo w in g c o m m a n d to in s ta ll H D F 5 in
yo u r m a c h in e # In s ta ll H D F 5 d a ta f o rm a t to s a v e
th e K e ra s m o d e ls
$ s u d o a p t-g e t in s ta ll lib h d f5 - s e ria l- d e v p y th o n - h 5 p y
# In s ta ll o p e n c v
$ s u d o a p t- g e t in s ta ll p yth o n - o p e nc v
S e tting up G P U fo r d e e p le a rnin g
H e re c o m e s th e m o s t im p o rta n t p a rt. A s y o u k n o w th a t G P U p la ys a n im p o rta n t r o le
in d e e p le a rn in g m o d e llin g . In th is s e c tio n , w e a re g o in g to s e t u p th e G P U s u p p o r t
b y ins ta llin g tw o c o m p o n en ts n a m e ly C U D A a n d c u D N N . B u t to fu n c tio n p r o p e rly
th e y ne e d N V ID IA G P U .
C U D A in s talla tio n c o d e
$ w get
h ttp s ://d e v e lo p e r. d o w n lo a d .n vid ia .c o m /c o m p u te /c u d a/ re p o s / ub u n tu 2 0 0 4 /x 8
6 _ 6 4 /c u d a- u b u n tu 2 0 0 4 .p in
$ s u d o m v c u d a - u b un tu 20 0 4 .p in /e tc /a p t/p re fe re n c e s .d /c u d a - re p o s ito ry- p in - 6 0 0
$ s u d o a p t- k e y a d v - - fe tc h - k e y s
h ttp s ://d e ve lo p er. d o w n lo ad .n vid ia. c o m /c o m p u te /c u d a /re p o s /ub un tu 2 0 0 4 /x 8 6 _ 6 4 /7 f
a 2 af 8 0 .p ub
$ s u d o a d d - a p t- re p o s ito ry " d e b
h ttp s :/ /d e v elo p e r.d o w n lo a d .n v id ia .c o m /c o m p u te /c u d a /re p o s /u b un tu 20 0 4 /x 8 6 _ 64 /
/"
$ s ud o ap t- g e t u p d a te
$ s ud o a p t- g e t - y ins ta ll c u d a
Ins ta ll cu D N N
lOM oA RcP SD| 27042 294
D o w n lo a d in g c u D N N
N V ID IA m e m b e r s hip f o r D o w n lo a d in g
c u D N N F ill in th e n e c e s s a ry fie ld s .
N V ID IA m e m b e rs h ip fo r D o w n lo a d in g c u D N N
N V ID IA m e m b e rs h ip fo r D o w n lo a d in g c u D N N
D o w n lo a d s u rve y fo r c u D N N
S e le c tin g th e O S fo r c u D N N d o w n lo a d
O n c e yo u a re in th e d ire c to ry w h e re th e lib ra ry h a s b e e n d o w n lo a d e d ( b y d e fa u lt it is
th e d o w n lo a d fo ld er o f y o u r c o m p u te r) ru n th e c o m m a n d b e lo w . U s e th e file n a m e in
p la c e o f * * * * in th e c o m m a n d .
$ s ud o d p k g - i d p k g - i * * * * * * .d e b
Y o u c a n fo llo w th e in s ta lla tio n p r o c e s s fr o m th is p a g e . W ith th is th e c u D N N in s ta lla tio n
is c o m p le te d .
# In s ta llin g T e n s o rF lo w u s in g p ip 3 c o m m a n d fo r P yth o n 3
$ s ud o p ip 3 ins ta ll te n s o rflo w
Ins ta llin g K e ra s
T h is is th e fin a l s te p o f s ettin g u p y o u r d e e p le a rn in g w o rk s ta tio n a n d yo u a re g o o d to
g o . Y o u c a n ru n th e s im p le b e lo w c o m m a n d .
$ s ud o p ip 3 ins ta ll k e ra s
O r yo u c an in s ta ll it fro m G ithu b to o . T h e b e n e fits o f in s ta llin g K e r as fro m G ith u b a re
th a t y o u w ill g e t lo ts o f e x a m p le c o d e s fro m th e re . Y o u c a n ru n tho s e e x a m p le s c rip ts
to te s t th em o n y o u r m a c h in e . T h e s e a re v e ry g o o d s o u rc e o f le a rn in g .
$ g it c lo ne h ttp s ://g ith u b .c o m /f c h o lle t/k e ra s
$ c d k e ra s
$ s u d o p yth o n s e tu p . p y in s ta ll
$ s ud o p ip 3 in s ta ll th e an o
C o n g ra tu latio n s !!! y o u ha v e fin is h e d w ith a ll in s ta lla tio n s a n d c o m p le te d th e s e t u p f o r
yo u r d e e p le a rn in g w o r k s ta tio n. Y o u a r e n o w re a d y to e x e c u te y o u r firs t c o d e o f d e e p
le a rn in g ne u ra l n e tw o r k .
T h e a rg u m e n t n u m _ w o rd s = 1 0 0 0 0 m e a ns yo u ’ ll o n ly k ee p th e to p 1 0 ,0 0 0 m o s t fr e q u e n tly
o c c u rr in g w o rd s in th e tra inin g d a ta . R a re w o rd s w ill b e d is c a rd e d . T h is a llo w s y o u to w o rk w ith
ve c to r d a ta o f m a n a g ea b le s ize
9999
F o r k ic k s , h ere ’ s h o w y o u c a n q u ic k ly d e c o d e o n e o f th e s e re v ie w s b ac k to E n g lis h w o rd s :
lOM oA RcP SD| 27042 294
lOM oA RcP SD| 27042 294
Y o u c a n ’ t fe e d lis ts o f in te g e rs in to a n e u ra l n e tw o r k . Y o u h a v e to tu rn yo u r lis ts in to te n s o r s .
T h e re a re tw o w a ys to d o th a t:
O ne -h ot e n code y ou r lists to turn the m into v e ctors of 0 s a n d 1s. Th is w o uld m ea n , for in sta n ce ,
turn in g the se que n ce [3 , 5 ] in to a 10 ,0 0 0 -dim e n sion al ve ctor tha t w o uld be a ll 0 s exc ep t fo r ind ic es 3
a n d 5 , w h ich w o uld be 1s. T he n you cou ld u se as the first la ye r in y our n e tw ork a D e nse la ye r, ca pa ble of
h a ndling floa tin g-p oint v ec to r d ata .
H e re ’ s w h a t th e s a m p le s lo o k lik e n o w :
T h e in p ut d a ta is v ec to rs , a n d th e la b e ls are s c ala rs ( 1s a n d 0 s ): th is is th e e a s ie s t s e tu p yo u ’ ll
e ve r e n c o u nte r. A ty p e o f ne tw o rk th a t p e rf o rm s w e ll o n s u c h a p r o b le m is a s im p le s ta c k o f
fu lly c o n n e c te d ( D e n s e ) lay e rs w ith re lu a c tiv a tio n s :D e n s e (1 6 , a c tiv a tio n = 're lu ').
lOM oA RcP SD| 27042 294
lOM oA RcP SD| 27042 294
w h a t y o u w o u ld e x p e c t w h e n r un n in g g ra d ie n t d e s c e n t o p tim iz a tio n—
th e q u an tity yo u ’ re try in g to m in im iz e s h o u ld b e le s s w ith e v e ry ite r atio n .
lOM oA RcP SD| 27042 294
lOM oA RcP SD| 27042 294
3.5 .
2.
3.
lOM oA RcP SD| 27042 294
lOM oA RcP SD| 27042 294
D a ta P re p
ve c to r ize th e in p ut d a ta
= n p .ze ro s ( (le n (s e q u e n c e s ), d im en s io n ))
fo r i, s e q u e n c e in
se qu e n ce ] = 1.
v ec to rize _ s e q u e n c e s ( te s t_ d a ta ) # 2
V en cotriz e testin g da ta
e x a m p le . d e f to _ o n e _ h o t( la b e ls , d im e n s io n = 4 6 ) :
la b e l in
e n u m e ra te ( la b e ls ) :
re s u lts [i, la b e l] = 1 .
re tu rn r e s ults
o n e _ h o t_ tra in _ la b e ls =
o n e _ h o t_ te s t_ la b els = to _ o n e_ h o t( te s t_ la b e ls )# 2
N o te th a t th e re is a b u ilt- in w a y to d o th is in K e ra s :
o n e _ h o t_ tra in _ la b e ls =
o n e _ h o t_ te s t_ la b els =
to _ c a te g o ric a l( te s t_ la b e ls )
lOM oA RcP SD| 27042 294
B uildin g th e m od el
In a s ta c k o f D e ns e la y e rs lik e th a t w e h a ve b e e n u s in g , e a c h la y er c a n o n ly a c c e s s in fo rm a tio n
p r es e n t in th e o u tp u t o f th e p re vio u s la ye r. If o ne lay e r d ro p s s o m e in f o rm a tio n re lev a n t to th e
c la s s if ic a tio n p ro b le m , th is in fo r m a tio n c a n n e ve r b e re c o ve re d b y la te r la ye rs : e a c h la ye r c a n
p o te n tia lly be co m e an in fo rm a tio n b o ttle n e c k . In th e p re v io u s ex a m p le , we used
1 6- d im en s io na l in te rm e d ia te la ye rs , b ut a 1 6 - d im e n s io n a l s p a c e m a y b e to o lim ite d to le a rn to
s e p a ra te 46 d iffe re n t c la s s e s : su ch s m a ll la y er s m ay ac t a s in fo rm a tio n b o ttle n e c ks ,
p e rm an e n tly d r o p p in g re lev a n t in fo rm a tio n . F o r th is re a s o n w e w ill u s e la rg e r la ye r s . L e t’ s g o
w ith 6 4 u nits .
M o d e l D e fin a tio n
m od el =
k e ra s .S e q ue n tia l([
lay e rs .D e n s e ( 6 4 ,
a c tiva tio n = 'r elu ') ,
lay e rs .D e n s e ( 6 4 ,
a c tiva tio n = 'r elu ') ,
lay e rs .D e n s e ( 4 6 ,
a c tiva tio n = 's o ftm a x ')
])
N o te a b o ut th is a r c h ite c tu re :
Co m pile th e
m o de l
p',
V a lid a tio n o f th e a p p ro a c h
x _ tra in [:10 0 0 ]
y_ va l =
o n e _ h o t_ tra in _ la b e ls [:10 0 0 ]
tra in th e m o d e l fo r 2 0 e p o c hs .
T r ain in g th e m o d e l
p a rtia l_ y_ tra in ,
e po ch s= 2
0 , b a tc h _ s iz e = 5 12 ,
v a lid a tio n _ d a ta = (x _ va l,
y _ v a l) )
lOM oA RcP SD| 27042 294
E p o c h 1/ 20
- 2 s 8 1m s /s te p - lo s s : 3 .1 0 2 9 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
E p o c h 2 /2 0
- 1s 3 8 m s /s te p - lo s s : 1. 4 8 0 7 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
0 .6 9 9 2 - v a l_ lo s s: 1. 29 6 4 - va l_ a c c u ra c y:
0 .7 2 3 0
E p o c h 3 /2 0
- 1s 3 6 m s /s te p - lo s s : 1. 0 7 6 3 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
E p o c h 4 /2 0
- 1s 3 6 m s /s te p - lo s s : 0 .8 4 4 1 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
E p o c h 5 /2 0
- 1s 3 7 m s/ ste - loss: -
p a c cu ra cy :
0 .8 6 5 8 - v a l_loss: 0 .9 456 - v a l_a cc u ra cy : 0 .8 0 5 0
E poch 6 /2 0
Epoc h 7/ 2 0
16/ 16 [= = == = == == = == = == = == == = == = == = == = ] - 3 6 m s/ st - loss: 0 .4 18 1 ac cu ra cy :
1s ep -
0 .9 160 - va l_lo ss: 0 .8 7 65 - va l_ acc urac y:
0 .8 140 Ep och
8 /2 0
- 1s - loss: -
35 m s/ ste p 0 .3 48 5 a c cu ra cy :
lOM oA RcP SD| 27042 294
0 .9 3 16 - v a l_ lo s s : 0 .8 8 9 5 - va l_ ac c u ra c y: 0 . 8 0 6 0
E p o c h 9 /2 0
- 1 s 3 6 m s /s te p - lo s s : 0 .2 8 2 9 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
0 .9 3 9 0 - va l_ lo s s : 0 . 8 8 2 9 - va l_ a c c u ra c y :
0 .8 1 10
E p o c h 1 0 /2 0
- 1 s 3 6 m s /s te p - lo s s : 0 .2 2 4 6 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
- 1 s 3 6 m s /s te p - lo s s : 0 .18 9 4 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y:
= == = ]
0 .9 5 3 2 - va l_ lo s s : 0 .9 0 6 0 - va l_ a c c u ra c y:
0 .8 12 0
E p o c h 1 2 /2 0
1 6 /16 [= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ] - 1 s 3 7 m s / s te p - lo s s : 0 . 17 6 5 - a c c u ra c y:
0 . 9 53 8 - v a l_ lo s s : 0 .9 0 6 8 - v a l_ a c c u ra c y :
0 . 8 1 6 0 E p o c h 1 3 /2 0
1 6 /16 [= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ] - 1s 3 7 m s / s te p - lo s s : 0 . 16 1 0 - a c c ur a c y:
0 .9 5 2 9 - v a l_ lo s s : 0 .9 3 9 4 - va l_ a c c u ra c y : 0 .8 10 0
lOM oA RcP SD| 27042 294
E p o c h 1 4 /2 0
- 1 s 3 7 m s /s te p - lo s s : 0 . 14 3 8 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c ur a c y:
= == = ]
0 .9 5 7 4 - va l_ lo s s : 0 .9 2 5 4 - v al_ a c c ur a c y:
0 .8 19 0
E p o c h 1 5 /2 0
- 1 s 3 5 m s /s te p - lo s s : 0 .1 3 0 5 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c ur a c y:
= == = ]
0 .9 5 8 4 - v a l_ lo s s : 0 .9 6 6 6 - va l_ a c c u ra c y:
0 .8 0 6 0
E p o c h 1 6 /2 0
- 1 s 3 7 m s /s te p - lo s s : 0 .1 2 9 1 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y:
= == = ]
0 .9 5 6 2 - v a l_ lo s s : 0 .9 5 3 7 - v a l_ a c c ur a c y:
0 .8 12 0
E p o c h 1 7 /2 0
- 1s 3 6 m s /s te p - lo s s : 0 .11 4 0 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = ac c u ra c y:
= == = ]
0 .9 5 9 3 - va l_ lo s s : 1 .0 2 0 2 - va l_ a c c u ra c y:
0 .8 0 2 0
E p o c h 1 8 /2 0
- 1 s 3 8 m s /s te p - lo s s : 0 .1 16 7 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c ur a c y:
= == = ]
0 .9 5 6 7 - v a l_ lo s s : 0 .9 9 4 2 - v a l_ a c c u ra c y :
0 .8 0 7 0
E p o c h 1 9 /2 0
- 1s 3 8 m s /s te p - lo s s : 0 .0 97 2 -
[= = = = = = = = = = = = = = = = = = = = = = = = = = a c c u ra c y :
= == = ]
0 .9 6 6 9 - va l_ lo s s : 1 .0 7 0 9 - va l_ a c c u ra c y:
0 .7 9 6 0
E p o c h 2 0 /2 0
1 6 /16 [= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ] - 1s 3 4 m s /s te p - lo s s : 0 .1 0 3 5 - a c c u ra c y:
lOM oA RcP SD| 27042 294
0 .9 6 0 7 - va l_ lo s s : 1 .0 5 3 0 - v a l_ a c c u ra c y : 0 .8 0 2 0
ra n g e ( 1 , le n ( lo s s ) + 1 )
la b e l= 'T r a in in g
va l_ lo s s , 'r',
p lt. le g e n d ( ) p lt.s h o w ( )
lOM oA RcP SD| 27042 294