liveBook · Manning

Probability distribution

As explained in Build Python Web Apps with Streamlit

A probability distribution assigns likelihoods to the possible values or events of a random variable.

A probability distribution shows how likely each possible outcome is. In an LLM, it describes the likelihood assigned to every candidate token for the next step in a response. section 9.6.1

Use the distribution to understand how response settings change model behavior:

  • Temperature changes the curve’s shape: higher values flatten it, making less-likely tokens more selectable and responses more creative; lower values make it more pronounced. section 9.6.1
  • top_p limits selection to the most likely tokens whose cumulative probability reaches the chosen cutoff. section 9.6.1

A top_p cutoff

Suppose the next-token probabilities are “but” 0.6, “then” 0.2, “a” 0.1, “this” 0.06, and “that” 0.02. With top_p set to 0.8, the model keeps “but” and “then,” whose combined probability reaches 0.8, and discards the others. section 9.6.1

Figure 9.10 How temperature and top_p affect the creativity and predictability of an LLM’s output.

Compare how temperature and top_p affect an LLM’s creativity and predictability. section 9.6.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines the token-likelihood curve and works through temperature and top_p, without developing broader probability theory.
Examples
Uses five candidate tokens with explicit probabilities to demonstrate a top_p cutoff.
What it assumes
Assumes only basic understanding that probabilities range from 0 to 1 and introduces token selection through a concrete example.
What you can do after
Operate/configure LLM generation by relating temperature and top_p settings to creativity and predictability.
How it connects
Connects probability distributions to tokens, large language models, temperature, and top_p.

Also explained in

Compare how 27 books explain probability distribution →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.