ContentsThe library

How a Model Picks Its Next Word

Making the Output Fit a Format

Last timeWhy It Gets Stuck

If the answer has to be valid JSON, or one of four labels, the reliable way is not to ask nicely. It is to set the probability of every token that would break the format to zero before sampling.

Prompting a model to reply in a particular format works most of the time, which

is the problem. A format that holds on ninety-eight percent of calls fails

several times an hour at any real volume, and the failures are exactly the ones

that stop a program.

Zero the illegal tokens

The alternative is to stop asking. At each step, decide which tokens could

legally come next, set the probability of all the others to zero, and rescale.

FIG 1Where the constraint sits
Nothing about the model changes. The constraint is a filter between the distribution and the choice, applied at every step, which is why the result is guaranteed rather than probable.
FIG 2Masking and rescaling
one if this token is allowed here, zero if it is not
the mass the model put on allowed tokens, the same divisor for every survivor
Identical in form to the rescaling after truncation. The difference is what decides the survivors: there it was the model's own ranking, here it is an external rule that does not care about probability at all.

Because the divisor is shared, the odds between two allowed tokens come through

untouched. If the model preferred one over another three to one before the mask,

it still does after. The constraint sets the menu and the model orders from it.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Model Does Not Write Anything
  2. 02Two Different Questionsopening only
  3. 03What a Beam Keeps, and What It Costsopening only
  4. 04What Temperature Actually Doesopening only
  5. 05Throwing Away the Worst Optionsopening only
  6. 06The Loop Is the Most Probable Continuationopening only
  7. 07Making the Output Fit a Formatyou are here
  8. 08Guessing Ahead Without Changing the Answeropening only

Read alongside