Compare greedy selection with overall sequence likelihood
Watch the spaces around tokens and probability values. · 155 words
Greedy decoding and whole-sequence scoring optimize different things. Greedy decoding selects the highest-probability next token at each step. Overall sequence likelihood multiplies the probabilities of all tokens in a complete candidate sequence. For model probability p, a sequence x1, x2, ..., xn has likelihood P(x1|x0)P(x2|x1)...P(xn|x(n-1)). Because probabilities are at most 1, extra tokens can reduce the product; log probabilities are often added instead. Length normalization may also be used.
Consider the context "At the museum I saw". Two candidates are "the large map" and "a large coin." Their conditional token probabilities are P(the)=0.35, P(large|the)=0.25, and P(map|the large)=0.20. Thus, the first sequence has likelihood 0.35 x 0.25 x 0.20 = 0.0175. The second has P(a)=0.30, P(large|a)=0.25, and P(coin|a large)=0.40, giving 0.30 x 0.25 x 0.40 = 0.0300. Greedy decoding starts with "the" because 0.35 exceeds 0.30, but "a large coin" has the greater overall likelihood. A beam search keeps several partial candidates to reduce this risk.
Check your recall
Which candidate has the greater overall likelihood, and why can greedy decoding still choose differently?
Check your answer
"a large coin" has the greater likelihood, 0.0300 compared with 0.0175. Greedy decoding chooses "the" because it gives the highest probability at the first step, without considering the full likelihood of every candidate.
Sources and credits
Original KeyTouch lesson. Background reading · Hugging Face · LLM Course.