Use JSON Lines data files hosted in the Hub

#1
by albertvillanova HF staff - opened
Files changed (1) hide show
  1. biomrc.py +30 -50
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 = ['English']
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 = 'License information unavailable'
73
 
 
74
  _URLS = {
75
  "large": {
76
  "A": {
77
- "train": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_train.json.gz",
78
- "val": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_val.json.gz",
79
- "test": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_test.json.gz",
80
  },
81
  "B": {
82
- "train": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_train_B.json.gz",
83
- "val": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_val_B.json.gz",
84
- "test": "https://archive.org/download/biomrc_dataset/biomrc_large/dataset_test_B.json.gz",
85
  },
86
  },
87
  "small": {
88
  "A": {
89
- "train": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_train_small.json.gz",
90
- "val": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_val_small.json.gz",
91
- "test": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_test_small.json.gz",
92
  },
93
  "B": {
94
- "train": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_train_small_B.json.gz",
95
- "val": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_val_small_B.json.gz",
96
- "test": "https://archive.org/download/biomrc_dataset/biomrc_small/dataset_test_small_B.json.gz",
97
  },
98
  },
99
  "tiny": {
100
- "A": {
101
- "test": "https://archive.org/download/biomrc_dataset/biomrc_tiny/dataset_tiny.json.gz"
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
- biomrc = json.load(fp)
216
- for _id, (ab, ti, el, an) in enumerate(
217
- zip(
218
- biomrc["abstracts"],
219
- biomrc["titles"],
220
- biomrc["entities_list"],
221
- biomrc["answers"],
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
- biomrc = json.load(fp)
236
- for _id, (ab, ti, el, an) in enumerate(
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": ti,
251
  "type": "multiple_choice",
252
- "choices": [x.split(" :: ")[0] for x in el],
253
- "context": ab,
254
- "answer": [an.split(" :: ")[0]],
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