Datasets:
Thomas Lemberger
commited on
Commit
·
dd092a0
1
Parent(s):
16031ca
updating data files and loader script
Browse files- sd-nlp.py +102 -68
- sd_figs.zip +2 -2
- sd_panels.zip +2 -2
sd-nlp.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and
|
| 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.
|
|
@@ -12,69 +12,74 @@
|
|
| 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 |
from __future__ import absolute_import, division, print_function
|
| 18 |
|
| 19 |
import json
|
| 20 |
-
|
| 21 |
-
|
| 22 |
import datasets
|
| 23 |
|
| 24 |
|
| 25 |
-
_NER_LABEL_NAMES = [
|
| 26 |
-
"O",
|
| 27 |
-
"I-SMALL_MOLECULE",
|
| 28 |
-
"B-SMALL_MOLECULE",
|
| 29 |
-
"I-GENEPROD",
|
| 30 |
-
"B-GENEPROD",
|
| 31 |
-
"I-SUBCELLULAR",
|
| 32 |
-
"B-SUBCELLULAR",
|
| 33 |
-
"I-CELL",
|
| 34 |
-
"B-CELL",
|
| 35 |
-
"I-TISSUE",
|
| 36 |
-
"B-TISSUE",
|
| 37 |
-
"I-ORGANISM",
|
| 38 |
-
"B-ORGANISM",
|
| 39 |
-
"I-EXP_ASSAY",
|
| 40 |
-
"B-EXP_ASSAY",
|
| 41 |
-
]
|
| 42 |
-
_SEMANTIC_ROLES_LABEL_NAMES = ["O", "I-CONTROLLED_VAR", "B-CONTROLLED_VAR", "I-MEASURED_VAR", "B-MEASURED_VAR"]
|
| 43 |
-
_BORING_LABEL_NAMES = ["O", "I-BORING", "B-BORING"]
|
| 44 |
-
_PANEL_START_NAMES = ["O", "B-PANEL_START"]
|
| 45 |
-
|
| 46 |
-
_CITATION = """\
|
| 47 |
-
@Unpublished{
|
| 48 |
-
huggingface: dataset,
|
| 49 |
-
title = {SourceData NLP},
|
| 50 |
-
authors={Thomas Lemberger, EMBO},
|
| 51 |
-
year={2021}
|
| 52 |
-
}
|
| 53 |
-
"""
|
| 54 |
-
|
| 55 |
-
_DESCRIPTION = """\
|
| 56 |
-
This dataset is based on the SourceData database and is intented to facilitate training of NLP tasks in the cell and molecualr biology domain.
|
| 57 |
-
"""
|
| 58 |
-
|
| 59 |
-
_HOMEPAGE = "https://huggingface.co/datasets/EMBO/sd-nlp"
|
| 60 |
-
|
| 61 |
-
_LICENSE = "CC-BY 4.0"
|
| 62 |
-
|
| 63 |
-
_URLS = {
|
| 64 |
-
"NER": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 65 |
-
"ROLES": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 66 |
-
"BORING": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 67 |
-
"PANELIZATION": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panelization.zip",
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
| 71 |
"""SourceDataNLP provides datasets to train NLP tasks in cell and molecular biology."""
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
VERSION = datasets.Version("0.0.1")
|
| 74 |
|
| 75 |
BUILDER_CONFIGS = [
|
| 76 |
datasets.BuilderConfig(name="NER", version="0.0.1", description="Dataset for entity recognition"),
|
| 77 |
-
datasets.BuilderConfig(name="
|
|
|
|
| 78 |
datasets.BuilderConfig(name="BORING", version="0.0.1", description="Dataset for semantic roles."),
|
| 79 |
datasets.BuilderConfig(
|
| 80 |
name="PANELIZATION",
|
|
@@ -91,18 +96,30 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
|
| 91 |
{
|
| 92 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 93 |
"labels": datasets.Sequence(
|
| 94 |
-
feature=datasets.ClassLabel(num_classes=len(_NER_LABEL_NAMES), names=_NER_LABEL_NAMES)
|
| 95 |
),
|
| 96 |
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
| 97 |
}
|
| 98 |
)
|
| 99 |
-
elif self.config.name == "
|
| 100 |
features = datasets.Features(
|
| 101 |
{
|
| 102 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 103 |
"labels": datasets.Sequence(
|
| 104 |
feature=datasets.ClassLabel(
|
| 105 |
-
num_classes=len(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
)
|
| 107 |
),
|
| 108 |
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
|
@@ -113,7 +130,7 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
|
| 113 |
{
|
| 114 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 115 |
"labels": datasets.Sequence(
|
| 116 |
-
feature=datasets.ClassLabel(num_classes=len(_BORING_LABEL_NAMES), names=_BORING_LABEL_NAMES)
|
| 117 |
),
|
| 118 |
}
|
| 119 |
)
|
|
@@ -122,18 +139,19 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
|
| 122 |
{
|
| 123 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 124 |
"labels": datasets.Sequence(
|
| 125 |
-
feature=datasets.ClassLabel(num_classes=len(_PANEL_START_NAMES), names=_PANEL_START_NAMES)
|
| 126 |
),
|
|
|
|
| 127 |
}
|
| 128 |
)
|
| 129 |
|
| 130 |
return datasets.DatasetInfo(
|
| 131 |
-
description=_DESCRIPTION,
|
| 132 |
features=features,
|
| 133 |
supervised_keys=("input_ids", "labels"),
|
| 134 |
-
homepage=_HOMEPAGE,
|
| 135 |
-
license=_LICENSE,
|
| 136 |
-
citation=_CITATION,
|
| 137 |
)
|
| 138 |
|
| 139 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
|
@@ -142,12 +160,12 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
|
| 142 |
if self.config.data_dir:
|
| 143 |
data_dir = self.config.data_dir
|
| 144 |
else:
|
| 145 |
-
url = _URLS[self.config.name]
|
| 146 |
data_dir = dl_manager.download_and_extract(url)
|
| 147 |
-
if self.config.name in ["NER", "
|
| 148 |
data_dir += "/sd_panels"
|
| 149 |
elif self.config.name == "PANELIZATION":
|
| 150 |
-
data_dir += "/
|
| 151 |
else:
|
| 152 |
raise ValueError(f"unkonwn config name: {self.config.name}")
|
| 153 |
return [
|
|
@@ -183,22 +201,38 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
|
| 183 |
for id_, row in enumerate(f):
|
| 184 |
data = json.loads(row)
|
| 185 |
if self.config.name == "NER":
|
| 186 |
-
|
| 187 |
-
tag_mask = [0 if tag == "O" else 1 for tag in
|
| 188 |
-
yield id_, {
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
geneprod = ["B-GENEPROD", "I-GENEPROD", "B-PROTEIN", "I-PROTEIN", "B-GENE", "I-GENE"]
|
| 192 |
-
tag_mask = [1 if t in geneprod else 0 for t in
|
| 193 |
yield id_, {
|
| 194 |
"input_ids": data["input_ids"],
|
| 195 |
"labels": data["label_ids"]["geneprod_roles"],
|
| 196 |
"tag_mask": tag_mask,
|
| 197 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
elif self.config.name == "BORING":
|
| 199 |
yield id_, {"input_ids": data["input_ids"], "labels": data["label_ids"]["boring"]}
|
| 200 |
elif self.config.name == "PANELIZATION":
|
|
|
|
|
|
|
| 201 |
yield id_, {
|
| 202 |
"input_ids": data["input_ids"],
|
| 203 |
"labels": data["label_ids"]["panel_start"],
|
|
|
|
| 204 |
}
|
|
|
|
| 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.
|
|
|
|
| 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 |
+
# template from : https://github.com/huggingface/datasets/blob/master/templates/new_dataset_script.py
|
| 18 |
+
|
| 19 |
+
"""Loading script for the biolang dataset for language modeling in biology."""
|
| 20 |
|
| 21 |
from __future__ import absolute_import, division, print_function
|
| 22 |
|
| 23 |
import json
|
| 24 |
+
import pdb
|
|
|
|
| 25 |
import datasets
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
class SourceDataNLP(datasets.GeneratorBasedBuilder):
|
| 29 |
"""SourceDataNLP provides datasets to train NLP tasks in cell and molecular biology."""
|
| 30 |
|
| 31 |
+
_NER_LABEL_NAMES = [
|
| 32 |
+
"O",
|
| 33 |
+
"I-SMALL_MOLECULE",
|
| 34 |
+
"B-SMALL_MOLECULE",
|
| 35 |
+
"I-GENEPROD",
|
| 36 |
+
"B-GENEPROD",
|
| 37 |
+
"I-SUBCELLULAR",
|
| 38 |
+
"B-SUBCELLULAR",
|
| 39 |
+
"I-CELL",
|
| 40 |
+
"B-CELL",
|
| 41 |
+
"I-TISSUE",
|
| 42 |
+
"B-TISSUE",
|
| 43 |
+
"I-ORGANISM",
|
| 44 |
+
"B-ORGANISM",
|
| 45 |
+
"I-EXP_ASSAY",
|
| 46 |
+
"B-EXP_ASSAY",
|
| 47 |
+
]
|
| 48 |
+
_SEMANTIC_GENEPROD_ROLES_LABEL_NAMES = ["O", "I-CONTROLLED_VAR", "B-CONTROLLED_VAR", "I-MEASURED_VAR", "B-MEASURED_VAR"]
|
| 49 |
+
_SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES = ["O", "I-CONTROLLED_VAR", "B-CONTROLLED_VAR", "I-MEASURED_VAR", "B-MEASURED_VAR"]
|
| 50 |
+
_BORING_LABEL_NAMES = ["O", "I-BORING", "B-BORING"]
|
| 51 |
+
_PANEL_START_NAMES = ["O", "B-PANEL_START"]
|
| 52 |
+
|
| 53 |
+
_CITATION = """\
|
| 54 |
+
@Unpublished{
|
| 55 |
+
huggingface: dataset,
|
| 56 |
+
title = {SourceData NLP},
|
| 57 |
+
authors={Thomas Lemberger, EMBO},
|
| 58 |
+
year={2021}
|
| 59 |
+
}
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
_DESCRIPTION = """\
|
| 63 |
+
This dataset is based on the SourceData database and is intented to facilitate training of NLP tasks in the cell and molecualr biology domain.
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
_HOMEPAGE = "https://huggingface.co/datasets/EMBO/sd-nlp"
|
| 67 |
+
|
| 68 |
+
_LICENSE = "CC-BY 4.0"
|
| 69 |
+
|
| 70 |
+
_URLS = {
|
| 71 |
+
"NER": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 72 |
+
"ROLES": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 73 |
+
"BORING": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_panels.zip",
|
| 74 |
+
"PANELIZATION": "https://huggingface.co/datasets/EMBO/sd-nlp/resolve/main/sd_figs.zip",
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
VERSION = datasets.Version("0.0.1")
|
| 78 |
|
| 79 |
BUILDER_CONFIGS = [
|
| 80 |
datasets.BuilderConfig(name="NER", version="0.0.1", description="Dataset for entity recognition"),
|
| 81 |
+
datasets.BuilderConfig(name="GENEPROD_ROLES", version="0.0.1", description="Dataset for semantic roles."),
|
| 82 |
+
datasets.BuilderConfig(name="SMALL_MOL_ROLES", version="0.0.1", description="Dataset for semantic roles."),
|
| 83 |
datasets.BuilderConfig(name="BORING", version="0.0.1", description="Dataset for semantic roles."),
|
| 84 |
datasets.BuilderConfig(
|
| 85 |
name="PANELIZATION",
|
|
|
|
| 96 |
{
|
| 97 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 98 |
"labels": datasets.Sequence(
|
| 99 |
+
feature=datasets.ClassLabel(num_classes=len(self._NER_LABEL_NAMES), names=self._NER_LABEL_NAMES)
|
| 100 |
),
|
| 101 |
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
| 102 |
}
|
| 103 |
)
|
| 104 |
+
elif self.config.name == "GENEPROD_ROLES":
|
| 105 |
features = datasets.Features(
|
| 106 |
{
|
| 107 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 108 |
"labels": datasets.Sequence(
|
| 109 |
feature=datasets.ClassLabel(
|
| 110 |
+
num_classes=len(self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES), names=self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES
|
| 111 |
+
)
|
| 112 |
+
),
|
| 113 |
+
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
| 114 |
+
}
|
| 115 |
+
)
|
| 116 |
+
elif self.config.name == "SMALL_MOL_ROLES":
|
| 117 |
+
features = datasets.Features(
|
| 118 |
+
{
|
| 119 |
+
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 120 |
+
"labels": datasets.Sequence(
|
| 121 |
+
feature=datasets.ClassLabel(
|
| 122 |
+
num_classes=len(self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES), names=self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES
|
| 123 |
)
|
| 124 |
),
|
| 125 |
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
|
|
|
| 130 |
{
|
| 131 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 132 |
"labels": datasets.Sequence(
|
| 133 |
+
feature=datasets.ClassLabel(num_classes=len(self._BORING_LABEL_NAMES), names=self._BORING_LABEL_NAMES)
|
| 134 |
),
|
| 135 |
}
|
| 136 |
)
|
|
|
|
| 139 |
{
|
| 140 |
"input_ids": datasets.Sequence(feature=datasets.Value("int32")),
|
| 141 |
"labels": datasets.Sequence(
|
| 142 |
+
feature=datasets.ClassLabel(num_classes=len(self._PANEL_START_NAMES), names=self._PANEL_START_NAMES)
|
| 143 |
),
|
| 144 |
+
"tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
|
| 145 |
}
|
| 146 |
)
|
| 147 |
|
| 148 |
return datasets.DatasetInfo(
|
| 149 |
+
description=self._DESCRIPTION,
|
| 150 |
features=features,
|
| 151 |
supervised_keys=("input_ids", "labels"),
|
| 152 |
+
homepage=self._HOMEPAGE,
|
| 153 |
+
license=self._LICENSE,
|
| 154 |
+
citation=self._CITATION,
|
| 155 |
)
|
| 156 |
|
| 157 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
|
|
|
| 160 |
if self.config.data_dir:
|
| 161 |
data_dir = self.config.data_dir
|
| 162 |
else:
|
| 163 |
+
url = self._URLS[self.config.name]
|
| 164 |
data_dir = dl_manager.download_and_extract(url)
|
| 165 |
+
if self.config.name in ["NER", "GENEPROD_ROLES", "SMALL_MOL_ROLES", "BORING"]:
|
| 166 |
data_dir += "/sd_panels"
|
| 167 |
elif self.config.name == "PANELIZATION":
|
| 168 |
+
data_dir += "/sd_figs"
|
| 169 |
else:
|
| 170 |
raise ValueError(f"unkonwn config name: {self.config.name}")
|
| 171 |
return [
|
|
|
|
| 201 |
for id_, row in enumerate(f):
|
| 202 |
data = json.loads(row)
|
| 203 |
if self.config.name == "NER":
|
| 204 |
+
labels = data["label_ids"]["entity_types"]
|
| 205 |
+
tag_mask = [0 if tag == "O" else 1 for tag in labels]
|
| 206 |
+
yield id_, {
|
| 207 |
+
"input_ids": data["input_ids"],
|
| 208 |
+
"labels": labels,
|
| 209 |
+
"tag_mask": tag_mask,
|
| 210 |
+
}
|
| 211 |
+
elif self.config.name == "GENEPROD_ROLES":
|
| 212 |
+
labels = data["label_ids"]["entity_types"]
|
| 213 |
geneprod = ["B-GENEPROD", "I-GENEPROD", "B-PROTEIN", "I-PROTEIN", "B-GENE", "I-GENE"]
|
| 214 |
+
tag_mask = [1 if t in geneprod else 0 for t in labels]
|
| 215 |
yield id_, {
|
| 216 |
"input_ids": data["input_ids"],
|
| 217 |
"labels": data["label_ids"]["geneprod_roles"],
|
| 218 |
"tag_mask": tag_mask,
|
| 219 |
}
|
| 220 |
+
elif self.config.name == "SMALL_MOL_ROLES":
|
| 221 |
+
labels = data["label_ids"]["entity_types"]
|
| 222 |
+
small_mol = ["B-SMALL_MOLECULE", "I-SMALL_MOLECULE"]
|
| 223 |
+
tag_mask = [1 if t in small_mol else 0 for t in labels]
|
| 224 |
+
yield id_, {
|
| 225 |
+
"input_ids": data["input_ids"],
|
| 226 |
+
"labels": data["label_ids"]["small_mol_roles"],
|
| 227 |
+
"tag_mask": tag_mask,
|
| 228 |
+
}
|
| 229 |
elif self.config.name == "BORING":
|
| 230 |
yield id_, {"input_ids": data["input_ids"], "labels": data["label_ids"]["boring"]}
|
| 231 |
elif self.config.name == "PANELIZATION":
|
| 232 |
+
labels = data["label_ids"]["panel_start"]
|
| 233 |
+
tag_mask = [1 if t == "B-PANEL_START" else 0 for t in labels]
|
| 234 |
yield id_, {
|
| 235 |
"input_ids": data["input_ids"],
|
| 236 |
"labels": data["label_ids"]["panel_start"],
|
| 237 |
+
"tag_mask": tag_mask,
|
| 238 |
}
|
sd_figs.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fbf923d27a98176e57949103906f5bef4fd829bfc9526ecd0e1d1bc24f1cea72
|
| 3 |
+
size 21662607
|
sd_panels.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d88d2267474583a71010c80015bb1659c3d6f547c3323a072a5c62617eca3316
|
| 3 |
+
size 36651093
|