Commit
·
465c955
1
Parent(s):
3f3d86e
upload hubscripts/bio_sim_verb_hub.py to hub from bigbio repo
Browse files- bio_sim_verb.py +169 -0
bio_sim_verb.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
This repository contains the evaluation datasets for the paper Bio-SimVerb and
|
17 |
+
Bio-SimLex: Wide-coverage Evaluation Sets of Word Similarity in Biomedicine by
|
18 |
+
Billy Chiu, Sampo Pyysalo and Anna Korhonen.
|
19 |
+
"""
|
20 |
+
|
21 |
+
import csv
|
22 |
+
from typing import Dict, List, Tuple
|
23 |
+
|
24 |
+
import datasets
|
25 |
+
|
26 |
+
from .bigbiohub import pairs_features
|
27 |
+
from .bigbiohub import BigBioConfig
|
28 |
+
from .bigbiohub import Tasks
|
29 |
+
|
30 |
+
# TODO: Add BibTeX citation
|
31 |
+
_LANGUAGES = ['English']
|
32 |
+
_PUBMED = True
|
33 |
+
_LOCAL = False
|
34 |
+
_CITATION = """\
|
35 |
+
@article{article,
|
36 |
+
title = {
|
37 |
+
Bio-SimVerb and Bio-SimLex: Wide-coverage evaluation sets of word
|
38 |
+
similarity in biomedicine
|
39 |
+
},
|
40 |
+
author = {Chiu, Billy and Pyysalo, Sampo and Vulić, Ivan and Korhonen, Anna},
|
41 |
+
year = 2018,
|
42 |
+
month = {02},
|
43 |
+
journal = {BMC Bioinformatics},
|
44 |
+
volume = 19,
|
45 |
+
pages = {},
|
46 |
+
doi = {10.1186/s12859-018-2039-z}
|
47 |
+
}
|
48 |
+
"""
|
49 |
+
|
50 |
+
_DATASETNAME = "bio_sim_verb"
|
51 |
+
_DISPLAYNAME = "Bio-SimVerb"
|
52 |
+
|
53 |
+
_DESCRIPTION = """
|
54 |
+
This repository contains the evaluation datasets for the paper Bio-SimVerb and \
|
55 |
+
Bio-SimLex: Wide-coverage Evaluation Sets of Word Similarity in Biomedicine by \
|
56 |
+
Billy Chiu, Sampo Pyysalo and Anna Korhonen.
|
57 |
+
"""
|
58 |
+
|
59 |
+
_HOMEPAGE = "https://github.com/cambridgeltl/bio-simverb"
|
60 |
+
|
61 |
+
_LICENSE = 'License information unavailable'
|
62 |
+
|
63 |
+
_URLS = {
|
64 |
+
_DATASETNAME: "https://raw.githubusercontent.com/cambridgeltl/bio-simverb/master/wvlib/word-similarities/bio-simverb/Bio-SimVerb.txt",
|
65 |
+
}
|
66 |
+
|
67 |
+
_SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
|
68 |
+
|
69 |
+
_SOURCE_VERSION = "1.0.0"
|
70 |
+
_BIGBIO_VERSION = "1.0.0"
|
71 |
+
|
72 |
+
|
73 |
+
# TODO: Name the dataset class to match the script name using CamelCase instead of snake_case
|
74 |
+
# Append "Dataset" to the class name: BioASQ --> BioasqDataset
|
75 |
+
class BioSimVerb(datasets.GeneratorBasedBuilder):
|
76 |
+
"""Evaluation of word similarity in biomedical texts."""
|
77 |
+
|
78 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
79 |
+
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
80 |
+
|
81 |
+
BUILDER_CONFIGS = [
|
82 |
+
BigBioConfig(
|
83 |
+
name="bio_sim_verb_source",
|
84 |
+
version=SOURCE_VERSION,
|
85 |
+
description="bio_sim_verb source schema",
|
86 |
+
schema="source",
|
87 |
+
subset_id="bio_sim_verb",
|
88 |
+
),
|
89 |
+
BigBioConfig(
|
90 |
+
name="bio_sim_verb_bigbio_pairs",
|
91 |
+
version=BIGBIO_VERSION,
|
92 |
+
description="bio_sim_verb BigBio schema",
|
93 |
+
schema="bigbio_pairs",
|
94 |
+
subset_id="bio_sim_verb",
|
95 |
+
),
|
96 |
+
]
|
97 |
+
|
98 |
+
DEFAULT_CONFIG_NAME = "bio_sim_verb_source"
|
99 |
+
|
100 |
+
def _info(self) -> datasets.DatasetInfo:
|
101 |
+
|
102 |
+
if self.config.schema == "source":
|
103 |
+
features = datasets.Features(
|
104 |
+
{
|
105 |
+
"text_1": datasets.Value("string"),
|
106 |
+
"text_2": datasets.Value("string"),
|
107 |
+
"label": datasets.Value("float32"),
|
108 |
+
}
|
109 |
+
)
|
110 |
+
|
111 |
+
# Using in pairs schema
|
112 |
+
elif self.config.schema == "bigbio_pairs":
|
113 |
+
features = pairs_features
|
114 |
+
|
115 |
+
return datasets.DatasetInfo(
|
116 |
+
description=_DESCRIPTION,
|
117 |
+
features=features,
|
118 |
+
homepage=_HOMEPAGE,
|
119 |
+
license=str(_LICENSE),
|
120 |
+
citation=_CITATION,
|
121 |
+
)
|
122 |
+
|
123 |
+
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
124 |
+
"""Returns SplitGenerators."""
|
125 |
+
|
126 |
+
urls = _URLS[_DATASETNAME]
|
127 |
+
data_dir = dl_manager.download_and_extract(urls)
|
128 |
+
|
129 |
+
return [
|
130 |
+
datasets.SplitGenerator(
|
131 |
+
name=datasets.Split.TRAIN,
|
132 |
+
# Whatever you put in gen_kwargs will be passed to _generate_examples
|
133 |
+
gen_kwargs={"filepath": data_dir, "split": "train"},
|
134 |
+
)
|
135 |
+
]
|
136 |
+
|
137 |
+
def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
|
138 |
+
"""Yields examples as (key, example) tuples."""
|
139 |
+
|
140 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
141 |
+
csv_reader = csv.reader(
|
142 |
+
csv_file,
|
143 |
+
quotechar='"',
|
144 |
+
delimiter="\t",
|
145 |
+
quoting=csv.QUOTE_ALL,
|
146 |
+
skipinitialspace=True,
|
147 |
+
)
|
148 |
+
|
149 |
+
if self.config.schema == "source":
|
150 |
+
for id_, row in enumerate(csv_reader):
|
151 |
+
text_1, text_2, label = row
|
152 |
+
yield id_, {
|
153 |
+
"text_1": text_1,
|
154 |
+
"text_2": text_2,
|
155 |
+
"label": float(label),
|
156 |
+
}
|
157 |
+
|
158 |
+
elif self.config.schema == "bigbio_pairs":
|
159 |
+
uid = 0
|
160 |
+
for id_, row in enumerate(csv_reader):
|
161 |
+
uid += 1
|
162 |
+
text_1, text_2, label = row
|
163 |
+
yield id_, {
|
164 |
+
"id": str(uid),
|
165 |
+
"document_id": "NULL",
|
166 |
+
"text_1": text_1,
|
167 |
+
"text_2": text_2,
|
168 |
+
"label": str(label),
|
169 |
+
}
|