Visualizations
092 / 500

092 · Machine learning

Temperature Garden

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.

  • Interpolated Kneser-Ney smoothing
  • Greedy, beam, top-k and nucleus decoding
  • Gumbel-max sampling with common random numbers
  • Tapered Bezier botanical rendering
  • Greedy label collision avoidance

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

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.
PreviousVector Balls512 chrome spheres, depth sorted, morphing from a torus knot to DNA to a smiling face. NextInvented AtlasA parchment map of a world that never was, with rivers, realms and its own language.

Related visualizations

  • Huffman GardenAlgorithms Letter frequencies sprout into a Huffman tree drawn as a botanical plate.
  • CPPN GardenMachine learning Breed images grown by tiny neural networks by picking the ones you like.
  • Skip-gram ConstellationMachine learning Word2vec learns from scratch, and king minus man plus woman lands on queen.
  • Floral OrnamentGenerative art Scrolls, acanthus leaves and flowers grow to fill any frame, like an engraver's panel.
  • Mondrian ForestMachine learning Decision trees cut the plane into a De Stijl painting; a forest blurs it into glazes.
  • Symbolic RegressionMachine learning Genetic programming breeds formulas until it rediscovers the law behind the data.
  • Attention LoomMachine learning A tiny transformer learns to braid, reverse and sort digits, attention woven as thread.
  • Growing Neural CellsMachine learning Cells running one tiny learned rule grow a gecko from a single seed and heal its wounds.
  • Bandit CasinoMachine learning Epsilon-greedy, UCB1 and Thompson sampling race to find the best slot machine.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs