Decoding Rules

Decoding Rules


Decoding rules are the settings that decide which token gets picked from the probability distribution a language model produces at each step. The model does not actually produce one answer. It produces a probability for every token in the vocabulary, and these rules make the choice. The same model with the same prompt writes visibly different text under different decoding settings.

The settings you meet most are temperature, top-k and top-p. Temperature sharpens or flattens the distribution: a low value all but guarantees the most likely token, a high value gives less expected options a chance. Top-k limits the choice to the k most probable tokens. Top-p accumulates probability until it crosses a threshold and cuts the pool there. Alongside those, repetition penalties stop a phrase looping, and stop sequences say where generation ends.

The right setting depends on the job. Code generation, data extraction and classification have one correct answer, so temperature stays low. Headline options, ad copy and brainstorming want variety, so it goes up.

A worked example: in a flow writing product descriptions, temperature at 0.2 makes the copy repetitive and formulaic. Push it to 0.9 and variety arrives, but so do errors in the product specifics. Teams usually settle somewhere near 0.5 and fix it there.

Moving all the knobs at once tangles their effects, so changing one parameter at a time gives a result you can actually read.

From generative AI strategy to custom agent development and retrieval architectures, we help you scale AI responsibly.
Discuss your AI project