Train a Next-Word Predictor from Tokenized Sentences

Asked at Bloomberg · Coding & Leetcode-style Questions · Difficulty: Medium

You are given a set of tokenized training sentences (each sentence is a list of words). Train a "next-word predictor". After training, for any query word `q`, return the most likely word that immediately follows `q` in the training data.

Loading the problem…