Commit
·
ab2c994
1
Parent(s):
b18babd
Create EpiClassify4GARD.py
Browse files- EpiClassify4GARD.py +137 -0
EpiClassify4GARD.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 HuggingFace Datasets Authors.
|
| 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 |
+
# Lint as: python3
|
| 17 |
+
"""INSERT TITLE"""
|
| 18 |
+
|
| 19 |
+
import logging
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_CITATION = """\
|
| 24 |
+
*REDO*
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
_DESCRIPTION = """\
|
| 29 |
+
**REWRITE*
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
_URL = "https://huggingface.co/datasets/wzkariampuzha/EpiClassifySet/raw/main/"
|
| 34 |
+
_TRAINING_FILE = "epi_classify_train.tsv"
|
| 35 |
+
_VAL_FILE = "epi_classify_val.tsv"
|
| 36 |
+
_TEST_FILE = "epi_classify_test.tsv"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class EpiSetConfig(datasets.BuilderConfig):
|
| 40 |
+
"""BuilderConfig for Conll2003"""
|
| 41 |
+
|
| 42 |
+
def __init__(self, **kwargs):
|
| 43 |
+
"""BuilderConfig forConll2003.
|
| 44 |
+
Args:
|
| 45 |
+
**kwargs: keyword arguments forwarded to super.
|
| 46 |
+
"""
|
| 47 |
+
super(EpiSetConfig, self).__init__(**kwargs)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class EpiSet(datasets.GeneratorBasedBuilder):
|
| 51 |
+
"""EpiSet4NER by GARD."""
|
| 52 |
+
|
| 53 |
+
BUILDER_CONFIGS = [
|
| 54 |
+
EpiSetConfig(name="EpiSet4NER", version=datasets.Version("1.0.0"), description="EpiSet4NER by NIH NCATS GARD"),
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
def _info(self):
|
| 58 |
+
return datasets.DatasetInfo(
|
| 59 |
+
description=_DESCRIPTION,
|
| 60 |
+
features=datasets.Features(
|
| 61 |
+
{
|
| 62 |
+
"idx": datasets.Value("string"),
|
| 63 |
+
#"abstracts": datasets.Value("string"),
|
| 64 |
+
"abstracts": datasets.Sequence(datasets.Value("string")),
|
| 65 |
+
'''
|
| 66 |
+
"labels": datasets.Sequence(
|
| 67 |
+
datasets.features.ClassLabel(
|
| 68 |
+
names=[
|
| 69 |
+
"O", #(0)
|
| 70 |
+
"B-LOC", #(1)
|
| 71 |
+
"I-LOC", #(2)
|
| 72 |
+
"B-EPI", #(3)
|
| 73 |
+
"I-EPI", #(4)
|
| 74 |
+
"B-STAT", #(5)
|
| 75 |
+
"I-STAT", #(6)
|
| 76 |
+
]
|
| 77 |
+
)
|
| 78 |
+
),
|
| 79 |
+
'''
|
| 80 |
+
"labels": datasets.features.ClassLabel(
|
| 81 |
+
names=[
|
| 82 |
+
"1 = Epi Abstract",
|
| 83 |
+
"2 = Not Epi Abstract",
|
| 84 |
+
]
|
| 85 |
+
),
|
| 86 |
+
|
| 87 |
+
}
|
| 88 |
+
),
|
| 89 |
+
supervised_keys=None,
|
| 90 |
+
homepage="https://github.com/ncats/epi4GARD/tree/master/Epi4GARD#epi4gard",
|
| 91 |
+
citation=_CITATION,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
def _split_generators(self, dl_manager):
|
| 95 |
+
"""Returns SplitGenerators."""
|
| 96 |
+
urls_to_download = {
|
| 97 |
+
"train": f"{_URL}{_TRAINING_FILE}",
|
| 98 |
+
"val": f"{_URL}{_VAL_FILE}",
|
| 99 |
+
"test": f"{_URL}{_TEST_FILE}",
|
| 100 |
+
}
|
| 101 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 102 |
+
|
| 103 |
+
return [
|
| 104 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 105 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["val"]}),
|
| 106 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 107 |
+
]
|
| 108 |
+
|
| 109 |
+
def _generate_examples(self, filepath):
|
| 110 |
+
logging.info("⏳ Generating examples from = %s", filepath)
|
| 111 |
+
with open(filepath, encoding="utf-8") as f:
|
| 112 |
+
guid = 0
|
| 113 |
+
abstracts = []
|
| 114 |
+
labels = []
|
| 115 |
+
for line in f:
|
| 116 |
+
if line.startswith("-DOCSTART-") or line == "" or line == "\n" or line == "abstract\tlabel\n":
|
| 117 |
+
if abstracts:
|
| 118 |
+
yield guid, {
|
| 119 |
+
"idx": str(guid),
|
| 120 |
+
"abstracts": abstracts,
|
| 121 |
+
"labels": labels,
|
| 122 |
+
}
|
| 123 |
+
guid += 1
|
| 124 |
+
abstracts = []
|
| 125 |
+
labels = []
|
| 126 |
+
else:
|
| 127 |
+
# EpiSet abstracts are space separated
|
| 128 |
+
splits = line.split("\t")
|
| 129 |
+
abstracts.append(splits[0])
|
| 130 |
+
labels.append(splits[1].rstrip())
|
| 131 |
+
# last example
|
| 132 |
+
if tokens:
|
| 133 |
+
yield guid, {
|
| 134 |
+
"idx": str(guid),
|
| 135 |
+
"abstracts": abstracts,
|
| 136 |
+
"labels": labels,
|
| 137 |
+
}
|