All problems
Interpolation Probability
Problem
Return the linearly interpolated trigram probability lambdas[0] * P(w3 | w1 w2) + lambdas[1] * P(w3 | w2) + lambdas[2] * P(w3).
The three dictionaries are keyed by 'w1 w2 w3', 'w2 w3', and w3 respectively. Missing entries contribute 0.0.
Hint
Look up each order with dict.get and blend the three values with the weights.
Test cases
case 1
in: [["a","b"],"c",{"a b c":0.2},{"b c":0.4},{"c":0.1},[0.5,0.3,0.2]]
expected: 0.24
case 2
in: [["a","b"],"c",{},{},{"c":0.5},[0.2,0.3,0.5]]
expected: 0.25
case 3
in: [["a","b"],"c",{},{"b c":1},{},[0,1,0]]
expected: 1
case 4
in: [["x","y"],"z",{},{},{},[0.33,0.33,0.34]]
expected: 0
Starter codePython
def interpolation_prob(context, token, tri_probs, bi_probs, uni_probs, lambdas):
# Your code here
pass4 test cases · run your code against them in the editor