
You've been using ChatGPT or another AI assistant for a few weeks, and something bothers you. Sometimes you ask the same question twice and get completely different answers. Other times, you want the AI to be creative and it keeps giving you the same safe, predictable response. A colleague tells you the model has a "temperature" setting, and you nod like you know what that means. You don't. This lesson fixes that.
AI language models don't work like search engines that retrieve a fixed answer. They generate text probabilistically — meaning every word is the result of a calculated guess. The parameters that control how those guesses are made are some of the most practically useful levers you have as a business user. Adjusting them is the difference between getting boilerplate marketing copy and genuinely creative options, or between getting a confident hallucination and a more careful, hedged response.
By the end of this lesson, you'll understand what temperature and other key generation parameters actually do under the hood — with no math degree required — and you'll know exactly how to set them for common business tasks like drafting reports, generating creative content, building chatbots, and extracting structured data.
What you'll learn:
top_p, max_tokens, and frequency_penalty workNo coding experience is required for most of this lesson. The hands-on exercise uses a small amount of Python via the OpenAI API, but we walk through every line. You should have a basic familiarity with what a large language model (LLM) is — knowing that it generates text based on patterns learned from training data is enough.
Before we touch any settings, you need a mental model of what's actually happening when an AI generates text. This isn't optional background — it's the foundation for understanding every parameter we'll cover.
When a language model generates the next word in a sentence, it doesn't look up the "correct" answer in a database. Instead, it calculates a probability score for every word in its vocabulary. If you've prompted the model with "The quarterly revenue report shows that sales have," the model might calculate something like:
The model then samples from this distribution — it picks a word, weighted by those probabilities. This process repeats for every single word (technically, "token") in the response. The output you see is the result of hundreds or thousands of these sampling decisions chained together.
This is why the same prompt can produce different outputs. The model isn't being inconsistent — it's sampling from a probability distribution every time. Temperature is the dial that controls how extreme or how flat that distribution is before sampling happens.
Key concept: A "token" is roughly 3-4 characters or about 0.75 words in English. When parameters mention tokens, think of it loosely as words. A 100-token response is approximately 75 words.
Temperature is a single number — almost always between 0 and 2 — that reshapes the probability distribution before sampling occurs.
Here's the intuition: imagine you have a bag of marbles, where each marble is labeled with a possible next word. The more marbles a word has, the more likely it is to be drawn. Temperature changes whether you flatten that bag out (making it harder to tell which marble is more likely) or compress it dramatically (making the most common marble almost certain to be drawn).
Low temperature (closer to 0): The model becomes more deterministic. High-probability words become overwhelmingly likely to be chosen. The output is predictable, consistent, and "safe." If you ran the same prompt 10 times at temperature 0, you'd get nearly identical outputs.
High temperature (closer to 2): The probability distribution flattens. Lower-probability words become viable choices more often. The output becomes more varied, surprising, and creative — but also more likely to go off-track or produce unusual word choices.
Temperature at exactly 1: No reshaping happens. The model samples from the distribution as-is.
Let's see this in practice. Suppose you prompt an AI with: "Write a tagline for a project management software company."
At temperature 0.1, you might get:
"Manage your projects smarter, faster, and together."
Run it again:
"Manage your projects smarter, faster, and together."
Nearly identical. Safe. Predictable. Fine.
At temperature 1.4, you might get:
"Where chaos becomes choreography."
Run it again:
"Your team's second brain, finally untangled."
Very different outputs. One of them might be brilliant. One might be weird. This variability is exactly what you want when you're exploring options — and exactly what you don't want when you need consistency.
Warning: Temperature 0 doesn't actually guarantee perfectly identical outputs in all implementations due to floating-point arithmetic and hardware differences. It gets close to deterministic, but build systems that require absolute consistency using other mechanisms (like caching) rather than relying on temperature 0 alone.
Temperature adjusts the entire probability distribution. top_p (also called nucleus sampling) takes a different approach: it limits which words are even eligible to be chosen before sampling occurs.
When top_p is set to 0.9, the model looks at all the words in its vocabulary, sorts them from most to least probable, then draws a boundary such that the words above the boundary cumulatively account for 90% of the probability. Only those words are in the running. Everything else — the long tail of weird, unlikely words — gets eliminated before sampling.
Think of it like a hiring filter. Temperature affects how much you weight candidates during the final decision. top_p decides who even makes it to the interview.
At top_p = 1.0: All words are eligible. No filtering.
At top_p = 0.5: Only the top words collectively representing 50% of the probability mass are eligible. This is quite restrictive — the model sticks to its highest-confidence options.
At top_p = 0.9: A middle ground. Unusual words can still appear if they fall within the top 90% of probable choices.
Should you adjust both temperature and top_p? Generally, no — at least not as a beginner. They interact in complex ways, and most practitioners recommend adjusting one or the other. OpenAI's own documentation suggests this explicitly. Pick temperature as your primary knob, and leave top_p at its default (usually 1.0) unless you have a specific reason.
max_tokens is straightforward: it caps the maximum number of tokens the model will generate in a single response. The model might still stop earlier if it reaches a natural endpoint (like finishing a sentence or completing a structured task), but it will never exceed this limit.
This matters for several practical reasons:
Cost: With most API-based models, you pay per token. A support chatbot that habitually writes 800-word responses to simple questions is burning money unnecessarily.
User experience: Responses that are too long frustrate users who needed a quick answer.
System design: If you're injecting AI output into a database field, a UI component, or a structured document, you need predictable length.
For a customer support bot answering common questions, you might set max_tokens to 150. For a tool that summarizes legal documents, you might set it to 600. For a creative writing assistant, you might go higher.
Tip: If the model seems to be cutting off mid-sentence, your
max_tokensvalue is too low. Increase it, or redesign your prompt to encourage more concise responses.
These two parameters address a common and annoying problem: AI models that repeat themselves.
frequency_penalty ranges from -2 to 2. Positive values reduce the likelihood that the model will repeat words that have already appeared in the output. The more times a word has already been used, the more its future probability is suppressed.
Setting frequency_penalty to 0.5 or 0.7 is often enough to noticeably reduce redundant phrasing in longer outputs. This is particularly valuable for:
presence_penalty also ranges from -2 to 2, but it works slightly differently. Rather than penalizing proportionally to how often a word has appeared, it applies a flat penalty to any word that has appeared at all. This encourages the model to introduce new topics and concepts, not just new phrasings.
Use presence_penalty when you want the model to actively explore a broader range of ideas in its output, rather than dwelling on a narrow theme.
Warning: High values for either penalty (above 1.5) can make responses feel fragmented or unnatural, as the model starts avoiding words it actually needs to use for coherent sentences. Start conservative — 0.3 to 0.7 is a practical working range.
Now let's get practical. Here are five common business scenarios with recommended parameter starting points and the reasoning behind each.
You're using an AI to pull specific fields — customer name, order ID, complaint category — from messy support emails and format them as JSON.
temperature: 0.0
top_p: 1.0
max_tokens: 300
frequency_penalty: 0
presence_penalty: 0
Why: You need the model to follow your instructions precisely and consistently. Creativity is your enemy here. Temperature 0 pushes the model toward its highest-confidence interpretation every time.
The bot needs to sound human and empathetic, but responses must be accurate and not go wildly off-script.
temperature: 0.5
top_p: 1.0
max_tokens: 200
frequency_penalty: 0.3
presence_penalty: 0
Why: A little temperature adds natural variation so the bot doesn't sound like a robot. A low frequency penalty keeps responses from recycling the same phrases. Max tokens is capped to prevent rambling.
You want 5 different taglines for a new product. You want genuine variety, not 5 versions of the same idea.
temperature: 1.2
top_p: 0.95
max_tokens: 100
frequency_penalty: 0.5
presence_penalty: 0.3
Why: Higher temperature and presence penalty push the model to explore different angles. You're deliberately inviting variance because the goal is a menu of options, not one reliable answer.
Executives need consistent, accurate summaries of financial and operational reports. Tone should be neutral and professional.
temperature: 0.2
top_p: 1.0
max_tokens: 500
frequency_penalty: 0.2
presence_penalty: 0
Why: Low temperature for reliability and accuracy. Slight frequency penalty to keep 500-word summaries from repeating the same points.
A team wants an AI to generate ideas for solving a logistics problem. They want unexpected angles, not safe guesses.
temperature: 1.5
top_p: 0.95
max_tokens: 600
frequency_penalty: 0.4
presence_penalty: 0.5
Why: High temperature and high presence penalty actively push the model toward novel territory. The tradeoff is some outputs will be impractical — but that's acceptable in a brainstorming context where humans are filtering the results.
Navigate to platform.openai.com and sign in. In the left sidebar, click on "Playground," then select "Chat" from the options at the top. On the right side of the screen, you'll see a panel labeled "Configuration" — this is where all your parameters live.
You'll find sliders and input fields for:
max_tokens) — set a numberMake a change, run the same prompt several times, and watch how the output shifts. The Playground is your sandbox — use it deliberately to build intuition before deploying anything.
For teams integrating AI into workflows, you'll set these parameters programmatically:
from openai import OpenAI
client = OpenAI(api_key="your-api-key-here")
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You are a professional business analyst who writes concise, accurate summaries."
},
{
"role": "user",
"content": "Summarize the following quarterly sales report in 3 bullet points: [paste report text here]"
}
],
temperature=0.2,
max_tokens=300,
frequency_penalty=0.2,
presence_penalty=0.0,
top_p=1.0
)
print(response.choices[0].message.content)
Every parameter is passed as a keyword argument to the .create() method. Change the values, re-run the script, and compare outputs.
This exercise requires a free OpenAI account and access to the Playground (no paid API tier needed for basic Playground access).
Scenario: You work in marketing at a mid-sized software company. You need to generate tagline options for a new product called "FlowDesk" — a tool that helps remote teams manage asynchronous communication.
Step 1: Open the OpenAI Playground (Chat mode). In the system prompt field, type:
You are a creative copywriter specializing in B2B SaaS marketing.
In the user message field, type:
Write a one-sentence tagline for FlowDesk, a tool that helps remote teams manage asynchronous communication without meetings.
Step 2: Set temperature to 0.1. Click submit. Copy the result. Click submit again. Note how similar the two responses are.
Step 3: Change temperature to 1.4. Submit the same prompt five times. Record each result. You should see meaningful variation — some options will be more conventional, some will be surprising.
Step 4: Now add a frequency penalty of 0.6. Submit three more times. Notice whether the language diversity changes.
Step 5: Choose your top three tagline candidates from the high-temperature runs. Bring those back to temperature 0.2 and ask the model: Refine this tagline to sound more professional: [your chosen tagline]. You're now using low temperature to reliably polish a high-temperature idea — combining both modes intentionally.
Reflection questions:
Mistake: Setting temperature to 0 and expecting perfect consistency forever Temperature 0 minimizes variation but doesn't eliminate it completely. If you need system-level consistency (like deterministic data formatting), use temperature 0 plus a highly structured prompt plus output parsing — not temperature alone.
Mistake: Cranking temperature to 2 and wondering why outputs are nonsense Temperature above 1.5 genuinely makes low-probability tokens competitive. The model may produce grammatically strange or logically incoherent text. For most creative tasks, 1.0 to 1.3 is the sweet spot. Only go higher if you're explicitly experimenting.
Mistake: Setting max_tokens too low and blaming the model for incomplete answers
If every response ends abruptly, check your max_tokens setting before adjusting anything else. This is the number one cause of truncated responses.
Mistake: Adjusting both temperature and top_p simultaneously as a beginner These parameters interact. When learning, change one at a time. Temperature is almost always the better starting lever.
Mistake: Using high temperature for tasks that need factual accuracy High temperature makes factually incorrect outputs more likely because lower-probability tokens (which may include incorrect information) become more competitive. For anything involving facts, figures, or structured data, keep temperature low.
Mistake: Ignoring that parameter defaults vary by platform The default temperature in ChatGPT's interface, the Playground, and the API may differ. When you find a combination that works, document the exact values — don't assume they'll transfer automatically.
You now understand that AI text generation is inherently probabilistic, and that parameters give you meaningful control over where that probability sits. Temperature is your primary lever — low for consistency and accuracy, high for creativity and variety. top_p is an alternative sampling limiter. max_tokens controls length and cost. frequency_penalty and presence_penalty reduce repetition at different scales.
The real skill isn't memorizing optimal values — it's developing the judgment to ask what kind of output does this task actually require? and then matching your parameters to that answer.
Next steps to continue building on this foundation:
Explore the OpenAI Playground systematically. Pick one business prompt you use regularly and run it at five different temperature settings. Build your own intuition rather than trusting someone else's recommendations blindly.
Read the next lesson in this path: Prompt Engineering Fundamentals — because parameters and prompts work together. A well-crafted prompt can often achieve what you'd otherwise need aggressive parameter tuning for.
Experiment with other models. Anthropic's Claude, Google's Gemini, and Meta's Llama family all have temperature and similar parameters. The underlying concepts are consistent; the specific behavior at a given value can differ.
Build a parameter cheat sheet for your team. Document the settings you use for each recurring AI task in your workflow. This is one of the highest-leverage things a team can do to standardize AI output quality.
Learning Path: Intro to AI & Prompt Engineering