Update dataset.py
Browse files- dataset.py +31 -14
dataset.py
CHANGED
|
@@ -6,6 +6,30 @@ import datasets
|
|
| 6 |
class M3Retrieve(datasets.GeneratorBasedBuilder):
|
| 7 |
VERSION = datasets.Version("1.0.0")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def _info(self):
|
| 10 |
return datasets.DatasetInfo(
|
| 11 |
description="M3Retrieve: Benchmarking Multimodal Retrieval for Medicine",
|
|
@@ -29,32 +53,25 @@ class M3Retrieve(datasets.GeneratorBasedBuilder):
|
|
| 29 |
)
|
| 30 |
|
| 31 |
def _split_generators(self, dl_manager):
|
| 32 |
-
"""Returns SplitGenerators
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
subfolder = os.path.join(data_dir, self.config.name)
|
| 37 |
-
|
| 38 |
-
# Validate that the subfolder exists
|
| 39 |
-
if not os.path.isdir(subfolder):
|
| 40 |
-
raise ValueError(f"Dataset folder '{self.config.name}' not found in {data_dir}.")
|
| 41 |
-
|
| 42 |
return [
|
| 43 |
datasets.SplitGenerator(
|
| 44 |
name="queries",
|
| 45 |
-
gen_kwargs={"filepath": os.path.join(
|
| 46 |
),
|
| 47 |
datasets.SplitGenerator(
|
| 48 |
name="corpus",
|
| 49 |
-
gen_kwargs={"filepath": os.path.join(
|
| 50 |
),
|
| 51 |
datasets.SplitGenerator(
|
| 52 |
name="qrels",
|
| 53 |
-
gen_kwargs={"filepath": os.path.join(
|
| 54 |
),
|
| 55 |
]
|
| 56 |
|
| 57 |
-
|
| 58 |
def _generate_examples(self, filepath, key):
|
| 59 |
"""Yields examples as (key, example) tuples."""
|
| 60 |
if key in ["queries", "corpus"]:
|
|
|
|
| 6 |
class M3Retrieve(datasets.GeneratorBasedBuilder):
|
| 7 |
VERSION = datasets.Version("1.0.0")
|
| 8 |
|
| 9 |
+
BUILDER_CONFIGS = [
|
| 10 |
+
datasets.BuilderConfig(name=subfolder, version=VERSION, description=f"Dataset for {subfolder}")
|
| 11 |
+
for subfolder in [
|
| 12 |
+
"Anatomy_and_Physiology",
|
| 13 |
+
"Cardiology",
|
| 14 |
+
"Dermatology",
|
| 15 |
+
"Endocrinology_and_Diabetes",
|
| 16 |
+
"Gastroenterology",
|
| 17 |
+
"Hematology",
|
| 18 |
+
"Microbiology_and_Cell_Biology",
|
| 19 |
+
"Miscellaneous",
|
| 20 |
+
"Neurology_and_Neuroscience",
|
| 21 |
+
"Ophthalmology_and_Sensory_Systems",
|
| 22 |
+
"Orthopedics_and_Musculoskeletal",
|
| 23 |
+
"Pharmacology",
|
| 24 |
+
"Psychiatry_and_Mental_Health",
|
| 25 |
+
"Pubmed",
|
| 26 |
+
"Radiology_and_Imaging",
|
| 27 |
+
"Reproductive_System",
|
| 28 |
+
"Respiratory_and_Pulmonology",
|
| 29 |
+
"Surgical_Specialties",
|
| 30 |
+
]
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
def _info(self):
|
| 34 |
return datasets.DatasetInfo(
|
| 35 |
description="M3Retrieve: Benchmarking Multimodal Retrieval for Medicine",
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
def _split_generators(self, dl_manager):
|
| 56 |
+
"""Returns SplitGenerators."""
|
| 57 |
+
dataset_name = self.config.name # Get the selected dataset folder name
|
| 58 |
+
data_dir = os.path.join(self.config.data_dir, dataset_name) # Set path to selected dataset
|
| 59 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return [
|
| 61 |
datasets.SplitGenerator(
|
| 62 |
name="queries",
|
| 63 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "queries.jsonl"), "key": "queries"},
|
| 64 |
),
|
| 65 |
datasets.SplitGenerator(
|
| 66 |
name="corpus",
|
| 67 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "corpus.jsonl"), "key": "corpus"},
|
| 68 |
),
|
| 69 |
datasets.SplitGenerator(
|
| 70 |
name="qrels",
|
| 71 |
+
gen_kwargs={"filepath": os.path.join(data_dir, "qrels/test.tsv"), "key": "qrels"},
|
| 72 |
),
|
| 73 |
]
|
| 74 |
|
|
|
|
| 75 |
def _generate_examples(self, filepath, key):
|
| 76 |
"""Yields examples as (key, example) tuples."""
|
| 77 |
if key in ["queries", "corpus"]:
|