AI Dictionary of Terms

Temperature

A parameter that controls the randomness and creativity of a language model’s output by scaling the probability distribution of next-token predictions, where lower values produce more deterministic, focused outputs and higher values produce more diverse, creative outputs.

The Simple Version

Imagine you’re at an ice cream shop. The shop has 100 flavors.

Temperature controls how “adventurous” the AI is when choosing the next word. Low temperature = safe, predictable answers. High temperature = creative, surprising answers.

Detailed Explanation

Temperature is a hyperparameter applied during the softmax function that converts model logits (raw scores) into probabilities for the next token.

Mathematical Effect:

probability(token) = exp(logit(token) / temperature) / Σ exp(logit(i) / temperature)

How Temperature Works:

Visual Intuition:

Temperature = 0.2:  [████████████████████] 95% | [██] 3% | [█] 2%
Temperature = 1.0:  [██████████] 50% | [████] 25% | [██] 15% | [█] 10%
Temperature = 2.0:  [█████] 30% | [████] 25% | [███] 20% | [██] 15% | [█] 10%

Common Temperature Settings:

Interaction with Other Parameters:

Key Characteristics

Business Context

Temperature selection directly impacts AI output quality and consistency:

When to Use Low Temperature (0.0 - 0.3):

When to Use High Temperature (0.7 - 1.0):

Enterprise Considerations:

Best Practices:

Real-World Analogy

A jazz musician improvising. At low temperature, they stick closely to the melody, playing safe, predictable notes. At high temperature, they take wild risks, playing unexpected notes and exploring unconventional harmonies. Both approaches have value — low temperature for reliability, high temperature for creativity — but the right choice depends on the context (a classical concert vs. a jazz club).

Code Example

# Demonstrating temperature effects
from openai import OpenAI

client = OpenAI()

prompt = "Write a haiku about artificial intelligence."

# Low temperature (deterministic, focused)
low_temp = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.2
)
print("Temperature 0.2:", low_temp.choices[0].message.content)
# Likely: "Silicon minds think / Processing endless data / Learning, never sleeping"

# Medium temperature (balanced)
med_temp = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.7
)
print("\nTemperature 0.7:", med_temp.choices[0].message.content)
# More varied: "Neural networks dream / Of electric sheep at night / Waking to new thoughts"

# High temperature (creative, diverse)
high_temp = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": prompt}],
    temperature=1.0
)
print("\nTemperature 1.0:", high_temp.choices[0].message.content)
# Very varied: "Algorithms bloom / In gardens of computation / Wisdom emerges"

# Run the same prompt multiple times to see variation
print("\n--- Running same prompt 3 times with temperature=0.9 ---")
for i in range(3):
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": prompt}],
        temperature=0.9
    )
    print(f"Run {i+1}:", response.choices[0].message.content)

Common Misconceptions

Sources & Further Reading