*RNN seq2seq models
I
enjoyed
the
movie
transformers
Naan
transfarmar
padaththai
rasiththen
Naan
transfarmar
padaththai
Naan
transfarmar
padaththai
rasiththen
Naan
transfarmar
padaththai
With Attention
I
enjoyed
the
movie
transformers
Naan
transfarmar
padaththai
rasiththen
Feed Forward Networks
Self-Attention
Self-Attention
Encoder-Decoder Attention
Feed Forward Networks
Word Embedding
I
enjoyed
the
movie
transformers
Self-Attention
| 1 | 0 | 0 |
|---|
| 0 | 1 | 0 |
|---|
| 1 | 1 | 0 |
|---|
| 1 | 0 | 1 |
|---|
| 1 | 1 | 1 |
|---|
| The | animal | didn't | cross | the | street | bacause | it | |
|---|---|---|---|---|---|---|---|---|
| The | ||||||||
| animal | ||||||||
| didn't | ||||||||
| cross | ||||||||
| the | ||||||||
| street | ||||||||
| because | ||||||||
| it |
| The | animal | didn't | cross | the | street | bacause | it | |
|---|---|---|---|---|---|---|---|---|
| The | 0.6 | 0.1 | 0.05 | 0.05 | 0.02 | 0.02 | 0.02 | 0.1 |
| animal | 0.02 | 0.5 | 0.06 | 0.15 | 0.02 | 0.05 | 0.01 | 0.12 |
| didn't | 0.01 | 0.35 | 0.45 | 0.1 | 0.01 | 0.02 | 0.01 | 0.03 |
| cross | . | |||||||
| the | . | |||||||
| street | . | |||||||
| because | . | |||||||
| it | 0.01 | 0.6 | 0.02 | 0.1 | 0.01 | 0.2 | 0.01 | 0.01 |
| The | animal | didn't | cross | the | street | bacause | it | |
|---|---|---|---|---|---|---|---|---|
| The | 0.6 | 0.1 | 0.05 | 0.05 | 0.02 | 0.02 | 0.02 | 0.1 |
| animal | 0.02 | 0.5 | 0.06 | 0.15 | 0.02 | 0.05 | 0.01 | 0.12 |
| didn't | 0.01 | 0.35 | 0.45 | 0.1 | 0.01 | 0.02 | 0.01 | 0.03 |
| cross | . | |||||||
| the | . | |||||||
| street | . | |||||||
| because | . | |||||||
| it | 0.01 | 0.6 | 0.02 | 0.1 | 0.01 | 0.2 | 0.01 | 0.01 |
I
enjoyed
the
movie
transformers
Self-Attention
| 1 | 0 | 0 |
|---|
| 0 | 1 | 0 |
|---|
| 1 | 1 | 0 |
|---|
| 1 | 0 | 1 |
|---|
| 1 | 1 | 1 |
|---|
I
transformers
Self-Attention
| 1 | 0 | 0 |
|---|
| 1 | 1 | 1 |
|---|
| 0.3 | 0.2 |
|---|
| 0.1 | 0.5 |
|---|
| -0.1 | 0.25 |
|---|
| 0.11 | 0.89 |
|---|
| 0 | 0.4 |
|---|
| 0.2 | 0.7 |
|---|
Fixed
variable
I
transformers
Self-Attention
| 1 | 0 | 0 |
|---|
| 1 | 1 | 1 |
|---|
Let's focus on first calculating the first output from self-attention layer
| 0.3 | 0.2 |
|---|
| 0.1 | 0.5 |
|---|
| -0.1 | 0.25 |
|---|
| 0.11 | 0.89 |
|---|
| 0 | 0.4 |
|---|
| 0.2 | 0.7 |
|---|
Fixed
variable
\(^*\)Note: The original paper follows \(softmax(\frac{QK^T}{\sqrt{d_k}})V\) as it represents embedding \(h_j\) as a row vector
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Concatenate
Linear
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Concatenate (:\(T \times 512\))
Linear
Concatenate (:\(T \times 512\))
Linear
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Concatenate (:\(T \times 512\))
Linear
Scaled Dot Product
Attention
Scaled Dot Product
Attention
Scaled Dot Product
Attention
The input is projected into \(h=8\) different representation subspaces.
I
enjoyed
the
movie
transformers
Feed Forward Network
Multi-Head Attention
I
enjoyed
the
movie
transformers
Multi-Head Attention
FFN
1
FFN
2
FFN
5
FFN
4
FFN
3
I
enjoyed
the
movie
transformers
Multi-Head Attention
FFN
1
FFN
2
FFN
5
FFN
4
FFN
3
I
enjoyed
the
movie
transformers
Multi-Head Attention
FFN
1
FFN
2
FFN
5
FFN
4
FFN
3
Identical network for each position \(z_i\)
Feed Forward Network
Multi-Head Attention
I
enjoyed
the
movie
transformers
I
enjoyed
the
movie
transformers
Layer-1
Layer-2
Layer-6
I
enjoyed
the
movie
transformers
Naan
transfarmar
padaththai
rasithen
Naan
transfarmar
padaththai
rasithen
Layer-1
Layer-2
Layer-6
Feed Forward Network
Masked Multi-Head (Self)Attention
Multi-Head (Cross) Attention
Note: Encoder block also uses masking in attention sublayer in practice to mask the padded tokens in sequences having length < T
Feed Forward Network
Masked Multi-Head (Self)Attention
Multi-Head (Cross) Attention
Naan
transfarmar
padaththai
rasiththen
<Go>
Feed Forward Network
Naan
transfarmar
padaththai
rasiththen
<Go>
Feed Forward Network
Linear \(W_D\)
Softmax
I
Enjoyed
I
Multi-Head Attention
Feed forward NN
Add&Norm
Add&Norm
Multi-Head cross Attention
Feed forward NN
Add&Norm
Add&Norm
Multi-Head Maksed Attention
Add&Norm