← Microsoft Interview Insights

Microsoft·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Did a technical screen for an ML Engineer role at Microsoft that focused on sequence decoding. Pretty implementation-heavy, no fluff.

Questions Asked (1)

Q1

Extend a greedy decoder to beam search with beam width k. Walk through how you'd maintain multiple partial hypotheses, score extensions using log-probabilities, and decide when to finalize.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew beam search conceptually but fumbled the implementation details under pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by contrasting greedy decoding with beam search, emphasizing how beam search maintains k hypotheses to avoid local optima. Then walk through the algorithm step-by-step: initialization, expansion, scoring with log-probabilities, pruning, and finalization. Conclude with trade-offs and practical considerations like length normalization.

Pro tip: Mention that beam search is not guaranteed to find the global optimum but often improves results; also highlight the importance of length normalization to avoid favoring shorter sequences, and discuss how to handle end-of-sequence tokens.

1. Initialize the beam

Start with a single hypothesis containing the start token and a score of 0 (log-probability). Set beam width k.

2. Expand and score candidates

For each hypothesis in the beam, generate all possible next tokens from the vocabulary. Compute the new score by adding the log-probability of the token to the hypothesis score.

3. Prune to top k hypotheses

Collect all candidate extensions, sort them by score (higher is better), and keep the top k hypotheses. If a hypothesis ends with an end-of-sequence token, mark it as complete but keep it in the beam for now.

4. Repeat until stopping criterion

Continue expanding and pruning until all hypotheses in the beam are complete or a maximum length is reached. Optionally, stop early if the top hypothesis is complete and its score cannot be beaten by any incomplete hypothesis.

5. Finalize and select best hypothesis

Among complete hypotheses, select the one with the highest score, applying length normalization if needed. Return the corresponding sequence.

Key Points to Mention

  • Log-probabilities are used to avoid numerical underflow and because they turn multiplication into addition.
  • Beam width k controls the trade-off between computational cost and search quality; larger k explores more but is slower.
  • Length normalization (e.g., dividing by length or using a length penalty) is crucial to prevent bias toward shorter sequences.
  • Handling of end-of-sequence tokens: once a hypothesis generates EOS, it is considered complete and should not be expanded further.
  • Stopping criteria: either when all beams are complete or when a maximum length is reached; early stopping can be used if the best complete hypothesis cannot be surpassed.
  • Beam search is a heuristic and may not find the global optimum, but it often outperforms greedy decoding.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.