Diffusion Language Models › What the Network Must Predict
Language AI HandbookAll chapters 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 is masked at a step with positive mask probability. Bayes’ rule gives the original token distribution at that position:
where:
- , : candidate real tokens in the vocabulary
- : the prior probability (unigram marginal) of token at position
- : the probability position is masked at time given the true token
The likelihood term equals for every , because masking is independent of content. It cancels:
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 , including which positions are visible and what they contain:
The forward likelihood is zero for a clean candidate inconsistent with any visible position. For every consistent , the factor is common and cancels whenever the observed partial state has positive mass. Each surviving candidate still contributes its own prior probability:
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 nonzero entries. With 50,000 lexical tokens and ten masked positions, an exhaustive table over the candidates has 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:
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.
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 . Given the true token , what is the distribution of the previous state? Two cases, both computed by Bayes:
The two sum to one, as they must: . The first expression is the probability that the position was visible at and got masked at step , divided by the probability it is masked at ; the second is the probability it was already masked at , again normalized. The first numerator uses the masking probability conditional on survival to the previous step. Define
Here is the probability of staying masked, and is the probability of being revealed at this step. Replacing the unknown with the model's prediction gives the generative reverse step for masked positions:
Positions that are already visible are copied unchanged with probability one. This is a proper distribution over : the mask mass plus the token mass sums to . The model predicts on the lexical tokens. Extend it by setting in the displayed equation. The term with supplies the remaining mass on . Notice the structure: with probability the position is revealed and its value is drawn from the model's prediction, and with probability 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 , each of the masked positions independently reveals with probability . The number revealed is therefore . 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]Expand
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]Expand

Every position is revealed exactly once. Summing the unconditional reveal probability over all steps gives . Nothing is revealed twice, and nothing is left over. The telescoping sum is a direct consequence of the schedule running from to , and it is what makes the reverse chain a valid generative process rather than merely a sequence of partial repairs.
With the linear schedule and steps, these quantities collapse to something you can compute in your head: at step (counting in the reverse direction) the reveal probability is exactly . At the last step everything remaining is revealed at once. To see the , substitute and into the definition of : the numerator is and the denominator is , so the ratio is . 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!