Greedy, beam, top-k, nucleus and temperature sampling grown as a botanical plate.
A word-level trigram language model with interpolated Kneser-Ney smoothing is trained on 27 public domain poems the moment the page loads, and a plant grows from a seed phrase one word per node. Each stem segment is as thick as the probability of the word chosen there, and its side branches are the runners-up, so you can see how much the model hesitated at every step. The decoding strategy decides which branch the stem follows: greedy always takes the top word, top-k and nucleus prune the distribution (pruned words wither and are struck through), temperature reshapes it as p to the power 1/T, and beam search grows several whole sequences at once while dropped beams dry out on the plant. Sampling uses the Gumbel-max trick with fixed noise per word, so dragging the temperature morphs one plant continuously from a single greedy stem into a thicket of unlikely words, while a bee walks the stem and the side panel shows the distribution at its flower.
Try it. Pick a strategy, then drag the temperature, k, p or beam width sliders, or drag sideways across the garden to change the temperature. Click a side flower to graft that word into the poem and regrow everything above it, click empty paper to sow new random numbers, and click the seed marker (or type a phrase and press Enter) to plant a new seed. Keys 1 to 5 switch strategy, the arrow keys nudge the temperature and the strategy's parameter, space resows.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a 'temperature garden' that shows how language model decoding strategies work, by growing a tree of possible next words. Use JavaScript and the HTML canvas element, in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Give it a warm paper-colored background.
- Paste a few public domain poems into a string (Shakespeare's Sonnet 18, Blake's The Tyger, Frost's The Road Not Taken). Split them into lowercase words and punctuation, with a token for each line break.
- Build a bigram model: for every word, count which words follow it. Turn counts into probabilities, and apply a temperature T by raising each probability to the power 1/T and renormalizing.
- From a seed word, grow a plant upward: at each step sample the next word, draw the stem segment with thickness proportional to that word's probability, and draw the other likely words as thinner side branches with their labels. Write the generated line of verse under the plant.
- Add a temperature slider and regrow when it changes.
Once that works, make it beautiful:
- Upgrade to a trigram model with backoff to bigrams and unigrams so rare contexts still give sensible choices.
- Add buttons for greedy, top-k, nucleus (top-p) and beam search. Draw pruned words as withered brown buds, and for beam search grow every beam as its own stem.
- Sample with the Gumbel-max trick and fixed random noise per word, so dragging the slider morphs the plant smoothly instead of reshuffling it.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as Kneser-Ney smoothing, letting me click a side branch to graft that word into the text, or a side panel that charts the distribution at each step.