Slide credit from HungYi Lee & Richard Socher 1
Review
Word Vector
Word2Vec Variants
Skipgram: predicting surrounding words given the target word
(Mikolov+, 2013)CBOW (continuous bagofwords): predicting the
target word given the surrounding words
(Mikolov+, 2013)LM (Language modeling): predicting the next words given the proceeding contexts
(Mikolov+, 2013)Mikolov et al., “Efficient estimation of word representations in vector space,” in ICLR Workshop, 2013. 3 Mikolov et al., “Linguistic regularities in continuous space word representations,” in NAACL HLT, 2013.
Word2Vec LM
Goal: predicting the next words given the proceeding contexts
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
5
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
Language Modeling
Goal: estimate the probability of a word sequence
Example task: determinate whether a sequence is grammatical or makes more sense
7
recognize speech or
wreck a nice beach Output =
“recognize speech”
If P(recognize speech)
> P(wreck a nice beach)
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
NGram Language Modeling
Goal: estimate the probability of a word sequence
Ngram language model
◦
Probability is conditioned on a window of (n1) previous words
◦
Estimate the probability based on the training data
9
𝑃 beachnice = 𝐶 𝑛𝑖𝑐𝑒 𝑏𝑒𝑎𝑐ℎ
𝐶 𝑛𝑖𝑐𝑒 Count of “nice” in the training data
Count of “nice beach” in the training data
Issue: some sequences may not appear in the training data
NGram Language Modeling
Training data:
◦The dog ran ……
◦The cat jumped ……
P( jumped  dog ) = 0 P( ran  cat ) = 0
give some small probability
smoothing
0.0001 0.0001
The probability is not accurate.
The phenomenon happens because we cannot collect all the possible text in the world as training data.
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
11
Neural Language Modeling
Idea: estimate not from count, but
from the NN prediction
Neural Network
vector of “START”
P(next word is
“wreck”)
Neural Network
vector of “wreck”
P(next word is “a”)
Neural Network
vector of “a”
P(next word is
“nice”)
Neural Network
vector of “nice”
P(next word is
“beach”)
P(“wreck a nice beach”) = P(wreckSTART)P(awreck)P(nicea)P(beachnice)
Neural Language Modeling
Bengio et al., “A Neural Probabilistic Language Model,” in JMLR, 2003. 13
Issue: fixed context window for conditioning
input hidden
output
context vector
Probability distribution of the next word
Neural Language Modeling
The input layer (or hidden layer) of the related words are close
◦If P(jumpdog) is large, P(jumpcat) increase accordingly (even there is not “… cat jump …” in the data)
h
_{1}h
_{2}dog
cat
rabbit
Smoothing is automatically done
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
15
Recurrent Neural Network
Idea: condition the neural network on all previous words and tie the weights at each time step
Assumption: temporal information matters
RNN Language Modeling
17
vector of “START”
P(next word is
“wreck”)
vector of “wreck”
P(next word is “a”)
vector of “a”
P(next word is
“nice”)
vector of “nice”
P(next word is
“beach”)
input hidden output
context vector word prob dist
Idea: pass the information from the previous hidden layer to leverage all contexts
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
RNNLM Formulation
19
At each time step,
…… ……
……
……
vector of the current word probability of the next word
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
Recurrent Neural Network Definition
21 http://www.wildml.com/2015/09/recurrentneuralnetworkstutorialpart1introductiontornns/
: tanh, ReLU
Model Training
All model parameters can be updated by y
_{t1}y
_{t}y
_{t+1}target
predicted
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
23
Backpropagation
… …
1 2
j … …
1 2
l
i w
ijLayer l Layer l 1
1
1
1 l x
l a
j l l j
iBackward Pass
⋮
⋮
Forward Pass
⋮
⋮
Error
signal
Backpropagation
25 l
iBackward Pass
⋮
⋮
Error signal
1
2
n
…
y1
C
^{z}1^{L}
^{}
^{z}2^{L}
zn^{L}
y2
C
yn
C
Layer L
2 1
i
…
Layer l
^{z}1^{l}
^{z}_{2}^{l}
^{z}_{i}^{l}^{}
δ_{1}l
δ_{2}l
l
δi
2
…
1^{L}^{1}
z
1
m
Layer L1
…
…
…
_{ }_{W}^{L} ^{T} ^{W}^{l}^{}^{1} ^{T}
^{y}C
L 1

