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
Text in source language
Translated text in target language
Input text
Predict the class/sentiment
Input text
Summarize
Question
Answer
Input text
Input text
Predict the class/sentiment
Input text
Summarize
Question
Answer
Input text
Input text
Predict the class/sentiment
Input text
Summarize
Question
Answer
Input text
Input text
Predict the class/sentiment
Input text
Summarize
Question
Answer
Input text
" Wow, India has now reached the moon"
An excerpt from business today "What sets this mission apart is the pivotal role of artificial intelligence (AI) in guiding the spacecraft during its critical descent to the moon's surface."
He likes to stay
He likes to stray
He likes to sway
Language Modeling
(Pre-training)
Raw text
Downstream tasks
(Fine-tuning)
(Samples and labels)
a. An apple ate I
b. I ate an apple
c. I ate apple
d. an apple
e. ....
Definition
a. I enjoyed reading a book
b. I enjoyed reading a thermometer
\(x_1,x_2,\cdots,x_{i-1}\)
\(P(x_i)\)
Multi-Head Attention
Feed forward NN
Add&Norm
Add&Norm
\(x_1,<mask>,\cdots,x_{T}\)
\(P(<mask>)\)
Multi-Head masked Attention
Feed forward NN
Add&Norm
Add&Norm
\(x_1,x_2,\cdots,x_{i-1}\)
\(P(x_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
\(x_1,<mask>,\cdots,x_{T}\)
\(<go>\)
\(P(<mask>)\)
Feed Forward Network
Masked Multi-Head (Self)Attention
Multi-Head (Cross) Attention
Feed Forward Network
Masked Multi-Head (Self)Attention
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 4
Transformer Block 5
Where \(h_n[i]\) is the \(i-\)the output vector in \(h_n\) block.
BookCorpus
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Transformer Block 1
<go>
at
the
bell
labs
hamming
bound
...................
new
a
devising
..............
<stop>
Transformer Block 1
<go>
at
the
bell
labs
hamming
bound
...................
new
a
devising
..............
<stop>
Feed Forward Neural Network
Multi-head masked attention
<go>
at
the
bell
labs
hamming
bound
...................
new
a
devising
..............
<stop>
Concatenate
Linear
Layer norm
Residual connection
<go>
at
the
bell
labs
hamming
bound
...................
new
a
devising
..............
<stop>
Layer norm
Residual connection
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
| Layer | Parameters (in Millions) |
|---|---|
| Embedding Layer | |
| Attention layers | |
| FFN Layers | |
| Total |
Embedding Matrix
*Without rounding the number of parameters in each layer
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
\(\leftarrow\) Question \(\rightarrow\)
\(\leftarrow\) Choice-1 \(\rightarrow\)
Linear-1
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
\(\leftarrow\) Question \(\rightarrow\)
\(\leftarrow\) Choice-2 \(\rightarrow\)
Linear-2
Linear-2
Linear-1
Transformer Block 1
Transformer Block 2
Transformer Block 3
Transformer Block 12
Embedding Matrix
Input:
Output:
Stoping Criteria:
I like cold water
I like cold coffee
coffee like cold coffee
coffee coffee coffee coffee
I like I like
I like cold coffee
coffee like cold coffee
I like I like
I like coffee
coffee coffee coffee coffee
I like cold water
I like cold coffee
Outputs*
* Assuming the sequence has the highest probability among all \(|\mathcal{V}|^5\) sequences
t=1
t=2
| 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
cold
<stop>
coffee
I
like
water
time steps
I
like
cold
coffee
<stop>
0.1
0.15
0.25
0.4
0.05
0.05
0.1
0.15
0.25
0.05
0.35
0.1
0.45
0.05
0.1
0.05
0.15
0.2
0.15
0.3
0.35
0.01
0.09
0.1
0.1
0.5
0.2
0.1
0.05
0.05
| 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
cold
<stop>
coffee
I
like
water
time steps
I
like
cold
coffee
<stop>
0.1
0.15
0.25
0.4
0.05
0.05
0.1
0.15
0.25
0.05
0.35
0.1
0.45
0.05
0.1
0.05
0.15
0.2
0.15
0.3
0.35
0.01
0.09
0.1
0.1
0.5
0.2
0.1
0.05
0.05
| 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
cold
<stop>
coffee
I
like
water
time steps
coffee
like
cold
water
<stop>
0.1
0.15
0.25
0.4
0.05
0.05
0.65
0.05
0.05
0.05
0.1
0.1
0.04
0.01
0.1
0.03
0.02
0.8
0.1
0.5
0.2
0.1
0.05
0.05
0.15
0.1
0.05
0.05
0.55
0.1
t=1
t=2
t=1
t=2
t=3
t=1
t=2
t=3
| 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
cold
<stop>
coffee
I
like
water
time steps
0.1
0.15
0.25
0.4
0.05
0.05
0.65
0.05
0.05
0.05
0.09
0.11
0.04
0.01
0.1
0.03
0.02
0.8
0.1
0.5
0.2
0.1
0.05
0.05
0.1
0.15
0.05
0.05
0.55
0.1
I
<stop>
I
<stop>
The proability of top-k tokens will be normalized relatively, \(P(I)=0.61,P(coffee)=0.39\) before sampling a token.
| 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
cold
<stop>
coffee
I
like
water
time steps
0.1
0.15
0.25
0.4
0.05
0.05
0.65
0.05
0.05
0.05
0.09
0.11
0.04
0.01
0.1
0.03
0.02
0.8
0.1
0.5
0.2
0.1
0.05
0.05
0.1
0.15
0.05
0.05
0.55
0.1
coffee
like
cold
coffee
<stop>
coffee
like
cold
coffee
<stop>
I
<stop>
she
said
,
"
I
never
thought
knew
had
saw
said
could
meant
I
ate
the
pizza
while
it
was
still
hot
cooling
warm
on
heating
going
she
said
,
"
I
never
thought
knew
had
saw
said
could
meant
I
ate
the
pizza
while
it
was
still
hot
cooling
warm
on
heating
going