TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

163. MMR Diversification

Medium

Greedily select k documents that balance relevance to the query with diversity from already-selected documents.

Signature: def mmr(query_sim: np.ndarray, doc_doc_sim: np.ndarray, lam: float, k: int) -> list

At each step, pick the un-selected document d that maximizes:

lam * query_sim[d] - (1 - lam) * max_{s in selected} doc_doc_sim[d, s]

For the first selection (no prior s), use just lam * query_sim[d]. Return the list of selected indices in selection order.

Math

MMR=argd∈/Smax​[λ⋅sim(d,q)−(1−λ)⋅s∈Smax​sim(d,s)]

Asked at

NumPy

import numpy as np

 

def mmr(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?