Linear approximations to HMM filtering

Andrew Mah, Joshua L. Pughe-Sanford, Sarah E Harvey, Alex H WilliamsNeurIPS 2026

TL;DR

When massive sequence models like Transformers predict the next token, they often appear to build intricate internal maps of hidden probabilities—a feat typically assumed to require deep, nonlinear magic. This paper reveals that a humble recurrent neural network with purely linear dynamics and a standard softmax readout can learn nearly identical probability representations. By mathematically proving when linear systems can—and cannot—fake nonlinear Bayesian inference, the authors draw a crisp boundary between tasks that genuinely demand complex architectures and benchmarks that are secretly solvable by simple linear algebra.

What Problem Does This Paper Address?

Imagine listening to a muffled conversation through a wall. To guess the next word, your brain maintains a belief state: a running probability distribution over what topic is currently being discussed, updated with every new sound. In mathematics, when sequences are generated by Hidden Markov Models (HMMs—systems where underlying states transition invisibly while emitting observable tokens), tracking this belief state optimally requires Bayesian filtering, an inherently nonlinear process.

Recently, mechanistic interpretability researchers noticed something thrilling: Transformers and deep State Space Models (SSMs) trained on next-token prediction spontaneously organize their internal activations into beautiful fractal geometries that mirror these exact Bayesian belief states.

Linear RNNs learn the exact same fractal belief state geometry as optimal Bayesian filters and Transformers on the Mess3 HMM.

There is just one catch: Mah et al. noticed that a single-layer linear RNN—a bare-bones network whose hidden state evolves via simple matrix addition ($h_t = F h_{t-1} + G u_t$) before passing through a static softmax readout—produces the exact same fractal geometry! This raises a fundamental question: When is linear recurrence actually enough to approximate nonlinear Bayesian filtering, and when do we truly need expressive, nonlinear architectures?

Methods

Bayesian filtering in an HMM is a tug-of-war between two steps:

  1. Conditioning: Updating beliefs based on a new observation (multiplicative in probability space).
  2. Updating: Shifting beliefs forward in time via the HMM's transition matrix $T$ (additive/linear in probability space).

Because a softmax readout exponentiates the RNN's hidden states, the linear RNN naturally operates in log-probability space. Here, addition becomes multiplication! This makes the conditioning step trivial for a linear RNN, while the linear transition update becomes stubbornly nonlinear.

To analyze how well a linear RNN handles this trade-off, the authors:

  • Characterize Exact Solutions: Using algebraic constraints, they derive the exact family of RNN weights ("the solution family") capable of perfectly integrating the Bayesian filter across all positive priors.
  • Bound Approximation Error: For general HMMs where exact integration is impossible, they measure error in log-space using a projective metric called the Hilbert distance (which neatly upper-bounds KL divergence). Using the Birkhoff contraction coefficient ($c \in [0, 1]$, a measure of how aggressively a matrix squeezes different probability vectors together), they prove a dissipation relation showing how step-by-step approximation errors accumulate or decay over time.

Datasets

Rather than relying on natural language corpora, the authors evaluate their theory on controlled synthetic sequence benchmarks where ground-truth Bayesian posteriors can be calculated exactly:

  • Mess3 HMM: A 3-state HMM benchmark from recent Transformer interpretability literature used to visualize fractal belief geometries.
  • Unstructured Random HMMs: 150 HMMs with 16 or 32 states, whose transition and emission matrices are sampled from Dirichlet distributions with varying sparsity ($\beta_T, \beta_E \in [0.01, 1]$).
  • Adversarial Clustered HMMs: Newly constructed hierarchical HMMs divided into $K$ distinct cliques of states. By tuning an interpolation parameter $\epsilon_T \in [0, 1]$, these models range from fully connected graphs to isolated clusters that trap the system in coherent modes for long periods—mimicking real-world domains like topic dynamics or navigation.

