Diffusion Language Models › What the Network Must Predict

Michael BrenndoerferNovember 17, 20268 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 136Diffusion Language Models › What the Network Must Predict
Reading section 4 of 13 · What the Network Must Predict · 8 minSection 4 of 13 · 8 min

Section 4 of 13 · 8 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The derivation uses three distinct distributions. The first is the per-position conditional given only that a position is masked. The second is the joint posterior given the entire masked state. The third consists of the per-position marginals predicted by the network.

The token conditional is uninformative

Suppose you observe only that position ii is masked at a step with positive mask probability. Bayes’ rule gives the original token distribution at that position:

q(x0i=v∣xti=m)=q(xti=m∣x0i=v) q(x0i=v)∑v′q(xti=m∣x0i=v′) q(x0i=v′).q(x_0^i = v \mid x_t^i = m) = \frac{q(x_t^i = m \mid x_0^i = v)\,q(x_0^i = v)}{\sum_{v'} q(x_t^i = m\mid x_0^i = v')\,q(x_0^i = v')}.

where:

  • vv, v′v': candidate real tokens in the vocabulary VV
  • q(x0i=v)q(x_0^i = v): the prior probability (unigram marginal) of token vv at position ii
  • q(xti=m∣x0i=v)q(x_t^i = m \mid x_0^i = v): the probability position ii is masked at time tt given the true token vv

The likelihood term q(xti=m∣x0i=v)q(x_t^i = m \mid x_0^i = v) equals 1−αˉt1-\bar\alpha_t for every vv, because masking is independent of content. It cancels:

q(x0i=v∣xti=m)=q(x0i=v).q(x_0^i = v \mid x_t^i = m) = q(x_0^i = v).

The mask at one position alone gives the position’s marginal token distribution. In the full corrupted sequence, the visible tokens provide information about the missing values. The set of masks tells the model which information is missing.

The joint posterior carries the information

The useful object is the joint posterior over the entire clean sequence given the whole masked state xtx_t, including which positions are visible and what they contain:

q(x0∣xt)=q(xt∣x0) pdata(x0)∑x0′q(xt∣x0′) pdata(x0′).q(x_0 \mid x_t) = \frac{q(x_t \mid x_0)\,p_{\text{data}}(x_0)}{\sum_{x_0'} q(x_t \mid x_0')\,p_{\text{data}}(x_0')}.

The forward likelihood is zero for a clean candidate inconsistent with any visible position. For every consistent x0x_0, the factor q(xt∣x0)=(1−αˉt)∣S∣αˉtL−∣S∣q(x_t\mid x_0)=(1-\bar\alpha_t)^{|S|}\bar\alpha_t^{L-|S|} is common and cancels whenever the observed partial state has positive mass. Each surviving candidate still contributes its own prior probability:

q(x0∣xt)∝pdata(x0)⋅1 ⁣[x0Sˉ=xtSˉ].q(x_0 \mid x_t) \propto p_{\text{data}}(x_0)\cdot\mathbb{1}\!\left[x_0^{\bar S} = x_t^{\bar S}\right].

The joint posterior is just the data distribution restricted to the strings consistent with the visible positions, renormalized. In the worked example below, this is an explicit finite table we can compute exactly. The formula is worth examining, because it says that the masked state acts as a hard constraint: it rules out every string that disagrees with what is visible, and reweights the survivors by their prior probability. All the context in the visible positions enters through that indicator, and none of it enters through the mask rate.

The posterior has at most K∣S∣K^{|S|} nonzero entries. With 50,000 lexical tokens and ten masked positions, an exhaustive table over the candidates has 500001050000^{10} rows. The model below represents one categorical distribution per masked position.

The model is a mean-field approximation to the joint

A network outputs one categorical distribution per position. On a possible partial state, use the product of its masked-position predictions as an approximation to the clean joint posterior:

q(x0∣xt)≈1 ⁣[x0Sˉ=xtSˉ]∏i∈Sfθi(x0i∣xt).q(x_0 \mid x_t) \approx \mathbb{1}\!\left[x_0^{\bar S}=x_t^{\bar S}\right]\prod_{i\in S} f_\theta^i(x_0^i\mid x_t).

The product on the right defines a normalized distribution over clean completions. The visible tokens are fixed. With the population masked-token loss and a model that can represent the true marginals, each predicted factor can match its context-conditioned marginal. The product still represents missing positions independently within that update.

Mean-field gap

Positions revealed in the same step are sampled independently under this reverse transition. Even exact marginals can produce a jointly inconsistent combination, such as a singular subject with a plural verb. At fixed length under a finer linear schedule, simultaneous reveals become less likely.

Revealing one position per step removes the need to approximate dependencies within a reveal group. If the decoder uses exact data conditionals and a fixed or independently sampled reveal order, the chain rule recovers the data distribution. Learned prediction errors and a reveal policy that selects among sampled token values can still change the output law.

The reverse step

Now we can write the reverse transition. Consider a position masked at time tt. Given the true token x0i=vx_0^i = v, what is the distribution of the previous state? Two cases, both computed by Bayes:

q(xt−1i=v∣xti=m,x0i=v)=βtαˉt−11−αˉt,q(xt−1i=m∣xti=m,x0i=v)=1−αˉt−11−αˉt.q(x_{t-1}^i = v \mid x_t^i = m, x_0^i = v) = \frac{\beta_t \bar\alpha_{t-1}}{1-\bar\alpha_t}, \qquad q(x_{t-1}^i = m \mid x_t^i = m, x_0^i = v) = \frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}.

The two sum to one, as they must: βtαˉt−1+1−αˉt−1=1−αˉt−1(1−βt)=1−αˉt\beta_t\bar\alpha_{t-1} + 1 - \bar\alpha_{t-1} = 1 - \bar\alpha_{t-1}(1-\beta_t) = 1-\bar\alpha_t. The first expression is the probability that the position was visible at t−1t-1 and got masked at step tt, divided by the probability it is masked at tt; the second is the probability it was already masked at t−1t-1, again normalized. The first numerator uses the masking probability conditional on survival to the previous step. Define

ρt=1−αˉt−11−αˉt,rt=1−ρt=αˉt−1−αˉt1−αˉt.\rho_t = \frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}, \qquad r_t = 1 - \rho_t = \frac{\bar\alpha_{t-1}-\bar\alpha_t}{1-\bar\alpha_t}.

Here ρt\rho_t is the probability of staying masked, and rtr_t is the probability of being revealed at this step. Replacing the unknown x0ix_0^i with the model's prediction gives the generative reverse step for masked positions:

pθ(xt−1i=v∣xt)=rt fθi(v∣xt)+ρt 1[v=m].p_\theta(x_{t-1}^i = v \mid x_t) = r_t\, f_\theta^i(v\mid x_t) + \rho_t\,\mathbb{1}[v = m].

Positions that are already visible are copied unchanged with probability one. This is a proper distribution over Vˉ\bar V: the mask mass plus the token mass sums to 11. The model predicts fθi(v∣xt)f_\theta^i(v\mid x_t) on the KK lexical tokens. Extend it by setting fθi(m∣xt)=0f_\theta^i(m\mid x_t)=0 in the displayed equation. The term with ρt\rho_t supplies the remaining mass on mm. Notice the structure: with probability rtr_t the position is revealed and its value is drawn from the model's prediction, and with probability ρt\rho_t it stays masked. The unknown clean token has been integrated out and replaced by the model's belief about it, which is the only place the network enters the reverse chain.

Two structural observations follow immediately, and both matter in practice.

At step tt, each of the nmaskedn_{\text{masked}} masked positions independently reveals with probability rtr_t. The number revealed is therefore Binomial(nmasked,rt)\mathrm{Binomial}(n_{\text{masked}},r_t). In the exact reverse data process, the reveal times are independent of the final lexical sequence because the forward masks were drawn independently of that sequence. The learned product sampler still draws reveal decisions without consulting lexical predictions. Which positions reveal together can affect its final lexical distribution, as the two-token example shows.

The binomial spread is worth examining directly, because it makes the mean-field risk concrete: a step can reveal several positions at once, and those positions are then sampled independently.

PythonIn [2]
CollapseExpand
import math

import numpy as np

reveal_n = 6
reveal_r = 1 / 3
reveal_counts = np.arange(reveal_n + 1)
reveal_pmf = np.array(
    [
        math.comb(reveal_n, int(x))
        * reveal_r ** int(x)
        * (1 - reveal_r) ** (reveal_n - int(x))
        for x in reveal_counts
    ]
)
VisualizationOut [4]
CollapseExpand
Bar chart shows binomial probabilities for the number of positions revealed in one step.
Binomial distribution of the number of masked positions revealed at one reverse step, with six masked positions and a reveal probability of one third. The distribution assigns positive probability to two or more reveals.

Every position is revealed exactly once. Summing the unconditional reveal probability over all steps gives ∑t(αˉt−1−αˉt)=αˉ0−αˉT=1\sum_t (\bar\alpha_{t-1}-\bar\alpha_t) = \bar\alpha_0 - \bar\alpha_T = 1. Nothing is revealed twice, and nothing is left over. The telescoping sum is a direct consequence of the schedule running from αˉ0=1\bar\alpha_0 = 1 to αˉT=0\bar\alpha_T = 0, and it is what makes the reverse chain a valid generative process rather than merely a sequence of partial repairs.

With the linear schedule αˉk=1−k/T\bar\alpha_k = 1 - k/T and TT steps, these quantities collapse to something you can compute in your head: at step kk (counting k=T,T−1,…,1k = T, T-1, \dots, 1 in the reverse direction) the reveal probability is exactly 1/k1/k. At the last step everything remaining is revealed at once. To see the 1/k1/k, substitute αˉk−1=1−(k−1)/T\bar\alpha_{k-1} = 1-(k-1)/T and αˉk=1−k/T\bar\alpha_k = 1-k/T into the definition of rtr_t: the numerator is 1/T1/T and the denominator is k/Tk/T, so the ratio is 1/k1/k. This is the schedule used throughout the worked example and the implementation, and it is why the loss weight in those sections takes the simple form it does.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy