Build a bigram next-word predictor with weighted sampling

Quick Overview

This question evaluates understanding of basic probabilistic language modeling—specifically bigram/first-order Markov models and weighted sampling for next-word prediction—within the Machine Learning (natural language processing) domain, emphasizing practical implementation skills alongside conceptual scalability trade-offs.

Build a bigram next-word predictor with weighted sampling

Company: Google

Role: Software Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Technical Screen

You are given a training set of token sequences (sentences), for example: ``` [["a","b","c"], ["a","s","d"]] ``` 1) Train a simple **next-word prediction** model that, for each word `w`, counts which words most frequently appear **immediately after** `w` (a bigram / 1st-order Markov model). 2) At inference time, given a current word `w`, output a **random next word** sampled **proportionally to the observed counts** after `w` (i.e., weighted by frequency). 3) Discuss what you would do if the vocabulary and/or number of distinct next-words per token is very large (memory and latency constraints).

Quick Answer: This question evaluates understanding of basic probabilistic language modeling—specifically bigram/first-order Markov models and weighted sampling for next-word prediction—within the Machine Learning (natural language processing) domain, emphasizing practical implementation skills alongside conceptual scalability trade-offs.

|Home/Machine Learning/Google
Google logo
Google
Jan 11, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenMachine Learning
7
0

You are given a training set of token sequences (sentences), for example:

[["a","b","c"],
 ["a","s","d"]]
  1. Train a simple next-word prediction model that, for each word w , counts which words most frequently appear immediately after w (a bigram / 1st-order Markov model).
  2. At inference time, given a current word w , output a random next word sampled proportionally to the observed counts after w (i.e., weighted by frequency).
  3. Discuss what you would do if the vocabulary and/or number of distinct next-words per token is very large (memory and latency constraints).
Loading comments...