wzkariampuzha commited on
Commit
90233b4
1 Parent(s): 667c52f

Create EpiSet4NER-v1.py

Browse files
Files changed (1) hide show
  1. EpiSet4NER-v1.py +135 -0
EpiSet4NER-v1.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
21
+ import datasets
22
+
23
+
24
+ _CITATION = """\
25
+ *REDO*
26
+ @inproceedings{wang2019crossweigh,
27
+ title={CrossWeigh: Training Named Entity Tagger from Imperfect Annotations},
28
+ author={Wang, Zihan and Shang, Jingbo and Liu, Liyuan and Lu, Lihao and Liu, Jiacheng and Han, Jiawei},
29
+ booktitle={Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)},
30
+ pages={5157--5166},
31
+ year={2019}
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ **REWRITE*
37
+ EpiSet4NER is a dataset generated from 620 rare disease abstracts labeled using statistical and rule-base methods. The test set was then manually corrected by a rare disease expert.
38
+ For more details see *INSERT PAPER* and https://github.com/ncats/epi4GARD/tree/master/EpiExtract4GARD#epiextract4gard
39
+ """
40
+
41
+ _URL = "https://github.com/NCATS/epi4GARD/raw/master/EpiExtract4GARD/datasets/EpiCustomV3/"
42
+ _TRAINING_FILE = "train.tsv"
43
+ _VAL_FILE = "val.tsv"
44
+ _TEST_FILE = "test.tsv"
45
+
46
+
47
+ class EpiSetConfig(datasets.BuilderConfig):
48
+ """BuilderConfig for Conll2003"""
49
+
50
+ def __init__(self, **kwargs):
51
+ """BuilderConfig forConll2003.
52
+ Args:
53
+ **kwargs: keyword arguments forwarded to super.
54
+ """
55
+ super(EpiSetConfig, self).__init__(**kwargs)
56
+
57
+
58
+ class EpiSet(datasets.GeneratorBasedBuilder):
59
+ """EpiSet4NER by GARD."""
60
+
61
+ BUILDER_CONFIGS = [
62
+ EpiSetConfig(name="EpiSet4NER", version=datasets.Version("3.2.1"), description="EpiSet4NER by NIH NCATS GARD"),
63
+ ]
64
+
65
+ def _info(self):
66
+ return datasets.DatasetInfo(
67
+ description=_DESCRIPTION,
68
+ features=datasets.Features(
69
+ {
70
+ "id": datasets.Value("string"),
71
+ "tokens": datasets.Sequence(datasets.Value("string")),
72
+ "ner_tags": datasets.Sequence(
73
+ datasets.features.ClassLabel(
74
+ names=[
75
+ "O", #(0)
76
+ "B-LOC", #(1)
77
+ "I-LOC", #(2)
78
+ "B-EPI", #(3)
79
+ "I-EPI", #(4)
80
+ "B-STAT", #(5)
81
+ "I-STAT", #(6)
82
+ ]
83
+ )
84
+ ),
85
+ }
86
+ ),
87
+ supervised_keys=None,
88
+ homepage="https://github.com/ncats/epi4GARD/tree/master/EpiExtract4GARD#epiextract4gard",
89
+ citation=_CITATION,
90
+ )
91
+
92
+ def _split_generators(self, dl_manager):
93
+ """Returns SplitGenerators."""
94
+ urls_to_download = {
95
+ "train": f"{_URL}{_TRAINING_FILE}",
96
+ "val": f"{_URL}{_VAL_FILE}",
97
+ "test": f"{_URL}{_TEST_FILE}",
98
+ }
99
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
100
+
101
+ return [
102
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
103
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["val"]}),
104
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
105
+ ]
106
+
107
+ def _generate_examples(self, filepath):
108
+ logging.info("⏳ Generating examples from = %s", filepath)
109
+ with open(filepath, encoding="utf-8") as f:
110
+ guid = 0
111
+ tokens = []
112
+ ner_tags = []
113
+ for line in f:
114
+ if line.startswith("-DOCSTART-") or line == "" or line == "\n":
115
+ if tokens:
116
+ yield guid, {
117
+ "id": str(guid),
118
+ "tokens": tokens,
119
+ "ner_tags": ner_tags,
120
+ }
121
+ guid += 1
122
+ tokens = []
123
+ ner_tags = []
124
+ else:
125
+ # EpiSet tokens are space separated
126
+ splits = line.split("\t")
127
+ tokens.append(splits[0])
128
+ ner_tags.append(splits[1].rstrip())
129
+ # last example
130
+ if tokens:
131
+ yield guid, {
132
+ "id": str(guid),
133
+ "tokens": tokens,
134
+ "ner_tags": ner_tags,
135
+ }