Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Copyright Notice

These slides are distributed under the Creative Commons License.

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.

For the rest of the details of the license, see https://creativecommons.org/licenses/by-sa/2.0/legalcode


Sequence to
sequence models

Basic models
deeplearning.ai
Sequence to sequence model
% "&$ % "*$ % "+$ % ",$ % "-$
Jane visite l’Afrique en septembre
Jane is visiting Africa in September.
. "&$ . "*$ . "+$ . ",$ . "-$ . "/$

!"#$ ⋯

% "&$ % "'( $

[Sutskever et al., 2014. Sequence to sequence learning with neural networks]


[Cho et al., 2014. Learning phrase representations using RNN encoder-decoder for statistical machine translation] Andrew Ng
Image captioning . "&$ . "*$ . "+$ . ",$ . "-$ . "/$
A cat sitting on a chair

MAX-POOL MAX-POOL

11 × 11 3 × 3 5 × 5 3 × 3 3 × 3 3 × 3
s=4 s=2 same s=2 same
55×55 ×96 27×27 ×96 27×27 ×256 13×13 ×256 13×13 ×384

MAX-POOL
= ⋮ ⋮ ⋮
3 × 3 3 × 3
s=2 Softmax
1000
13×13 ×384 13×13 ×256 6×6 ×256 9216 4096 4096

.9 "&$ .9 "*$ .9 "':$


%
[Mao et. al., 2014. Deep captioning with multimodal recurrent neural networks]
[Vinyals et. al., 2014. Show and tell: Neural image caption generator]
[Karpathy and Li, 2015. Deep visual-semantic alignments for generating image descriptions] Andrew Ng
Sequence to
sequence models

Picking the most


