Datasets:
Add files using upload-large-folder tool
Browse files- mixbench.py +33 -34
mixbench.py
CHANGED
|
@@ -5,73 +5,74 @@ import datasets
|
|
| 5 |
|
| 6 |
_DESCRIPTION = """
|
| 7 |
MixBench is a benchmark for mixed-modality retrieval across text, image, and image+text corpora.
|
| 8 |
-
Each config corresponds to a
|
| 9 |
"""
|
| 10 |
|
| 11 |
_HOMEPAGE = "https://huggingface.co/datasets/mixed-modality-search/MixBench25"
|
| 12 |
|
| 13 |
_SUBSETS = ["MSCOCO", "Google_WIT", "VisualNews", "OVEN"]
|
| 14 |
-
_SPLITS = ["query", "corpus", "mixed_corpus", "qrel"]
|
| 15 |
|
| 16 |
class MixBench(datasets.GeneratorBasedBuilder):
|
| 17 |
BUILDER_CONFIGS = [
|
| 18 |
datasets.BuilderConfig(
|
| 19 |
-
name=
|
| 20 |
version=datasets.Version("1.0.0"),
|
| 21 |
-
description=f"
|
| 22 |
-
)
|
| 23 |
-
for subset in _SUBSETS
|
| 24 |
-
for split in _SPLITS
|
| 25 |
]
|
| 26 |
|
| 27 |
def _info(self):
|
|
|
|
| 28 |
return datasets.DatasetInfo(
|
| 29 |
description=_DESCRIPTION,
|
| 30 |
homepage=_HOMEPAGE,
|
| 31 |
features=datasets.Features({
|
| 32 |
-
"
|
| 33 |
-
"corpus_id": datasets.Value("string"),
|
| 34 |
-
"text": datasets.Value("string"),
|
| 35 |
-
"image": datasets.Value("string"),
|
| 36 |
-
"score": datasets.Value("int32"),
|
| 37 |
})
|
| 38 |
)
|
| 39 |
|
| 40 |
def _split_generators(self, dl_manager):
|
| 41 |
-
subset
|
| 42 |
subset_dir = os.path.join(dl_manager.manual_dir or dl_manager.download_and_extract(""), subset)
|
| 43 |
|
| 44 |
-
if split == "query":
|
| 45 |
-
file_path = os.path.join(subset_dir, "queries.jsonl")
|
| 46 |
-
elif split == "corpus":
|
| 47 |
-
file_path = os.path.join(subset_dir, "corpus.jsonl")
|
| 48 |
-
elif split == "mixed_corpus":
|
| 49 |
-
file_path = os.path.join(subset_dir, "mixed_corpus.jsonl")
|
| 50 |
-
elif split == "qrel":
|
| 51 |
-
file_path = os.path.join(subset_dir, "qrels", "qrels.tsv")
|
| 52 |
-
else:
|
| 53 |
-
raise ValueError(f"Unknown split: {split}")
|
| 54 |
-
|
| 55 |
return [
|
| 56 |
datasets.SplitGenerator(
|
| 57 |
-
name=
|
| 58 |
-
gen_kwargs={"path":
|
| 59 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
]
|
| 61 |
|
| 62 |
def _generate_examples(self, path, split):
|
| 63 |
-
if split
|
| 64 |
with open(path, encoding="utf-8") as f:
|
| 65 |
for idx, line in enumerate(f):
|
| 66 |
item = json.loads(line)
|
| 67 |
yield idx, {
|
| 68 |
-
"query_id": item.get("query_id", "")
|
| 69 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
"text": item.get("text", ""),
|
| 71 |
"image": item.get("image", ""),
|
| 72 |
-
"score": 0,
|
| 73 |
}
|
| 74 |
-
|
| 75 |
elif split == "qrel":
|
| 76 |
with open(path, encoding="utf-8") as f:
|
| 77 |
reader = csv.DictReader(f, delimiter="\t")
|
|
@@ -79,7 +80,5 @@ class MixBench(datasets.GeneratorBasedBuilder):
|
|
| 79 |
yield idx, {
|
| 80 |
"query_id": row["query_id"],
|
| 81 |
"corpus_id": row["corpus_id"],
|
| 82 |
-
"text": "",
|
| 83 |
-
"image": "",
|
| 84 |
"score": int(row["score"]),
|
| 85 |
}
|
|
|
|
| 5 |
|
| 6 |
_DESCRIPTION = """
|
| 7 |
MixBench is a benchmark for mixed-modality retrieval across text, image, and image+text corpora.
|
| 8 |
+
Each config corresponds to a dataset (e.g., MSCOCO), and defines splits: query, corpus, mixed_corpus, and qrel.
|
| 9 |
"""
|
| 10 |
|
| 11 |
_HOMEPAGE = "https://huggingface.co/datasets/mixed-modality-search/MixBench25"
|
| 12 |
|
| 13 |
_SUBSETS = ["MSCOCO", "Google_WIT", "VisualNews", "OVEN"]
|
|
|
|
| 14 |
|
| 15 |
class MixBench(datasets.GeneratorBasedBuilder):
|
| 16 |
BUILDER_CONFIGS = [
|
| 17 |
datasets.BuilderConfig(
|
| 18 |
+
name=subset,
|
| 19 |
version=datasets.Version("1.0.0"),
|
| 20 |
+
description=f"MixBench subset: {subset}"
|
| 21 |
+
) for subset in _SUBSETS
|
|
|
|
|
|
|
| 22 |
]
|
| 23 |
|
| 24 |
def _info(self):
|
| 25 |
+
# Placeholder: will be replaced in _split_generators
|
| 26 |
return datasets.DatasetInfo(
|
| 27 |
description=_DESCRIPTION,
|
| 28 |
homepage=_HOMEPAGE,
|
| 29 |
features=datasets.Features({
|
| 30 |
+
"placeholder": datasets.Value("string")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
})
|
| 32 |
)
|
| 33 |
|
| 34 |
def _split_generators(self, dl_manager):
|
| 35 |
+
subset = self.config.name
|
| 36 |
subset_dir = os.path.join(dl_manager.manual_dir or dl_manager.download_and_extract(""), subset)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return [
|
| 39 |
datasets.SplitGenerator(
|
| 40 |
+
name="query",
|
| 41 |
+
gen_kwargs={"path": os.path.join(subset_dir, "queries.jsonl"), "split": "query"},
|
| 42 |
+
),
|
| 43 |
+
datasets.SplitGenerator(
|
| 44 |
+
name="corpus",
|
| 45 |
+
gen_kwargs={"path": os.path.join(subset_dir, "corpus.jsonl"), "split": "corpus"},
|
| 46 |
+
),
|
| 47 |
+
datasets.SplitGenerator(
|
| 48 |
+
name="mixed_corpus",
|
| 49 |
+
gen_kwargs={"path": os.path.join(subset_dir, "mixed_corpus.jsonl"), "split": "mixed_corpus"},
|
| 50 |
+
),
|
| 51 |
+
datasets.SplitGenerator(
|
| 52 |
+
name="qrel",
|
| 53 |
+
gen_kwargs={"path": os.path.join(subset_dir, "qrels", "qrels.tsv"), "split": "qrel"},
|
| 54 |
+
),
|
| 55 |
]
|
| 56 |
|
| 57 |
def _generate_examples(self, path, split):
|
| 58 |
+
if split == "query":
|
| 59 |
with open(path, encoding="utf-8") as f:
|
| 60 |
for idx, line in enumerate(f):
|
| 61 |
item = json.loads(line)
|
| 62 |
yield idx, {
|
| 63 |
+
"query_id": item.get("query_id", ""),
|
| 64 |
+
"text": item.get("text", ""),
|
| 65 |
+
"image": item.get("image", ""),
|
| 66 |
+
}
|
| 67 |
+
elif split in {"corpus", "mixed_corpus"}:
|
| 68 |
+
with open(path, encoding="utf-8") as f:
|
| 69 |
+
for idx, line in enumerate(f):
|
| 70 |
+
item = json.loads(line)
|
| 71 |
+
yield idx, {
|
| 72 |
+
"corpus_id": item.get("corpus_id", ""),
|
| 73 |
"text": item.get("text", ""),
|
| 74 |
"image": item.get("image", ""),
|
|
|
|
| 75 |
}
|
|
|
|
| 76 |
elif split == "qrel":
|
| 77 |
with open(path, encoding="utf-8") as f:
|
| 78 |
reader = csv.DictReader(f, delimiter="\t")
|
|
|
|
| 80 |
yield idx, {
|
| 81 |
"query_id": row["query_id"],
|
| 82 |
"corpus_id": row["corpus_id"],
|
|
|
|
|
|
|
| 83 |
"score": int(row["score"]),
|
| 84 |
}
|