Skip to content

Diffusion for text: masked diffusion language models such as LLaDA

Instead of writing left to right, start from a fully masked answer and unmask it over several steps. See how masked diffusion trains, why its loss is reweighted by the mask rate, and what it trades against autoregressive generation.

Advanced ~12 min7 steps

What runs in CodeSplash

You will be able to

  • Describe the forward masking process and the reverse unmasking model
  • Explain why the training loss divides by the masking rate
  • Contrast step-wise unmasking with left-to-right generation in speed, context and length

Read first

01

Noise for text is masking

Read

Image diffusion adds Gaussian noise and learns to remove it. Text has no small steps between tokens, so a masked diffusion language modelMasked diffusion language modelGenerates text by starting from all-masked tokens and unmasking over several steps; trained to predict masked tokens at every mask rate. uses masking as its noise. Pick a time t between 0 and 1 and replace each token with [MASK] independently with probability t. At t = 1 everything is masked.

A Transformer without a causal mask learns to predict the original tokens at the masked positions from everything visible, on both sides. It looks like BERT's masked language modelingMasked language modelingPretraining by hiding a share of tokens and predicting them from both sides: the objective behind BERT and RoBERTa., except that the mask rate varies from almost nothing to everything.

02

The loss, reweighted

Read

Training samples t, masks the sequence, and scores the masked positions:

L=Et[1t L∑i masked−log⁡pθ(xi∣xt)]\mathcal{L} = \mathbb{E}_t\left[\frac{1}{t\,L}\sum_{i\,\text{masked}} -\log p_\theta(x_i \mid x_t)\right]

Dividing by t L makes low-noise steps, with few masked tokens, count as much as high-noise ones; the result bounds the text's negative log-likelihood, so it can be compared with an autoregressive model's. With mask rate 0.4, length 5 and two masked tokens predicted at probabilities 0.7 and 0.5, the reference program's loss is 0.525.

03

Generating by unmasking

Read

Generation starts from a prompt followed by a fully masked answer of fixed length. At each step the model predicts every masked token; the most confident predictions are kept and the rest re-masked; the next step predicts again with more context filled in.

LLaDA (8 billion parameters) showed that this can reach the quality of similar-size autoregressive models on many benchmarks. It can also revise and fill in the middle, and it handles some reversal tasks better, because nothing forces left-to-right order.

04

Fewer steps, faster?

Predict

Predict first

A 64-token answer is generated in 8 unmasking steps instead of 64. What is the trade-off?

Faster, with no change in qualityFaster, but tokens decided in the same step can't see each other, so quality can dropSlower, because every step predicts every token
Reveal

Faster, but tokens decided in the same step are predicted independently of one another, so they can clash. Fewer steps, more parallel decisions, more risk of incoherence.

05

Where it stands in CodeSplash

Read
EntryIn CodeSplash
LLaDA masked diffusion (LNG080)Explained here; no connected runtime serves it

LLaDA's weights are MIT-licensed but need about 16 GB.

Reference · LNG080 · Explained hereLLaDA masked diffusion language modelModels language through iterative masked-token denoising instead of exclusively left-to-right next-token generation.
06

Check: masked diffusion

Checkpoint

Check yourself

What is the "noise" in a masked diffusion language model?

Show the answer

Answer: b

Masking is the discrete analog of adding noise: at t = 0 the text is clean, at t = 1 it is all masks.

Check yourself

Why is the masked-token loss divided by the mask rate t?

Show the answer

Answer: a

At small t only a few tokens are masked; the 1/t weight rescales their contribution so every noise level counts fairly.

Check yourself

What can a masked diffusion model do that a left-to-right model can't do directly?

Show the answer

Answer: b

Unmasking works on all positions at once and in any order; autoregressive models extend only the right end.

07

Recap

Recap
  • Masked diffusion uses masking as noise; a bidirectional Transformer learns to unmask.
  • The loss weights masked tokens by 1/t, bounding the log-likelihood.
  • Generation unmasks a fixed-length answer over steps; fewer steps are faster but less coherent. Explained here.

Concepts in this lesson