Choose Decoding Settings: Temperature, Top-k, and Nucleus Sampling
Last updated: November 29, 2026
Quick Overview
Implement next-token sampling with temperature, top-k, and top-p (nucleus) filtering, and explain which settings you would use for factual answers versus creative captions in Meta AI.
Meta
November 29, 20260
0
0 solved
Implement next-token sampling with temperature, top-k, and top-p (nucleus) filtering, and explain which settings you would use for factual answers versus creative captions in Meta AI.
Decoding is a cheap lever that directly changes how Meta AI feels to users, from accurate answers to playful Instagram captions. The interviewer checks a correct implementation and an intuitive grasp of what each knob does to the distribution.
What the Interviewer Expects
- Apply temperature to logits before the softmax
- Implement top-k and top-p filtering and renormalize
- Handle temperature zero as greedy decoding
- Explain the effect of each knob on diversity and errors
- Recommend settings per use case
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Why does greedy decoding produce repetitive text in long generations?
- How does a repetition penalty work and what can go wrong with it?
- Why might you prefer top-p over top-k when the distribution shape changes a lot?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Input is a vector of logits over the vocabulary. Output is one token ID. Temperature 0 means greedy. Top-k of 0 means no top-k filter; top-p of 1.0 means no nucleus filter....
Approach
Temperature reshapes the distribution: . sharpens it toward the argmax; flattens it. Top-k keeps the k highest-probability tokens. Top-p keeps the smallest s...