Part XI — Sequence Models: RNNs, LSTMs, Attention & The Transformer Block · Chapter 1

Why sequences break feedforward networks

Hook

A convolution slides a filter across space and doesn't care where a pattern sits. Text and time series have a similar-looking problem — but sliding a filter across a sentence doesn't fix it, because for language the thing that matters most is often the order itself.

Intuition
token X = (1, 0), token Y = (0, 1) — "X then Y" and "Y then X" both sum to (1, 1)

"X then Y" and "Y then X" are different sequences — in language, "dog bites man" and "man bites dog" are not the same story. But a common way to turn a sequence into a fixed-size vector is to just add up its tokens. Addition doesn't care about order: X+YX + Y and Y+XY + X land on the exact same point. Once that sum is computed, the order is simply gone — there is no way to recover it from the vector alone.

Formalize

Feed that pooled vector into a plain dense layer with weights (w1,w2)(w_1, w_2) and a sigmoid, trained to output 00 for "X then Y" and 11 for "Y then X":

y^=σ(w1p1+w2p2),p=pool(sequence)\hat{y} = \sigma(w_1 p_1 + w_2 p_2), \qquad p = \text{pool}(\text{sequence})
  • y^\hat{y} — the network's predicted output.
  • σ\sigma — the sigmoid function, squashing the result into a value between 00 and 11.
  • w1,w2w_1, w_2 — the two learned weights of the dense layer.
  • p1,p2p_1, p_2 — the two components of the pooled vector.
  • p=pool(sequence)p = \text{pool}(\text{sequence}) — the fixed-size vector produced by summing (pooling) the sequence's tokens together.
  1. Pooling erases the order

    Since pp is identical for both sequences, y^\hat{y} is identical for both — for every choice of w1,w2w_1, w_2.

  2. No amount of training can fix it

    No amount of training can make this network output two different things for two inputs it has already made indistinguishable.

Play
w = (1.50, -0.50) — loss = 0.8133 (best possible: 0.6931)

Drag the point anywhere in this plane. The loss never depends on w1w_1 and w2w_2 separately — only on their sum. Every point along the diagonal where w1+w2=0w_1 + w_2 = 0 sits in the exact same flat valley, all at the same loss. There's no direction to search in that helps, because the representation this network is working from threw away the one thing that would have let it succeed.

Worked example
  1. Pick a weight — w1 = 2, w2 = -2

    The pooled input is (1,1)(1,1) for both sequences, so the logit is 2(1)+(2)(1)=02(1) + (-2)(1) = 0 either way, giving y^=σ(0)=0.5\hat{y}=\sigma(0)=0.5 for both.

  2. Compute the loss
    • For "X then Y" (target 00) it's log(10.5)=ln2-\log(1-0.5) = \ln 2
    • For "Y then X" (target 11) it's log(0.5)=ln2-\log(0.5) = \ln 2
  3. Average

    ln20.693\ln 2 \approx 0.693 — exactly the loss of a coin flip, because that's genuinely the best this architecture can do.

Checkpoint

Drag the point until the loss reaches its best possible value, 0.693 — the loss of a network that can only guess.

w = (2.00, 2.00) — loss = 2.0181
Drag the point to try it
Summary
y^=σ(w1p1+w2p2),p=pool(sequence)\hat{y} = \sigma(w_1 p_1 + w_2 p_2), \qquad p = \text{pool}(\text{sequence})

This isn't a training problem — more epochs, a better optimizer, or more data won't fix it. It's an architecture problem: any network that collapses a sequence into an order-blind summary before it ever sees a weight has already thrown away the information the task needed. What sequence models actually need is a way to process tokens one at a time, in order, while remembering what came before — which is exactly what the next chapter builds.