class_docstr: Base class for information retrieval models.
docstr: Helper function which calculates mean reciprocal rank.
  Args:
      query2passages: dict which contains passage ids and corresponding
          scores for each query
      query2rel: dict which contains ids of relevant passages for each query
docstr_tok: ["Helper","function","which","calculates","mean","reciprocal","rank",".","Args",":","query2passages",":","dict","which","contains","passage","ids","and","corresponding","scores","for","each","query","query2rel",":","dict","which","contains","ids","of","relevant","passages","for","each","query"]
code: def calculate_mean_reciprocal_rank(query2passages, query2rel):
      """
      Helper function which calculates mean reciprocal rank.
      Args:
          query2passages: dict which contains passage ids and corresponding
              scores for each query
          query2rel: dict which contains ids of relevant passages for each query
      """
      reciprocal_ranks = []
  
      for query in query2passages:
          indices = np.argsort(query2passages[query]["scores"])[::-1]
          sorted_psgs = query2passages[query]["psg_ids"][indices]
  
          reciprocal_ranks.append(0)
          for i, psg_id in enumerate(sorted_psgs):
              if psg_id in query2rel[query]:
                  reciprocal_ranks[-1] = 1 / (i + 1)
                  break
      return np.mean(reciprocal_ranks)
  
imports: import math
  from typing import Dict, Optional
  import numpy
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from nemo.collections.nlp.data import BertInformationRetrievalDataset
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.collections.nlp.modules.common.lm_utils import get_lm_model
  from nemo.core.classes.common import typecheck
label_desc: Use image node_id 5 for calling the BaseIRModel obj's underlying member method code with example usage: obj.calculate_mean_reciprocal_rank(query2passages, query2rel) and returns: np