Loading...
Given a corpus and a context word, predict the most likely next word using bigram counts.
If there are ties, return the word that comes first alphabetically.
Input format:
Output: The predicted next word and its probability (rounded to 4 decimal places), separated by a space.
i like cats i like dogs i hate rain i
like 0.6667
Step 1: Find all bigrams starting with "i" i→like (2 times), i→hate (1 time)
Step 2: Find most frequent "like" has count 2, "hate" has count 1 Most frequent: "like"
Step 3: Calculate probability P(like | i) = 2/3 = 0.6667