gabrielaltay commited on
Commit
8849146
1 Parent(s): 1fc9a81

upload hubscripts/bio_simlex_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. bio_simlex.py +163 -0
bio_simlex.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Bio-SimLex enables intrinsic evaluation of word representations. This evaluation
18
+ can serve as a predictor of performance on various downstream tasks in the
19
+ biomedical domain. The results on Bio-SimLex using standard word representation
20
+ models highlight the importance of developing dedicated evaluation resources for
21
+ NLP in biomedicine for particular word classes (e.g. verbs).
22
+ """
23
+
24
+ from typing import Dict, List, Tuple
25
+
26
+ import datasets
27
+
28
+ from .bigbiohub import pairs_features
29
+ from .bigbiohub import BigBioConfig
30
+ from .bigbiohub import Tasks
31
+
32
+ _LANGUAGES = ['English']
33
+ _PUBMED = True
34
+ _LOCAL = False
35
+ _CITATION = """\
36
+ @article{article,
37
+ title = {
38
+ Bio-SimVerb and Bio-SimLex: Wide-coverage evaluation sets of word
39
+ similarity in biomedicine
40
+ },
41
+ author = {Chiu, Billy and Pyysalo, Sampo and Vulić, Ivan and Korhonen, Anna},
42
+ year = 2018,
43
+ month = {02},
44
+ journal = {BMC Bioinformatics},
45
+ volume = 19,
46
+ pages = {},
47
+ doi = {10.1186/s12859-018-2039-z}
48
+ }
49
+ """
50
+
51
+ _DATASETNAME = "bio_simlex"
52
+ _DISPLAYNAME = "Bio-SimLex"
53
+
54
+ _DESCRIPTION = """\
55
+ Bio-SimLex enables intrinsic evaluation of word representations. This evaluation \
56
+ can serve as a predictor of performance on various downstream tasks in the \
57
+ biomedical domain. The results on Bio-SimLex using standard word representation \
58
+ models highlight the importance of developing dedicated evaluation resources for \
59
+ NLP in biomedicine for particular word classes (e.g. verbs).
60
+ """
61
+
62
+ _HOMEPAGE = "https://github.com/cambridgeltl/bio-simverb"
63
+
64
+ _LICENSE = 'License information unavailable'
65
+
66
+ _URLS = {
67
+ _DATASETNAME: "https://github.com/cambridgeltl/bio-simverb/blob/master/wvlib/word-similarities/\
68
+ bio-simlex/Bio-SimLex.txt?raw=true"
69
+ }
70
+
71
+ _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
72
+
73
+ _SOURCE_VERSION = "1.0.0"
74
+ _BIGBIO_VERSION = "1.0.0"
75
+
76
+
77
+ class BioSimlexDataset(datasets.GeneratorBasedBuilder):
78
+ """
79
+ Bio-SimLex enables intrinsic evaluation of word representations. Config schema
80
+ as source gives score between 0-10 for pairs of words. The source schema casts
81
+ labels as `float`, but the bigbio schema casts them as `str`.
82
+ """
83
+
84
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
85
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
86
+
87
+ BUILDER_CONFIGS = [
88
+ BigBioConfig(
89
+ name="bio_simlex_source",
90
+ version=SOURCE_VERSION,
91
+ description="bio_simlex source schema",
92
+ schema="source",
93
+ subset_id="bio_simlex",
94
+ ),
95
+ BigBioConfig(
96
+ name="bio_simlex_bigbio_pairs",
97
+ version=BIGBIO_VERSION,
98
+ description="bio_simlex BigBio schema",
99
+ schema="bigbio_pairs",
100
+ subset_id="bio_simlex",
101
+ ),
102
+ ]
103
+
104
+ DEFAULT_CONFIG_NAME = "bio_simlex_source"
105
+
106
+ def _info(self) -> datasets.DatasetInfo:
107
+
108
+ if self.config.schema == "source":
109
+ features = datasets.Features(
110
+ {
111
+ "text_1": datasets.Value("string"),
112
+ "text_2": datasets.Value("string"),
113
+ "score": datasets.Value("float32"),
114
+ }
115
+ )
116
+
117
+ elif self.config.schema == "bigbio_pairs":
118
+ features = pairs_features
119
+
120
+ return datasets.DatasetInfo(
121
+ description=_DESCRIPTION,
122
+ features=features,
123
+ homepage=_HOMEPAGE,
124
+ license=str(_LICENSE),
125
+ citation=_CITATION,
126
+ )
127
+
128
+ def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
129
+ """Returns SplitGenerators."""
130
+
131
+ url = _URLS[_DATASETNAME]
132
+ data_dir = dl_manager.download_and_extract(url)
133
+
134
+ return [
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.TRAIN,
137
+ gen_kwargs={
138
+ "filepath": data_dir,
139
+ "split": "train",
140
+ },
141
+ ),
142
+ ]
143
+
144
+ def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
145
+ """Yields examples as (key, example) tuples."""
146
+ with open(filepath, "r", encoding="utf-8") as f:
147
+ for id_, line in enumerate(f):
148
+ word1, word2, score = line.split("\t")
149
+ if self.config.schema == "source":
150
+ yield id_, {
151
+ "text_1": word1,
152
+ "text_2": word2,
153
+ "score": float(score),
154
+ }
155
+
156
+ elif self.config.schema == "bigbio_pairs":
157
+ yield id_, {
158
+ "id": str(id_),
159
+ "document_id": str(id_),
160
+ "text_1": word1,
161
+ "text_2": word2,
162
+ "label": str(score.strip()),
163
+ }