Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Masked Diffusion Language Models: Denoising Loss as a Likelihood Surrogate

Welcome back. Last time, you saw that the denoiser trains on masked clean text but generates from states shaped by its own earlier predictions. Today we’ll look at what its training loss actually measures. The central distinction is between predicting the next token of a sequence and predicting missing tokens at many noise levels. That distinction explains both why your mini diffusion model can generate text and why its loss is not an ordinary next-token likelihood.


A likelihood you can calculate left to right

For an autoregressive model, the probability assigned to a sequence is built from next-token probabilities:

Taking the logarithm turns that product into a sum. During training, you can therefore score each token given the true preceding tokens and add the scores to obtain the model’s log-likelihood for the whole sequence.

The opening of Large Language Diffusion Models states this formulation explicitly. Read only the short passage around its Equation (2):

Large Language Diffusion Models

Read the introduction of Large Language Diffusion Models for its precise definition of autoregressive likelihood.

In Section 1, “Introduction,” find the paragraph beginning “The predominant approach relies on the autoregressive modeling.” Read the formulation through the sentence immediately after Equation (2). Focus on what each probability conditions on.

A masked diffusion model is different as a model, not because the chain rule has stopped being true. Any distribution over sequences can be written as a left-to-right product by the chain rule. But your denoiser does not directly provide those next-token conditionals: it takes a partially masked sequence, may use visible context on both sides of a blank, and predicts tokens for masked positions. Generation then uses several such predictions to turn a fully masked sequence into text.

You can picture the diffusion model’s probability for a completed sentence as combining the probabilities of possible intermediate masking and unmasking paths. Those paths are hidden when you look only at the final sentence. Consequently, a call to your denoiser does not give you a term to insert into the autoregressive product above.


What the denoiser learns instead

Your training loop already has the ingredients. Take a clean sequence , choose a noise level , and independently mask each eligible position with probability . Call the resulting sequence . The model sees and predicts the original token wherever position was masked.

Sasha Rush’s Simple Diffusion Language Models connects this reconstruction task to the training objective:

Simple Diffusion Language Models

Watch “Simple Diffusion Language Models” by Sasha Rush for the intuition behind drawing a masking level, weighting reconstruction errors, and training a mask predictor.

Watch the loss ingredients, then the weighting summary. Focus on the difference between predicting an original token at a blank and predicting the next token after a prefix; you do not need to follow the continuous-time derivation.

For the simple schedule in which the masking probability equals , a standard masked-diffusion objective can be written as

Here the indicator selects only masked positions. The expression inside the sum is cross-entropy for the correct original token, not a score for the token that happens to be visible at position . In your padded batches, the indicator must also exclude padding. Each new training pass can draw a different and mask pattern from the same clean example, so the denoiser practices filling blanks with little context, much context, and amounts in between.

The paper gives both this objective and its connection to sequence likelihood. Read Section 2.1 in two short stretches:

Large Language Diffusion Models

Return to Large Language Diffusion Models to connect the mask predictor’s loss to a probabilistic generative model.

In Section 2, “Approach,” subsection 2.1, “Probabilistic Formulation,” begin with “The forward process gradually masks tokens independently.” Read the masking description through Equation (3) and its explanation. Then continue from “Once trained, we can simulate a reverse process” through the paragraph discussing Equation (4), ending with “akin to LLMs.” Read the likelihood connection. Focus on what Equation (4) bounds, rather than trying to derive it.

Under the paper’s specified reverse-process construction, its masked denoising objective is an upper bound on expected negative log-likelihood. Equivalently, its negative gives a lower bound on expected log-likelihood. This is why masked cross-entropy is a principled training surrogate: reducing it trains a model whose reverse process defines a distribution over completed sequences, without requiring you to calculate the exact probability of every sequence by summing over its possible hidden paths.

“Surrogate” does not mean “identical to likelihood.” A lower denoising loss need not translate directly into a particular improvement in the samples from your greedy, confidence-based notebook sampler. That sampler makes reveal choices differently from the stochastic reverse process used to establish the bound.


Why weight the loss by noise level?

Suppose there are four valid positions, and the average cross-entropy at a masked position is . At , you expect one masked position, so the expected sum of masked losses is . At , you expect three, so the expected sum is . Dividing each sum by its respective makes both expected weighted sums .

The point is not to force every actual mask draw to contain exactly its expected number of blanks. It is to account for the fact that higher masking rates expose more positions to the loss on average. For this linear schedule, the factor is . With a different masking schedule, the weighting associated with a likelihood-bound derivation generally changes too; it is not safe to assume that always applies.

This also clarifies how to interpret the safe loss you implemented earlier. Dividing the batch’s total masked cross-entropy by its actual number of masked tokens gives a convenient, stable average loss per masked prediction. It handles batches with different mask counts, provided the zero-mask case is handled safely. But it is not, in general, the same numerical objective as first taking each example’s sum of masked losses, weighting it by , and then averaging examples. Both can train a denoiser; only the latter, under the stated model and schedule assumptions, is the particular objective discussed in the paper.


Takeaways

An autoregressive model directly multiplies next-token probabilities to score text. A masked diffusion model instead learns to reconstruct hidden tokens across randomly chosen noise levels; its sequence distribution comes from an iterative reverse process. Masked-position cross-entropy is the practical prediction task, and schedule weighting connects a particular version of that task to a bound on negative log-likelihood.

Next, you’ll use the clean sequence, corrupted state, noise level, denoiser prediction, and reverse update to translate the linked paper’s notation into the tensors and operations in your Colab notebook.

Can't find a good explanation? Sign up and we'll make it for you

Sign up