gabrielaltay commited on
Commit
4e12778
1 Parent(s): 4026a3b

upload hubscripts/minimayosrs_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. minimayosrs.py +164 -0
minimayosrs.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ MayoSRS consists of 101 clinical term pairs whose relatedness was determined by
18
+ nine medical coders and three physicians from the Mayo Clinic.
19
+ """
20
+
21
+ from typing import Dict, List, Tuple
22
+
23
+ import datasets
24
+ import pandas as pd
25
+
26
+ from .bigbiohub import pairs_features
27
+ from .bigbiohub import BigBioConfig
28
+ from .bigbiohub import Tasks
29
+
30
+ _LANGUAGES = ['English']
31
+ _PUBMED = False
32
+ _LOCAL = False
33
+ _CITATION = """\
34
+ @article{pedersen2007measures,
35
+ title={Measures of semantic similarity and relatedness in the biomedical domain},
36
+ author={Pedersen, Ted and Pakhomov, Serguei VS and Patwardhan, Siddharth and Chute, Christopher G},
37
+ journal={Journal of biomedical informatics},
38
+ volume={40},
39
+ number={3},
40
+ pages={288--299},
41
+ year={2007},
42
+ publisher={Elsevier}
43
+ }
44
+ """
45
+
46
+ _DATASETNAME = "minimayosrs"
47
+ _DISPLAYNAME = "MiniMayoSRS"
48
+
49
+ _DESCRIPTION = """\
50
+ MiniMayoSRS is a subset of the MayoSRS and consists of 30 term pairs on which a higher inter-annotator agreement was
51
+ achieved. The average correlation between physicians is 0.68. The average correlation between medical coders is 0.78.
52
+ """
53
+
54
+ _HOMEPAGE = "https://conservancy.umn.edu/handle/11299/196265"
55
+
56
+ _LICENSE = 'Creative Commons Zero v1.0 Universal'
57
+
58
+ _URLS = {
59
+ _DATASETNAME: "https://conservancy.umn.edu/bitstream/handle/11299/196265/MiniMayoSRS.csv?sequence=2&isAllowed=y"
60
+ }
61
+
62
+ _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
63
+
64
+ _SOURCE_VERSION = "1.0.0"
65
+
66
+ _BIGBIO_VERSION = "1.0.0"
67
+
68
+
69
+ class MinimayosrsDataset(datasets.GeneratorBasedBuilder):
70
+ """MiniMayoSRS is a subset of the MayoSRS and consists of 30 term pairs on which a higher inter-annotator agreement
71
+ was achieved. The average correlation between physicians is 0.68. The average correlation between medical coders
72
+ is 0.78.
73
+ """
74
+
75
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
76
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
77
+
78
+ BUILDER_CONFIGS = [
79
+ BigBioConfig(
80
+ name="minimayosrs_source",
81
+ version=SOURCE_VERSION,
82
+ description="MiniMayoSRS source schema",
83
+ schema="source",
84
+ subset_id="minimayosrs",
85
+ ),
86
+ BigBioConfig(
87
+ name="minimayosrs_bigbio_pairs",
88
+ version=BIGBIO_VERSION,
89
+ description="MiniMayoSRS BigBio schema",
90
+ schema="bigbio_pairs",
91
+ subset_id="minimayosrs",
92
+ ),
93
+ ]
94
+
95
+ DEFAULT_CONFIG_NAME = "minimayosrs_source"
96
+
97
+ def _info(self) -> datasets.DatasetInfo:
98
+
99
+ if self.config.schema == "source":
100
+ features = datasets.Features(
101
+ {
102
+ "text_1": datasets.Value("string"),
103
+ "text_2": datasets.Value("string"),
104
+ "code_1": datasets.Value("string"),
105
+ "code_2": datasets.Value("string"),
106
+ "label_physicians": datasets.Value("float32"),
107
+ "label_coders": datasets.Value("float32"),
108
+ }
109
+ )
110
+
111
+ elif self.config.schema == "bigbio_pairs":
112
+ features = pairs_features
113
+
114
+ return datasets.DatasetInfo(
115
+ description=_DESCRIPTION,
116
+ features=features,
117
+ homepage=_HOMEPAGE,
118
+ license=str(_LICENSE),
119
+ citation=_CITATION,
120
+ )
121
+
122
+ def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
123
+ """Returns SplitGenerators."""
124
+
125
+ urls = _URLS[_DATASETNAME]
126
+ filepath = dl_manager.download_and_extract(urls)
127
+
128
+ return [
129
+ datasets.SplitGenerator(
130
+ name=datasets.Split.TRAIN,
131
+ gen_kwargs={"filepath": filepath},
132
+ )
133
+ ]
134
+
135
+ def _generate_examples(self, filepath) -> Tuple[int, Dict]:
136
+ """Yields examples as (key, example) tuples."""
137
+
138
+ data = pd.read_csv(
139
+ filepath,
140
+ sep=",",
141
+ header=0,
142
+ names=[
143
+ "label_physicians",
144
+ "label_coders",
145
+ "code_1",
146
+ "code_2",
147
+ "text_1",
148
+ "text_2",
149
+ ],
150
+ )
151
+
152
+ if self.config.schema == "source":
153
+ for id_, row in data.iterrows():
154
+ yield id_, row.to_dict()
155
+
156
+ elif self.config.schema == "bigbio_pairs":
157
+ for id_, row in data.iterrows():
158
+ yield id_, {
159
+ "id": id_,
160
+ "document_id": id_,
161
+ "text_1": row["text_1"],
162
+ "text_2": row["text_2"],
163
+ "label": str((row["label_physicians"] + row["label_coders"]) / 2),
164
+ }