Decoding
How generative models choose outputs: beam search, top-k, top-p, and more.
Beam SearchBeam search is a decoding method that generates text one word at a time while keeping only as many high-probability partial sentences as the beam width, efficiently finding an output with high probability as a whole sentence.
Contrastive SearchContrastive search is a decoding method that, from the top k candidates, uses a score to pick one word that has high model probability and whose representation is not too similar to the words in the preceding context. Without random choice, it prevents both repetition of the same phrases and drift from the context.
Diverse Beam SearchDiverse beam search is a decoding method that splits the beam into several groups and searches with a penalty that lowers the score of later groups when they choose the same word as earlier groups. With almost the same computation as beam search, it outputs multiple candidate sentences that differ from one another.
Locally Typical SamplingLocally Typical Sampling is a decoding method that keeps only those next-word candidates whose information content (surprisal) is close to the average information content of the context (the entropy), and then samples randomly from them. By avoiding both overly predictable and overly surprising words, it produces human-like text with less repetition.
Nucleus (Top-p) SamplingNucleus (top-p) sampling is a decoding method that adds up the next-word probabilities in descending order, keeps only the words until the total reaches p, and picks one of them at random. Because the number of candidates adapts to the shape of the distribution, it generates open-ended text that is both natural and diverse.
Speculative SamplingSpeculative sampling is a generation method in which a small draft model writes several tokens ahead, a large target model checks them all in a single computation, and a special accept/reject rule decides which to keep. It makes generation roughly 2 times faster while keeping the distribution of the generated text the same as that of the large model.
Top-k SamplingTop-k sampling is a decoding method that keeps only the top k of the next-word probabilities produced by a language model and randomly picks one of them in proportion to its probability. By removing very low-probability words, it prevents the text from breaking down while preserving diversity.
