Simple Algorithm
Deep Learning · Emergence · 28 min

RNNs as Dynamical Systems

Fixed points, line attractors and reverse-engineering trained networks.

A trained recurrent network is a dynamical system: a map from state to state, nudged by its inputs. Its fixed points, attractors and slow regions are the mechanism by which it remembers, counts and decides. Here you analyze those structures with the tools of dynamical systems, find them numerically inside trained networks, and meet the regime, at the edge of chaos, where untrained random networks compute best.

What you’ll learn

  • Linearize an RNN around a fixed point, classify its stability from the eigenvalues of the Jacobian, and analyze the bifurcation of h↦tanh⁡(wh)h\mapsto\tanh(wh) at w=1w=1.
  • Find fixed and slow points of a trained network by minimizing q(h)=12∥F(h)−h∥2q(\mathbf h)=\tfrac12\lVert F(\mathbf h)-\mathbf h\rVert^2, and explain how saddles mediate memory transitions in the 3-bit flip-flop.
  • Explain line attractors as the mechanism of evidence integration in sentiment RNNs, and the universality of fixed-point topology across architectures.
  • State and prove the singular-value condition for the echo state property, and explain reservoir computing and the edge of chaos.

Fixed points and their stability

Hold the input at a constant value x\mathbf x (often zero, between events) and an RNN becomes an autonomous dynamical system ht+1=F(ht)\mathbf h_{t+1}=F(\mathbf h_t) with F(h)=ϕ(Wh+Ux+b)F(\mathbf h)=\phi(W\mathbf h+U\mathbf x+\mathbf b). A fixed point satisfies h∗=F(h∗)\mathbf h^*=F(\mathbf h^*). Near it, write ht=h∗+δt\mathbf h_t=\mathbf h^*+\boldsymbol\delta_t; to first order the deviation evolves linearly, δt+1≈Jδt\boldsymbol\delta_{t+1}\approx J\boldsymbol\delta_t, with J=∂F/∂h ∣h∗=diag⁡(ϕ′(a∗)) WJ=\partial F/\partial\mathbf h\,|_{\mathbf h^*}=\operatorname{diag}(\phi'(\mathbf a^*))\,W: the same Jacobian whose products govern backpropagation through time.

DerivationProof of the stable case
  1. ∥J∥≤ρ(J)+ε<r<1\lVert J\rVert\le\rho(J)+\varepsilon<r<1

    For any square matrix and any ε>0\varepsilon>0 there is a vector norm whose induced matrix norm satisfies ∥J∥≤ρ(J)+ε\lVert J\rVert\le\rho(J)+\varepsilon. Since ρ(J)<1\rho(J)<1, choose ε\varepsilon so that r=ρ(J)+2ε<1r=\rho(J)+2\varepsilon<1.

  2. ∥F(h∗+δ)−h∗∥≤(∥J∥+ε)∥δ∥≤r ∥δ∥\lVert F(\mathbf h^*+\boldsymbol\delta)-\mathbf h^*\rVert\le(\lVert J\rVert+\varepsilon)\lVert\boldsymbol\delta\rVert\le r\,\lVert\boldsymbol\delta\rVert

    Differentiability gives F(h∗+δ)=h∗+Jδ+o(∥δ∥)F(\mathbf h^*+\boldsymbol\delta)=\mathbf h^*+J\boldsymbol\delta+o(\lVert\boldsymbol\delta\rVert), so on a small enough ball the remainder is at most ε∥δ∥\varepsilon\lVert\boldsymbol\delta\rVert:

  3. ∥ht−h∗∥≤r t ∥h0−h∗∥\lVert\mathbf h_t-\mathbf h^*\rVert\le r^{\,t}\,\lVert\mathbf h_0-\mathbf h^*\rVert

    The ball is mapped into itself and every step shrinks the deviation by at least the factor rr, so ∥δt∥≤rt∥δ0∥→0\lVert\boldsymbol\delta_t\rVert\le r^t\lVert\boldsymbol\delta_0\rVert\to0. The unstable case uses the expanding eigendirection in the same way.

A one-unit memory. Take ht+1=tanh⁡(wht)h_{t+1}=\tanh(wh_t) with w>0w>0. The origin is always a fixed point with slope J=wJ=w: stable for w<1w<1, unstable for w>1w>1. At w=1w=1 a pitchfork bifurcation creates two new fixed points ±h∗\pm h^* solving h∗=tanh⁡(wh∗)h^*=\tanh(wh^*), with slope w(1−h∗2)w(1-h^{*2}). They are stable, so the unit settles to +h∗+h^* or −h∗-h^* depending on the sign of its initial state and keeps that bit forever: a flip-flop made of one neuron. In larger networks the zoo of attractors grows: isolated point attractors store discrete memories, a continuum of marginally stable fixed points forms a line attractor (an eigenvalue equal to 1 along the line) that stores a continuous value, limit cycles generate rhythms, and chaotic attractors produce irregular activity.

Predict before you look

For ht+1=tanh⁡(2ht)h_{t+1}=\tanh(2h_t) the positive fixed point is h∗≈0.9575h^*\approx0.9575. What is the slope J=2(1−h∗2)J=2(1-h^{*2}) there? (Below 1 means stable.)

Show the answer

0.17

h∗2≈0.9168h^{*2}\approx0.9168, so J≈2×0.0832≈0.166J\approx2\times0.0832\approx0.166: strongly stable, and a perturbation shrinks to about a sixth of its size at every step. The origin, with slope 2, is unstable, so the network must commit to one of the two memories. For comparison, w=1.5w=1.5 gives h∗≈0.859h^*\approx0.859 and slope 0.390.39, and w=3w=3 gives h∗≈0.995h^*\approx0.995 and slope 0.030.03.

Opening the black box

In a network with hundreds of units you cannot draw the phase portrait. Sussillo & Barak (2013) proposed finding the important points numerically. For continuous-time dynamics h˙=F(h)\dot{\mathbf h}=F(\mathbf h) they minimize the squared speed q(h)=12∥F(h)∥2q(\mathbf h)=\tfrac12\lVert F(\mathbf h)\rVert^2; for a discrete map the analog is q(h)=12∥F(h)−h∥2q(\mathbf h)=\tfrac12\lVert F(\mathbf h)-\mathbf h\rVert^2. Zeros of qq are fixed points. Points where qq is small but not zero are slow points: the state barely moves there, so the linearization stays accurate for a while and still explains the computation. Minimizing qq from many states visited while the network performs its task finds attractors, repellers and saddles alike, whereas running the dynamics forward finds only attractors and running it backward only repellers.

python
import torch

def slow_points(rnn, h_init, steps=2000, lr=1e-2):
    W, U = rnn.weight_hh_l0.detach(), rnn.weight_ih_l0.detach()
    b = (rnn.bias_hh_l0 + rnn.bias_ih_l0).detach()
    x = torch.zeros(U.shape[1])                     # input held at zero
    F = lambda h: torch.tanh(h @ W.T + x @ U.T + b)
    h = h_init.clone().requires_grad_(True)         # (B, n) states from real runs
    opt = torch.optim.Adam([h], lr=lr)
    for _ in range(steps):
        q = 0.5 * ((F(h) - h) ** 2).sum(dim=1)      # squared speed of each point
        opt.zero_grad()
        q.sum().backward()
        opt.step()
    h = h.detach()
    q = 0.5 * ((F(h) - h) ** 2).sum(dim=1)
    eigs = [torch.linalg.eigvals(torch.autograd.functional.jacobian(F, hi))
            for hi in h[q < 1e-8]]                  # stability of each fixed point
    return h, q, eigs

A minimal fixed-point finder for a one-layer nn.RNN with tanh units. Candidates with qq near zero are fixed points; eigenvalues of the Jacobian inside the unit circle mark stable directions. In practice one also merges duplicate points and keeps slow points with small nonzero qq.

The 3-bit flip-flop. A network receives three input channels of brief ±1\pm1 pulses at random times and must hold on each of three outputs the sign of the last pulse on the matching input, ignoring the other channels: 23=82^3=8 memories. Sussillo & Barak trained a 1,000-unit network on it with the FORCE algorithm, minimized qq from 600 states sampled along its trajectories, and found 26 distinct fixed points. Eight were stable, one at each memory, arranged like the corners of a cube when plotted in the top three principal components. Between them lay saddles with exactly one unstable direction: a pulse pushes the state across a saddle's stable manifold, and the unstable direction carries it into the neighboring memory. Two further fixed points had four unstable directions. Nobody designed this structure, and unlike a hand-built attractor network it sometimes had more than one saddle between the same two memories.

Check your understanding

Why can't you find the flip-flop's saddles by simply running the trained network, forward or backward in time, from many starting states?

  1. Saddles are not fixed points, so no method finds them
  2. Forward runs converge to attractors and backward runs to repellers; a saddle repels along some direction in both time directions, so generic trajectories leave it, while minimizing qq finds fixed points of any stability
  3. The network is too large to simulate
  4. Saddles exist only in continuous time
Show the answer

B. Forward runs converge to attractors and backward runs to repellers; a saddle repels along some direction in both time directions, so generic trajectories leave it, while minimizing qq finds fixed points of any stability

A saddle has both contracting and expanding directions. Running time forward, trajectories near it escape along the expanding direction; running time backward, they escape along the contracting one. qq vanishes at every fixed point whatever its stability, so descending on qq can land on a saddle.

Line attractors and evidence integration

A sentiment classifier reads a review word by word and is scored only on its final state. Maheswaranathan, Williams, Golub, Ganguli & Sussillo (2019) applied the fixed-point method to LSTMs, GRUs and vanilla RNNs trained on several sentiment datasets, and found the same mechanism each time: an approximate line attractor. The slow points formed a one-dimensional curve; linearized around them, the dynamics had a single eigenvalue very close to 1, pointing along the curve, while every other mode decayed quickly. The readout was aligned with the line, and each word pushed the state along it by an amount set by its valence. Eigen-decomposing the linearized dynamics shows why that structure is an integrator.

DerivationEach mode is a leaky accumulator
  1. δt=Jδt−1+bt,ci,t=ℓi⊤δt ⟹ ci,t=λi ci,t−1+ℓi⊤bt\boldsymbol\delta_{t}=J\boldsymbol\delta_{t-1}+\mathbf b_t,\qquad c_{i,t}=\boldsymbol\ell_i^\top\boldsymbol\delta_t\ \Longrightarrow\ c_{i,t}=\lambda_i\,c_{i,t-1}+\boldsymbol\ell_i^\top\mathbf b_t

    Near a slow point, the input of word tt enters through some vector bt\mathbf b_t. Diagonalize J=∑iλiriℓi⊤J=\sum_i\lambda_i\mathbf r_i\boldsymbol\ell_i^\top with right and left eigenvectors normalized so that ℓi⊤rj=δij\boldsymbol\ell_i^\top\mathbf r_j=\delta_{ij}:

  2. ci,T=∑t=1Tλi T−t ℓi⊤btc_{i,T}=\sum_{t=1}^{T}\lambda_i^{\,T-t}\,\boldsymbol\ell_i^\top\mathbf b_t

    Each mode is a one-dimensional leaky accumulator of its own projection of the inputs, starting from ci,0=0c_{i,0}=0:

  3. λ1≈1:c1,T≈∑t=1Tℓ1⊤bt(total evidence)\lambda_1\approx1:\qquad c_{1,T}\approx\sum_{t=1}^T\boldsymbol\ell_1^\top\mathbf b_t\quad(\text{total evidence})

    A mode with ∣λi∣≪1\abs{\lambda_i}\ll1 remembers only the last few words. The mode with λ1≈1\lambda_1\approx1 simply adds up every word's contribution, with a memory of about 1/(1−λ1)1/(1-\lambda_1) steps. If the readout looks along r1\mathbf r_1, the classifier computes a sum of per-word valences, close to a bag-of-words counter, built from recurrent dynamics.

Universality. In a companion study the same authors trained thousands of vanilla, LSTM, GRU and other recurrent networks on tasks drawn from neuroscience (Maheswaranathan et al., 2019). The geometry of the learned representations, compared with standard similarity measures such as canonical correlation analysis, varied a great deal across architectures. The topology, meaning the number of fixed points, their stability and how transitions connect them, and key properties of the linearized dynamics, was far more consistent. One caveat: when a task forces one stable point per condition, matching topologies may reflect the task more than the architecture. The approach comes from neuroscience, where the same tools are used to interpret recordings from populations of neurons as computation through dynamics (Vyas, Golub, Sussillo & Shenoy, 2020); Mante et al. (2013), for instance, trained a network on the same context-dependent decision task as monkeys, found that its activity resembled recordings from prefrontal cortex, and reverse-engineered it: approximate line attractors integrated the evidence, and the context determined which input was integrated.

Reservoirs and the edge of chaos

What if the recurrent weights are never trained at all? An echo state network (Jaeger, 2001) drives a large, fixed, random recurrent network, the reservoir, with the input and trains only a linear readout of its states, by ridge regression. Liquid state machines (Maass, Natschläger & Markram, 2002) are the spiking-neuron counterpart. Training is a single least-squares solve, which made reservoir computing attractive in the 2000s, when training recurrent weights by gradient descent was still hard. It works only if the reservoir forgets where it started: its state must become a function of the recent input history alone.

DerivationProof
  1. ∥ht−ht′∥=∥tanh⁡(Wht−1+Uxt)−tanh⁡(Wht−1′+Uxt)∥≤∥W(ht−1−ht−1′)∥≤σmax⁡(W) ∥ht−1−ht−1′∥\lVert\mathbf h_t-\mathbf h'_t\rVert=\lVert\tanh(W\mathbf h_{t-1}+U\mathbf x_t)-\tanh(W\mathbf h'_{t-1}+U\mathbf x_t)\rVert\le\lVert W(\mathbf h_{t-1}-\mathbf h'_{t-1})\rVert\le\sigma_{\max}(W)\,\lVert\mathbf h_{t-1}-\mathbf h'_{t-1}\rVert

    (a) tanh is 1-Lipschitz in each coordinate, so it does not increase Euclidean distances. Two trajectories with the same input therefore contract by at least σmax⁡(W)\sigma_{\max}(W) per step:

  2. ∥ht−ht′∥≤σmax⁡(W)t ∥h0−h0′∥ ⟶ 0\lVert\mathbf h_t-\mathbf h'_t\rVert\le\sigma_{\max}(W)^{t}\,\lVert\mathbf h_0-\mathbf h'_0\rVert\ \longrightarrow\ 0

    Iterating gives geometric convergence for every input sequence, whatever the two starting states:

  3. (b) With zero input, h=0\mathbf h=\mathbf 0 is a fixed point with Jacobian WW, since tanh⁡′(0)=1\tanh'(0)=1. If ρ(W)>1\rho(W)>1 it is unstable: a trajectory started at 0\mathbf 0 stays there, while one started nearby moves away along an expanding direction, and the two never converge.

For a random WW with independent N(0,g2/n)\mathcal N(0,g^2/n) entries, the eigenvalues fill the disk of radius gg as n→∞n\to\infty (the circular law), so gg sets the spectral radius. In the continuous-time version of such networks, Sompolinsky, Crisanti & Sommers (1988) showed with a dynamic mean-field analysis that the large-nn limit has a sharp transition: for g<1g<1 activity decays to a stable fixed point, for g>1g>1 it becomes chaotic. Driven reservoirs show their richest computation near this boundary: Bertschinger & Natschläger (2004) found that randomly connected threshold networks perform complex computations on time series only near the transition between ordered and chaotic dynamics, the edge of chaos. The same notion of criticality governs signal propagation through deep feed-forward networks (the backprop topic's Criticality & Finite-Width Effects).

Key takeaways

  • With the input held fixed, an RNN is a map FF; near a fixed point deviations evolve by J=diag⁡(ϕ′(a∗))WJ=\operatorname{diag}(\phi'(\mathbf a^*))W. All eigenvalues inside the unit circle mean stability, one outside means instability, and mixed moduli make a saddle; h↦tanh⁡(wh)h\mapsto\tanh(wh) turns into a one-bit memory through a pitchfork bifurcation at w=1w=1.
  • Minimizing q(h)=12∥F(h)−h∥2q(\mathbf h)=\tfrac12\lVert F(\mathbf h)-\mathbf h\rVert^2 finds fixed and slow points of trained networks. In the 3-bit flip-flop, 8 attractors store the memories and one-unstable-direction saddles mediate the transitions (Sussillo & Barak, 2013).
  • Sentiment RNNs integrate evidence along an approximate line attractor with one eigenvalue near 1; each linearized mode is a leaky accumulator ci,T=∑tλiT−tℓi⊤btc_{i,T}=\sum_t\lambda_i^{T-t}\boldsymbol\ell_i^\top\mathbf b_t. Fixed-point topology is more universal across architectures than representational geometry.
  • An untrained random reservoir with a trained readout works if it has the echo state property: σmax⁡(W)<1\sigma_{\max}(W)<1 suffices, ρ(W)>1\rho(W)>1 breaks it for zero input. Random networks change from ordered to chaotic near spectral radius 1, and driven networks compute best near that edge.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A fixed point of a trained RNN has Jacobian eigenvalues of modulus 0.50.5, 0.90.9 and 1.31.3. What is it?

  1. A stable fixed point, because most eigenvalues are inside the unit circle
  2. A line attractor
  3. A saddle: unstable, attracting along two directions and repelling along the third; such points can route the state from one memory to another
  4. Undecidable without simulation, because one eigenvalue exceeds 1
Show the answer

C. A saddle: unstable, attracting along two directions and repelling along the third; such points can route the state from one memory to another

One eigenvalue outside the unit circle makes the fixed point unstable, and the two inside make it attracting along their directions: a saddle. In the 3-bit flip-flop such one-unstable-direction saddles sit between memories and mediate the transitions.

Question 2

Minimizing q(h)=12∥F(h)−h∥2q(\mathbf h)=\tfrac12\lVert F(\mathbf h)-\mathbf h\rVert^2 ends at a point where qq is small but not zero. How should you use it?

  1. As a slow point: the state moves very little there, so the linearization around it can still explain the network's behavior locally
  2. Discard it: only exact fixed points carry information
  3. As proof that the optimizer failed to converge
  4. As an unstable fixed point, since q>0q>0
Show the answer

A. As a slow point: the state moves very little there, so the linearization around it can still explain the network's behavior locally

Sussillo & Barak's point is that slow points, where the network barely moves, also organize the computation. Over the time the state spends there, the dynamics are well approximated by an affine map, which can be analyzed like a fixed point's linearization.

Question 3

Linearized along its line attractor, a sentiment RNN has one eigenvalue 0.9990.999 and all others below 0.50.5 in modulus. What does it compute, approximately?

  1. It remembers only the last two words of the review
  2. It stores the exact sequence of words
  3. It oscillates with a period of about 1,000 words
  4. It adds up each word's contribution along the line, a running total of evidence with a memory of about 1,000 steps, while forgetting other information within a few words
Show the answer

D. It adds up each word's contribution along the line, a running total of evidence with a memory of about 1,000 steps, while forgetting other information within a few words

The mode with λ≈0.999\lambda\approx0.999 is a leaky accumulator with time constant 1/(1−λ)=1,0001/(1-\lambda)=1{,}000 steps, while modes with ∣λ∣<0.5\abs\lambda<0.5 halve at every step. The readout along the line reports the accumulated valence.

Question 4

Which statement about the echo state property of ht=tanh⁡(Wht−1+Uxt)\mathbf h_t=\tanh(W\mathbf h_{t-1}+U\mathbf x_t) is correct?

  1. A spectral radius ρ(W)<1\rho(W)<1 guarantees it for every input sequence
  2. A largest singular value σmax⁡(W)<1\sigma_{\max}(W)<1 guarantees it for every input sequence
  3. It holds only if WW is trained by gradient descent
  4. It requires W=0W=0
Show the answer

B. A largest singular value σmax⁡(W)<1\sigma_{\max}(W)<1 guarantees it for every input sequence

tanh is 1-Lipschitz, so two trajectories under the same input contract by σmax⁡(W)\sigma_{\max}(W) per step. The spectral radius condition is weaker: ρ(W)>1\rho(W)>1 destroys the property for zero input, but ρ(W)<1\rho(W)<1 does not guarantee it for all inputs.

Further reading

  • D. Sussillo & O. Barak, "Opening the black box: Low-dimensional dynamics in high-dimensional recurrent neural networks," Neural Computation 25(3), 626–649 (2013).
  • N. Maheswaranathan, A. H. Williams, M. D. Golub, S. Ganguli & D. Sussillo, "Reverse engineering recurrent networks for sentiment classification reveals line attractor dynamics," NeurIPS (2019).
  • N. Maheswaranathan, A. H. Williams, M. D. Golub, S. Ganguli & D. Sussillo, "Universality and individuality in neural dynamics across large populations of recurrent networks," NeurIPS (2019).
  • H. Jaeger, "The 'echo state' approach to analysing and training recurrent neural networks," GMD Report 148, German National Research Center for Information Technology (2001).
  • S. Vyas, M. D. Golub, D. Sussillo & K. V. Shenoy, "Computation through neural population dynamics," Annual Review of Neuroscience 43, 249–275 (2020).