Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Generating text

Text diffusion: writing a block of tokens by cleaning up noise

Must a language model write from left to right? What if it could fill in a whole block of text at once?

After the prompt “the hare”, a model has seven more tokens to write: “sat on the grass in the sun”.

Every token waits its turn

Writing adds one token per pass, and each pass must wait for the one before it.

Seven tokens written in seven passesWriting: the hare sat on the grass in the sun.Writingtheharesatpass 1on2the3grass4in5the6sun7
Each token needs its own pass, and each pass needs the token before it. Seven tokens, seven passes in a row.

Speculative decoding checks guesses in bulk, but each kept token still depends on the ones before it. Could one pass fill several positions on its own?

Let every position guess at once

Start with seven blanks after the prompt, and predict all of them in one pass.

For that, a blank must see the blanks after it too, so we drop the rule that a column cannot look ahead. Every position can now see every other.

Filling every blank in one pass gives words that clashStart: the hare blank blank blank blank blank blank blank. One pass: the hare sat on on grass the in sun (✗).Startthehare???????One passtheharesatonongrasstheinsun✗
Each blank chose its most likely word on its own. Two of them chose “on”, and “the” and “in” came out in the wrong order.

Every guess is reasonable on its own, but none of them knew what the others would choose.

Keep the sure ones, look again

So keep only the words the model is most sure of, and blank the rest. Run it again: the remaining blanks can now see the words already chosen.

Seven tokens written in three passes by keeping the surest words each timePass 1: the hare sat blank blank grass blank blank sun (+3). Pass 2: the hare sat on the grass blank blank sun (+2). Pass 3: the hare sat on the grass in the sun (+2).Pass 1theharesat??grass??sun+3Pass 2theharesatonthegrass??sun+2Pass 3theharesatonthegrassinthesun+2blankfilled this passfilled earlier
Each pass keeps the words the model is surest of and fills the rest later, when it can see them. Seven tokens in three passes.

Starting from noise and cleaning it up a little each pass is how image generators work too. Applied to text, it is called text diffusion.

Learning to fill blanks

Training uses the same game. Take real text, blank out a random share of it, and train the model to fill the blanks back in.

Training sentences with a few or most of their words blanked outText: the hare sat on the grass in the sun. A few: the hare blank on the grass blank the sun. Most: blank hare blank blank the blank blank blank sun.TexttheharesatonthegrassinthesunA fewthehare?onthegrass?thesunMost?hare??the???sun
Sometimes only a few words are hidden, sometimes nearly all. Filling them in teaches the model to start from blanks and finish the job.

Block by block

Real models fill one block at a time. Google’s DiffusionGemma writes 256 tokens per block in at most 48 passes. Each finished block joins the cache, like the prompt, and the next block starts.

It starts each block from random tokens rather than blanks, and can still change a word it had kept. Google reports text up to 4 times as fast as writing token by token on a GPU, at some cost in quality.

Writing faster by doing more per pass is one approach. Another is to make each pass read less: store the weights in fewer bits.

Sources and assumptions

The words chosen in each pass are illustrative, not the output of a model. Models choose how many positions to keep per pass in different ways; keeping the most confident predictions is one common rule. In the article the model fills blanks; DiffusionGemma’s version, which starts from random tokens and can change kept ones, is described in the last section.

← Browse all subjectsBack to the beginning ↑