liveBook · Manning

Temperature

As explained in Build Applications with Local AI Models on a Mac

A language-model generation setting that controls the randomness of token selection.

Temperature controls how predictable or varied a language model’s responses are. The model scores possible next tokens—pieces of text—and chooses one at each step. Temperature changes how strongly that choice favors the highest-scoring option. section 13.3.1

Try three settings with the same prompt:

  • 0.0 favors the highest-probability token at each step. Replies tend to be predictable, but this does not guarantee accuracy or safety. section 13.3.1
  • 0.7 sometimes selects less-probable but reasonable tokens. It is a starting point for natural, varied replies; defaults differ by model and runtime. section 13.3.1
  • 1.5–2.0 makes unusual choices more likely. Replies can be inventive, but also incoherent. section 13.3.1

One writing prompt, three results

A sunset description moves from straightforward at 0.0, to vivid at 0.7, to surreal at 1.5. Change only temperature to see how word choice shifts. section 13.3.1

Temperature does not set the assistant’s personality: a system prompt guides its behavior and presentation. Start by adjusting temperature alone; top_k, top_p, and repeat_penalty offer finer control when needed. section 13.3 section 13.3.1

model_names = [model["name"] for model in ollama_models]
model_labels = {model["name"]: model["label"] for model in ollama_models}
llm_model = st.selectbox(
    "LLM Model (Ollama)",
    model_names,
    index=selected_model_index,
    format_func=lambda name: model_labels.get(name, name),
)

whisper_label = st.selectbox("Whisper Model", list(WHISPER_MODELS.keys()))
whisper_model = WHISPER_MODELS[whisper_label]

temperature = st.slider("Temperature", min_value=0.0, max_value=2.0,
                        value=0.7, step=0.1)

A Streamlit slider lets users choose 0.0–2.0 in steps of 0.1, starting at 0.7. The selected value is passed to Ollama as a generation option. section 10.5.2

How Build Applications with Local AI Models on a Mac covers it

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 it assumes
Starts with an existing chatbot and explains next-token selection in plain language.
What you can do after
Apply it via a Streamlit slider and Ollama generation options to adjust chatbot response variety.
How it connects
Distinguishes temperature from system prompts and relates it to top_k, top_p, and repeat_penalty.

Also explained in

Compare how 17 books explain temperature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Applications with Local AI Models on a Mac. The section links point to the parts of the book it draws on.