Inferensys

Glossary

Maximal Marginal Relevance (MMR)

A re-ranking algorithm that balances a phrase's relevance to the document against its redundancy with already selected keyphrases.
Developer working on RAG retrieval system, document chunks visible on screen, technical workspace with code editor.
DIVERSITY-DRIVEN RE-RANKING

What is Maximal Marginal Relevance (MMR)?

Maximal Marginal Relevance (MMR) is a re-ranking algorithm that iteratively selects documents or keyphrases by balancing their relevance to a query against their redundancy with items already selected, ensuring a diverse result set.

Maximal Marginal Relevance (MMR) is a greedy algorithm that constructs a ranked list by maximizing a linear combination of relevance and novelty. For each candidate, it computes a score that rewards high similarity to the query while penalizing high similarity to previously selected items, controlled by a trade-off parameter lambda.

Originally proposed by Carbonell and Goldstein for text summarization and information retrieval, MMR is widely applied in keyphrase extraction to prevent the selection of near-duplicate phrases. By suppressing redundant candidates, it ensures the final set of keyphrases provides broad topical coverage of the source document.

Algorithm Mechanics

Key Features of MMR

Maximal Marginal Relevance (MMR) is a re-ranking algorithm that constructs a diverse yet relevant set of keyphrases by iteratively penalizing candidates that are too similar to already selected terms.

01

The Core Greedy Algorithm

MMR builds the final keyphrase set iteratively. In each step, it selects the candidate that maximizes the MMR score, which is a linear combination of relevance and novelty. The algorithm starts with the most relevant phrase and then penalizes subsequent candidates based on their maximum similarity to the already chosen set, ensuring broad topical coverage.

02

The Lambda Hyperparameter

The λ (lambda) parameter, typically ranging from 0 to 1, controls the trade-off between relevance and diversity.

  • λ=1: Pure relevance ranking; the algorithm ignores redundancy and selects the top-scoring candidates.
  • λ=0: Maximal diversity; the algorithm aggressively penalizes similarity, potentially selecting less relevant but unique phrases.
  • λ=0.5 to 0.7: A common balanced range for keyphrase extraction, ensuring the selected terms are both salient and distinct.
0.5–0.7
Optimal Lambda Range
03

Similarity Metric Selection

The penalty term in MMR relies on a pairwise similarity function between candidate phrases. The choice of this metric critically shapes the final output.

  • Cosine Similarity on TF-IDF vectors: A classic, sparse representation that penalizes lexical overlap.
  • Cosine Similarity on Embeddings: Using models like BERT or Sentence-BERT captures semantic redundancy, penalizing synonyms and paraphrases.
  • Jaccard Similarity: A simple token-overlap coefficient useful for penalizing exact word repetition.
04

Relevance Scoring Foundation

MMR is a re-ranking framework, not a standalone extraction method. It requires an initial relevance score for each candidate phrase. This score can come from any upstream method:

  • TF-IDF or BM25 for statistical salience.
  • TextRank for graph-based centrality.
  • Embedding similarity (e.g., cosine similarity between the phrase embedding and the document embedding). MMR then adjusts these raw relevance scores by subtracting the redundancy penalty.
05

Redundancy Penalty Mechanism

For a candidate phrase c and the set of already selected phrases S, the penalty is calculated as max_{s in S} sim(c, s). This means a candidate is penalized based on its similarity to the single most similar already-selected phrase. This max-based penalty aggressively prevents near-duplicate keyphrases from entering the final set, promoting a high-level topical diversity rather than a clustered set of related terms.

MMR EXPLAINED

Frequently Asked Questions

Clear, technical answers to the most common questions about the Maximal Marginal Relevance algorithm and its role in keyphrase extraction and search diversification.

Maximal Marginal Relevance (MMR) is a greedy re-ranking algorithm that iteratively selects documents or keyphrases by balancing their relevance to a query against their redundancy with items already selected. The core mechanism uses a linear combination formula: MMR = Argmax[ λ * Sim(D_i, Q) - (1 - λ) * max Sim(D_i, D_j) ], where λ controls the diversity-relevance trade-off. At each iteration, the algorithm computes the marginal gain of adding a candidate—subtracting the maximum similarity it shares with the existing result set from its query relevance score. This ensures the final ranked list maximizes novelty while minimizing repetition, making it essential for search result diversification and keyphrase extraction where presenting redundant information degrades user utility.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.