This page assumes you have seen nothing. We name every squiggle on the Sequence-to-sequence models page, draw the picture it stands for, and say why the topic cannot live without it. Read top to bottom — each item is a rung, and every rung stands on the one below it.
A sequence is just an ordered list of things where order matters. "I am happy" is a sequence of three words. Reverse it — "happy am I" — and it means something different (or nothing). That "order matters" is the whole reason we need special machinery: a normal calculator adds numbers where order doesn't change the answer, but language does.
Figure s01 — Three word-boxes "I / am / happy" in a row labelled x1,x2,x3, with arrows showing left-to-right order; below, the reversed list is flagged in pink as a different meaning. Read it to see that a sequence is an ordered list where shuffling changes meaning.
The parent writes x1,x2,…,xTx. Let's earn every piece.
The letter x means "an input token."
The little number below — the subscript — is a position label. x1 = the first token, x2 = the second. It is not multiplication and not a power; it is an address, like seat numbers in a row.
The parent also uses t as a subscript (xt). Here t stands for time step: we imagine reading the sentence left to right, one token per "tick" of a clock. t=1 is the first tick.
Question: In "Comment ça va?", what is Tx?
Tx=3 (three tokens).
Question: What does the un-subscripted x mean in P(y∣x)?
the whole input sequence [x1,…,xTx], not a single token.
A single number can't hold the meaning of a word — "happy" needs many shades (positive? emotional? adjective?). So we use a vector: an ordered list of numbers stacked together, like [0.1,0.6,−0.3,0.4].
Figure s02 — A single vector drawn as four stacked yellow slots holding 0.1,0.6,−0.3,0.4, each slot annotated "dimension 1..4", titled "a vector in R4". Read it to see that a vector is just several numbers stacked, and the count of slots is its dimension.
Bold letters (like h, and later c) signal "this is a vector, not a single number."
Each slot in the vector is a dimension. A vector with 4 slots "lives in 4-dimensional space."
Question: What does a vector in R512 tell you?
it holds 512 real-number slots — it is 512-dimensional.
We just said each token becomes an index (a single whole number like 0,1,2). But §2 said meaning needs a vector, not one number. How do we bridge the two? With an embedding.
Picture a lookup table with one row per vocabulary word. Row 0 holds a vector for "I", row 1 for "am", and so on. Feeding token index 2 ("happy") means "go fetch row 2" — out pops a vector.
Figure s05 — An embedding table drawn as rows indexed 0,1,2; a blue arrow shows index 2 selecting row 2 and pulling out the vector that becomes x2 fed to the LSTM. Read it to see that the LSTM never eats a raw index — it eats the looked-up vector.
Question: What is E[1]?
the embedding vector stored in row 1 of the table — the vector for token index 1.
Now the star of the show. As the encoder reads token by token, it keeps a running summary of everything seen so far. That summary is a vector called the hidden state, written ht.
Picture a person reading a sentence aloud while jotting notes on a single sticky note. After each word they update the sticky note — old notes plus the new word give new notes. The sticky note is ht.
Figure s03 — Three memory-boxes h1,h2,h3 chained by arrows labelled "carry memory", each fed from below by its token x1,x2,x3; the last box is tagged "= context c". Read it to watch the sticky-note memory update at every step and become the context vector at the end.
h0 = the blank sticky note before reading (all zeros).
ht=LSTM(xt,ht−1) reads: "the new note is made from the new token xtand the previous note ht−1."
Every hidden state is itself a vector of the same size: ht∈Rdh. So h1,h2,…all share the same dh slots — the sticky note never changes size, only its contents.
The superscript in ht(enc) vs ht(dec) just says which machine's note it is — encoder or decoder. It's a name tag, not math.
The names LSTM and GRU are two specific recipes for this update-the-sticky-note step, designed so early words aren't forgotten too fast. You can treat them as black boxes here; the details live in LSTM networks and GRU networks.
Question: What is dh for the vector h2=[0.4,0.2,0.1,−0.2]?
dh=4 — the same size as every other hidden state.
After the encoder reads the last token, its final sticky note hTx(enc) has "seen" the whole sentence. We give it a new name:
c=hTx(enc)
That's it — c (for context, or "the thought") is simply the last hidden state, promoted to the role of "the compressed meaning of the entire input." It's the single vector that gets handed from the reader machine to the writer machine. Because it is a hidden state, c∈Rdh too — same dh slots as every ht.
The encoder's job is done: it handed over c. Now the decoder — a second LSTM — writes the output one token at a time, keeping its own running memory ht(dec).
Two things must happen to start the writer:
Initialize its memory from the meaning vector. We set the decoder's very first hidden state to the context: h0(dec)=c. This is literally "load the thought into the writer's head before it speaks."
Give it a starting word. It has no real previous word yet, so we feed a special "start" token as y0 — the <SOS> token defined just below.
Then, at each output step t, the decoder updates its memory from its previous memory and the previous output token:
ht(dec)=LSTM(E[yt−1],ht−1(dec))
Read it exactly like the encoder recurrence, but the "input token" is now the previous output wordyt−1 (looked up through the embedding table E), and the memory it builds on is the decoder's own ht−1(dec).
Question: What is the decoder's starting memory h0(dec)?
the context vector c handed over by the encoder.
Question: What is fed as y0 at the first output step?
The decoder must choose the next word. It never says "the word is X" flatly — it gives a probability to every possible word.
To turn raw scores into probabilities we need a gadget that (a) makes everything positive and (b) makes the total add up to 1. That gadget is the softmax.
Figure s04 — A bar chart: pink bars are raw scores for four candidate tokens, blue bars are the softmax probabilities (summing to 1), with "Estoy" dominating. Read it to see softmax squash arbitrary scores into a clean probability distribution.
V = the vocabulary, the full list of possible tokens. ∣V∣ = how many there are.
Wo and bo (the parent's softmax(Woht(dec)+bo)) are just learned numbers that reshape the hidden vector into one score per vocabulary word. Wo is a matrix ("weights"), bo a vector ("bias") — think of them as a tunable lens.
Question: If softmax outputs [0.01,0.92,0.05,0.02], which token does greedy decoding pick?
A whole sentence's probability is each word's probability multiplied together:
P(y1,…,yTy∣x)=∏t=1TyP(yt∣y<t,c)
Multiplying many small probabilities gives a tiny number that computers round to zero. The fix: take the logarithm.
Applying it to the whole-sentence product. Take log of both sides of the product above. By the rule "log of a product = sum of the logs," applied Ty times:
log∏t=1TyP(yt∣y<t,c)=∑t=1TylogP(yt∣y<t,c)
Question: Why minimize −logP instead of maximizing P?
They're equivalent — maximizing P = minimizing −logP — but the log form turns a fragile product into a safe sum and is easy to differentiate.
Question: What single number does L report?
how wrong the model's predicted probabilities are on one training example; smaller = better.
We met <SOS> in §4b as the "go" signal. Its partner answers a different question: how does the decoder know when to stop writing? A sentence has no fixed length, so we need an explicit "I'm done" signal.
Question: What role does <SOS> play at decoding step 1?
It is the "previous token" y0 that primes the decoder before any real word exists.
Question: When does autoregressive decoding stop?
when the model emits <EOS> (or hits the max-length safety cap).
The arrows say "you must understand the tail before the head." Notice every path funnels into the seq2seq node, and it in turn points onward to attention — the very next topic. Backprop through both machines is backpropagation through time; the full modern successor is Transformers.