| | import os |
| | import json |
| | import datasets |
| | import csv |
| |
|
| | _DESCRIPTION = """\ |
| | MixBench is a benchmark for evaluating mixed-modality retrieval. It contains queries and corpora from four datasets: MSCOCO, Google_WIT, VisualNews, and OVEN. \ |
| | Each subset provides: query, corpus, mixed_corpus, and qrel splits. |
| | """ |
| |
|
| |
|
| | _HOMEPAGE = "https://huggingface.co/datasets/mixed-modality-search/MixBench25" |
| |
|
| |
|
| | _SUBSETS = ["MSCOCO", "Google_WIT", "VisualNews", "OVEN"] |
| |
|
| | class MixBenchConfig(datasets.BuilderConfig): |
| | def __init__(self, name, **kwargs): |
| | if name not in _SUBSETS: |
| | raise ValueError(f"Unknown subset: {name}. Choose from {_SUBSETS}") |
| | super().__init__(name=name, version=datasets.Version("1.0.0"), **kwargs) |
| |
|
| |
|
| | class MixBench(datasets.GeneratorBasedBuilder): |
| | BUILDER_CONFIGS = [MixBenchConfig(name=subset) for subset in _SUBSETS] |
| |
|
| | def _info(self): |
| | features = datasets.Features({ |
| | "query_id": datasets.Value("string"), |
| | "corpus_id": datasets.Value("string"), |
| | "text": datasets.Value("string"), |
| | "image": datasets.Value("string"), |
| | "score": datasets.Value("int32"), |
| | }) |
| | return datasets.DatasetInfo( |
| | description=_DESCRIPTION, |
| | features=features, |
| | homepage=_HOMEPAGE, |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | |
| | |
| | |
| | |
| | |
| | subset_dir = os.path.join(dl_manager.manual_dir or dl_manager._base_path, self.config.name) |
| | return [ |
| | datasets.SplitGenerator( |
| | name="query", |
| | gen_kwargs={"path": os.path.join(subset_dir, "queries.jsonl"), "split": "query"}, |
| | ), |
| | datasets.SplitGenerator( |
| | name="corpus", |
| | gen_kwargs={"path": os.path.join(subset_dir, "corpus.jsonl"), "split": "corpus"}, |
| | ), |
| | datasets.SplitGenerator( |
| | name="mixed_corpus", |
| | gen_kwargs={"path": os.path.join(subset_dir, "mixed_corpus.jsonl"), "split": "mixed_corpus"}, |
| | ), |
| | datasets.SplitGenerator( |
| | name="qrel", |
| | gen_kwargs={"path": os.path.join(subset_dir, "qrels", "qrels.tsv"), "split": "qrel"}, |
| | ), |
| | ] |
| |
|
| | def _generate_examples(self, path, split): |
| | if split == "qrel": |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | with open(path, encoding="utf-8") as f: |
| | reader = csv.DictReader(f, delimiter="\t") |
| | for idx, row in enumerate(reader): |
| | yield idx, { |
| | "query_id": row["query_id"], |
| | "corpus_id": row["corpus_id"], |
| | "score": int(row["score"]), |
| | } |
| | else: |
| | with open(path, encoding="utf-8") as f: |
| | for idx, line in enumerate(f): |
| | row = json.loads(line) |
| | yield idx, { |
| | "query_id": row.get("query_id", ""), |
| | "corpus_id": row.get("corpus_id", ""), |
| | "text": row.get("text", ""), |
| | "image": row.get("image", ""), |
| | "score": 0, |
| | } |
| |
|