Sampling and decoding practice problems

15 problems · 0 solved

A language model outputs scores for every possible next token, and a decoding strategy decides which token to actually pick. Greedy decoding always takes the top choice, while sampling adds controlled randomness so text is less repetitive. Temperature works like a dial between safe and adventurous answers. These problems cover the decoding methods used in real LLM APIs. You will turn logits into probabilities without overflow, greedy decode until end of sequence, keep the top k tokens, apply top-p nucleus filtering and min-p filtering, filter with locally typical sampling, apply repetition, frequency and presence penalties, ban tokens and repeated n-grams, rank beams with a length penalty, decode with beam search, generate a full sequence with temperature, top-k and top-p, and decode under a finite-state grammar. Start with the Easy problems on stable softmax, greedy decoding and top-k. Then do top-p, penalties and typical sampling, and finish with beam search and grammar-constrained decoding. Decoding settings change output quality more than many people expect, and interviewers for LLM roles often ask you to explain or code top-p or beam search.

Easy 7

Medium 5

Hard 3

Related topics

All practice problems