Log inStart free
LESSON 7.07 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Attention in seq2seq

Watch a decoder pick which English words to read for each French word.


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

Go Pro · $8.25/mo
EXPLAINER · 7.07 · ATTENTION BAY5 ENGLISH WORDS · 5 STATES h
01
Stage 1 of 6 · Encoder states
The encoder RNN reads the 5 English words. It keeps every hidden state, h₁ to h₅.
Explain it simply

Both networks here are plain tanh RNNs, not the GRUs of the seq2seq lesson. The encoder reads the English words from left to right. After each word it writes a new state, the row of 8 bars under it. All the states stay, so the decoder can look back at any of them.

5 English words, each with a row of 8 cells: the encoder states h1 to h5. The words: the, black, cat, eats, bread.

English states h, context cdecoder state s, scores, attention weights, wordsone number per cellwrong word
EnglishFrenchtheh₁blackh₂cath₃eatsh₄breadh₅le?h₃ has readthe black catEnglishFrenchtheh₁blackh₂cath₃eatsh₄breadh₅le?h₃ has readthe black cat
Toy: the trained 7.C1 network, 2 tanh RNNs, 8 numbers per state
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
hj=tanh⁡(Wx xj+Wh hj−1+b)\sy{h}{data}{h_j} = \tanh(\sy{W}{param}{W_x}\, \sy{x}{data}{x_j} + \sy{W}{param}{W_h}\, \sy{h}{data}{h_{j-1}} + b)
h3=[−0.95, −0.99, −0.48, 0.74, 0.96, −0.63, −0.97, −1.00]h_{3} = [-0.95,\,-0.99,\,-0.48,\,0.74,\,0.96,\,-0.63,\,-0.97,\,-1.00]

Each state mixes the new word with the state before it.

Common mix-ups

MYTHEach French word reads the English word at its own position.

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

Predict, then reveal
3 CHECKS · PRO
Q01With learned attention, which English word gets the largest weight for French word 3, noir?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 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.