Discepency in the qrels

#2
by Dipto084 - opened

Hello,

In the qrels split of the dataset, there are corpus ids that start with 6:, whereas all the corpus ids in the corpus split all the corpus ids start with 5:. How to correct this mapping?

Multimodal Representation Benchmark org

Hi, the qrel-to-corpus mapping is inherited from the original M-BEIR dataset: https://huggingface.co/datasets/TIGER-Lab/M-BEIR.
After review, I’ve confirmed that the issue originates from the original data.
I recommend cleaning the qrels by removing redundant positive entries before calculating the metrics.

Hello, thanks for responding. I am not sure what is inferred by 'I recommend cleaning the qrels by removing redundant positive entries before calculating the metrics.' Do we get rid of all the entries with '6:' in the corpus id from the qrels. Could you please elaborate a bit more on this?

Multimodal Representation Benchmark org

Sure, you can use the following script to clean the qrels.

from datasets import load_dataset
import pandas as pd
from tqdm import tqdm
import logging

def clean_qrels(corpus_dataset, qrels_dataset, output_path=None):
    """
    Clean qrels by removing entries where the document ID doesn't exist in the corpus.
    
    Args:
        corpus_dataset: HuggingFace dataset containing the corpus
        qrels_dataset: HuggingFace dataset containing the qrels
        output_path: Optional path to save the cleaned qrels as CSV
        
    Returns:
        cleaned_qrels: Pandas DataFrame containing the cleaned qrels
    """
    # Set up logging
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(__name__)

    # Convert corpus to set of IDs for faster lookup
    logger.info("Creating set of corpus document IDs...")
    corpus_ids = set(corpus_dataset['id'])
    
    # Convert qrels to pandas for easier processing
    logger.info("Converting qrels to DataFrame...")
    qrels_df = pd.DataFrame({
        'query-id': qrels_dataset['query-id'],
        'Q0': qrels_dataset['Q0'],
        'corpus-id': qrels_dataset['corpus-id'],
        'score': qrels_dataset['score']
    })
    
    # Get initial statistics
    initial_count = len(qrels_df)
    
    # Filter qrels to only include existing documents
    logger.info("Filtering qrels...")
    cleaned_qrels = qrels_df[qrels_df['corpus-id'].isin(corpus_ids)]
    
    # Get final statistics
    final_count = len(cleaned_qrels)
    removed_count = initial_count - final_count
    
    # Log statistics
    logger.info(f"Initial qrels count: {initial_count}")
    logger.info(f"Final qrels count: {final_count}")
    logger.info(f"Removed {removed_count} entries ({(removed_count/initial_count)*100:.2f}%)")
    
    # Save to file if output path is provided
    if output_path:
        logger.info(f"Saving cleaned qrels to {output_path}")
        cleaned_qrels.to_csv(output_path, index=False)
    
    return cleaned_qrels

if __name__ == "__main__":
    # Load datasets
    corpus = load_dataset('MRBench/mbeir_oven_task6', 'corpus', split='corpus')
    qrels = load_dataset('MRBench/mbeir_oven_task6', 'qrels', split='test')
    
    # Clean qrels
    cleaned_qrels = clean_qrels(
        corpus_dataset=corpus,
        qrels_dataset=qrels,
        output_path="cleaned_qrels.csv"
    )

Sign up or log in to comment