Level 2 — RecallSequence Models

Sequence Models

30 minutes40 marksprintable — key stays hidden on paper

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 hth_t and output yty_t at time step tt, 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 hth_t in terms of the update gate ztz_t, candidate state h~t\tilde{h}_t, and previous state ht1h_{t-1}. (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 αti\alpha_{ti} via a softmax, and the context vector is ct=iαtihic_t = \sum_i \alpha_{ti} h_i. Given raw scores e=[2, 1, 0]e = [2,\ 1,\ 0] for three encoder states, compute the attention weights α\alpha (round to 3 decimals). (4 marks)

Q9. Explain the idea behind beam search decoding with beam width kk. How does it differ from greedy decoding? For a vocabulary of size VV and beam width kk, 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) ht=tanh(Whhht1+Wxhxt+bh)h_t = \tanh(W_{hh} h_{t-1} + W_{xh} x_t + b_h) yt=Whyht+byy_t = W_{hy} h_t + b_y

  • WxhW_{xh}: input-to-hidden weights; WhhW_{hh}: hidden-to-hidden (recurrent) weights; WhyW_{hy}: hidden-to-output weights; bh,byb_h, b_y: biases. (1 for each correct equation = 2; 2 for correct definitions of matrices/bias) Why: the recurrent term Whhht1W_{hh}h_{t-1} 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 khkhk1\prod_k \frac{\partial h_k}{\partial h_{k-1}}; each factor Whhdiag(tanh)\approx W_{hh}^\top \text{diag}(\tanh'). Since tanh1|\tanh'|\le 1 and repeated multiplication of terms <1<1 decays geometrically, the product 0\to 0. (2)

Q3. (4 marks) — 1 mark each gate + 1 for completeness/correctness:

  • Forget gate ftf_t: decides what fraction of the old cell state to keep/discard.
  • Input gate iti_t: decides what new candidate information to add to the cell state.
  • Output gate oto_t: decides what part of the cell state is exposed as the hidden state hth_t.

Q4. (4 marks)

  • Gates: update gate ztz_t and reset gate rtr_t. (2) ht=(1zt)ht1+zth~th_t = (1 - z_t)\odot h_{t-1} + z_t \odot \tilde{h}_t (2) Why: ztz_t interpolates between keeping the old state and taking the new candidate — an adaptive memory mixing. (Accept the equivalent convention ht=ztht1+(1zt)h~th_t = z_t h_{t-1} + (1-z_t)\tilde h_t if stated consistently.)

Q5. (4 marks)

  • Unidirectional RNN processes the sequence in one direction (past→future), so hth_t depends only on inputs up to tt. 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 e=[2,1,0]e=[2,1,0]: αi=eeijeej,=e2+e1+e0=7.389+2.718+1=11.107\alpha_i = \frac{e^{e_i}}{\sum_j e^{e_j}}, \quad \sum = e^2+e^1+e^0 = 7.389+2.718+1 = 11.107

  • α1=7.389/11.107=0.665\alpha_1 = 7.389/11.107 = 0.665
  • α2=2.718/11.107=0.245\alpha_2 = 2.718/11.107 = 0.245
  • α3=1/11.107=0.090\alpha_3 = 1/11.107 = 0.090 (2 for method, 2 for correct values ≈ [0.665, 0.245, 0.090])

Q9. (4 marks)

  • Beam search keeps the top-kk highest-probability partial sequences ("beams") at each decoding step, expanding all of them and retaining the best kk overall. (2)
  • Difference: greedy decoding (k=1k=1) 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: k×Vk \times V. (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"}
]