Token Lab검색

FRONTIER / RESEARCH TO PRACTICE

Diffusion language models: masking and iterative decoding

Prerequisites: cross-entropy, Transformers and generative modeling. Understand LLaDA-style masked generation without equating parallelism with speed.

Study guide & lesson outlineLEARNING CONTRACT

Understand → implement → investigate

Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.

This technical article displays the English edition.

Mechanism & assumptions

LLaDA studies a language diffusion model using forward masking and a learned reverse process. The model predicts masked tokens conditioned on visible context; iterative generation differs from a left-to-right autoregressive factorization. The training objective includes noise-level weighting, so an ordinary masked-token classifier is only a teaching baseline, not a faithful reproduction. Engineering choices include sequence length, unmasking schedule, confidence calibration and whether tokens can be revised. Parallel token updates can still require expensive repeated full-sequence evaluations.

Text / 原始公式
Teaching masked loss = −(1/M) Σ_(i masked) log pθ(x_i | visible context)
M = number of masked positions; handle M=0 explicitly
Compute ledger ≈ steps × cost_per_full_sequence_pass

Worked example

Two masked positions assign probabilities 0.8 and 0.5 to their correct tokens. The mean masked cross-entropy is −(ln 0.8 + ln 0.5)/2≈0.458145. For a length-128 output with 16 full-sequence passes, the ledger counts 2048 token-position evaluations. This is not 2048 autoregressive decoding steps: kernels, caching and parallel work differ. A wall-clock measurement is required.

Implementation exercise

Begin with a tiny discrete sequence reconstruction task. Compare random versus confidence-based unmasking with identical masks and model weights. Report exact-match accuracy, per-position accuracy and sensitivity to step count. Then specify a real-model comparison at equal quality or latency, including stop behavior and output length; never infer general reasoning quality from reconstruction alone.

Deliver code, fixed seeds, raw results and one counterexample. These are experiment specifications, not executed GPU benchmarks.

Why can confidence-based unmasking lock in mistakes?

Confidence can be miscalibrated, especially under heavily masked context. Early wrong tokens alter later conditioning. Compare calibration across noise levels and test revision policies rather than trusting the highest score.

arXiv ↗ · PDF ↗

Original teaching examples; sources checked October 2026. These are foundational mechanisms relevant to engineering, not a claim to cover every latest model.

Related prerequisite / next lesson →

AI/LM curriculum & checkpoints →Frontier index →
MATHEMATICAL REVIEW · 2026-10-26

Assumptions, implementation & acceptance

The displayed cross-entropy uses natural logarithms and is measured in nats. A masked-position average must divide by the number of evaluated masks; the toy loss does not reproduce an entire discrete diffusion objective.

Formula conditions, units and worked arithmetic reviewed. The implementation isolates one numerical mechanism; it does not train a policy or control real hardware.

Tokens → sampled masked positions → Predict missing-token probabilities → Sum negative natural logarithms → Divide by evaluated mask count
Mechanism map: follow the transformations from top to bottom.

Before running: predict a boundary case

The result is nats. Divide by ln2 for bits; do not divide by unmasked token count.

Hint: isolate the assumption

Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.

Minimal executable example

Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node diffusion-language.mjs. No third-party runtime dependencies.

const solve=()=>{
const maskedProbabilities=[.8,.5];
return -maskedProbabilities.reduce((s,p)=>s+Math.log(p),0)/maskedProbabilities.length;
};
const actual=solve();
const expected=0.4581453659370775;
if(JSON.stringify(actual)===JSON.stringify(expected)){console.log('PASS',actual)}else{
const a=[actual].flat(), b=[expected].flat();
if(a.length!==b.length||a.some((v,i)=>!Number.isFinite(v)||Math.abs(v-b[i])>1e-10))throw Error('Numerical mismatch');
console.log('PASS within 1e-10',actual);
}
Reference output — reveal after predicting
0.4581453659370775

Test and transfer

The result is nats. Divide by ln2 for bits; do not divide by unmasked token count.

Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.

Download complete kit (.tar.gz) · Complete reference kit and regression checks

Predict, test and keep evidence

Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.

Open notebook / export / clear →

The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope