3.5.7 · D5Sequence Models
Question bank — Sequence-to-sequence models
Before the questions, three tiny pictures set up the exact mental images the traps attack.



True or false — justify
The input and output sequences of a seq2seq model must have the same length.
False — the encoder/decoder split makes and independent; the decoder keeps emitting tokens until it produces
<EOS>, regardless of input length.The encoder outputs one hidden state per input token, but only the last one becomes in the basic (pre-attention) model.
True — vanilla seq2seq discards and keeps only ; reusing the discarded states is exactly what attention adds.
Teacher forcing is used during both training and inference.
False — teacher forcing feeds the ground-truth previous token, which only exists during training; at inference the decoder must feed its own prediction back in (see figure s02).
Increasing the beam width is guaranteed to give a sequence with higher total probability.
False — a larger explores more paths so it usually finds an equal-or-better scoring sequence, but there is no guarantee of the global optimum; only exhaustive search would, and even that maximizes model probability, not translation quality.
The softmax in the decoder produces a probability distribution over the output vocabulary, not the input vocabulary.
True — the decoder predicts target-language tokens, so has outputs and softmax normalizes across those.
The context vector changes at every decoding step in the basic seq2seq model.
False — in the basic model is computed once and held fixed for the whole decode; only attention recomputes a fresh context vector per decoding step.
The context vector is used only to predict the first output token, then discarded.
False — seeds the decoder's memory as (figure s01), and in many variants is also concatenated to every decoder input, so its influence persists across the whole output.
Cross-entropy loss for the sequence is the sum over positions of the per-token negative log-probabilities.
True — the sequence probability is a product , and taking turns a product into a sum, giving ; the derivation of this equivalence lives in cross-entropy loss.
Greedy decoding and beam search with produce the same output.
True — with a single beam, beam search keeps only the top-1 partial sequence at every step, which is exactly the argmax-at-each-step rule of greedy decoding.
A bidirectional encoder can be used to make the decoder bidirectional too.
False — the decoder generates left-to-right and cannot see future output tokens (they don't exist yet), so it stays unidirectional; only the encoder, which sees the whole input at once, can be bidirectional.
Padding tokens added to short inputs for batching still contribute to the loss and to the encoder's summary.
False — padding is masked out: the loss ignores padded positions and masking stops padded steps from polluting , otherwise every batch would learn from meaningless filler.
Spot the error
Each item is a student statement in quotes, followed by the correction.
Correction
Wrong — decoding length is controlled by the decoder emitting
<EOS> (or hitting a max-length cap), not by input length; the input was already fully consumed during encoding.Correction
Wrong reason — softmax is used because we must pick one token from classes and therefore need a valid probability distribution; speed is not the motivation.
Correction
Wrong — under teacher forcing the ground-truth token is fed at regardless of the prediction (figure s02); feeding the model's own token is inference behaviour, and that gap causes exposure bias.
Correction
Backwards — each token contributes a log-probability, and since a probability is its log is ; a longer sequence therefore adds more negative terms, giving a smaller (more negative) raw sum. So raw sums penalize length, which is why length normalization divides by the length to level the field.
Correction
Wrong — has the encoder's hidden dimension , unrelated to ; the vocabulary size only appears at the final softmax layer's output width via .
Correction
Wrong — gradients flow from the loss back through the decoder, into , and then through the entire encoder; BPTT spans both RNNs, as covered in backpropagation through time.
Correction
Wrong — they are two distinct vocabulary entries:
<SOS> is the decoder's initial input to kick off generation, <EOS> is a predicted output that signals stopping.Why questions
Why do we use an LSTM or GRU for the encoder rather than a plain feed-forward network?
Because input length varies per example, and only a recurrent structure (3.5.01-Recurrent-neural-networks, 3.5.05-LSTM-networks, 3.5.06-GRU-networks) can consume an arbitrary-length sequence with one fixed set of weights.
Why does the basic seq2seq model struggle with long input sentences?
Because all information is squeezed into one fixed-size ; for long inputs this is an information bottleneck and early tokens get forgotten by the time the encoder reaches .
Why is minimizing negative log-likelihood equivalent to maximizing the probability of the correct sequence?
Because is monotonically increasing, so maximizing maximizes ; flipping the sign turns "maximize" into "minimize", giving a loss the optimizer can descend.
Why is exposure bias a training/inference mismatch rather than just a bad model?
Because at training the decoder always sees correct previous tokens (teacher forcing, figure s02), so it never learns to recover from its own mistakes, yet at inference it must feed its own possibly-wrong tokens — the two regimes present different input distributions.
Why does beam search improve over greedy decoding on translation quality?
Because greedy commits to the single best token each step and can walk into a dead-end, while beam search keeps hypotheses alive so a locally-suboptimal early token can still lead to a globally better sequence (details in 4.2.01-Beam-search).
Why do we need masking when we pad a batch of variable-length inputs?
Because padding just fills short sequences up to the batch's max length; without a mask the encoder would treat filler as real tokens and the loss would be computed on meaningless positions, corrupting both and the gradients.
Why can attention be seen as fixing the exact weakness of the fixed context vector?
Because attention lets the decoder build a fresh context each step from all encoder states, so no single vector must memorize the whole input — the bottleneck disappears (3.5.08-Attention-mechanism, taken further in 3.5.09-Transformers).
Why do we still cap generation at a maximum length even though we train the model to emit <EOS>?
Because a poorly-trained decoder might never emit
<EOS> and loop forever; the length cap is a safety net guaranteeing termination.Edge cases
What does a seq2seq model output when the input is a single token (e.g. "Bonjour" → "Hello")?
It works fine: the encoder runs one step to produce , and the decoder generates tokens until
<EOS>; there is no requirement that .What happens if the decoder emits <EOS> as its very first token after <SOS>?
The output sequence is empty (length zero) — a valid, if usually undesirable, outcome; the model has decided the correct translation is "nothing".
In beam search, what happens when one beam produces <EOS> while others have not finished?
That completed hypothesis is frozen with its length-normalized score (figure s03); the remaining beams keep expanding, and at the very end the best frozen hypothesis across all finish-times is chosen.
If two candidate sequences in beam search have identical raw log-probability sums but different lengths, which wins after length normalization?
The longer one wins, because dividing the same total by a larger length gives a higher (less negative) per-token average — the length-normalization effect.
What is the smallest sensible vocabulary the decoder can have?
At least
<SOS>, <EOS>, and one real token; without <EOS> it could never signal termination and without <SOS> the decoder would have no initial input.What happens to gradients through if the input sequence is extremely long?
They can vanish or explode across many encoder time steps (the classic BPTT problem, 3.4.03-Backpropagation-through-time); LSTM/GRU gating mitigates but does not fully cure this.
What happens in a batch where inputs are padded to length 12 but one sentence is length 3?
The 9 padded steps are masked so they neither update nor add loss; the encoder's effective summary for that sentence is taken at its true last step (position 3), not at the padded position 12.
If teacher forcing is turned off entirely during training (feed model's own predictions), what breaks?
Early in training predictions are near-random, so errors compound step-by-step and the decoder rarely sees correct context, making learning slow and unstable — teacher forcing exists to avoid exactly this.
Recall Quick self-check
Cover every answer and re-derive the reason, not the yes/no. If you can justify all four sections — including the padding/masking edge cases and why raw log-sums penalize length — without peeking, you are ready for 3.5.08-Attention-mechanism.