Deeplearning - Ai Deeplearning - Ai
Deeplearning - Ai Deeplearning - Ai
DeepLearning.AI makes these slides available for educational purposes. You may not use or distribute
these slides for commercial purposes. You may make copies of these slides and use or distribute them for
educational purposes as long as you cite DeepLearning.AI as the source of the slides.
Why sequence
deeplearning.ai
models?
Examples of sequence data
“The quick brown fox jumped
Speech recognition over the lazy dog.”
Music generation ∅
“There is nothing to like
Sentiment classification in this movie.”
Notation
deeplearning.ai
Motivating example
x: Harry Potter and Hermione Granger invented a new spell.
Andrew Ng
Representing words
x: Harry Potter and Hermione Granger invented a new spell.
! "#$ ! "%$ ! "&$ ⋯ ! "($
Andrew Ng
Representing words
x: Harry Potter and Hermione Granger invented a new spell.
! "#$ ! "%$ ! "&$ ⋯ ! "($
And = 367
Invented = 4700
A=1
New = 5976
Spell = 8376
Harry = 4075
Potter = 6830
Hermione = 4200
Gran… = 4000
Andrew Ng
Recurrent Neural
Networks
Recurrent Neural
deeplearning.ai
Network Model
Why not a standard network?
! "#$ ) "#$
! "%$ ) "%$
⋮ ⋮ ⋮ ⋮
! "'($ ) "'*$
Problems:
- Inputs, outputs can be different lengths in different examples.
- Doesn’t share features learned across different positions of text.
Andrew Ng
Recurrent Neural Networks
Andrew Ng
Simplified RNN notation
+"1$ = 3(566 +"1/#$ + 568 ! "1$ + 96 )
Andrew Ng
Recurrent Neural
Networks
Backpropagation
deeplearning.ai
through time
Forward propagation and backpropagation
'( "&$ '( ")$ '( "*$ '( "+. $
Andrew Ng
Forward propagation and backpropagation
Different types
deeplearning.ai
of RNNs
Examples of sequence data
“The quick brown fox jumped
Speech recognition over the lazy dog.”
Music generation ∅
“There is nothing to like
Sentiment classification in this movie.”
Andrew Ng
Examples of RNN architectures
Andrew Ng
Summary of RNN types
() #'% () #'% () #*% () #+, % ()
"#$% "#$% ⋯ "#$% ⋯
& #'% & & #'% & #*% & #+. %
One to one One to many Many to one
"#$% "#$% ⋯ ⋯ ⋯
⋯
Andrew Ng
Language modelling with an RNN
Training set: large corpus of english text.
Sampling novel
deeplearning.ai
sequences
Sampling a sequence from a trained RNN
'( "&$ '( "/$ '( "0$ '( ")* $
Andrew Ng
Character-level language model
y<n> la 1 softmax co do dai bang voi vocabulary. Cho nao co percentage cao nhat thi y<n> la word do (hoac chon theo random choice,
danh xe percentage).
Nhu vay P(n) = P(y<n>) trong softmax. Do do, P(ca cau y) = P(y<0>).P(y<1>)....
News Shakespeare
President enrique peña nieto, announced The mortal moon hath her eclipse in love.
sench’s sulk former coming football langston
paring. And subject of this thou art another this fold.
“I was not at all surprised,” said hich langston. When besser be my love to me see sabl’s.
“Concussion epidemic”, to be examined. For whose are ruse of mine eyes heaves.
Andrew Ng
Recurrent Neural
Networks
Vanishing gradients
deeplearning.ai
with RNNs
Vanishing gradients with RNNs
Vi du: Translate tu tieng viet sang
tieng anh. Den tu "đã là" ta dich
sang were hay was. RNN can '( "&$ '( "-$ '( "/$ '( ")* $
thong tin ty trc do de chon, nhung
tu cat thi o qua xa. Co lay history
nhung qua xa thi khong update
duoc. Do do can LSTM.
% ⋮ ⋮ ⋮ ⋮ ⋯ ⋮ ⋮ ⋮ '(
Exploding gradients.
Andrew Ng
Recurrent Neural
Networks
Gated Recurrent
deeplearning.ai
Unit (GRU)
RNN unit
Andrew Ng
GRU (simplified)
Andrew Ng
Recurrent Neural
Networks
=#$% = ! #$%
Khac voi GRU, LSTM co he so rieng cho c~ la Tu va c_ la Tf, ngoai ra con 1 he so To chuyen tu ct thanh at. Nhu vay thi he so c~ la To*Tu va c_ la To*Tf
=#$% = Γ? ∗ ! #$%
[Hochreiter & Schmidhuber 1997. Long short-term memory] Andrew Ng
LSTM in pictures
D #$%
=#$%
Γ8 = 9(,8 =#$12%, 4 #$% + 68 )
! #$12% * ⨁ ! #$%
--
Γ> = 9(,> =#$12%, 4 #$% + 6> ) tanh ! #$%
* =#$%
Γ? = 9(,? =#$12%, 4 #$% + 6? ) =#$12% B #$%
C #$%
!̃ #$% A #$%
*
=#$%
! #$% = Γ8 ∗ !̃ #$% + Γ> ∗ ! #$12%
forget gate update gate tanh output gate
=#$% = Γ? ∗ ! #$%
4 #$%
D #2% D #F% Duong a la duong value D #G%
Duong c la duong history, luu tru cac
softmax softmax softmax
gia tri qua khu de bo sung cho a
=#2% =#F% #G% =
! #F%
-- --
! #G%
--
! #2%
! #E% * ⨁ ! #2% * ⨁ ! #F% * ⨁
Bidirectional RNN
deeplearning.ai
Getting information from the future
He said, “Teddy bears are on sale!”
He said, “Teddy Roosevelt was a great President!”
!" #)% !" #(% !" #*% !" #.% !" #-% !" #/% !" #$%
' #)% ' #(% ' #*% ' #.% ' #-% ' #/% ' #$%
He said, “Teddy bears are on sale!”
Andrew Ng
Wy khong chi thoa man Wy*a_(forward) = a(forward)
Andrew Ng
Recurrent Neural
Networks
Deep RNNs
deeplearning.ai
Deep RNN example softmax of tôi softmax of yêu
softmax of class (dog,cat) = (1x2) (1x923) (1x923)
([#]"+$
Ex: "I love you too" one hot of love one hot of you
!"#$ ! "%$ ! "&$ (1x1023) ! "'$
va 1 dict co 1023 tu english (1x1023)
va 923 tu tieng viet one hot of I in vocab too (1x1023)
mat (1x1023)
Deep RNN la Deeper tung block => so luong weight tang cao tu length of RNN L thanh L*depth
Andrew Ng