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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
UMNSRS, developed by Pakhomov, et al., consists of 725 clinical term pairs whose semantic similarity and relatedness.
|
| 18 |
+
The similarity and relatedness of each term pair was annotated based on a continuous scale by having the resident touch
|
| 19 |
+
a bar on a touch sensitive computer screen to indicate the degree of similarity or relatedness. The Intraclass
|
| 20 |
+
Correlation Coefficient (ICC) for the reference standard tagged for similarity was 0.47, and 0.50 for relatedness.
|
| 21 |
+
Therefore, as suggested by Pakhomov and colleagues, the subset below consists of 401 pairs for the similarity set and
|
| 22 |
+
430 pairs for the relatedness set which each have an ICC equal to 0.73.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
from typing import Dict, List, Tuple
|
| 26 |
+
|
| 27 |
+
import datasets
|
| 28 |
+
import pandas as pd
|
| 29 |
+
|
| 30 |
+
from .bigbiohub import pairs_features
|
| 31 |
+
from .bigbiohub import BigBioConfig
|
| 32 |
+
from .bigbiohub import Tasks
|
| 33 |
+
|
| 34 |
+
_LANGUAGES = ['English']
|
| 35 |
+
_PUBMED = False
|
| 36 |
+
_LOCAL = False
|
| 37 |
+
_CITATION = """\
|
| 38 |
+
@inproceedings{pakhomov2010semantic,
|
| 39 |
+
title={Semantic similarity and relatedness between clinical terms: an experimental study},
|
| 40 |
+
author={Pakhomov, Serguei and McInnes, Bridget and Adam, Terrence and Liu, Ying and Pedersen, Ted and Melton, \
|
| 41 |
+
Genevieve B},
|
| 42 |
+
booktitle={AMIA annual symposium proceedings},
|
| 43 |
+
volume={2010},
|
| 44 |
+
pages={572},
|
| 45 |
+
year={2010},
|
| 46 |
+
organization={American Medical Informatics Association}
|
| 47 |
+
}
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
_DATASETNAME = "umnsrs"
|
| 51 |
+
_DISPLAYNAME = "UMNSRS"
|
| 52 |
+
|
| 53 |
+
_DESCRIPTION = """\
|
| 54 |
+
UMNSRS, developed by Pakhomov, et al., consists of 725 clinical term pairs whose semantic similarity and relatedness.
|
| 55 |
+
The similarity and relatedness of each term pair was annotated based on a continuous scale by having the resident touch
|
| 56 |
+
a bar on a touch sensitive computer screen to indicate the degree of similarity or relatedness.
|
| 57 |
+
The following subsets are available:
|
| 58 |
+
- similarity: A set of 566 UMLS concept pairs manually rated for semantic similarity (e.g. whale-dolphin) using a
|
| 59 |
+
continuous response scale.
|
| 60 |
+
- relatedness: A set of 588 UMLS concept pairs manually rated for semantic relatedness (e.g. needle-thread) using a
|
| 61 |
+
continuous response scale.
|
| 62 |
+
- similarity_mod: Modification of the UMNSRS-Similarity dataset to exclude control samples and those pairs that did not
|
| 63 |
+
match text in clinical, biomedical and general English corpora. Exact modifications are detailed in the paper (Corpus
|
| 64 |
+
Domain Effects on Distributional Semantic Modeling of Medical Terms. Serguei V.S. Pakhomov, Greg Finley, Reed McEwan,
|
| 65 |
+
Yan Wang, and Genevieve B. Melton. Bioinformatics. 2016; 32(23):3635-3644). The resulting dataset contains 449 pairs.
|
| 66 |
+
- relatedness_mod: Modification of the UMNSRS-Relatedness dataset to exclude control samples and those pairs that did
|
| 67 |
+
not match text in clinical, biomedical and general English corpora. Exact modifications are detailed in the paper
|
| 68 |
+
(Corpus Domain Effects on Distributional Semantic Modeling of Medical Terms. Serguei V.S. Pakhomov, Greg Finley,
|
| 69 |
+
Reed McEwan, Yan Wang, and Genevieve B. Melton. Bioinformatics. 2016; 32(23):3635-3644).
|
| 70 |
+
The resulting dataset contains 458 pairs.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
_HOMEPAGE = "https://conservancy.umn.edu/handle/11299/196265/"
|
| 74 |
+
|
| 75 |
+
_LICENSE = 'Creative Commons Zero v1.0 Universal'
|
| 76 |
+
|
| 77 |
+
_BASE_URL = "https://conservancy.umn.edu/bitstream/handle/11299/196265/"
|
| 78 |
+
|
| 79 |
+
_URLS = {
|
| 80 |
+
"umnsrs_similarity": _BASE_URL + "UMNSRS_similarity.csv",
|
| 81 |
+
"umnsrs_relatedness": _BASE_URL + "UMNSRS_relatedness.csv",
|
| 82 |
+
"umnsrs_similarity_mod": _BASE_URL + "UMNSRS_similarity_mod449_word2vec.csv",
|
| 83 |
+
"umnsrs_relatedness_mod": _BASE_URL + "UMNSRS_relatedness_mod458_word2vec.csv",
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
_SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
|
| 87 |
+
|
| 88 |
+
_SOURCE_VERSION = "1.0.0"
|
| 89 |
+
|
| 90 |
+
_BIGBIO_VERSION = "1.0.0"
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class UmnsrsDataset(datasets.GeneratorBasedBuilder):
|
| 94 |
+
"""UMNSRS, developed by Pakhomov, et al., contains clinical term pairs whose semantic similarity and
|
| 95 |
+
relatedness were scored by experts."""
|
| 96 |
+
|
| 97 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 98 |
+
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
| 99 |
+
|
| 100 |
+
BUILDER_CONFIGS = []
|
| 101 |
+
|
| 102 |
+
for subset in ["similarity", "relatedness"]:
|
| 103 |
+
for mod in ["_mod", ""]:
|
| 104 |
+
BUILDER_CONFIGS.append(
|
| 105 |
+
BigBioConfig(
|
| 106 |
+
name=f"umnsrs_{subset}{mod}_source",
|
| 107 |
+
version=SOURCE_VERSION,
|
| 108 |
+
description=f"UMNSRS {subset}{mod} source schema",
|
| 109 |
+
schema="source",
|
| 110 |
+
subset_id=f"umnsrs_{subset}{mod}",
|
| 111 |
+
)
|
| 112 |
+
)
|
| 113 |
+
BUILDER_CONFIGS.append(
|
| 114 |
+
BigBioConfig(
|
| 115 |
+
name=f"umnsrs_{subset}{mod}_bigbio_pairs",
|
| 116 |
+
version=BIGBIO_VERSION,
|
| 117 |
+
description=f"UMNSRS {subset}{mod} BigBio schema",
|
| 118 |
+
schema="bigbio_pairs",
|
| 119 |
+
subset_id=f"umnsrs_{subset}{mod}",
|
| 120 |
+
)
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
DEFAULT_CONFIG_NAME = "umnsrs_similarity_source"
|
| 124 |
+
|
| 125 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 126 |
+
|
| 127 |
+
if self.config.schema == "source":
|
| 128 |
+
features = datasets.Features(
|
| 129 |
+
{
|
| 130 |
+
"mean_score": datasets.Value("float32"),
|
| 131 |
+
"std_score": datasets.Value("float32"),
|
| 132 |
+
"text_1": datasets.Value("string"),
|
| 133 |
+
"text_2": datasets.Value("string"),
|
| 134 |
+
"code_1": datasets.Value("string"),
|
| 135 |
+
"code_2": datasets.Value("string"),
|
| 136 |
+
}
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
elif self.config.schema == "bigbio_pairs":
|
| 140 |
+
features = pairs_features
|
| 141 |
+
|
| 142 |
+
return datasets.DatasetInfo(
|
| 143 |
+
description=_DESCRIPTION,
|
| 144 |
+
features=features,
|
| 145 |
+
homepage=_HOMEPAGE,
|
| 146 |
+
license=str(_LICENSE),
|
| 147 |
+
citation=_CITATION,
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
| 151 |
+
"""Returns SplitGenerators."""
|
| 152 |
+
|
| 153 |
+
urls = _URLS[self.config.subset_id]
|
| 154 |
+
filepath = dl_manager.download_and_extract(urls)
|
| 155 |
+
|
| 156 |
+
return [
|
| 157 |
+
datasets.SplitGenerator(
|
| 158 |
+
name=datasets.Split.TRAIN,
|
| 159 |
+
gen_kwargs={
|
| 160 |
+
"filepath": filepath,
|
| 161 |
+
},
|
| 162 |
+
)
|
| 163 |
+
]
|
| 164 |
+
|
| 165 |
+
def _generate_examples(self, filepath) -> Tuple[int, Dict]:
|
| 166 |
+
"""Yields examples as (key, example) tuples."""
|
| 167 |
+
print(filepath)
|
| 168 |
+
data = pd.read_csv(
|
| 169 |
+
filepath,
|
| 170 |
+
sep=",",
|
| 171 |
+
header=0,
|
| 172 |
+
names=["mean_score", "std_score", "text_1", "text_2", "code_1", "code_2"],
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
if self.config.schema == "source":
|
| 176 |
+
for id_, row in data.iterrows():
|
| 177 |
+
yield id_, row.to_dict()
|
| 178 |
+
elif self.config.schema == "bigbio_pairs":
|
| 179 |
+
for id_, row in data.iterrows():
|
| 180 |
+
yield id_, {
|
| 181 |
+
"id": id_,
|
| 182 |
+
"document_id": id_,
|
| 183 |
+
"text_1": row["text_1"],
|
| 184 |
+
"text_2": row["text_2"],
|
| 185 |
+
"label": row["mean_score"],
|
| 186 |
+
}
|