Skip to content

Temperature Explorer

Run the Temperature Explorer MicroSim Fullscreen
Edit in the p5.js Editor

About This MicroSim

This MicroSim visualizes how the temperature parameter affects the probability distribution of next-token selection in large language models. A bar chart displays the top 10 candidate tokens with their adjusted probabilities, and students can generate tokens one at a time or in batches to see how temperature influences the resulting text.

At temperature 0, the model always selects the highest-probability token (greedy decoding). As temperature increases, the probability distribution flattens, giving lower-ranked tokens a greater chance of being selected -- producing more creative but potentially less coherent output.

How to Use

  1. Adjust the temperature slider from 0.0 to 2.0 and observe how the bar chart changes
  2. Click "Generate Next Token" to sample one token from the current distribution
  3. Click "Generate 10 Tokens" to quickly build a sequence and see the cumulative effect
  4. Try different temperatures with the same prompt to compare deterministic vs. creative output
  5. Edit the prompt in the input field and click Reset to start a new experiment

Iframe Embed Code

You can add this MicroSim to any web page by adding this to your HTML:

1
2
3
4
<iframe src="https://dmccreary.github.io/prompt-class/sims/temperature-explorer/main.html"
        height="552"
        width="100%"
        scrolling="no"></iframe>

Lesson Plan

Grade Level

High School through Undergraduate

Duration

10-15 minutes

Prerequisites

Basic understanding of what a language model does (predicts the next token)

Activities

  1. Exploration (5 min): Set temperature to 0.0 and generate 10 tokens. Note that the same tokens are always selected. Then set temperature to 2.0 and generate 10 tokens. Compare the outputs.
  2. Guided Practice (5 min): Find the "sweet spot" temperature that produces text that is both interesting and coherent. Try values between 0.5 and 1.0.
  3. Assessment (5 min): Predict what will happen at temperature 1.5 before generating, then verify your prediction.

Assessment

  • Can the student explain why temperature 0 always produces the same output?
  • Can the student describe the tradeoff between creativity and coherence?
  • Can the student predict the approximate behavior at a given temperature?

References

  1. Temperature parameter in LLMs - Wikipedia
  2. Softmax function - Wikipedia