Temperature
A temperature parameter adjusts the concentration of a probability distribution, affecting sampling randomness or the likelihood of accepting less favorable transitions.
Optimization Algorithms: AI techniques for design, planning, and control problems
A simulated-annealing control value that influences the likelihood of accepting worsening state transitions.
- How it is used
- Controls acceptance of worsening moves to balance exploration and exploitation in simulated annealing.
- How deep it goes
- Works through the acceptance calculation and cooling parameters, then illustrates their effects with hand iterations and implementation examples.
- Examples
- Uses a bounded quadratic minimization with T = 5, a rejected move, and a geometric cooling update.
- What you can do after
- Operate/configure it by selecting a starting temperature, cooling rule, attempts per temperature, and stopping temperature, then tuning their trade-offs.
Natural Language Processing in Action, Second Edition
Temperature is a decoding parameter that rescales token scores to control the randomness of a generated distribution.
- How it is used
- Controls variation in next-token selection and repeated chatbot responses.
- How deep it goes
- Explains temperature through ranked token choices and greedy-search behavior, then shows a configuration value without deriving a score-scaling formula.
- Examples
- Uses a token-choice diagram, a GPT-2 greedy continuation, and a LangChain Replicate math-tutor configuration.
- What you can do after
- Operate/configure it in a LangChain Replicate chatbot and evaluate varied responses against conversation goals.
Read how Natural Language Processing in Action, Second Edition explains temperature →
Build a Reasoning Model (From Scratch)
A token sampling method that draws from a probability distribution after temperature rescaling to control randomness.
- How it is used
- Prepares next-token probabilities for inference-time top-p filtering.
- How deep it goes
- Demonstrates scaling at temperature 1.0 and softmax, then shifts to top-p filtering rather than detailing temperature choices.
- Examples
- Uses ten-entry toy logits, a probability bar plot, and a temperature-1.0 PyTorch pipeline.
- What you can do after
- Apply it via PyTorch by scaling next-token logits and converting them to probabilities before filtering.
Read how Build a Reasoning Model (From Scratch) explains temperature →
Build Python Web Apps with Streamlit
Temperature is a language-model sampling parameter that controls how broadly probability is spread across possible next tokens.
- How it is used
- Tunes response variability while generating questions for a multi-question trivia game.
- How deep it goes
- Explains next-token probabilities and temperature’s effect on their distribution, then shows API configuration without deriving the sampling mathematics.
- Examples
- Uses a trivia game that requests questions with temperature=0.7, top_p=0.9, a changing seed and a list of earlier questions.
- What you can do after
- Apply it via the OpenAI Python library to vary generated questions while checking whether the selected model supports explicit configuration.
Read how Build Python Web Apps with Streamlit explains temperature →
Generative AI in Action
Temperature is a model-generation setting that controls the degree of randomness in the model's output distribution.
- How it is used
- Tunes text-generation variability per API call to suit creative work or tasks needing more consistent responses.
- How deep it goes
- Defines the setting and compares outputs at three values, without deriving the underlying probability calculation.
- Examples
- Compares three pet-grooming naming outputs at 0.8 and 0.2, then shows nonsensical results at 1.8.
- What you can do after
- Operate/configure it per completion API call and compare repeated outputs against the task’s need for variety or consistency.
Data Analysis with LLMs
Temperature is a model-generation setting that controls the degree of stochastic variation in selecting output tokens from their probability distribution.
- How it is used
- Controls output variation in chat completions, from creative stories to repeatable sentiment classification.
- How deep it goes
- Explains the effect on token selection, the 0–2 range, and practical trade-offs without deriving model internals.
- Examples
- Uses a GPT-4o story call at 1.5 and a GPT-3.5 Turbo review classifier at 0.
- What you can do after
- Apply it via OpenAI’s Python library to increase story variation or minimize randomness in classification.
Effective Conversational AI
Temperature is a generation parameter that controls the degree of randomness in a language model's token selection.
- How it is used
- Uses temperature with sampling decoding to broaden chatbot intent examples and increase generated-response creativity.
- How deep it goes
- Defines temperature as a randomness and diversity control, but stops short of explaining its implementation or numerical scale.
- Examples
- Generates password synonyms, verb phrases, and transcript summaries while illustrating useful variation alongside oddities and hallucination risk.
- What you can do after
- Apply it via sampling-decoding settings to trade deterministic repetition for creative variation, then review outputs for relevance and hallucinations.
Building Reliable AI Systems
Temperature is a language-model generation parameter that controls the randomness of token selection.
- How it is used
- Tunes chatbot response predictability and diversity for tasks with different reliability and creativity needs.
- How deep it goes
- Explains the next-token effect, compares settings, and gives API examples, but does not derive the probability adjustment mathematically.
- Examples
- Compares iPhone specification answers at 0.3 and 0.8 and configures temperature in grocery-store idea prompts.
- What you can do after
- Operate/configure it through supported model APIs and evaluate the predictability–variety trade-off without treating determinism as correctness.
Read how Building Reliable AI Systems explains temperature →
Deep Learning with R, Third Edition
Temperature is a generation parameter that controls the concentration or spread of a model's next-token probability distribution.
- How it is used
- Controls diversity during autoregressive text generation by adjusting how broadly next-token sampling explores the model distribution.
- How deep it goes
- Explains logits, softmax concentration, generated-output effects, and combination with top-k, without deriving the probability transformation.
- Examples
- Uses generated text at temperatures 0.2, 0.8, and 2, plus combined top-k examples with k values of 5 and 20.
- What you can do after
- Apply it via a random sampling function and tune generation between repetitive low-temperature output and erratic high-temperature output.
Read how Deep Learning with R, Third Edition explains temperature →
Machine Learning Platform Engineering
Temperature is a generation setting that adjusts how strongly token selection favors high-probability alternatives.
- How it is used
- Controls response variability and informs testing strategy for production LLM applications.
- How deep it goes
- Defines zero and higher-temperature behavior, then stops short of guaranteeing reproducible outputs.
- Examples
- Compares 0.0, 0.7, and 1.5 settings and configures Gemini 2.5 Flash with zero temperature.
- What you can do after
- Configure Gemini through LangChain and evaluate variable responses without relying on exact string matches.
Read how Machine Learning Platform Engineering explains temperature →
Build a Large Language Model (From Scratch)
A decoding method that rescales next-token probabilities with a temperature to make sampling more or less random.
- How it is used
- Controls diversity during autoregressive text generation alongside optional top-k filtering.
- How deep it goes
- Implements logit scaling, softmax conversion, and multinomial sampling, while deferring systematic setting combinations to exercises.
- Examples
- Demonstrates a 15-token continuation using temperature 1.4 and top-k 25, contrasting it with a memorized passage.
- What you can do after
- Apply it via a modified generate function and compare outputs across temperature and top-k settings.
Read how Build a Large Language Model (From Scratch) explains temperature →
AI Agents in Action, Second Edition
- How it is used
- Tunes token sampling to trade consistency against creativity for an agent’s role.
- How deep it goes
- Explains temperature’s effect on sampling and demonstrates settings, while warning that zero does not guarantee identical outputs.
- Examples
- Compares coder and creative-writer settings and tests agent consistency at temperatures 0 and 1.0.
- What you can do after
- Configure OpenAI Agents SDK model settings for more consistent outputs, then compare repeated runs.
Read how AI Agents in Action, Second Edition explains temperature →
Spring AI in Action
Temperature is a language-model generation parameter from 0 to 2 that scales token probabilities to control response randomness.
- How it is used
- Controls randomness in language-model token selection during chat generation.
- How deep it goes
- Defines the 0-to-2 range and behavioral effect without deriving the probability-scaling mathematics.
- Examples
- Uses candidate words with decreasing probabilities and shows global or programmatic configuration at 0.7.
- What you can do after
- Apply it via ChatOptions or application.properties to tune generation randomness.
Transformers in Action
Temperature sampling is a sampling strategy that adjusts the sharpness of a token probability distribution before selecting the next token.
- How it is used
- Controls randomness and output diversity during token selection for text generation.
- How deep it goes
- Explains logit adjustment, softmax sharpness, limiting behavior, and a Transformers implementation, without deriving the formula.
- Examples
- Uses a Transformers generate() listing with temperature 0.7, three returned sequences, and a generated AI-researcher continuation.
- What you can do after
- Apply it via Transformers to produce more focused or more diverse text continuations.
The Complete Obsolete Guide to Generative AI
Temperature is a generation parameter that controls the randomness or diversity of a language model's output.
- How it is used
- Adjusts generation randomness to match a prompt’s desired creativity, focus, tone, verbosity, or cost.
- How deep it goes
- Defines the setting, gives its 0–2 range and default, and demonstrates contrasting outputs without explaining sampling internals.
- Examples
- Demonstrates restaurant recommendations at 1.3 and 0.2, plus a creative story prompt using 0.8.
- What you can do after
- Operate temperature through the OpenAI Playground and transfer tested settings into API code.
Read how The Complete Obsolete Guide to Generative AI explains temperature →
Build Applications with Local AI Models on a Mac
A language-model generation setting that controls the randomness of token selection.
- How it is used
- Controls whether Ollama chatbot replies favor predictable or varied wording.
- How deep it goes
- Explains next-token choice and compares three settings without deriving the underlying probabilities.
- Examples
- Compares three sunset descriptions and shows a Streamlit temperature slider.
- What you can do after
- Apply it via a Streamlit slider and Ollama generation options to adjust chatbot response variety.
Read how Build Applications with Local AI Models on a Mac explains temperature →
Machine Learning Algorithms in Depth
A temperature parameter is a positive scaling value that controls the probability of accepting unfavorable transitions in simulated annealing.
- How it is used
- Controls acceptance of higher-energy transitions during simulated annealing.
- How deep it goes
- Explains acceptance behavior and cooling, but does not derive the transition-probability formula in the supplied description.
- Examples
- Uses an energy-minimization search with a cooling schedule that multiplies temperature by 0.9.
- What you can do after
- Apply it by controlling acceptance of higher-energy proposals and lowering temperature with a cooling schedule.
Read how Machine Learning Algorithms in Depth explains temperature →
Related concepts
- softmaxuses · Softmax is a function that exponentiates a vector of scores and normalizes the results into nonnegative values that sum to one.
- logituses · A logit is a real-valued quantity representing an outcome’s log-odds or, in machine learning, an unnormalized model score used to derive probabilities.
- hyperparameterkind of · A hyperparameter is a setting chosen outside ordinary parameter learning that controls a model, algorithm, or learning procedure.
- output varianceconfigures · Output variance is the degree to which an AI model produces different results for ostensibly repeated or similar prompts.
- language modelconfigures · A language model is a computational model that represents patterns in linguistic tokens to estimate sequence probabilities and predict or generate language from context.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
















