Manuscript Offprint

arXiv:2610.12741

Neural expectation-maximization and meta-models

Zhuolin Fu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

We interpret Transformer networks as learned approximations to a hybrid probabilistic-inference procedure that combines max-product Loopy Belief Propagation (LBP) with Expectation–Maximization (EM). In this view, a Transformer performs inference in partially observed Markov Random Fields (MRFs) whose structure and parameters are not given a priori but are inferred from data. We show that self-attention implements a differentiable approximation to max-product LBP on an input-conditioned, dynamically structured MRF, with attention weights encoding learned structural affinities. We further establish an EM correspondence at the level of depth: each layer updates latent representations in an E-step-like forward pass, while the transition θ(l)→θ(l+1)\theta^{(l)} \to \theta^{(l+1)} across layers acts as an implicit M-step. Building on this interpretation, we introduce meta-models, a design paradigm in which inputs generate instance-specific parameters, unifying mechanisms such as self-attention, mixture-of-experts, and gated units within a single framework. Empirical results support the proposed perspective.

Keywords Self-attention · Transformer · Loopy Belief Propagation · Expectation-Maximization · Meta-Model

1 Introduction

Figure

Figure 1: Expectation-Maximization interpretation of DNNs. A layer corresponds to an iteration of the EM. The forward pass corresponds to the E-step. The transition from parameter θ′\theta' to the next layer θ\theta implicitly corresponds to the M-step.

Figure

Figure 2: Illustration of a meta-model. The input vector x first interacts with the 3D meta-parameter Θ\Theta and outputs the 2D parameter θ\theta. Then, x interacts with θ\theta and produces the output z. Meta-model is what makes a model capable of in-context learning. Self-attention, MoE, GLUs, etc. are members of meta-models.

Transformers have become the dominant architecture for modern sequence modeling, language understanding, and large-scale generative modeling since the introduction of self-attention [26]. Despite their empirical success, the internal computation performed by a Transformer remains difficult to characterize in algorithmic terms. A growing body of work has therefore shifted from treating Transformers as black-box function approximators toward explaining what their layers, attention heads, and residual streams compute [8, 22]. This paper contributes to that line of work by asking whether Transformer computation can be understood as a familiar inference procedure rather than as a collection of isolated architectural mechanisms.

Existing explanations illuminate important aspects of Transformer behavior, but they remain partial. Studies of in-context learning show that Transformers can implement gradient-descent-like or Bayesian updates; and message-passing views relate attention to graph computation [1, 5, 28, 27]. However, these perspectives do not fully account for how self-attention, depth, latent-variable refinement, graph-structure selection, and layerwise parameter changes fit into a single probabilistic picture.

We propose such an interpretation by viewing Transformers as neuralized Expectation-Maximization. Under this view, the underlying model is a partially observed Markov Random Field (MRF) with both unknown structure and parameters. Self-attention approximates Loopy Belief Propagation (LBP) over a dynamically inferred graph structure, where the attention between two tokens acts as the soft connection strength within such MRF and the value vector acts as the maximizer of the aggregated message (aka. belief). Successive layers play the role of Expectation-Maximization (EM) iterations [7, 29, 16] for parameter learning. Specifically, a layer of a Transformer corresponds to an iteration of the EM. The forward pass of a layer corresponds to the E-step, where the latent variables are updated based on the last iteration. The change from the parameters θ(l)\theta^{(l)} of layer ll to θ(l+1)\theta^{(l+1)} of the next layer implicitly corresponds to the M-step, where the parameters are updated.

This paper makes the following contributions:

• We derive a correspondence between self-attention and approximate LBP on a dynamically structured MRF, where attention weights act as learned structural affinities and values approximate individual message maximizers.

• We interpret the depth of a Transformer as an EM-like iterative procedure in which the forward pass updates latent variables and the transition between layer parameters corresponds to parameter refinement.

• We use this EM perspective to motivate meta-models, a design paradigm in which the parameters θ\theta of a forward pass are generated from the input by meta-parameters Θ\Theta.

• We show that self-attention, Mixture-of-Experts layers, gated mechanisms, LSTM, and selective state-space models can be viewed as members or close relatives of this meta-model principle.

References (32)