SevyDevy

Module 2 · How a language model thinks · Lesson 10 of 32

Temperature: the creativity dial

8 minFree GenAI course · BeginnerLesson 2.6By Saket Bhatnagar

Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.

In short

  • At every step the model has a list of possible next tokens, each with a chance. Temperature changes how it picks from that list.
  • Low temperature almost always takes the top choice: safe, focused, repeatable. High temperature gives long shots a real chance: creative, but risky.
  • Use low settings for facts, code and data; medium for chat; higher only for brainstorming and fiction.
Soon

Video lesson · coming soon

What is temperature in AI? The creativity dial

Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.

  1. 01 Same question, different answer
  2. 02 Every word comes from a menu
  3. 03 The DJ at a sangeet
  4. 04 Sharpen or flatten the chances
  5. 05 Drag the slider from 0 to 1.5
  6. 06 Low for facts, high for ideas
  7. 07 Try the dial, then the context window

Priya asks a chat app for a birthday wish for her dadi. She likes it, asks again, and gets a completely different wish. Same question, new answer. Meanwhile her friend Arjun is building a tool that reads bills, and he is annoyed because it wrote “₹1,240” once and “Rs 1240.00” the next time.

Both of them are meeting the same hidden setting. It has a funny name, temperature, and once you see what it does, AI answers stop feeling random.

The model always has a menu of next words

You learned that a model writes one token at a time. It never knows the next word for sure. Instead, for every possible token it works out a chance. After “Happy birthday, dear”, the word “Dadi” might get a big share, “Nani” a smaller one, and “Mumbai” almost nothing.

Then the app has to choose one token from that menu. It could always take the top choice. Or it could roll a weighted dice, where likely words win more often but less likely words sometimes win too. That choosing step is called sampling.

How the dial reshapes the chances

Inside, the model first gives every token a raw score. Those scores are turned into chances that add up to 100%. Temperature steps in between: the scores are divided by the temperature before they become chances.

Divide by a small number, like 0.2, and the gaps between scores grow. The leader pulls far ahead, so the bars look sharp and tall. Divide by a big number, like 1.5, and the gaps shrink. The bars flatten, and words from the bottom of the list start getting real chances. At exactly 1, the model’s own chances are left as they are.

Where temperature acts when the model picks a word

Temperature does not change what the model knows. It only changes how boldly the app picks from the model’s list.

Diagram connections:

  • Text so far to Score every token (read)
  • Score every token to Temperature dial (reshape)
  • Temperature dial to Chances per token (convert)
  • Chances per token to Pick one token (sample)
  • Pick one token to Text so far (add, repeat)
  • Text so far: Your prompt plus every token written until now.
  • Score every token: The model gives each possible next token a raw score.
  • Temperature dial: Low sharpens the scores, high flattens them.
  • Chances per token: The scores become percentages that add up to 100.
  • Pick one token: A weighted random pick, or the top one at temperature 0.

Remember that this happens for every single token. One surprising pick early on changes the text that follows, and the next menu changes with it. That is why a small bump in temperature can send a whole answer in a new direction.

Try it yourselfTurn the creativity dial yourselfPick a starting line, drag the temperature slider to 0 and then to 1.5, and watch the bars sharpen and flatten. Then tap “Let the AI pick” a few times at each end.

Notice what you saw. At 0, the tallest bar takes 100% and “Let the AI pick” takes it every time; the label reads “Always the top word”. Near 1.5, the label says “Adventurous, sometimes odd”. The bars look much more alike, so each tap can give a different word, and the sentence can drift somewhere strange.

Low, medium or high: which one when?

There is no best temperature, only the right one for the job. Ask yourself one question: do I want the same correct answer every time, or do I want variety?

Rough temperature ranges by task (they vary by model and app)
TaskRough settingWhy
Reading data from bills, forms or emails0 to 0.2You want the same, exact answer every time.
Writing or fixing code0 to 0.3One wrong token can break the program.
Answering factual questions0 to 0.4Long-shot words are more likely to be wrong.
Everyday chat and explanations0.5 to 0.9Natural and varied, still sensible.
Brainstorming names, stories, poems0.9 to 1.2Surprise is the point; you will pick the best ideas.

So Arjun should set his bill reader near 0. Priya can leave her birthday wishes at a medium setting and enjoy the variety. Many apps allow a range of 0 to 1, others 0 to 2. Above about 1.2 or 1.5, most text starts to fall apart.

Temperature’s cousins: top-p and top-k

Think of a food delivery app showing you restaurants. One rule says “only show the top 5”. Another says “show the best ones until they cover 90% of the orders people usually place”. Both trim the long tail so you never see the dodgy places at the bottom.

Models have the same two trimming rules. Top-k keeps only the k most likely tokens, say the top 40, and picks among them. Top-p keeps the smallest group of top tokens whose chances add up to p, say 0.9, and picks among those. When the model is very sure, that group may hold one or two words. When it is unsure, the group grows.

Temperature changes the shape of the menu. Top-p and top-k cut its length. They are often used together. A common tip is to change one at a time, usually temperature, and leave the others at their defaults, so you know what made the difference.

Check yourself

Check yourself

Arjun’s app reads amounts from shop bills. Which temperature should he start with?

Pick an answer to see why it is right or wrong.

Check yourself

What does raising the temperature actually do?

Pick an answer to see why it is right or wrong.

Check yourself

Priya sets the temperature to 0 and the model gives a wrong date for a festival. What will happen if she asks again?

Pick an answer to see why it is right or wrong.

Remember these three

  1. Temperature reshapes the model’s chances for the next token: low sharpens them, high flattens them.
  2. Low is safe and repeatable for facts, code and data; high is creative and risky for ideas and stories.
  3. Temperature changes how boldly the model picks, never what it knows; top-p and top-k trim the list it picks from.

Questions people ask

What is temperature in AI?
Temperature is a setting that controls how a language model picks each next token from its list of chances. Low values make it pick the most likely token almost every time, and high values let less likely tokens win more often, giving more varied text.
What is a good temperature for ChatGPT-style chat?
For everyday chat, roughly 0.5 to 0.9 works well. Use 0 to 0.3 for code and reading data, up to about 0.4 for factual answers, and roughly 0.9 to 1.2 for brainstorming. The best value differs between models, so test a few.
What is the difference between temperature and top-p?
Temperature reshapes all the chances, making them sharper or flatter. Top-p keeps only the smallest group of likely tokens whose chances add up to a set amount, like 90%, and picks from those. They are often used together.
Does low temperature stop AI hallucinations?
No. It can reduce odd, long-shot words, but if the model’s top guess is wrong, it will repeat that mistake confidently. Grounding the model in real sources and checking facts matter far more.