David I. Inouye
Dynamic Content · Last Updated: October 23, 2026
Arc 6: Sequence-model architectures
We will follow one email-completion example through each choice.
Our focus: next-token completion. Repeating it generates a continuation.
Original illustration informed by Karpathy’s sequence-task examples.
Typed prefix: “please send the”
Possible continuations: “report” · “slides” · “agenda”
First: turn text into choices the model can predict.
Real application: Gmail Smart Compose (Chen et al., 2019). The email examples here are synthetic.
Synthetic vocabulary for the worked examples:
| Token | <BOS> | please | send | the | report | <EOS> |
|---|---|---|---|---|---|---|
| ID | 0 | 1 | 2 | 3 | 4 | 5 |
please send the report becomes the ID sequence \((1,2,3,4)\).
Next: turn each ID into learned features.
Synthetic table \(E\in\mathbb{R}^{6\times2}\):
| Token | Feature 1 | Feature 2 |
|---|---|---|
<BOS> |
0 | 0 |
please |
1 | 0 |
send |
0 | 1 |
the |
1 | 1 |
report |
1 | −1 |
<EOS> |
−1 | 0 |
For token ID \(w_t=2\) (send):
\[\boldsymbol{e}_t=E^{\mathsf T}\boldsymbol{o}_2 =\begin{bmatrix}0\\1\end{bmatrix}\]
\(\boldsymbol{o}_2=[0,0,1,0,0,0]^{\mathsf T}\) selects row 2.
Next: specify the target that teaches these features.
\[\boldsymbol{p}_t=\operatorname{softmax}(\boldsymbol{z}_t), \qquad \ell_t=-\log p_{t,w_{t+1}}\]
Allowed context for \(\boldsymbol{z}_t\): tokens through \(w_t\) only.
Putting it together: one next-token prediction at each position.
| Stage | Tensor shape | Meaning |
|---|---|---|
| Input IDs | [B,T] |
One integer ID at each position |
| Embedding lookup | [B,T,d] |
\(d\) learned features per token |
| Context model | [B,T,h] |
\(h\) context-dependent features per position |
| Vocabulary head | [B,T,V] |
\(V\) logits per next-token prediction |
| Targets | [B,T] |
One next-token ID per position |
B: batch size. T: input length. V: vocabulary size.
Padding is absent data: exclude padded targets from the loss.
Before fitting: keep evaluation emails separate.
| Group and split threads | Then create examples |
|---|---|
| Training threads | Training prefixes and next-token targets |
| Validation threads | Validation prefixes and next-token targets |
| Reserved test threads | Final held-out prefixes and targets |
Now build a baseline: how much of the prefix should it read?
\[\boldsymbol{z}_t=f_\theta\!\left( \begin{bmatrix}\boldsymbol{e}_{t-2}\\\boldsymbol{e}_{t-1}\\\boldsymbol{e}_t\end{bmatrix}\right) \in\mathbb{R}^{v}\]
Its limitation: anything before the window is unavailable to the model.
“Send the report today. Please attach the …”
“Send the slides today. Please attach the …”
Which change permits different predictions from a three-token model?
A. Add more hidden units
B. Include earlier tokens
C. Train on more emails
B. Identical input windows produce the same predicted distribution for fixed parameters.
| Fixed-window predictor | Recurrent predictor |
|---|---|
| Reads the most recent \(k\) tokens | Reads the current token and previous state |
| Earlier tokens fall outside the input | Earlier tokens can affect the state |
| Input width depends on \(k\) | State width stays fixed |
Next question: how can one learned update carry useful earlier information forward?