All problems
MMR Summary Selection
Problem
Select k sentences with maximal marginal relevance. Start empty, then repeatedly pick the remaining index maximizing lam * relevance[i] - (1 - lam) * max similarity from i to already selected sentences, where an empty selection makes the second term 0.
Ties go to the lowest index. Return the selected indices in selection order.
Hint
Recompute the penalty against the selected set on every iteration.
Test cases
case 1
in: [[0.9,0.8,0.7],[[1,0.1,0.1],[0.1,1,0.5],[0.1,0.5,1]],0.7,2]
expected: [0,1]
case 2
in: [[0.9,0.7,0.7],[[1,0.1,0.1],[0.1,1,0.5],[0.1,0.5,1]],0.5,2]
expected: [0,1]
case 3
in: [[0.9,0.8,0.7],[[1,0.1,0.1],[0.1,1,0.5],[0.1,0.5,1]],0.7,5]
expected: [0,1,2]
case 4
in: [[0.9],[[1]],0.7,0]
expected: []
case 5
in: [[],[],0.7,2]
expected: []
Starter codePython
def mmr_selection(relevance, similarity, lam, k):
# Your code here
pass5 test cases · run your code against them in the editor