Yashotantra Academy logo
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Inference · easy

5. Sampling parameters: temperature, top-p, penalties

Decoding settings control creativity, determinism, and repetition.

1 min read3 questionsup to 50 XPtopic 5/12

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

The model gives you a distribution; the sampler decides what you actually get.

| Parameter | Effect | Typical use | | --- | --- | --- | | `temperature` | Scales logits before softmax. 0 ≈ greedy, >1 flattens | 0-0.3 extraction, 0.7-1.0 drafting | | `top_p` | Nucleus sampling: keep smallest set of tokens with cumulative prob ≥ p | 0.9-1.0 | | `top_k` | Keep only the k most likely tokens | 40-100 | | `presence_penalty` | Discourages tokens already used at all | Reduce topic looping | | `frequency_penalty` | Discourages tokens by how often used | Reduce verbatim repetition | | `max_tokens` | Hard stop on output length | Cost control |

ts
const res = await client.chat.completions.create({
  model: "gpt-5-mini",
  temperature: 0,           // deterministic-ish for structured extraction
  top_p: 1,
  max_tokens: 512,
  messages: [{ role: "user", content: prompt }],
});

Gotcha: temperature 0 is *near*-deterministic, not guaranteed. Batching, GPU kernel nondeterminism, and mixture-of-experts routing can still shift outputs. Don't build exact-match tests on live model calls.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. What does lowering temperature toward 0 do?

  2. 2. What does top_p = 0.9 mean?

  3. 3. Which parameter best reduces literal repeated phrases?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP