How to apply the Retrieval Mean Reciprocal Rank (MRR)? #989
Replies: 4 comments 6 replies
-
|
cc: @lucadiliello |
Beta Was this translation helpful? Give feedback.
-
|
At the moment, you cannot because you don’t have scores. Your retrieval system is just embedding queries and documents but is not classifying document as relevant or not relevant. I don’t know whether you encoded the queries and the documents together or separately, but something you can do is to use the cosine similarity between the embeddings to retrieve the scores: scores = torch.nn.functional.cosine_similarity(output['query_rpr'], output['doc_rpr'], dim=1)and to compute a vector of relevant documents as: labels = torch.tensor([relevance_map[q_idx.item()] == d_idx for q_idx, d_idx in zip(output['query_idx'], output['doc_idx'])])Finally, you can compute the MRR with: mrr = RetrievalMRR()
result = mrr(scores, labels, output['query_idx']) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Is there an example where this MRR metric works in a large number of queries? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Suppose that after a forward pass, the model outputs a prediction as shown below:
{ "query_idx": tensor([0, 1, ..., 2]), "query_rpr": tensor([ [0.1790, 0.4046, ..., 0.5882], ... [0.1207, 0.6405, ..., 0.0214] ]), "doc_idx": tensor([9, 5, ..., 7]), "doc_rpr": tensor([ [0.290, 0.1045, ..., 0.8852], ... [0.774, 0.4056, ..., 0.1012] ]) }where:
query_idx: is the query index;query_rpr: is the query embedding;doc_idx: is the document idx;doc_rpr: is the document representation.and the relevance map contains:
{ # query_idx -> (relevant) doc_idx 0: 9, 1: 5, 3: 7, }Therefore, how can the MRR metric be applied in this scenario?
Beta Was this translation helpful? Give feedback.
All reactions