Skip to chapter content

Chapter 5 3 min read

The Creativity Dial — Temperature

Randomness vs. determinism

Back in Chapter 2’s exercise, I asked you to reload the page with [ai_course_ch2] on it twice in a row, and pointed out the wording wasn’t identical both times. I said that wasn’t a bug. This chapter is why.

What temperature actually controls

At each point while generating text, the model is choosing its next word from a range of statistically likely options. Left alone, it doesn’t always pick the single most probable one, there’s some randomness built in on purpose, which is why the same prompt doesn’t produce the same sentence twice. Temperature is the setting that controls how much randomness gets used.

A low temperature, close to 0, pushes the model toward its most likely, safest word choices every time. Run the same prompt five times at a low temperature and you’ll get five very similar answers. A high temperature, closer to 1, lets it wander further from the obvious choice, which produces more varied, more surprising wording, and also raises the odds of it saying something a little strange or drifting off the point.

Neither setting is “better.” A support bot answering “what’s your refund policy” needs the low end, consistent, predictable, boring in a good way. A tool generating five different tagline options for a client to choose from needs the high end, that’s the whole point of asking for variety.

Seeing it side by side

Create chapter-05-temperature.php inside includes:

<?php
/**
* Chapter 5: The Creativity Dial, Temperature
* Usage: add [ai_course_ch5] to any page or post to see the output.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // No direct access.
}
function ai_course_ch5_temperature() {
$prompt = 'Write a one-sentence product description for a stainless steel water bottle.';
$focused = wp_ai_client_prompt( $prompt )
->using_temperature( 0.1 )
->generate_text();
if ( is_wp_error( $focused ) ) {
return 'Could not generate the first example: ' . esc_html( $focused->get_error_message() );
}
$creative = wp_ai_client_prompt( $prompt )
->using_temperature( 0.9 )
->generate_text();
if ( is_wp_error( $creative ) ) {
return 'Could not generate the second example: ' . esc_html( $creative->get_error_message() );
}
$output = '<p><strong>Temperature 0.1:</strong><br>' . wp_kses_post( $focused ) . '</p>';
$output .= '<p><strong>Temperature 0.9:</strong><br>' . wp_kses_post( $creative ) . '</p>';
return $output;
}
add_shortcode( 'ai_course_ch5', 'ai_course_ch5_temperature' );

Add [ai_course_ch5] to a page and load it. Then reload the page a few more times without changing anything. Watch what happens to each line separately: the 0.1 version barely changes wording from one reload to the next, close to identical every time. The 0.9 version gives you a genuinely different sentence almost every reload, same prompt, same product, same model.

using_temperature() takes a number, usually somewhere between 0 and 1 (some providers allow going up to 2, worth checking your specific provider’s docs if you’re pushing past 1 and getting odd results). If you don’t set it at all, which is what every example before this chapter did, the provider uses its own default, typically somewhere in the middle.

Picking a number isn’t guesswork

A rough starting point: anything asking for a fact, a summary, a technical answer, or data extraction wants something low, 0.1 to 0.3. Anything asking for marketing copy, brainstorming, or creative variety wants something higher, 0.7 to 1. Most real use cases fall clearly into one camp or the other once you ask “do I want this answer to be the same every time, or do I want it to surprise me a little.”

Try it yourself

Take a prompt you’d actually use, a product description generator is a good one if you don’t already have your own, and test it at three temperatures: 0.2, 0.5, and 0.9. Read all three outputs and decide which one you’d actually ship. There’s rarely one objectively correct temperature, it depends on whether consistency or variety matters more for that specific feature, and this exercise is about training your own judgment for that call rather than memorizing a number.

This book is created with Chapterwright