File size: 7,962 Bytes
884d29f b5be315 884d29f 499380a 884d29f 5bf2050 884d29f faeb088 884d29f b5be315 884d29f faeb088 884d29f |
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""
BIOSSES computes similarity of biomedical sentences by utilizing WordNet as the
general domain ontology and UMLS as the biomedical domain specific ontology.
The original paper outlines the approaches with respect to using annotator
score as golden standard. Source view will return all annotator score
individually whereas the Bigbio view will return the mean of the annotator
score.
Note: The original files are Word documents, compressed using RAR. This data
loader uses a version that privides the same data in text format.
"""
import datasets
import pandas as pd
from .bigbiohub import pairs_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks
_DATASETNAME = "biosses"
_DISPLAYNAME = "BIOSSES"
_LANGUAGES = ["English"]
_PUBMED = False
_LOCAL = False
_CITATION = """
@article{souganciouglu2017biosses,
title={BIOSSES: a semantic sentence similarity estimation system for the biomedical domain},
author={Soğancıoğlu, Gizem, Hakime Öztürk, and Arzucan Özgür},
journal={Bioinformatics},
volume={33},
number={14},
pages={i49--i58},
year={2017},
publisher={Oxford University Press}
}
"""
_DESCRIPTION = """
BIOSSES computes similarity of biomedical sentences by utilizing WordNet as the
general domain ontology and UMLS as the biomedical domain specific ontology.
The original paper outlines the approaches with respect to using annotator
score as golden standard. Source view will return all annotator score
individually whereas the Bigbio view will return the mean of the annotator
score.
"""
_HOMEPAGE = "https://tabilab.cmpe.boun.edu.tr/BIOSSES/DataSet.html"
_LICENSE = "GPL_3p0"
_URLs = {
"source": "https://huggingface.co/datasets/bigscience-biomedical/biosses/raw/main/annotation_pairs_scores.tsv",
"bigbio_pairs": "https://huggingface.co/datasets/bigscience-biomedical/biosses/raw/main/annotation_pairs_scores.tsv",
}
_SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"
# The BIOSSES dataset does not provide canonical train/dev/test splits.
# However the BLUE and BLURB datasets use the following split definitions.
# see https://github.com/bigscience-workshop/biomedical/issues/664
TRAIN_INDEXES = [
78,
45,
35,
50,
27,
13,
87,
1,
58,
99,
55,
74,
66,
39,
44,
18,
84,
76,
19,
10,
75,
46,
15,
86,
60,
14,
51,
79,
29,
34,
94,
28,
62,
42,
21,
30,
11,
53,
6,
12,
26,
48,
31,
32,
77,
37,
95,
85,
36,
56,
43,
61,
16,
5,
67,
65,
54,
3,
73,
98,
17,
4,
92,
93,
]
DEV_INDEXES = [
88,
82,
8,
63,
47,
68,
40,
90,
100,
24,
41,
91,
80,
9,
72,
2,
]
TEST_INDEXES = [
59,
96,
70,
22,
81,
38,
57,
23,
33,
89,
69,
49,
7,
71,
97,
25,
83,
64,
52,
20,
]
class BiossesDataset(datasets.GeneratorBasedBuilder):
"""BIOSSES : Biomedical Semantic Similarity Estimation System"""
DEFAULT_CONFIG_NAME = "biosses_source"
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
BUILDER_CONFIGS = [
BigBioConfig(
name="biosses_source",
version=SOURCE_VERSION,
description="BIOSSES source schema",
schema="source",
subset_id="biosses",
),
BigBioConfig(
name="biosses_bigbio_pairs",
version=BIGBIO_VERSION,
description="BIOSSES simplified BigBio schema",
schema="bigbio_pairs",
subset_id="biosses",
),
]
def _info(self):
if self.config.name == "biosses_source":
features = datasets.Features(
{
"id": datasets.Value("int64"),
"document_id": datasets.Value("int64"),
"text_1": datasets.Value("string"),
"text_2": datasets.Value("string"),
"annotator_a": datasets.Value("int64"),
"annotator_b": datasets.Value("int64"),
"annotator_c": datasets.Value("int64"),
"annotator_d": datasets.Value("int64"),
"annotator_e": datasets.Value("int64"),
}
)
elif self.config.name == "biosses_bigbio_pairs":
features = pairs_features
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=str(_LICENSE),
citation=_CITATION,
)
def _split_generators(self, dl_manager):
my_urls = _URLs[self.config.schema]
dl_dir = dl_manager.download_and_extract(my_urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": dl_dir,
"split": "train",
"indexes": TRAIN_INDEXES,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": dl_dir,
"split": "validation",
"indexes": DEV_INDEXES,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": dl_dir,
"split": "test",
"indexes": TEST_INDEXES,
},
),
]
def _generate_examples(self, filepath, split, indexes):
df = pd.read_csv(filepath, sep="\t", encoding="utf-8")
df = df[df["sentence_id"].isin(indexes)]
if self.config.schema == "source":
for uid, row in df.iterrows():
yield uid, {
"id": uid,
"document_id": row["sentence_id"],
"text_1": row["sentence_1"],
"text_2": row["sentence_2"],
"annotator_a": row["annotator_a"],
"annotator_b": row["annotator_b"],
"annotator_c": row["annotator_c"],
"annotator_d": row["annotator_d"],
"annotator_e": row["annotator_e"],
}
elif self.config.schema == "bigbio_pairs":
for uid, row in df.iterrows():
yield uid, {
"id": uid,
"document_id": row["sentence_id"],
"text_1": row["sentence_1"],
"text_2": row["sentence_2"],
"label": str(
(
row["annotator_a"]
+ row["annotator_b"]
+ row["annotator_c"]
+ row["annotator_d"]
+ row["annotator_e"]
)
/ 5
),
}
|