March 31, 2026
Last lecture we hit a wall: the VQ-VAE produces a grid of codebook indices, but generating those indices from scratch requires modeling their sequential dependencies.
\[P(s_1, s_2, \ldots, s_{16}) = \prod_i P(s_i \,|\, s_1, \ldots, s_{i-1})\]
But sequences go far beyond image tokens.
Language is a sequence of words. Speech is a sequence of audio frames. Video is a sequence of images. Music, DNA, stock prices — any data where order matters.
The tools we build over the next few lectures apply to all of them.
Thus far, we have only seen deep learning architectures where information flows upward through the model
Feedforward in the sense that the only direct influence of a layer is to its child
For tabular data and image analysis:
Not necessarily equal number of inputs and outputs
Equal number of outputs and inputs
A feedforward network maps one fixed-size input to one fixed-size output. No memory. No sense of order.
We could concatenate the entire sequence into one long vector and feed it through an MLP. But sequences have variable length, and the model would need position-specific weights for every possible length.
No weight sharing across time. No generalization to new sequence lengths.
If the order of the input matters, we need an architecture that preserves it.
Recurrent Neural Networks (RNNs) are the backbone of sequence modeling
Adds knowledge to the NN architecture
If the order of the input matters, then we should preserve that information!
We can process a sequence of vectors, \(\mathbf{x}\), by applying a recurrence formula at every time step:
\[\mathbf{h}_t = f_w(\mathbf{h}_{t-1}, \mathbf{x}_t)\]
The hidden state vector contains latent information about the current state of the model
This information should persist throughout the sequence of predictions!
The hidden state is a latent vector — a compressed representation of the sequence, just like \(\mathbf{z}\) in the VAE is a compressed representation of an image.
Start with an initial state, \(\mathbf{h}_0\)
\[\underset{(m \times 1)}{\mathbf{h}_t} = \text{tanh}\left(\underset{(m \times m)}{\mathbf{W}_{hh}} \underset{(m \times 1)}{\mathbf{h}_{t-1}} + \underset{(m \times P)}{\mathbf{W}_{xh}} \underset{(P \times 1)}{\mathbf{x}_t} + \underset{(m \times 1)}{\mathbf{b}_h}\right)\]
\[\underset{(m \times 1)}{\mathbf{h}_t} = \text{tanh}\left(\underset{(m \times m)}{\mathbf{W}_{hh}} \underset{(m \times 1)}{\mathbf{h}_{t-1}} + \underset{(m \times P)}{\mathbf{W}_{xh}} \underset{(P \times 1)}{\mathbf{x}_t} + \underset{(m \times 1)}{\mathbf{b}_h}\right)\]
Drawing some parallels to what we’ve seen before:
A FCNN with a twist!
Note that \(\mathbf{x}_1\) only relates to \(\mathbf{y}_1\) through \(\mathbf{h}_1\)!
Given a hidden state, we say that \(\mathbf{y}_t\) is determined as:
\[\underset{(G \times 1)}{\mathbf{y}_t} = g\left(\underset{(G \times m)}{\mathbf{W}_{hy}} \underset{(m \times 1)}{\mathbf{h}_t} + \underset{(G \times 1)}{\mathbf{b}_y}\right)\]
The part that is so simple that it’s kinda dumb
Use the same \(\mathbf{W}_{hh}\), \(\mathbf{W}_{xh}\), and \(\mathbf{W}_{hy}\) at all time points
Let’s think about how \(\mathbf{y}_2\) is computed.
Let \(\xi()\) be the \(\text{tanh}\) activation. Dropping bias terms:
\[\mathbf{y}_2 = \mathbf{W}_{hy} \xi(\mathbf{W}_{hh} \xi(\mathbf{W}_{hh} \mathbf{h}_0 + \mathbf{W}_{xh} \mathbf{x}_1) + \mathbf{W}_{xh} \mathbf{x}_2)\]
Every output sees the full history through the chain of hidden states.
Let’s look at an aligned many-to-many model!
Goal: Given input characters, build a model to predict the next character!