All labs Animated labs The chapter Course home

Lab 04Decoding playground

A language model hands you a probability for every next token. Decoding is what turns that into one token, and it is decided after training. Move the three sliders and watch the same model behave very differently. Every number comes from decoding.py, so you can check it against the chapter.

Rows of the chapter's table:

what the model says what is left after your settings

What to look for

  • Set the temperature to 0. Every draw is the same token, and the entropy is 0. That is greedy decoding.
  • Raise it to 2 on the peaked distribution. The rare tokens climb, and drawing 100 now picks some of them.
  • Set top-k to 3, then switch between peaked and flat. On the peaked one, k = 3 keeps tokens the model had nearly ruled out. On the flat one it throws away good ones. A fixed k cannot see the shape.
  • Set top-p to 0.9 on both. The peaked one keeps two tokens and the flat one keeps eight. The cut follows the model's confidence, which is why nucleus sampling became the default.

Greedy can miss the best sentence

A tiny model with a three-word tree. Slide the beam width and see which three-word sentence it returns.

ranksequenceprobability

Width 1 is greedy: it takes the at 0.40 over a at 0.35 and never sees that a leads to bird and then sang.

Where this fits

This is the first half of Steering LLMs: Decoding and Prompting. Run decoding.py to print the same tables as text.