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.
- 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
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 contentsThis 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