Key Insights and Ideas

  • Exact linear filtering is exceedingly rare: A linear RNN with a softmax readout can exactly compute the Bayesian filter over all positive priors if and only if the HMM's transition matrix $T$ is either a permutation matrix (deterministic routing) or a dense rank-one matrix (total memory reset at every step).
  • Two mechanisms make nonlinear filtering "look" linear: Even though almost no HMMs are exactly integrable, linear RNNs approximate many of them shockingly well thanks to two forgiving regimes:
  • Fast Contraction (Small $c_T$): If the HMM mixes states quickly ($c_T \to 0$), past approximation errors are rapidly forgotten rather than compounded. Conversely, near-permutation matrices ($c_T \to 1$) integrate tiny perturbations over long horizons, causing errors to blow up.
  • Uniform Beliefs (Small $c_E$): When observations are noisy/weakly informative ($c_E \to 0$) and transitions are roughly doubly stochastic, beliefs hover near the uniform distribution—a mathematical sweet spot where the softmax-commutation error drops to zero.
Figure 2: Approximation error landscape across parameters in a two-state HMM. A. Instanta- neous error, st, Equation 12, over τ and p from Equation 13. B–C Time-averaged error, ℓt, from Equation 15, computed with p0 = ˆp0 = (1/2, 1/2)⊤plotted (B) over τ and ϵ from Equation 13 and (C) over τ1 and τ2 at fixed ϵ = .45. The color scale is logarithmic and shared across all panels.
  • Benchmarking Caveat: Many random HMMs used in recent literature to celebrate "emergent Bayesian inference" in Transformers sit squarely inside these two forgiving regimes—meaning simple linear dynamics already do most of the heavy lifting.

Key Results

  • Mess3 Geometry & Accuracy: On the Mess3 task, a trained linear RNN achieves a next-token KL divergence of $8.3 \times 10^{-6}$, learning weight matrices within 7% relative error of the authors' analytical solution family.
  • Random HMMs: Across 150 random HMMs, single-layer linear RNNs match the Bayes-optimal next-token predictor with a median KL divergence of $1.55 \times 10^{-3}$. Linearly decoding the true log-belief states from RNN activations yields an average KL divergence of 0.09 (vs. 0.27 for untrained networks), correlating tightly with prediction performance ($r = 0.986$). As predicted, error spikes significantly when sparsity pushes $c_T$ or $c_E$ to $1$ ($p = 1.05 \times 10^{-18}$).
  • A Surprise in Clustered HMMs: As clusters become isolated ($c_T \to 1$), linear RNN performance degrades as expected—until clusters are completely disconnected and emissions are highly informative ($\epsilon_T = \epsilon_E = 1$), where error suddenly drops! The RNN learns a clever two-stage shortcut: it uses the first few tokens to identify which cluster it is in, reducing the remaining sequence to an easy, fast-mixing sub-problem.

Limitations and Future Work

  • Counterfactual Generalization vs. Shortcuts: The mathematical proofs require the RNN to track beliefs from every strictly positive prior. As seen in bespoke and clustered HMMs, if beliefs are confined to a lower-dimensional subset of the probability simplex, linear RNNs can exploit "shortcut" solutions not captured by the general theory.
  • Zero Probabilities: Because finite inputs to a softmax function strictly output positive numbers, softmax-RNNs fundamentally struggle to represent exact zero probabilities on the boundary of the simplex.
  • Single-Layer Scope: The study analyzes single-layer networks with softmax readouts. Exploring alternative readouts and stacking linear layers with static nonlinearities—the exact recipe behind modern deep SSMs and Linear Recurrent Units (LRUs)—remains an exciting next step, particularly for tackling hierarchical, clustered environments.

Summary updated

Abstract

Complex sequence models, such as transformers and state space models (SSMs), learn to represent latent belief states when trained on next-token prediction. Surprisingly, we find that in previously studied tasks, this phenomenon can also be captured by linear recurrent models. This raises a natural question: when are linear models sufficient for optimal belief state approximation? We study this question in the canonical setting of hidden Markov models (HMMs), where Bayes-optimal prediction requires nonlinear filtering. We characterize the full class of HMMs whose filtering dynamics are exactly realizable by linear recurrent neural networks (RNNs). More generally, for arbitrary HMMs, we establish a dissipation relation which shows that approximation error decays at a rate determined by intrinsic properties of the underlying HMM. We validate our theoretical results through experiments on both randomly sampled HMMs and constructed adversarial examples. Together, these findings clarify when linear sequence models suffice for optimal inference and when nonlinearity is fundamentally necessary.
BibTeX
@inproceedings{mah2026linear,
  author = {Andrew Mah and Joshua L. Pughe-Sanford and Sarah E Harvey and Alex H Williams},
  title = {{Linear approximations to HMM filtering}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=9ETaeeas7a},
}
Figure