Choose Between Greedy, Beam Search, and Nucleus Sampling for Generation

Last updated: November 29, 2026

Quick Overview

Compare greedy decoding, beam search, top-k, and nucleus (top-p) sampling, implement a top-p filter, and say which you would use for Google Translate, Smart Compose, and an open-ended Gemini chat reply.

Google
Machine Learning
Machine Learning Engineer
Google
November 29, 2026
Machine Learning Engineer
Phone Screen
Machine Learning
Easy

0

0

0 solved


Compare greedy decoding, beam search, top-k, and nucleus (top-p) sampling, implement a top-p filter, and say which you would use for Google Translate, Smart Compose, and an open-ended Gemini chat reply.

Decoding choices are product decisions at Google: Translate wants the single most faithful output, Smart Compose wants short, safe, high-precision completions, and a chat assistant wants varied but coherent prose. The interviewer checks whether you can tie each algorithm's failure mode to a concrete product.

What the Interviewer Expects
  • Explains greedy and beam search as approximate maximization of sequence likelihood
  • Explains why maximum-likelihood decoding is repetitive and bland for open-ended text
  • Defines top-k and top-p and why top-p adapts to the shape of the distribution
  • Implements a top-p filter correctly, including renormalization
  • Matches strategies to products with reasons
  • Mentions length normalization for beam search
Key Topics to Cover
Beam search
Nucleus sampling
Top-k sampling
Temperature
Decoding strategies
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 beam search favor short outputs, and how does length normalization fix it?
  • How do temperature and top-p interact?
  • How would you make sampling deterministic for debugging and caching?
  • What does min-p sampling do differently from top-p?
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

At each step the model gives a next-token distribution. Decoding decides how to turn those into a sequence. I will cover greedy, beam search of width BB, top-k, and top-p, and then map them to three ...

Approach

Greedy takes the argmax each step. Beam search keeps the BB best partial sequences by total log-probability, which approximates the most likely full sequence. Top-k samples from the kk most likely t...


Submit Your Answer
Markdown supported