Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
gabrielaltay commited on
Commit
98092f7
1 Parent(s): 1104131

upload hubscripts/mqp_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. mqp.py +171 -0
mqp.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 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
+ Medical Question Pairs dataset by McCreery et al (2020) contains pairs of medical questions and paraphrased versions of
17
+ the question prepared by medical professional.
18
+ """
19
+
20
+ import csv
21
+ import os
22
+ from typing import Dict, Tuple
23
+
24
+ import datasets
25
+ from datasets import load_dataset
26
+
27
+ from .bigbiohub import pairs_features
28
+ from .bigbiohub import BigBioConfig
29
+ from .bigbiohub import Tasks
30
+
31
+ _LANGUAGES = ['English']
32
+ _PUBMED = False
33
+ _LOCAL = False
34
+ _CITATION = """\
35
+ @article{DBLP:journals/biodb/LiSJSWLDMWL16,
36
+ author = {Krallinger, M., Rabal, O., Lourenço, A.},
37
+ title = {Effective Transfer Learning for Identifying Similar Questions: Matching User Questions to COVID-19 FAQs},
38
+ journal = {KDD '20: Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining},
39
+ volume = {3458–3465},
40
+ year = {2020},
41
+ url = {https://github.com/curai/medical-question-pair-dataset},
42
+ doi = {},
43
+ biburl = {},
44
+ bibsource = {}
45
+ }
46
+ """
47
+
48
+ _DATASETNAME = "mqp"
49
+ _DISPLAYNAME = "MQP"
50
+
51
+ _DESCRIPTION = """\
52
+ Medical Question Pairs dataset by McCreery et al (2020) contains pairs of medical questions and paraphrased versions of
53
+ the question prepared by medical professional. Paraphrased versions were labelled as similar (syntactically dissimilar
54
+ but contextually similar ) or dissimilar (syntactically may look similar but contextually dissimilar). Labels 1: similar, 0: dissimilar
55
+ """
56
+
57
+ _HOMEPAGE = "https://github.com/curai/medical-question-pair-dataset"
58
+
59
+ _LICENSE = 'License information unavailable'
60
+ _URLs = {
61
+ _DATASETNAME: "https://raw.githubusercontent.com/curai/medical-question-pair-dataset/master/mqp.csv",
62
+ }
63
+
64
+ _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
65
+ _SOURCE_VERSION = "1.0.0"
66
+ _BIGBIO_VERSION = "1.0.0"
67
+
68
+
69
+ class MQPDataset(datasets.GeneratorBasedBuilder):
70
+ """Medical Question Pairing dataset"""
71
+
72
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
73
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
74
+
75
+ BUILDER_CONFIGS = [
76
+ BigBioConfig(
77
+ name="mqp_source",
78
+ version=SOURCE_VERSION,
79
+ description="MQP source schema",
80
+ schema="source",
81
+ subset_id="mqp",
82
+ ),
83
+ BigBioConfig(
84
+ name="mqp_bigbio_pairs",
85
+ version=BIGBIO_VERSION,
86
+ description="MQP BigBio schema",
87
+ schema="bigbio_pairs",
88
+ subset_id="mqp",
89
+ ),
90
+ ]
91
+
92
+ DEFAULT_CONFIG_NAME = "mqp_source"
93
+
94
+ def _info(self):
95
+
96
+ if self.config.schema == "source":
97
+ features = datasets.Features(
98
+ {
99
+ "document_id": datasets.Value("string"),
100
+ "text_1": datasets.Value("string"),
101
+ "text_2": datasets.Value("string"),
102
+ "label": datasets.Value("string"),
103
+ }
104
+ )
105
+
106
+ # Using in pairs schema
107
+ elif self.config.schema == "bigbio_pairs":
108
+ features = pairs_features
109
+
110
+ return datasets.DatasetInfo(
111
+ description=_DESCRIPTION,
112
+ features=features,
113
+ homepage=_HOMEPAGE,
114
+ license=str(_LICENSE),
115
+ citation=_CITATION,
116
+ )
117
+
118
+ def _split_generators(self, dl_manager):
119
+ """Returns SplitGenerators."""
120
+ my_urls = _URLs[_DATASETNAME]
121
+ data_dir = dl_manager.download_and_extract(my_urls)
122
+
123
+ return [
124
+ datasets.SplitGenerator(
125
+ name=datasets.Split.TRAIN,
126
+ gen_kwargs={
127
+ "filepath": data_dir,
128
+ "split": "train",
129
+ },
130
+ )
131
+ ]
132
+
133
+ def _generate_examples(self, filepath, split):
134
+ """Yields examples as (key, example) tuples."""
135
+
136
+ if split == "train": # There's only training dataset available atm
137
+ with open(filepath, encoding="utf-8") as csv_file:
138
+ csv_reader = csv.reader(
139
+ csv_file,
140
+ quotechar='"',
141
+ delimiter=",",
142
+ quoting=csv.QUOTE_ALL,
143
+ skipinitialspace=True,
144
+ )
145
+
146
+ if self.config.schema == "source":
147
+ for id_, row in enumerate(csv_reader):
148
+ document_id, text_1, text_2, label = row
149
+ yield id_, {
150
+ "document_id": document_id,
151
+ "text_1": text_1,
152
+ "text_2": text_2,
153
+ "label": label,
154
+ }
155
+
156
+ elif self.config.schema == "bigbio_pairs":
157
+ # global id (uid) starts from 1
158
+ uid = 0
159
+ for id_, row in enumerate(csv_reader):
160
+ uid += 1
161
+ document_id, text_1, text_2, label = row
162
+ yield id_, {
163
+ "id": uid, # uid is an unique identifier for every record that starts from 1
164
+ "document_id": document_id,
165
+ "text_1": text_1,
166
+ "text_2": text_2,
167
+ "label": label,
168
+ }
169
+ else:
170
+ print("There's no test/val split available for the given dataset")
171
+ return