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
Machine Learning
Machine Learning Engineer
Meta
November 29, 2026
Machine Learning Engineer
Phone Screen
Machine Learning
Easy

0

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
decoding strategies
temperature
nucleus sampling
top-k sampling
LLM generation
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample 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: pi∝exp⁡(zi/T)p_i \propto \exp(z_i / T). T<1T < 1 sharpens it toward the argmax; T>1T > 1 flattens it. Top-k keeps the k highest-probability tokens. Top-p keeps the smallest s...


Submit Your Answer
Markdown supported