Sequence Models
Level 2 — Recall (Definitions, Standard Problems, Short Derivations) Time Limit: 30 minutes | Total Marks: 40
Answer all questions. Use notation for mathematics where required.
Q1. Write the two core update equations of a vanilla (Elman) RNN for the hidden state and output at time step , clearly defining each weight matrix and bias. (4 marks)
Q2. State the vanishing gradient problem in RNNs. Explain briefly why the gradient of the loss with respect to early hidden states tends to shrink during Backpropagation Through Time (BPTT). (4 marks)
Q3. Name the three gates in an LSTM cell and state the one-line function of each. (4 marks)
Q4. A GRU has two gates. Name them and write the update equation for the final hidden state in terms of the update gate , candidate state , and previous state . (4 marks)
Q5. Distinguish between a unidirectional RNN and a bidirectional RNN. Give one task where a bidirectional RNN cannot be used and explain why. (4 marks)
Q6. Draw/describe the encoder–decoder (sequence-to-sequence) architecture. What is the "context vector" and what limitation does it introduce for long input sequences? (4 marks)
Q7. Define teacher forcing. State one advantage and one disadvantage of using it during training. (4 marks)
Q8. In Bahdanau (additive) attention, the alignment scores are converted to weights via a softmax, and the context vector is . Given raw scores for three encoder states, compute the attention weights (round to 3 decimals). (4 marks)
Q9. Explain the idea behind beam search decoding with beam width . How does it differ from greedy decoding? For a vocabulary of size and beam width , how many candidate expansions are scored at each step? (4 marks)
Q10. Briefly explain what a word embedding is. Name the two training variants of Word2Vec and state what each predicts. (4 marks)
End of Paper
Answer keyMark scheme & solutions
Q1. (4 marks)
- : input-to-hidden weights; : hidden-to-hidden (recurrent) weights; : hidden-to-output weights; : biases. (1 for each correct equation = 2; 2 for correct definitions of matrices/bias) Why: the recurrent term carries memory of past inputs.
Q2. (4 marks)
- Statement: during BPTT, gradients propagated back over many time steps become exponentially small, so early time steps receive negligible weight updates → the network fails to learn long-range dependencies. (2)
- Reason: the gradient contains a product of Jacobians ; each factor . Since and repeated multiplication of terms decays geometrically, the product . (2)
Q3. (4 marks) — 1 mark each gate + 1 for completeness/correctness:
- Forget gate : decides what fraction of the old cell state to keep/discard.
- Input gate : decides what new candidate information to add to the cell state.
- Output gate : decides what part of the cell state is exposed as the hidden state .
Q4. (4 marks)
- Gates: update gate and reset gate . (2) (2) Why: interpolates between keeping the old state and taking the new candidate — an adaptive memory mixing. (Accept the equivalent convention if stated consistently.)
Q5. (4 marks)
- Unidirectional RNN processes the sequence in one direction (past→future), so depends only on inputs up to . Bidirectional RNN runs two RNNs (forward + backward) and concatenates their hidden states, so each output depends on both past and future context. (2)
- Cannot be used for real-time / online / streaming generation (e.g., live speech-to-text output, autoregressive text generation) because the future part of the sequence is not yet available. (2)
Q6. (4 marks)
- Encoder RNN reads the input sequence and compresses it into a fixed-length context vector (its final hidden state). The decoder RNN is initialized with this context and generates the output sequence step by step. (2)
- Context vector = the summarized representation of the entire input. (1)
- Limitation: a single fixed-length vector becomes an information bottleneck for long inputs — performance degrades as input length grows (motivating attention). (1)
Q7. (4 marks)
- Teacher forcing: during training, the decoder receives the ground-truth previous token as input (instead of its own predicted token) when predicting the next token. (2)
- Advantage: faster, more stable convergence. (1)
- Disadvantage: exposure bias — mismatch between training (true tokens) and inference (predicted tokens) can hurt test-time performance. (1)
Q8. (4 marks) Softmax of :
- (2 for method, 2 for correct values ≈ [0.665, 0.245, 0.090])
Q9. (4 marks)
- Beam search keeps the top- highest-probability partial sequences ("beams") at each decoding step, expanding all of them and retaining the best overall. (2)
- Difference: greedy decoding () picks only the single most probable token each step and cannot recover from an early mistake; beam search explores multiple hypotheses. (1)
- Candidates scored per step: . (1)
Q10. (4 marks)
- A word embedding is a dense, low-dimensional real-valued vector representing a word such that semantically similar words are close in vector space. (2)
- Word2Vec variants: CBOW (predicts the target/center word from surrounding context words) and Skip-gram (predicts surrounding context words from the target word). (2)
[
{"claim":"Softmax weights of [2,1,0] round to [0.665,0.245,0.090] and sum to 1",
"code":"import math\ne=[2,1,0]\nd=sum(math.exp(x) for x in e)\na=[round(math.exp(x)/d,3) for x in e]\nresult = (a==[0.665,0.245,0.090]) and (round(sum(math.exp(x)/d for x in e),6)==1.0)"},
{"claim":"Denominator e^2+e^1+e^0 approx 11.107",
"code":"import math\nresult = round(math.exp(2)+math.exp(1)+math.exp(0),3)==11.107"},
{"claim":"Beam search scores k*V candidates per step for k=3,V=1000 -> 3000",
"code":"k=3; V=1000\nresult = k*V==3000"},
{"claim":"GRU convex combination: for z=0.7, h=(1-z)*h_prev+z*hcand with h_prev=2,hcand=5 equals 4.1",
"code":"z=0.7; hp=2; hc=5\nresult = round((1-z)*hp+z*hc,6)==4.1"}
]