Given a sample data set of sentences, write a function to predict next word.
Asked in the Round 3 stage. Build a frequency-based language model using trigrams, with fallback to bigrams and then overall word frequency.
sentences is a list of non-empty lowercase sentence strings. prefix is a non-empty string of lowercase words. Return the most frequent predicted word, breaking ties lexicographically, or None if the training data contains no words.
Example: sentences = ["i like tea", "i like coffee", "i like tea"], prefix = "i like" returns "tea".
def predict_next_word(sentences, prefix):