Loading...
Given a corpus of text, compute bigram probabilities.
A bigram probability is P(word2 | word1) = count(word1, word2) / count(word1).
Input format:
Round the probability to 4 decimal places.
Output: The bigram probability as a float.
the cat sat on the mat the cat
0.5
Step 1: Count bigrams starting with "the" "the cat" appears 1 time "the mat" appears 1 time Total: "the" appears 2 times as first word of a bigram
Step 2: Calculate probability P(cat | the) = count("the cat") / count("the") = 1 / 2 = 0.5