Bug: possible mistake in MMR calculation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 385
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
If I am reading the code correctly, there is a mistake in the implementation of maximal marginal relevance (MMR) calculation.
Referring to the original publication https://doi.org/10.1145/290941.291025, the calculation is:

and the code as currently implemented:
```python
mmr = (
1 - diversity
) * candidate_similarities - diversity * target_similarities.reshape(-1, 1)
mmr_idx = candidates_idx[np.argmax(mmr)]
```
assuming:
- `diversity` is equal to 1-λ
- _Sim_1(D_i,Q)_ corresponds to `candidate similarities`
- _max Sim_2(D_i,D_j)_ corresponds to `target_similarities`
and I am assuming the last point because of the code:
```python
target_similarities = np.max(
word_similarity[candidates_idx][:, keywords_idx], axis=1
)
```
the code should be:
```python
mmr = (1 - diversity) *
(candidate_similarities - diversity * target_similarities.reshape(-1, 1))
mmr_idx = candidates_idx[np.argmax(mmr)]
```
So it appears to me that `diversity` is not distributed to both similarity terms as in the original equation; there needs to be parens around the difference between the similarity terms
I would note that I have seen a similar lack of parentheses, which distribute the diversity term (λ), in other works, for example http://www.cs.bilkent.edu.tr/~canf/CS533/hwSpring14/eightMinPresentations/handoutMMR.pdf
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the Python MMR implementation containing the shown `mmr` expression and trace how `candidate_similarities`, `target_similarities`, and `diversity` are computed. Compare the implementation with the cited publication and determine the intended λ mapping; done means the formula is resolved and its behavior is checked by the project's existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100