🌍 Deep Learning · subject
Deep Learning Sequence Models and Recurrent Networks Syllabus
The Sequence Models and Recurrent Networks syllabus for Deep Learning in full: 4 chapters and 13 topics, every one listed below, plus 50 Sequence Models and Recurrent Networks flashcards with answers.
Sequence Models and Recurrent Networks syllabus: all 4 chapters
Expand any chapter to see its topics and sub-topics.
-
Recurrent Neural Networks
3 topics- RNN Architecture
- Sequence Modeling Tasks
- Bidirectional RNNs
-
Gated Recurrent Architectures
3 topics- Long Short-Term Memory (LSTM)
- Gated Recurrent Units (GRU)
- Long-Range Dependencies
-
Sequence-to-Sequence Models
4 topics- Encoder-Decoder Architecture
- Attention Mechanism
- Beam Search Decoding
- Teacher Forcing
-
Word Embeddings and Text Representation
3 topics- Word2Vec and GloVe
- Tokenization and Subword Units
- Contextual Embeddings
Deep Learning Sequence Models and Recurrent Networks flashcards — 50 questions with answers
What is the defining recurrence relation of a vanilla (Elman) RNN's hidden state?
$h_t = \tanh(W_{hh} h_{t-1} + W_{xh} x_t + b_h)$, with output $y_t = W_{hy} h_t + b_y$. The same weight matrices are shared across all time steps.
Why do RNNs share weights across time steps?
Weight sharing lets the network process sequences of arbitrary length with a fixed number of parameters and enforces the assumption that the same transition dynamics apply at every position (a form of temporal translation invariance).
In RNN backpropagation, what is Backpropagation Through Time (BPTT)?
BPTT unrolls the RNN across time steps into a deep feedforward graph and applies standard backpropagation, summing gradient contributions of the shared weights over all time steps: $\frac{\partial L}{\partial W} = \sum_{t} \frac{\partial L_t}{\partial W}$.
What causes the vanishing and exploding gradient problems in RNNs?
Gradients propagate through repeated multiplication by the recurrent Jacobian. Over $k$ steps the factor behaves like $\prod \|W_{hh}\|$; if the relevant eigenvalues are $<1$ gradients vanish exponentially, if $>1$ they explode, making long-range learning unstable.
What is gradient clipping and which RNN problem does it address?
Gradient clipping rescales the gradient when its norm exceeds a threshold: if $\|g\| > \theta$, set $g \leftarrow \frac{\theta}{\|g\|} g$. It mitigates the exploding gradient problem, not vanishing gradients.
Classify the four canonical RNN input/output configurations by shape.
One-to-one (fixed vector, e.g. plain classification), one-to-many (image captioning), many-to-one (sentiment classification), and many-to-many (sequence labeling if aligned, or encoder-decoder translation if unaligned).
What distinguishes a sequence labeling task from a sequence classification task?
Sequence labeling produces one output per input token (e.g. POS tagging, NER), so outputs are aligned and equal in length to inputs. Sequence classification produces a single label for the whole sequence (e.g. sentiment).
What is a language modeling task, and what quantity does it estimate?
Language modeling estimates the probability of a sequence via the chain rule $P(w_1,\dots,w_T) = \prod_{t=1}^{T} P(w_t \mid w_{1:t-1})$. Each step predicts the next token given the preceding context.
How is perplexity defined and what does it measure for a language model?
$\text{PPL} = \exp\!\left(-\frac{1}{T}\sum_{t=1}^{T} \log P(w_t \mid w_{1:t-1})\right)$. It is the exponentiated average negative log-likelihood; lower perplexity means the model assigns higher probability to the held-out text.
How does a bidirectional RNN compute its representation at each position?
It runs a forward RNN and an independent backward RNN, then concatenates their hidden states: $h_t = [\overrightarrow{h}_t ; \overleftarrow{h}_t]$, so each position sees both past and future context.
What is the main limitation of bidirectional RNNs regarding usage?
They require the entire input sequence to be available before producing outputs, so they cannot be used for real-time/online generation or autoregressive next-token prediction—only for tasks where the full sequence is known (e.g. tagging, encoding).
List the three gates of an LSTM cell and what each controls.
Forget gate $f_t$ (how much of the previous cell state to keep), input gate $i_t$ (how much new candidate information to write), and output gate $o_t$ (how much of the cell state to expose as the hidden state).
Write the full set of LSTM equations.
$f_t=\sigma(W_f[h_{t-1},x_t]+b_f)$, $i_t=\sigma(W_i[h_{t-1},x_t]+b_i)$, $o_t=\sigma(W_o[h_{t-1},x_t]+b_o)$, $\tilde{c}_t=\tanh(W_c[h_{t-1},x_t]+b_c)$, $c_t=f_t\odot c_{t-1}+i_t\odot\tilde{c}_t$, $h_t=o_t\odot\tanh(c_t)$.
Why does the LSTM cell state help preserve long-range gradients?
The cell-state update $c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t$ is additive (a near-linear 'constant error carousel'). When $f_t \approx 1$, gradients flow through $c_t$ with minimal decay, avoiding the multiplicative vanishing seen in vanilla RNNs.
What are the two roles of the LSTM's hidden state $h_t$ versus cell state $c_t$?
$c_t$ is the internal long-term memory carried mostly linearly through time; $h_t = o_t \odot \tanh(c_t)$ is the gated, exposed output used for predictions and passed to the next step's gates.
List the gates of a GRU and their roles.
Update gate $z_t$ (interpolates between previous hidden state and new candidate) and reset gate $r_t$ (controls how much past state influences the candidate). GRU has no separate cell state or output gate.
Write the GRU equations.
$z_t=\sigma(W_z[h_{t-1},x_t])$, $r_t=\sigma(W_r[h_{t-1},x_t])$, $\tilde{h}_t=\tanh(W[r_t\odot h_{t-1},x_t])$, $h_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde{h}_t$.
Compare GRU and LSTM in structure and parameter count.
GRU has 2 gates and merges cell and hidden state into one vector; LSTM has 3 gates plus a separate cell state. GRU has roughly 3/4 the parameters of an LSTM per unit, trains faster, and often performs comparably; LSTM can be stronger on very long or complex sequences.
In the GRU update $h_t=(1-z_t)\odot h_{t-1}+z_t\odot\tilde{h}_t$, what does $z_t \approx 0$ imply?
When $z_t \approx 0$ the unit copies the previous hidden state almost unchanged ($h_t \approx h_{t-1}$), letting information persist over many steps and preserving gradient flow for long-range dependencies.
What is a 'long-range dependency' and why is it hard for vanilla RNNs?
It is a statistical dependency between elements far apart in a sequence (e.g. subject-verb agreement across a long clause). Vanilla RNNs struggle because gradients over many steps vanish/explode, so the influence of distant inputs is lost.
Show the other 30 Sequence Models and Recurrent Networks flashcards
Besides gating, name two architectural strategies to help RNNs capture long-range dependencies.
Skip/residual connections across time steps (shorter gradient paths) and attention mechanisms that create direct connections between distant positions, bypassing the sequential bottleneck entirely.
Describe the encoder-decoder (seq2seq) architecture.
An encoder RNN compresses the input sequence into a context representation (e.g. its final hidden state $c$); a decoder RNN generates the output sequence autoregressively, conditioned on $c$ and its own previously generated tokens.
What is the 'information bottleneck' problem in a basic encoder-decoder?
Compressing the entire source sequence into a single fixed-length context vector forces long inputs through a narrow bottleneck, degrading performance as sequence length grows. Attention was introduced to solve this.
What quantities does an attention mechanism compute (query, key, value framing)?
For query $q$ and keys $k_i$/values $v_i$: scores $e_i = \text{score}(q,k_i)$, weights $\alpha_i=\text{softmax}(e_i)=\frac{\exp(e_i)}{\sum_j \exp(e_j)}$, and context $c=\sum_i \alpha_i v_i$.
Give the formula for scaled dot-product attention.
$\text{Attention}(Q,K,V)=\text{softmax}\!\left(\frac{QK^{\top}}{\sqrt{d_k}}\right)V$, where $d_k$ is the key dimension; dividing by $\sqrt{d_k}$ keeps dot products from growing large and saturating the softmax.
Why is the $\frac{1}{\sqrt{d_k}}$ scaling factor used in dot-product attention?
For large $d_k$, dot products $q\cdot k$ have variance proportional to $d_k$, pushing softmax into regions with tiny gradients. Scaling by $\frac{1}{\sqrt{d_k}}$ normalizes the variance to $\approx 1$, keeping gradients healthy.
Contrast additive (Bahdanau) and multiplicative (Luong) attention scoring.
Additive: $e_i = v^{\top}\tanh(W_1 q + W_2 k_i)$, a small feedforward net. Multiplicative: $e_i = q^{\top} k_i$ (or $q^{\top} W k_i$), a dot product—faster and more memory-efficient, especially with optimized matrix multiplication.
What is self-attention, and how does it differ from encoder-decoder attention?
In self-attention the queries, keys, and values all come from the same sequence, letting each position attend to every other position in that sequence. Encoder-decoder (cross) attention uses decoder queries against encoder keys/values.
What problem does beam search decoding solve, and how?
It approximately finds the highest-probability output sequence (intractable to search exhaustively) by keeping the top-$k$ partial hypotheses (the beam) at each decoding step and expanding only those, balancing search quality and cost.
Contrast greedy decoding with beam search.
Greedy decoding picks the single most probable token at each step ($k=1$), which is locally optimal but can miss globally better sequences. Beam search retains $k>1$ candidates, exploring more of the search space at higher computational cost.
Why does beam search use length normalization, and give a common form.
Raw sequence log-probabilities $\sum_t \log P(y_t\mid\cdot)$ decrease with length, biasing toward short outputs. Length normalization divides by a length penalty, e.g. score $=\frac{1}{L^{\alpha}}\sum_{t=1}^{L}\log P(y_t\mid y_{<t})$ with $\alpha\in(0,1]$.
What happens to beam search behavior as the beam width $k$ increases very large versus $k=1$?
$k=1$ is greedy search. Increasing $k$ explores more hypotheses and can raise likelihood, but beyond a point returns diminish and, in NMT, very large beams often produce shorter, lower-quality translations (the 'beam search curse').
What is teacher forcing in sequence model training?
During training the decoder is fed the ground-truth previous token (rather than its own prediction) as input at each step, so $P(y_t\mid y^{*}_{<t})$ is modeled. This stabilizes and speeds convergence.
What is exposure bias, and how does it relate to teacher forcing?
Exposure bias is the train/test mismatch caused by teacher forcing: at training the model always sees correct history, but at inference it sees its own (possibly wrong) outputs, so errors compound with no learned recovery.
What is scheduled sampling and what problem does it mitigate?
Scheduled sampling gradually replaces ground-truth previous tokens with the model's own predictions during training, according to a decaying probability, to reduce exposure bias from pure teacher forcing and bridge the train/test gap.
What is the core objective of Word2Vec, and name its two model variants.
Word2Vec learns dense word embeddings by predicting words from context. Variants: CBOW (predict the center word from surrounding context) and Skip-gram (predict surrounding context words from the center word).
State the Skip-gram softmax objective and why it is expensive.
$P(w_O\mid w_I)=\frac{\exp(v_{w_O}^{\prime\top} v_{w_I})}{\sum_{w=1}^{V}\exp(v_w^{\prime\top} v_{w_I})}$. The denominator sums over the whole vocabulary $V$, making each update $O(V)$—hence approximations like negative sampling or hierarchical softmax are used.
What is negative sampling in Word2Vec?
Instead of the full softmax, it trains a binary classifier to distinguish the true context word from $k$ randomly sampled 'negative' words, optimizing $\log\sigma(v_{w_O}^{\prime\top} v_{w_I}) + \sum_{i=1}^{k}\mathbb{E}_{w_i\sim P_n}[\log\sigma(-v_{w_i}^{\prime\top} v_{w_I})]$.
How does GloVe differ fundamentally from Word2Vec?
GloVe is count-based: it factorizes the global word-word co-occurrence matrix, fitting embeddings so $w_i^{\top}\tilde{w}_j + b_i + \tilde{b}_j \approx \log X_{ij}$. Word2Vec is prediction-based over local context windows; GloVe uses global corpus statistics directly.
Write GloVe's weighted least-squares objective.
$J=\sum_{i,j=1}^{V} f(X_{ij})\left(w_i^{\top}\tilde{w}_j + b_i + \tilde{b}_j - \log X_{ij}\right)^2$, where $f$ is a weighting function that downweights rare and caps frequent co-occurrences.
What famous property do Word2Vec/GloVe embeddings exhibit via vector arithmetic?
Linear analogies: $\vec{king}-\vec{man}+\vec{woman}\approx\vec{queen}$. Semantic and syntactic relations appear as roughly consistent offset vectors in embedding space.
Why are static embeddings like Word2Vec and GloVe limited for polysemy?
They assign a single fixed vector per word type regardless of context, so 'bank' (river vs. finance) collapses to one representation. Contextual embeddings solve this by producing token-specific vectors.
What is tokenization in NLP, and why is word-level tokenization problematic?
Tokenization splits text into units for the model. Word-level tokenization yields huge vocabularies, cannot handle out-of-vocabulary words, and wastes capacity on rare forms—motivating subword approaches.
Explain Byte-Pair Encoding (BPE) as a subword tokenization method.
BPE starts from characters and iteratively merges the most frequent adjacent symbol pair into a new symbol, repeating for a fixed number of merges. Frequent words become single tokens; rare words decompose into subword pieces, eliminating OOV.
How does WordPiece differ from BPE in choosing merges?
BPE merges the most frequent pair; WordPiece merges the pair that most increases the training-corpus likelihood, i.e. it picks the merge maximizing $\frac{P(ab)}{P(a)P(b)}$ under a language model, rather than raw frequency.
What advantage do subword tokenizers provide over word and character tokenization?
They give a fixed, moderate vocabulary with no true OOV tokens (rare words split into known subwords), while keeping sequences much shorter than character-level tokenization—balancing vocabulary size against sequence length.
What are contextual embeddings, and how do they differ from static embeddings?
Contextual embeddings assign each token a vector that depends on its surrounding sentence, produced by a deep model (e.g. ELMo, BERT). The same word gets different vectors in different contexts, capturing polysemy—unlike one-vector-per-type static embeddings.
How does ELMo produce contextual embeddings?
ELMo runs a deep bidirectional LSTM language model and forms each token's embedding as a learned, task-weighted linear combination of the hidden states across all biLSTM layers, capturing both syntax (lower layers) and semantics (higher layers).
What pretraining objective gives BERT its contextual, bidirectional representations?
Masked Language Modeling (MLM): randomly mask ~15% of input tokens and train the model to predict them from both left and right context, plus (originally) Next Sentence Prediction. This yields deeply bidirectional token embeddings.
Why are contextual embeddings generally preferred over Word2Vec/GloVe for downstream tasks?
They encode word sense in context, capture syntax and long-range dependencies through deep bidirectional processing, and provide transferable pretrained representations that can be fine-tuned—typically outperforming static embeddings on most NLP benchmarks.
Deep Learning Sequence Models and Recurrent Networks FAQ
What is in the Deep Learning Sequence Models and Recurrent Networks syllabus?
Deep Learning Sequence Models and Recurrent Networks is split into 4 chapters: Recurrent Neural Networks, Gated Recurrent Architectures, Sequence-to-Sequence Models and Word Embeddings and Text Representation. Together they contain 13 topics.
How many chapters are in Deep Learning Sequence Models and Recurrent Networks?
4 chapters, containing 13 topics. The largest chapter is Sequence-to-Sequence Models, with 4 topics.
Are there flashcards for Deep Learning Sequence Models and Recurrent Networks?
Yes — a 50-card Sequence Models and Recurrent Networks deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.