Log inStart free
LESSON 7.C1 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

From RNN to attention

Watch six trained networks translate one sentence, from a plain RNN to attention.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 7.C1 · TRANSLATION BAYGRU · FIXED VECTOR · 5 WORDS
01
Stage 1 of 5 · Read English
The encoder runs one GRU cell at each word. Each hidden state h holds 8 numbers.
Explain it simply

At the top you see the 5 English words. Under each word, the encoder writes its state, a row of 8 numbers. A bar up is a positive number, and a bar down is negative. The same GRU cell with the same weights does every step, so the last state has seen every word.

5 English words: "the black cat eats bread". Each has a GRU encoder state of 8 numbers under it, linked left to right.

English words, encoder states h, context cweights, gates (0 to 1)decoder states s, French words, attention weightswrong word
Englishencoder GRU · same Wₓ, Wₕ at every wordtheblackcateatsbreadEnglishencoder GRU · same Wₓ, Wₕ at every wordtheblackcateatsbread
Toy: 6 trained networks, 8 numbers per state
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
ht=cellWx, Wh(ht−1, xt)\sy{h}{data}{h_t} = \mathrm{cell}_{\sy{W}{param}{W_x,\,W_h}}(\sy{h}{data}{h_{t-1}},\, \sy{x}{data}{x_t})
ht=(1−zt)⊙nt+zt⊙ht−1h5=(−0.75, −0.11, 1.00, … )\begin{gathered} h_t = (1 - z_t) \odot n_t + z_t \odot h_{t-1} \\ h_{5} = (-0.75,\,-0.11,\,1.00,\,\dots) \end{gathered}

Each state mixes the last state with the next word.

Common mix-ups

MYTHA better cell, an LSTM or a GRU, fixes long sentences.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With the fixed vector, the GRU gets 2% of 9-word sentences right. Does attention do better?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.