liveBook · Manning

Temperature

As explained in Machine Learning Platform Engineering

Temperature is a generation setting that adjusts how strongly token selection favors high-probability alternatives.

Temperature controls how adventurous token selection is during LLM generation. At 0, generation favors the most probable next token, producing highly consistent responses; higher values increase variety while potentially reducing coherence. Because temperature changes output variability, it also changes how production systems must test and evaluate responses. section 12.1.1

Choose temperature according to the operational behavior your application needs:

  • Use temperature=0 when consistency, debugging, and reliable semantic evaluation matter most. Outputs are near-deterministic, but implementation details can still prevent exact reproducibility. section 12.2.6 section 12.5
  • Use higher values such as 0.7–1.0 to increase response variety, while accepting a greater risk of reduced coherence. section 12.1.1
  • Replace exact-string assertions with semantic correctness, factual accuracy, and guideline adherence when sampling makes repeated outputs differ. section 12.1.1

Consistent Gemini generation

A production RAG application can configure Gemini through LangChain with temperature=0. This favors the most probable tokens and supports consistent testing and debugging, while remaining short of guaranteed reproducibility. section 12.2.6 section 12.5

Listing 12.1 Parameters that control output randomness
temperature=0.0  #1
temperature=0.7  #2
temperature=1.5  #3

top_k=1 #4
top_k=40  #5
top_k=100  #6

top_p=0.1  #7
top_p=0.9  #8
top_p=1.0 #9

Compare temperature values from 0.0 through 1.5 alongside top-k and top-p settings that also control output randomness. section 12.1.1

Listing 12.11 Gemini config with zero temperature
llm = ChatGoogleGenerativeAI(
    model="gemini-2.5-flash",  #1
    temperature=0.,  #2
    google_api_key=os.environ["GEMINI_API_KEY"],  #3
    convert_system_message_to_human=True  #4
)

Inspect a complete Gemini 2.5 Flash configuration using zero temperature for production-oriented consistency. section 12.2.6

How Machine Learning Platform Engineering covers it

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.
How it connects
Connects sampling strategies with top-k, top-p, nondeterminism, semantic evaluation, and retrieval-augmented generation.

Also explained in

Compare how 17 books explain temperature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.