Language models, retrieval, prompting, and language adaptation · Reasoning, decoding, and discrete diffusion language · LNG080 · Model
LLaDA masked diffusion language model
Models language through iterative masked-token denoising instead of exclusively left-to-right next-token generation.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Models language through iterative masked-token denoising instead of exclusively left-to-right next-token generation. It provides a language-specific discrete diffusion alternative while remaining distinct from generic continuous diffusion methods covered elsewhere.
Question / objective
Can iterative masked denoising provide useful language generation beyond a causal token order?
Architecture / computational structure
A language denoiser predicts masked discrete tokens from partially observed sequences; a schedule governs corruption and reverse updates. Learned denoiser weights are parameters; masking schedule, step count, and remasking controls are hyperparameters.
Assumptions
Parallel token updates do not guarantee lower latency at equal quality, because many denoising passes may be required.
Formula / computational definition
A forward process masks tokens according to noise level t; a denoiser predicts original tokens from the partially masked sequence. The paper's loss weights masked-token log losses by the masking schedule, and reverse generation iteratively fills/refines masked positions.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Masking schedule, denoising steps, output length, remasking strategy, confidence-based selection, architecture size, and conditional prompt treatment.
Fitting, fine-tuning, and adaptation
Pretrain or fine-tune with the paper's masked-token denoising objective and correct noise weighting. Adapter support requires verification for the released architecture; do not substitute causal SFT without justification. Validate conditional generation, step/quality tradeoffs, length behavior, and retained capabilities under matching evaluation protocols.
How to use and calibrate
Compare task accuracy, conditional generation quality, steps-versus-quality curves, latency, editability, and the exact reported likelihood bound or estimator. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Generate or revise text through repeated masked-token completion while varying denoising steps.
Interpretation / pitfalls
Watch out
Length control, token dependencies, and likelihood estimation differ from causal models; autoregressive perplexity formulas cannot be transferred uncritically. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use the authors' released model and sampling code with compatible dependencies; generic causal-generation APIs may be inappropriate. R bridges Python via reticulate. The native example computes one masked denoising loss component, not full diffusion sampling or a trained LLaDA model.
Example scope: LLaDA-style masked-token denoising loss component with a fixed masking level; no diffusion sampler.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — LLaDA-style masked-token denoising loss component with a fixed masking level; no diffusion sampler.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
mask_probability = 0.4
masked_target_probabilities = [0.7,0.5]
sequence_length = 5
weighted_loss = nll(masked_target_probabilities)/(mask_probability*sequence_length)
print(weighted_loss)
Component demo, not a trained model — LLaDA-style masked-token denoising loss component with a fixed masking level; no diffusion sampler.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
mask_probability <- 0.4; masked_target_probabilities <- c(0.7,0.5)
sequence_length <- 5L
weighted_loss <- -sum(log(masked_target_probabilities))/(mask_probability*sequence_length)
print(weighted_loss)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG080.