xt ::: the input token (as a vector) fed upward into a teal encoder box at step t.
htenc ::: the encoder's hidden state — a teal box — a memory summarising input tokens 1 through t.
c ::: the context vector, the plum box in the middle: the single fixed-size summary the encoder hands to the decoder. Usually c=hTxenc (in the figure, h3enc).
htdec ::: the decoder's hidden state — an orange box — memory of what it has generated so far.
yt ::: the output token emitted upward from an orange box.
Tx ::: number of input tokens, i.e. the number of teal boxes (3 in the figure).
Ty ::: number of output tokens, i.e. the number of orange boxes. Crucially Tx and Ty can differ.
Recall Solution
False. The entire point of this architecture is decoupling: 5 input words can map to 7 output words — i.e. 5 teal boxes feeding 7 orange boxes. The context vector c (plum box) is the fixed-size bridge that lets Tx=Ty.
Recall Solution
(b)c=hTxenc — the final teal box (the plum arrow in the figure leaves h3enc), because by the last step it has recursively "seen" every input token.
Softmax turns scores into probabilities via P(v)=∑uezuezv. Why exponentiate?ez is always positive and monotonically increasing, so it maps any real score to a positive weight while preserving the ranking; dividing by the sum then normalises the weights to add to 1.
Numerators: e2.0=7.389, e1.0=2.718, e0.0=1.000. Sum =11.107.
P("am")=7.389/11.107=0.6652
P("is")=2.718/11.107=0.2447
P("the")=1.000/11.107=0.0900
They sum to 1 (a valid distribution). Greedy picks the argmax, i.e. "am" (highest probability 0.665).
Recall Solution
Why a product? The decoder is autoregressive: each output token depends on all previous ones, so the joint probability of the whole sequence factorises by the chain rule as
P(y1,y2,y3∣x)=P(y1∣x)P(y2∣y1,x)P(y3∣y1,y2,x).
Each listed probability is exactly one conditional factor. Multiplying:
P(y∗∣x)=0.5×0.4×0.25=0.05.
Taking the natural log turns product into a sum (why we log: avoids tiny-number underflow, see L5.2):
logP=ln0.5+ln0.4+ln0.25=(−0.6931)+(−0.9163)+(−1.3863)=−2.9957.
Recall Solution
L=−logP(y∗∣x)=−(−2.9957)=2.9957.Why this is cross-entropy. At each step the target distribution is a one-hot vector (probability 1 on the true token yt∗, 0 elsewhere). Cross-entropy between target q and model p is −∑vq(v)logp(v); with one-hot q this collapses to just −logp(yt∗) — the negative log-probability of the correct token. Summing over t gives exactly L above. So "negative log-likelihood" and "cross-entropy against one-hot targets" are the same number.
Lower loss ⇔ higher probability assigned to the correct sequence. The training objective L(θ)=−N1∑i∑tlogPθ(⋅) is exactly this, averaged over tokens and examples.
(b) Greedy compares only step-1 scores: 0.5>0.4, so it commits to "The" → locked onto Path A.
(c) Globally, Path B (0.20) beats Path A (0.15).
(d) Locally optimal ≠ globally optimal. A high-probability first token can lead to low-probability continuations. This motivates beam search, which keeps several hypotheses alive instead of committing early.
Recall Solution
Step 1: rank candidates → keep top 2: "Fox" (0.3) and "The" (0.2). "A" (0.15) is pruned.
Step 2: expand each surviving beam, multiplying probabilities:
"Fox jumps" =0.3×0.4=0.12
"Fox runs" =0.3×0.1=0.03
"The fox" =0.2×0.3=0.06
"The dog" =0.2×0.25=0.05
Keep top 2 overall: "Fox jumps" (0.12) and "The fox" (0.06). Note greedy would also have started with "Fox" but beam keeps "The fox" as a live backup in case its later continuations dominate.
Recall Solution
(a) — step by step.
There are V choices for each of Tx positions, so the number of distinct sequences is VTx=(104)50=10200.
To give each sequence a unique binary address ("index"), you need log2(number of sequences) bits. Why log2?b bits label exactly 2b distinct things, so to label N things you invert this: b=log2N.
Compute: log2(VTx)=Txlog2V=50×log2(104). Now log2(104)=4log210=4×3.3219=13.2877. So b=50×13.2877=664.39 bits.
So merely to index which of the 10200 sequences you mean already costs about 664 bits — and that assumes a perfect, lossless code. To reconstruct the meaning robustly (not just index it) a real encoder needs comfortably more headroom than this bare minimum.
(b) A float32 number is 32 bits, and there are 512 of them: 512×32=16,384 bits of raw storage.
(c) Here 16,384 bits is far more than the 664-bit index, so for a single length-50 sequence the vector has room. The bottleneck bites when sequences get long and you demand robust, lossy-tolerant meaning rather than a perfect index: the required information grows linearly in Tx (664 bits at Tx=50, doubling by Tx=100, and so on), while the context vector stays a fixed16,384 bits forever. Past some length the fixed budget is overwhelmed — the classic information bottleneck. This is what attention fixes by letting the decoder read all encoder states instead of one squeezed summary.
(a) First evaluate the embedding: emb(y0)=0.1 is the vector (here scalar) that represents the START token y0. Pre-activation:
Whh0dec+Whyemb(y0)+bh=1.0(0.5)+2.0(0.1)+0=0.7.
Apply tanh (squashes any real number into (−1,1) — why: keeps hidden states bounded and centred so they neither explode nor vanish across steps):
h1dec=tanh(0.7)=0.6044.(b) Feed this into the output layer to get the logit:
z=Woh1dec+bo=3.0×0.6044+(−0.5)=1.3131.
In a real network z would be a whole vector of such scores (one per vocabulary word) fed into softmax; here we computed the single scalar version to see the mechanics.
Recall Solution
(a) Teacher forcing feeds the ground-truth previous token → feed "love" (the model's mistake is ignored for the input, though still penalised in the loss).
(b) Free running feeds the model's own output → feed "adore", pushing the decoder into a state it may never have trained on.
(c) Test time is always free-running. A model trained only with teacher forcing never practised recovering from its own errors → exposure bias. Fixes: scheduled sampling (mix in own predictions during training) and professor forcing (match teacher-forced and free-running hidden-state distributions).
Recall Solution
No. L3.3 showed the required index information grows linearly with length while the context vector stays a fixed 16,384 bits; performance degrades sharply past ~20 words. The fix is the attention mechanism (3.5.09-Attention-mechanism): the decoder computes a fresh weighted blend of all encoder states h1enc,…,hTxenc at each step, so early tokens are no longer squeezed through one bottleneck. This idea generalises into the Transformer.
(a) Yes. With Tx=1, c=h1enc=fenc(x1,h0enc) — the recursion runs exactly once (one teal box). Perfectly valid; no degeneracy.
(b) Ruled out. With Tx=0 the encoder runs zero steps, so there is no hTxenc to become c; the only state available is the initial h0enc (all zeros), which carries no information. In practice this case is never fed — inputs must contain at least one real token (often a START marker is prepended, giving Tx≥1). So an empty-input translation is undefined and excluded by construction.
(c) An "empty output" is not truly empty: the decoder emits ⟨END⟩immediately at step 1. So Ty=1 in practice (the END marker). A genuinely zero-length sequence is undefined for an autoregressive decoder — there must be at least the stop signal.
(d) ⟨END⟩ is the learned stop signal — sampling it halts generation. If the decoder never assigns high probability to END, generation runs until a hard max-length cap forces a stop, often producing rambling or repeated output. This is why max-length limits are mandatory in practice.
Recall Solution
(a) The joint probability is the product of the 20 factors: 0.520=9.5367×10−7. (Still representable here — but watch what happens as length grows.)
(b) Log turns the product into a sum: ln(0.520)=20ln0.5=20×(−0.6931)=−13.8629.
(c) At length 20 the raw value 9.5×10−7 is fine. But the raw product decays exponentially in length: at length ≈130 we'd hit 0.5130≈7.3×10−40, which is below float32's smallest positive normal 1.2×10−38 → it underflows to exactly 0, and then ln0=−∞ destroys the gradient. The log, by contrast, decays only linearly: at length 130 it is a comfortable ln(0.5130)=130×(−0.6931)≈−90.1, nowhere near any limit. This justifies why the loss sums logs instead of multiplying probabilities — numerical stability under long sequences.
Recall Solution
Let q be the projection that ignores all but the last state: q({h1,…,hTx})=hTx. Then c=q(⋅)=hTxenc — the special case. The general q can be any pooling: mean-pool Tx1∑thtenc, max-pool, or — the powerful version — a content-dependent weighted sum∑tαthtenc where weights αt change per decoder step. That last form isattention: it lets cadapt to what the decoder currently needs, dissolving the single-vector bottleneck.
Recall Quick self-test
Why sum logs instead of multiplying probabilities in the loss? ::: Products of many sub-1 probabilities underflow to zero in floating point; logs turn the product into a sum that decays only linearly and stays representable.
What single change removes the fixed-context bottleneck? ::: Attention — a per-step weighted sum ∑tαthtenc over all encoder states instead of one final vector.
What causes exposure bias? ::: Training only with teacher forcing, so the decoder never practises recovering from its own mistakes it will face at test time.
Why subtract the max logit before softmax? ::: To stop large exponentials overflowing to infinity; it is algebraically identical since the shared factor cancels.