Introduction
When generating text, choosing the next word can be tricky because many options might fit. Temperature and sampling parameters help decide how creative or predictable the generated text will be.
Imagine you are picking songs for a party playlist. Temperature is like deciding if you want only popular hits (low temperature) or a mix including rare tracks (high temperature). Top-k is like choosing only from the top 10 songs on the chart, while top-p is like picking songs until you cover 80% of the party's favorite genres.
┌─────────────┐
│ Input │
└─────┬───────┘
│
▼
┌─────────────┐
│ Probability │
│ Distribution│
└─────┬───────┘
│
▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Temperature │─────▶│ Top-k │─────▶│ Top-p │
│ (Randomness)│ │ Sampling │ │ Sampling │
└─────────────┘ └─────────────┘ └─────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────┐
│ Next Word Selection │
└─────────────────────────────────────────────┘