All problems
Dice Bigram Coefficient
Problem
Return the Dice coefficient 2 * O / (c1 + c2) for the adjacent bigram (w1, w2), where O is how often w1 is immediately followed by w2 and c1, c2 are the token counts.
Return 0.0 when c1 + c2 is 0.
Hint
The coefficient is maximal when every occurrence of either word forms the bigram.
Test cases
case 1
in: [["new","york","new","york","city"],"new","york"]
expected: 1
case 2
in: [["the","cat","sat","on","the","mat"],"the","cat"]
expected: 0.6666666666666666
case 3
in: [["a","b","c"],"b","a"]
expected: 0
case 4
in: [[],"a","b"]
expected: 0
Starter codePython
def dice_bigram_coefficient(tokens, w1, w2):
# Your code here
pass4 test cases · run your code against them in the editor