Commit
·
f4bcff3
1
Parent(s):
61affc5
Use JSON Lines data files hosted in the Hub (#1)
Browse files- Use data files in the Hub in JSON Lines (25a33308e93df6c25bde00aa894e84c55dc5d0fe)
- Fix style (23b78195f068ee0bd239d5bc6ee39bb8f774fe74)
Co-authored-by: Albert Villanova <albertvillanova@users.noreply.huggingface.co>
biomrc.py
CHANGED
|
@@ -33,7 +33,7 @@ from .bigbiohub import qa_features
|
|
| 33 |
from .bigbiohub import BigBioConfig
|
| 34 |
from .bigbiohub import Tasks
|
| 35 |
|
| 36 |
-
_LANGUAGES = [
|
| 37 |
_PUBMED = True
|
| 38 |
_LOCAL = False
|
| 39 |
_CITATION = """\
|
|
@@ -69,40 +69,37 @@ sizes, also releasing our code, and providing a leaderboard.
|
|
| 69 |
|
| 70 |
_HOMEPAGE = "https://github.com/PetrosStav/BioMRC_code"
|
| 71 |
|
| 72 |
-
_LICENSE =
|
| 73 |
|
|
|
|
| 74 |
_URLS = {
|
| 75 |
"large": {
|
| 76 |
"A": {
|
| 77 |
-
"train": "
|
| 78 |
-
"val": "
|
| 79 |
-
"test": "
|
| 80 |
},
|
| 81 |
"B": {
|
| 82 |
-
"train": "
|
| 83 |
-
"val": "
|
| 84 |
-
"test": "
|
| 85 |
},
|
| 86 |
},
|
| 87 |
"small": {
|
| 88 |
"A": {
|
| 89 |
-
"train": "
|
| 90 |
-
"val": "
|
| 91 |
-
"test": "
|
| 92 |
},
|
| 93 |
"B": {
|
| 94 |
-
"train": "
|
| 95 |
-
"val": "
|
| 96 |
-
"test": "
|
| 97 |
},
|
| 98 |
},
|
| 99 |
"tiny": {
|
| 100 |
-
"A": {
|
| 101 |
-
|
| 102 |
-
},
|
| 103 |
-
"B": {
|
| 104 |
-
"test": "https://archive.org/download/biomrc_dataset/biomrc_tiny/dataset_tiny_B.json.gz"
|
| 105 |
-
},
|
| 106 |
},
|
| 107 |
}
|
| 108 |
|
|
@@ -212,46 +209,29 @@ class BiomrcDataset(datasets.GeneratorBasedBuilder):
|
|
| 212 |
|
| 213 |
if self.config.schema == "source":
|
| 214 |
with open(filepath, encoding="utf-8") as fp:
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
)
|
| 223 |
-
):
|
| 224 |
-
el = [self._parse_dict_from_entity(entity) for entity in el]
|
| 225 |
-
an = self._parse_dict_from_entity(an)
|
| 226 |
-
yield _id, {
|
| 227 |
-
"abstract": ab,
|
| 228 |
-
"title": ti,
|
| 229 |
-
"entities_list": el,
|
| 230 |
-
"answer": an,
|
| 231 |
-
}
|
| 232 |
elif self.config.schema == "bigbio_qa":
|
| 233 |
with open(filepath, encoding="utf-8") as fp:
|
| 234 |
uid = it.count(0)
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
zip(
|
| 238 |
-
biomrc["abstracts"],
|
| 239 |
-
biomrc["titles"],
|
| 240 |
-
biomrc["entities_list"],
|
| 241 |
-
biomrc["answers"],
|
| 242 |
-
)
|
| 243 |
-
):
|
| 244 |
# remove info such as code, label, synonyms from answer and choices
|
| 245 |
# f.e. @entity1 :: ('9606', 'Species') :: ['patients', 'patient']"
|
| 246 |
example = {
|
| 247 |
"id": next(uid),
|
| 248 |
"question_id": next(uid),
|
| 249 |
"document_id": next(uid),
|
| 250 |
-
"question":
|
| 251 |
"type": "multiple_choice",
|
| 252 |
-
"choices": [x.split(" :: ")[0] for x in
|
| 253 |
-
"context":
|
| 254 |
-
"answer": [
|
| 255 |
}
|
| 256 |
yield _id, example
|
| 257 |
|
|
|
|
| 33 |
from .bigbiohub import BigBioConfig
|
| 34 |
from .bigbiohub import Tasks
|
| 35 |
|
| 36 |
+
_LANGUAGES = ["English"]
|
| 37 |
_PUBMED = True
|
| 38 |
_LOCAL = False
|
| 39 |
_CITATION = """\
|
|
|
|
| 69 |
|
| 70 |
_HOMEPAGE = "https://github.com/PetrosStav/BioMRC_code"
|
| 71 |
|
| 72 |
+
_LICENSE = "License information unavailable"
|
| 73 |
|
| 74 |
+
_BASE_URL = "https://huggingface.co/datasets/biomrc/resolve/main/data/"
|
| 75 |
_URLS = {
|
| 76 |
"large": {
|
| 77 |
"A": {
|
| 78 |
+
"train": _BASE_URL + "biomrc_large/dataset_train.jsonl.gz",
|
| 79 |
+
"val": _BASE_URL + "biomrc_large/dataset_val.jsonl.gz",
|
| 80 |
+
"test": _BASE_URL + "biomrc_large/dataset_test.jsonl.gz",
|
| 81 |
},
|
| 82 |
"B": {
|
| 83 |
+
"train": _BASE_URL + "biomrc_large/dataset_train_B.jsonl.gz",
|
| 84 |
+
"val": _BASE_URL + "biomrc_large/dataset_val_B.jsonl.gz",
|
| 85 |
+
"test": _BASE_URL + "biomrc_large/dataset_test_B.jsonl.gz",
|
| 86 |
},
|
| 87 |
},
|
| 88 |
"small": {
|
| 89 |
"A": {
|
| 90 |
+
"train": _BASE_URL + "biomrc_small/dataset_train_small.jsonl.gz",
|
| 91 |
+
"val": _BASE_URL + "biomrc_small/dataset_val_small.jsonl.gz",
|
| 92 |
+
"test": _BASE_URL + "biomrc_small/dataset_test_small.jsonl.gz",
|
| 93 |
},
|
| 94 |
"B": {
|
| 95 |
+
"train": _BASE_URL + "biomrc_small/dataset_train_small_B.jsonl.gz",
|
| 96 |
+
"val": _BASE_URL + "biomrc_small/dataset_val_small_B.jsonl.gz",
|
| 97 |
+
"test": _BASE_URL + "biomrc_small/dataset_test_small_B.jsonl.gz",
|
| 98 |
},
|
| 99 |
},
|
| 100 |
"tiny": {
|
| 101 |
+
"A": {"test": _BASE_URL + "biomrc_tiny/dataset_tiny.jsonl.gz"},
|
| 102 |
+
"B": {"test": _BASE_URL + "biomrc_tiny/dataset_tiny_B.jsonl.gz"},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
},
|
| 104 |
}
|
| 105 |
|
|
|
|
| 209 |
|
| 210 |
if self.config.schema == "source":
|
| 211 |
with open(filepath, encoding="utf-8") as fp:
|
| 212 |
+
for _id, line in enumerate(fp):
|
| 213 |
+
example = json.loads(line)
|
| 214 |
+
example["entities_list"] = [
|
| 215 |
+
self._parse_dict_from_entity(entity) for entity in example["entities_list"]
|
| 216 |
+
]
|
| 217 |
+
example["answer"] = self._parse_dict_from_entity(example["answer"])
|
| 218 |
+
yield _id, example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
elif self.config.schema == "bigbio_qa":
|
| 220 |
with open(filepath, encoding="utf-8") as fp:
|
| 221 |
uid = it.count(0)
|
| 222 |
+
for _id, line in enumerate(fp):
|
| 223 |
+
example = json.loads(line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
# remove info such as code, label, synonyms from answer and choices
|
| 225 |
# f.e. @entity1 :: ('9606', 'Species') :: ['patients', 'patient']"
|
| 226 |
example = {
|
| 227 |
"id": next(uid),
|
| 228 |
"question_id": next(uid),
|
| 229 |
"document_id": next(uid),
|
| 230 |
+
"question": example["title"],
|
| 231 |
"type": "multiple_choice",
|
| 232 |
+
"choices": [x.split(" :: ")[0] for x in example["entities_list"]],
|
| 233 |
+
"context": example["abstract"],
|
| 234 |
+
"answer": [example["answer"].split(" :: ")[0]],
|
| 235 |
}
|
| 236 |
yield _id, example
|
| 237 |
|