deeplearning.ai
likely sentence
Machine translation as building a conditional
language model
'( "&$ '( ".$ '( "*, $

Language model: !"#$ ⋯

% "&$ % ".$

"*, $
'( "&$ '(

Machine translation: !"#$ ⋯ ⋯

% "&$ % "*+ $

Andrew Ng
Finding the most likely translation
Jane visite l’Afrique en septembre. /(' "&$ , … , ' "*, $ | %)

Jane is visiting Africa in September.


Jane is going to be visiting Africa in September.
In September, Jane will visit Africa.
Her African friend welcomed Jane in September.

arg max /(' "&$, … , ' "*, $| %)


:;<= ,…,:;>, =

Andrew Ng
Why not a greedy search?
"*, $
'( "&$ '(

!"#$ ⋯ ⋯

% "&$ % "*+ $

Jane is visiting Africa in September.


Jane is going to be visiting Africa in September.

Andrew Ng
Sequence to
sequence models

Beam search
deeplearning.ai
Beam search algorithm
Step 1
a 0(' "&$ | %)


'( "&$
in
⋮ !"#$ ⋯
10000 jane
⋮ % "&$ % "*+ $
september

zulu

Andrew Ng
Beam search algorithm
Step 1 Step 2
!"#$ ⋯
a
⋮ % "&$ % "*+ $
in

10000 jane
⋮ !"#$ ⋯
september
% "&$ % "*+ $

zulu
!"#$ ⋯

% "&$ % "*+ $ Andrew Ng


Beam search (4 = 3) "7$
in september '(
in september !"#$ ⋯
% "&$ % "*+ $

jane is '( "7$

jane is !"#$ ⋯
% "&$ % "*+ $
"7$
jane visits '(

jane visits !"#$ ⋯


% "&$ % "*+ $

0(' "&$ , ' "9$ | %) jane visits africa in september. <EOS>


Andrew Ng
Sequence to
sequence models

Refinements to
deeplearning.ai
beam search
Length normalization
45

arg max ( ) * +,- ., * +0- , … , * +,20- )


'
,60

45

arg max 7 log ) * +,- ., * +0- , … , * +,20- )


'
,60

45

7 log ) * +,- ., * +0- , … , * +,20- )


,60
Andrew Ng
Beam search discussion

Beam width B?

Unlike exact search algorithms like BFS (Breadth First Search) or


DFS (Depth First Search), Beam Search runs faster but is not
guaranteed to find exact maximum for arg max )(*|.).
'

Andrew Ng
Sequence to
sequence models

Error analysis on
deeplearning.ai
beam search
Example
Jane visite l’Afrique en septembre.

Human: Jane visits Africa in September.

Algorithm: Jane visited Africa last September.

!"#$ ⋯
% "&$ % "'( $

Andrew Ng
Error analysis on beam search
Human: Jane visits Africa in September. (+ ∗ )
Algorithm: Jane visited Africa last September. (+.)

Case 1:
Beam search chose +.. But + ∗ attains higher / + % .
Conclusion: Beam search is at fault.
Case 2:
+ ∗ is a better translation than +.. But RNN predicted / + ∗ % < / +. % .
Conclusion: RNN model is at fault.
Andrew Ng
Error analysis process
Human Algorithm / +∗ % / +. % At fault?

Jane visits Africa in Jane visited Africa


September. last September.

Figures out what faction of errors are “due to” beam


search vs. RNN model Andrew Ng
Sequence to
sequence models

Bleu score
deeplearning.ai
(optional)
Evaluating machine translation
French: Le chat est sur le tapis.

Reference 1: The cat is on the mat.

Reference 2: There is a cat on the mat.

MT output: the the the the the the the.

Precision: Modified precision:

[Papineni et. al., 2002. Bleu: A method for automatic evaluation of machine translation] Andrew Ng
Bleu score on bigrams
Example: Reference 1: The cat is on the mat.
Reference 2: There is a cat on the mat.
MT output: The cat the cat on the mat.

the cat
cat the
cat on
on the
the mat
[Papineni et. al., 2002. Bleu: A method for automatic evaluation of machine translation] Andrew Ng
Bleu score on unigrams
Example: Reference 1: The cat is on the mat.
Reference 2: There is a cat on the mat.
MT output: The cat the cat on the mat.

% 01234
56(7 (239:;<=) % 0123456(7 (3:;<=)
&'()*+,∈./ ')*+,∈./
!" = !' =

% 01234 (239:;<=) % 01234 (3:;<=)
&'()*+,∈./ ')*+,∈./

[Papineni et. al., 2002. Bleu: A method for automatic evaluation of machine translation] Andrew Ng
Bleu details
!' = Bleu score on n-grams only
Combined Bleu score:

1 if MT_output_length > reference_output_length


BP =
exp (1 − MT_output_length/reference_output_length) otherwise

[Papineni et. al., 2002. Bleu: A method for automatic evaluation of machine translation] Andrew Ng
Sequence to
sequence models

Attention model
deeplearning.ai
intuition
The problem of long sequences
"* $
'( "&$ '( ,

!"#$ ⋯ ⋯

% "&$ % "*+ $
Jane s'est rendue en Afrique en septembre dernier, a apprécié la culture et a rencontré beaucoup de
gens merveilleux; elle est revenue en parlant comment son voyage était merveilleux, et elle me tente
d'y aller aussi.
Jane went to Africa last September, and enjoyed the culture and met many wonderful people;
she came back raving about how wonderful her trip was, and is tempting me to go too.

Bleu
score

10 20 30 40 50 Sentence length Andrew Ng


Attention model intuition

'( "&$ '( ".$ '( "/$ '( "1$ '( "0$

!"#$

% "&$ % ".$ % "/$ % "1$ % "0$


jane visite l’Afrique en septembre
[Bahdanau et. al., 2014. Neural machine translation by jointly learning to align and translate] Andrew Ng
Sequence to
sequence models

Attention model
deeplearning.ai
Attention model

)"*$

! "#$ ! "%$ ! "&$ ! "($ ! "'$


jane visite l’Afrique en septembre
[Bahdanau et. al., 2014. Neural machine translation by jointly learning to align and translate] Andrew Ng
",,, . $
Computing attention +
",,, . $ ", $ ", . $
+ = amount of attention / should pay to )
/C ",@#$ /C ",$
.
",,, . $ 123 (5 67,7 8 )
+ = = . ? ",@#$ ? ",$
∑ .> 123 (5 67,7 8 )
7 ;<
+
? ",@#$
",,, . $
A
", . $ )"*$ ⋯
)
! "#$ ! "%$ ! "E> @#$ ! "E> $

[Bahdanau et. al., 2014. Neural machine translation by jointly learning to align and translate]
[Xu et. al., 2015. Show, attend and tell: Neural image caption generation with visual attention] Andrew Ng
Attention examples
July 20th 1969 1969 − 07 − 20

23 April, 1564 1564 − 04 − 23

",,, .$
Visualization of + :

Andrew Ng
Audio data

Speech recognition
deeplearning.ai
Speech recognition problem
! #
audio clip transcript

“the quick brown fox”

Andrew Ng
Attention model for speech recognition
“T” “h”

% &'( % &)( ⋯

+&,( ⋯

! &'( ! &)( ⋯ ! &---( ! &',,,(

Andrew Ng
CTC cost for speech recognition
(Connectionist temporal classification)
“the quick brown fox”
#. &'( #. &)( #. &',,,(

+&,( ⋯

! &'( ! &)( ! &',,,(

Basic rule: collapse repeated characters not separated by “blank”


[Graves et al., 2006. Connectionist Temporal Classification: Labeling unsegmented sequence data with recurrent neural networks] Andrew Ng
Audio data

Trigger word
deeplearning.ai
detection
What is trigger word detection?

Amazon Echo Baidu DuerOS Apple Siri Google Home


(Alexa) (xiaodunihao) (Hey Siri) (Okay Google)

Andrew Ng
Trigger word detection algorithm

!"#$

% "&$ % "'$ % "($

Andrew Ng
Conclusion

Summary and
deeplearning.ai
thank you
Specialization outline

1. Neural Networks and Deep Learning


2. Improving Deep Neural Networks: Hyperparameter
tuning, Regularization and Optimization
3. Structuring Machine Learning Projects
4. Convolutional Neural Networks
5. Sequence Models

Andrew Ng
Deep learning is a super power

Please buy this


from shutterstock
and replace in
final video.

Andrew Ng
Thank you.
-Andrew Ng

Andrew Ng

You might also like