All problems
Backoff Probability with Floor
Problem
Backoff uses the bigram maximum likelihood estimate when the bigram was seen, and scales the unigram probability by alpha otherwise: count / total when count > 0 else alpha * unigram_probability.
Given the bigram count and total, the unigram probability, and alpha, return the probability.
Hint
Only unseen bigrams fall back to the lower order.
Test cases
case 1
in: [5,100,0.01,0.4]
expected: 0.05
case 2
in: [0,100,0.01,0.4]
expected: 0.004
case 3
in: [1,4,0.5,0.1]
expected: 0.25
Starter codePython
def backoff_probability_with_floor(bigram_count, bigram_total, unigram_probability, alpha):
# Your code here
pass3 test cases · run your code against them in the editor