L
2^{L} ^{1}
z
^{L}^{1}
z_{m}
δl
Backpropagation through Time (BPTT)
Unfold
◦
Input: init, x
_{1}, x
_{2}, …, x
_{t}◦
Output: o
_{t}◦
Target: y
_{t}init
s_{t} y_{t}
x_{t} o_{t}
x_{t1} s_{t1}
x_{t2}
x_{1} s_{1}
s_{t2}
y
1C
y
2C
y
nC
^{y}
C
…
Backpropagation through Time (BPTT)
Unfold
◦
Input: init, x
_{1}, x
_{2}, …, x
_{t}◦
Output: o
_{t}◦
Target: y
_{t}27
init
s_{t} y_{t}
x_{t} o_{t}
x_{t1} s_{t1}
x_{t2}
x_{1} s_{1}
s_{t2}
1
2
n
…
1
2
n
…
^{y}
C
Backpropagation through Time (BPTT)
Unfold
◦
Input: init, x
_{1}, x
_{2}, …, x
_{t}◦
Output: o
_{t}◦
Target: y
_{t}init
s_{t} y_{t}
x_{t} o_{t}
x_{t1} s_{t1}
x_{t2}
x_{1} s_{1}
s_{t2}
^{y}
C
Backpropagation through Time (BPTT)
Unfold
◦
Input: init, x
_{1}, x
_{2}, …, x
_{t}◦
Output: o
_{t}◦
Target: y
_{t}29
init
s_{t} y_{t}
x_{t} o_{t}
x_{t1} s_{t1}
x_{t2}
x_{1} s_{1}
s_{t2}
j
i
i j
i j
i j
^{y}
C
Weights are tied together
the same memory
pointer pointer
Backpropagation through Time (BPTT)
Unfold
◦
Input: init, x
_{1}, x
_{2}, …, x
_{t}◦
Output: o
_{t}◦
Target: y
_{t}init
s_{t} y_{t}
x_{t} o_{t}
x_{t1} s_{t1}
x_{t2}
x_{1} s_{1}
s_{t2}
j
i
k i
k j i j
i
k j
^{y}
C
Weights are tied together
BPTT
31
For 𝐶
^{(1)}Backward Pass:
For 𝐶
^{(2)}For 𝐶
^{(3)}For 𝐶
^{(4)}Forward Pass: Compute s
_{1}, s
_{2}, s
_{3}, s
_{4}……
y
_{1}y
_{2}y
_{3}x
_{1}x
_{2}x
_{3}o
_{1}o
_{2}o
_{3}init
y
_{4}x
_{4}o
_{4}𝐶
^{(1)}𝐶
^{(2)}𝐶
^{(3)}𝐶
^{(4)}s
_{1}s
_{2}s
_{3}s
_{4}Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
RNN Training Issue
The gradient is a product of Jacobian matrices, each associated with a step in the forward computation
Multiply the same matrix at each time step during backprop
33
The gradient becomes very small or very large quickly
vanishing or exploding gradient
Bengio et al., “Learning longterm dependencies with gradient descent is difficult,” IEEE Trans. of Neural Networks, 1994. [link]
Pascanu et al., “On the difficulty of training recurrent neural networks,” in ICML, 2013. [link]
w
_{2}w
_{1}C ost
Rough Error Surface
The error surface is either very flat or very steep
Vanishing/Exploding Gradient Example
35
0 5 10 15 20 25 30 35
0 5 10 15 20 25 30 35
0 5 10 15 20 25 30 35
0 5 10 15 20 25 30 35
0 5 10 15 20 25 30 35
0 5 10 15 20 25 30 35
1 step 2 steps 5 steps
10 steps 20 steps 50 steps
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
How to Frame the Learning Problem?
The learning algorithm f is to map the input domain X into the output domain Y
Input domain: word, word sequence, audio signal, click logs Output domain: single label, sequence tags, tree structure, probability distribution
37
Y X
f :
Network design should leverage input and output domain properties
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
Input Domain – Sequence Modeling
Idea: aggregate the meaning from all words into a vector Method:
◦
Basic combination: average, sum
◦
Neural combination:
Recursive neural network (RvNN)
Recurrent neural network (RNN)
Convolutional neural network (CNN)
39
How to compute
規格
(specification)
誠意
(sincerity)
這
(this)
有
(have)
Ndim
誠意
這 規格 有
x_{4} h_{4}
Sentiment Analysis
Encode the sequential input into a vector using RNN
x1
x2
… …
y1
y2
… …
…
…
…
Input Output
yM
xN
RNN considers temporal information to learn sentence vectors as the input of classification tasks
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
41
Output Domain – Sequence Prediction
POS Tagging
Speech Recognition
Machine Translation
“推薦我台大後門的餐廳” 推薦/VV 我/PN 台大/NR 後門/NN
的/DEG 餐廳/NN
“大家好”
“How are you doing today?” “你好嗎?”
The output can be viewed as a sequence of classification
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
43
POS Tagging
Tag a word at each timestamp
◦Input: word sequence
◦Output: corresponding POS tag sequence
四樓 好 專業
N VA AD
Natural Language Understanding (NLU)
Tag a word at each timestamp
◦Input: word sequence
◦Output: IOBformat slot tag and intent tag
45
<START> just sent email to bob about fishing this weekend <END>
O O O O
Bcontact_name
O
Bsubject Isubject Isubject
send_email(contact_name=“bob”, subject=“fishing this weekend”) O
send_email
Temporal orders for input and output are the same
Outline
Language Modeling
◦Ngram Language Model
◦FeedForward Neural Language Model
◦Recurrent Neural Network Language Model (RNNLM) Recurrent Neural Network
◦Definition
◦Training via Backpropagation through Time (BPTT)
◦Training Issue Applications
◦Sequential Input
◦Sequential Output
◦ Aligned Sequential Pairs (Tagging)
◦ Unaligned Sequential Pairs (Seq2Seq/EncoderDecoder)
超棒 的 醬汁
Machine Translation
47
Cascade two RNNs, one for encoding and one for decoding
◦
Input: word sequences in the source language
◦
Output: word sequences in the target language
encoder
decoder
ChitChat Dialogue Modeling
Cascade two RNNs, one for encoding and one for decoding
◦
Input: word sequences in the question
◦
Output: word sequences in the response
Temporal ordering for input and output may be different
Concluding Remarks
Language Modeling
◦RNNLM
Recurrent Neural Networks
◦
Definition
◦
Backpropagation through Time (BPTT)
◦
Vanishing/Exploding Gradient
Applications
◦
Sequential Input: SequenceLevel Embedding
◦
Sequential Output: Tagging / Seq2Seq (EncoderDecoder)
49