Topic
Sampling Parameters: Top-p, Top-k & Penalties
11 posts on sampling parameters: top-p, top-k & penalties — part of glossary on the n4n AI blog.
What is top-k sampling and how does it work?
A precise technical explanation of top-k sampling for LLM inference, covering mechanics, trade-offs, and practical configuration guidance.
What is nucleus sampling (top-p) in language models?
Nucleus sampling (top-p) dynamically selects tokens from the smallest probability mass covering p% of the distribution, balancing coherence and diversity in LLM output.
Top-p vs top-k sampling: what's the difference?
A practitioner's comparison of top-p and top-k sampling, covering mechanics, trade-offs, and when to use each for LLM inference.
How top-p and temperature work together
A practical guide to how top-p and temperature interact during LLM sampling, with code examples, common pitfalls, and parameter combinations for different use cases.
How sampling parameters affect code generation quality
A practitioner's breakdown of how temperature, top-p, top-k, and penalties change code output quality — with concrete API examples and per-use-case settings.
How random sampling makes every LLM answer a bit different
Understand why LLMs produce different outputs for the same prompt — sampling mechanics, temperature, top-p, and how to control randomness in production.
How OpenAI's frequency_penalty parameter actually works
A practical guide to OpenAI's frequency_penalty parameter — how the math works, when to apply it, tuning strategies, and common mistakes that waste tokens.
Frequency penalty vs presence penalty, explained
Understand the mathematical difference between frequency penalty and presence penalty, when each reduces repetition, and how to tune them for your use case.
Default sampling settings across GPT-4o, Claude, and Llama 3
Compare default sampling parameters across GPT-4o, Claude, and Llama 3 — temperature, top-p, top-k, and penalties — with a verdict on which to choose per use case.
Combining top-p, top-k and temperature: a practical guide
A practical guide to combining top-p, top-k, and temperature sampling parameters for LLM inference, with code examples and common pitfalls.
Best top-p value for factual, low-variance answers
Find the best top-p value for factual answers with a repeatable tuning process, code examples, and verification steps for production LLM pipelines.
More topics in glossary
- Structured Outputs & JSON Mode19
- AI Agents Fundamentals12
- Hallucination in LLMs11
- Context Window & Context Length10
- Fine-Tuning Fundamentals9
- Foundation Models: Base vs Instruct vs Chat9
- Model Families & Naming Conventions: GPT-5, Claude, Gemini 3, Llama 4, Mistral, DeepSeek, Qwen, Grok9
- Grounding & Fact-Checking in AI8
- LLM Benchmarks: MMLU, HumanEval, SWE-bench & GPQA8
- Max Tokens, Stop Sequences & Output Truncation8
- Quantization Formats: GGUF, GPTQ, AWQ & INT4/INT88
- Chain-of-Thought Prompting7