-
Notifications
You must be signed in to change notification settings - Fork 2
/
sr_updates.py
239 lines (206 loc) · 7.27 KB
/
sr_updates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# coding=utf-8
# Copyright 2023 Wojciech Kusa
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pickle
from typing import List, Tuple, Dict, Any
import datasets
import pandas as pd
from csmed.loader.bigbiohub import BigBioConfig
from csmed.loader.bigbiohub import Tasks
from csmed.loader.bigbiohub import text_features
_LANGUAGES = ["English"]
_PUBMED = True
_LOCAL = False
_CITATION = """\
@article{@inproceedings{alharbi2019dataset,
title={A dataset of systematic review updates},
author={Alharbi, Amal and Stevenson, Mark},
booktitle={Proceedings of the 42nd International ACM SIGIR Conference on Research and Development in Information Retrieval},
pages={1257--1260},
year={2019}
}
"""
_DATASETNAME = "srupdates"
_DISPLAYNAME = "srupdates"
_DESCRIPTION = """\
Systematic Review Update Dataset - a dataset created to evaluate the retrieval performance in systematic reviews update.
"""
_HOMEPAGE = "https://github.com/Amal-Alharbi/Systematic_Reviews_Update"
_LICENSE = "Unknown"
_URLS = {
"srupdates": "https://raw.githubusercontent.com/Amal-Alharbi/Systematic_Reviews_Update/master/update_dataset.pkl.zip",
}
_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION, Tasks.QUESTION_ANSWERING]
_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"
_CLASS_NAMES = ["included", "excluded"]
REVIEWS = [
"CD000155",
"CD000160",
"CD000523",
"CD001298",
"CD001552",
"CD002064",
"CD002733",
"CD004069",
"CD004214",
"CD004241",
"CD004479",
"CD005025",
"CD005055",
"CD005083",
"CD005128",
"CD005426",
"CD005607",
"CD006839",
"CD006902",
"CD007020",
"CD007428",
"CD008127",
"CD008392",
"CD010089",
"CD010847",
]
class SrUpdatesDataset(datasets.GeneratorBasedBuilder):
"""Systematic Review Update Dataset - a dataset created to evaluate the retrieval performance in systematic reviews update.
It consists of 25 Intervention systematic reviews."""
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
BUILDER_CONFIGS = []
dataset_versions = REVIEWS
for dataset_version in dataset_versions:
BUILDER_CONFIGS.append(
BigBioConfig(
name=f"sr_updates_{dataset_version}_source",
version=SOURCE_VERSION,
description=f"srupdates {dataset_version} source schema",
schema="source",
subset_id=f"sr_updates_{dataset_version}",
)
)
BUILDER_CONFIGS.append(
BigBioConfig(
name=f"sr_updates_{dataset_version}_bigbio_text",
version=BIGBIO_VERSION,
description=f"srupdates {dataset_version} BigBio schema",
schema="bigbio_text",
subset_id=f"sr_updates_{dataset_version}",
)
)
BUILDER_CONFIGS.append(
BigBioConfig(
name="sr_updates_all_source",
version=SOURCE_VERSION,
description="srupdates all source schema",
schema="source",
subset_id="sr_updates_all",
)
)
DEFAULT_CONFIG_NAME = "sr_updates_all_source"
def _info(self) -> datasets.DatasetInfo:
if self.config.schema == "source":
features = datasets.Features(
{
"review_id": datasets.Value("string"),
"review_title": datasets.Value("string"),
"pmid": datasets.Value("string"),
"title": datasets.Value("string"),
"abstract": datasets.Value("string"),
"mesh_terms": [datasets.Value("string")],
"label": datasets.ClassLabel(names=_CLASS_NAMES),
}
)
elif self.config.schema == "bigbio_text":
features = text_features
else:
raise ValueError(f"Unsupported schema {self.config.schema}")
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_URLS["srupdates"])
reviews_pickle = pickle.load(open(f"{data_dir}/update_dataset.pkl", "rb"))
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"reviews_pickle": reviews_pickle,
"split": "train",
},
),
]
def _generate_examples(
self,
reviews_pickle: dict[str, Any],
split: str,
) -> Tuple[int, Dict]:
"""Yields examples as (key, example) tuples."""
review = "_".join(self.config.subset_id.split("_")[2:])
uid = 0
_examples = []
if review == "all":
reviews = reviews_pickle.keys()
else:
reviews = [review]
for r in reviews:
for study in reviews_pickle[r]["search_results"]["original_records"]:
if study[0] in reviews_pickle[r]["included"]["original_abs"]:
label = 1
else:
label = 0
_example = {
"review_id": r,
"review_title": reviews_pickle[r]["title"],
"pmid": study[0],
"title": study[1],
"abstract": study[2],
"mesh_terms": study[3],
"label": label,
}
_examples.append(_example)
df = pd.DataFrame(_examples)
for key, example in df.iterrows():
title = example["title"]
abstract = example["abstract"]
label = example["label"]
text = f"{title}\n\n{abstract}"
uid += 1
if self.config.schema == "source":
data = {
"review_id": example["review_id"],
"review_title": example["review_title"],
"pmid": example["pmid"],
"title": title,
"abstract": abstract,
"mesh_terms": example["mesh_terms"],
"label": label,
}
yield str(uid), data
elif self.config.schema == "bigbio_text":
data = {
"id": str(uid),
"document_id": example["pmid"],
"text": text,
"labels": [label],
}
yield str(uid), data
if __name__ == "__main__":
x = datasets.load_dataset(__file__, name="sr_updates_all_source")
print(type(x))
print(x)