def compute_metrics(qids_to_relevant_passageids, qids_to_ranked_candidate_passages):
    "Compute MRR metric\n    Args:\n    p_qids_to_relevant_passageids (dict): dictionary of query-passage mapping\n        Dict as read in with load_reference or load_reference_from_stream\n    p_qids_to_ranked_candidate_passages (dict): dictionary of query-passage candidates\n    Returns:\n        dict: dictionary of metrics {'MRR': <MRR Score>}\n    "
    all_scores = {}
    MRR = 0
    qids_with_relevant_passages = 0
    ranking = []
    recall_q_top1 = set()
    recall_q_top50 = set()
    recall_q_all = set()
    for qid in qids_to_ranked_candidate_passages:
        if (qid in qids_to_relevant_passageids):
            ranking.append(0)
            target_pid = qids_to_relevant_passageids[qid]
            candidate_pid = qids_to_ranked_candidate_passages[qid]
            for i in range(0, MaxMRRRank):
                if (candidate_pid[i] in target_pid):
                    MRR += (1.0 / (i + 1))
                    ranking.pop()
                    ranking.append((i + 1))
                    break
            for (i, pid) in enumerate(candidate_pid):
                if (pid in target_pid):
                    recall_q_all.add(qid)
                    if (i < 50):
                        recall_q_top50.add(qid)
                    if (i == 0):
                        recall_q_top1.add(qid)
                    break
    if (len(ranking) == 0):
        raise IOError('No matching QIDs found. Are you sure you are scoring the evaluation set?')
    MRR = (MRR / len(qids_to_relevant_passageids))
    recall_top1 = ((len(recall_q_top1) * 1.0) / len(qids_to_relevant_passageids))
    recall_top50 = ((len(recall_q_top50) * 1.0) / len(qids_to_relevant_passageids))
    recall_all = ((len(recall_q_all) * 1.0) / len(qids_to_relevant_passageids))
    all_scores['MRR@10'] = MRR
    all_scores['recall@1'] = recall_top1
    all_scores['recall@50'] = recall_top50
    all_scores['QueriesRanked'] = len(qids_to_ranked_candidate_passages)
    return all_scores
Compute MRR metric
Args:
p_qids_to_relevant_passageids (dict): dictionary of query-passage mapping
    Dict as read in with load_reference or load_reference_from_stream
p_qids_to_ranked_candidate_passages (dict): dictionary of query-passage candidates
Returns:
    dict: dictionary of metrics {'MRR': <MRR Score>}
def compute_metrics(qids_to_relevant_passageids, qids_to_ranked_candidate_passages):
    "Compute MRR metric\n    Args:\n    p_qids_to_relevant_passageids (dict): dictionary of query-passage mapping\n        Dict as read in with load_reference or load_reference_from_stream\n    p_qids_to_ranked_candidate_passages (dict): dictionary of query-passage candidates\n    Returns:\n        dict: dictionary of metrics {'MRR': <MRR Score>}\n    "
    all_scores = {}
    MRR = 0
    qids_with_relevant_passages = 0
    ranking = []
    recall_q_top1 = set()
    recall_q_top50 = set()
    recall_q_all = set()
    for qid in qids_to_ranked_candidate_passages:
        if (qid in qids_to_relevant_passageids):
            ranking.append(0)
            target_pid = qids_to_relevant_passageids[qid]
            candidate_pid = qids_to_ranked_candidate_passages[qid]
            for i in range(0, MaxMRRRank):
                if (candidate_pid[i] in target_pid):
                    MRR += (1.0 / (i + 1))
                    ranking.pop()
                    ranking.append((i + 1))
                    break
            for (i, pid) in enumerate(candidate_pid):
                if (pid in target_pid):
                    recall_q_all.add(qid)
                    if (i < 50):
                        recall_q_top50.add(qid)
                    if (i == 0):
                        recall_q_top1.add(qid)
                    break
    if (len(ranking) == 0):
        raise IOError('No matching QIDs found. Are you sure you are scoring the evaluation set?')
    MRR = (MRR / len(qids_to_relevant_passageids))
    recall_top1 = ((len(recall_q_top1) * 1.0) / len(qids_to_relevant_passageids))
    recall_top50 = ((len(recall_q_top50) * 1.0) / len(qids_to_relevant_passageids))
    recall_all = ((len(recall_q_all) * 1.0) / len(qids_to_relevant_passageids))
    all_scores['MRR@10'] = MRR
    all_scores['recall@1'] = recall_top1
    all_scores['recall@50'] = recall_top50
    all_scores['QueriesRanked'] = len(qids_to_ranked_candidate_passages)
    return all_scores