Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
10K - 100K
License:
Delete loading script
Browse files
fabner.py
DELETED
@@ -1,230 +0,0 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
"""FabNER is a manufacturing text corpus of 350,000+ words for Named Entity Recognition."""
|
15 |
-
|
16 |
-
import datasets
|
17 |
-
|
18 |
-
|
19 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
20 |
-
_CITATION = """\
|
21 |
-
@article{DBLP:journals/jim/KumarS22,
|
22 |
-
author = {Aman Kumar and
|
23 |
-
Binil Starly},
|
24 |
-
title = {"FabNER": information extraction from manufacturing process science
|
25 |
-
domain literature using named entity recognition},
|
26 |
-
journal = {J. Intell. Manuf.},
|
27 |
-
volume = {33},
|
28 |
-
number = {8},
|
29 |
-
pages = {2393--2407},
|
30 |
-
year = {2022},
|
31 |
-
url = {https://doi.org/10.1007/s10845-021-01807-x},
|
32 |
-
doi = {10.1007/s10845-021-01807-x},
|
33 |
-
timestamp = {Sun, 13 Nov 2022 17:52:57 +0100},
|
34 |
-
biburl = {https://dblp.org/rec/journals/jim/KumarS22.bib},
|
35 |
-
bibsource = {dblp computer science bibliography, https://dblp.org}
|
36 |
-
}
|
37 |
-
"""
|
38 |
-
|
39 |
-
# You can copy an official description
|
40 |
-
_DESCRIPTION = """\
|
41 |
-
FabNER is a manufacturing text corpus of 350,000+ words for Named Entity Recognition.
|
42 |
-
It is a collection of abstracts obtained from Web of Science through known journals available in manufacturing process
|
43 |
-
science research.
|
44 |
-
For every word, there were categories/entity labels defined namely Material (MATE), Manufacturing Process (MANP),
|
45 |
-
Machine/Equipment (MACEQ), Application (APPL), Features (FEAT), Mechanical Properties (PRO), Characterization (CHAR),
|
46 |
-
Parameters (PARA), Enabling Technology (ENAT), Concept/Principles (CONPRI), Manufacturing Standards (MANS) and
|
47 |
-
BioMedical (BIOP). Annotation was performed in all categories along with the output tag in 'BIOES' format:
|
48 |
-
B=Beginning, I-Intermediate, O=Outside, E=End, S=Single.
|
49 |
-
"""
|
50 |
-
|
51 |
-
_HOMEPAGE = "https://figshare.com/articles/dataset/Dataset_NER_Manufacturing_-_FabNER_Information_Extraction_from_Manufacturing_Process_Science_Domain_Literature_Using_Named_Entity_Recognition/14782407"
|
52 |
-
|
53 |
-
# TODO: Add the licence for the dataset here if you can find it
|
54 |
-
_LICENSE = ""
|
55 |
-
|
56 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
57 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
58 |
-
_URLS = {
|
59 |
-
"train": "https://figshare.com/ndownloader/files/28405854/S2-train.txt",
|
60 |
-
"validation": "https://figshare.com/ndownloader/files/28405857/S3-val.txt",
|
61 |
-
"test": "https://figshare.com/ndownloader/files/28405851/S1-test.txt",
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
def map_fabner_labels(string_tag):
|
66 |
-
tag = string_tag[2:]
|
67 |
-
# MATERIAL (FABNER)
|
68 |
-
if tag == "MATE":
|
69 |
-
return "Material"
|
70 |
-
# MANUFACTURING PROCESS (FABNER)
|
71 |
-
elif tag == "MANP":
|
72 |
-
return "Method"
|
73 |
-
# MACHINE/EQUIPMENT, MECHANICAL PROPERTIES, CHARACTERIZATION, ENABLING TECHNOLOGY (FABNER)
|
74 |
-
elif tag in ["MACEQ", "PRO", "CHAR", "ENAT"]:
|
75 |
-
return "Technological System"
|
76 |
-
# APPLICATION (FABNER)
|
77 |
-
elif tag == "APPL":
|
78 |
-
return "Technical Field"
|
79 |
-
# FEATURES, PARAMETERS, CONCEPT/PRINCIPLES, MANUFACTURING STANDARDS, BIOMEDICAL, O (FABNER)
|
80 |
-
else:
|
81 |
-
return "O"
|
82 |
-
|
83 |
-
|
84 |
-
class FabNER(datasets.GeneratorBasedBuilder):
|
85 |
-
"""FabNER is a manufacturing text corpus of 350,000+ words for Named Entity Recognition."""
|
86 |
-
|
87 |
-
VERSION = datasets.Version("1.2.0")
|
88 |
-
|
89 |
-
# This is an example of a dataset with multiple configurations.
|
90 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
91 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
92 |
-
|
93 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
94 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
95 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
96 |
-
|
97 |
-
# You will be able to load one or the other configurations in the following list with
|
98 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
99 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
100 |
-
BUILDER_CONFIGS = [
|
101 |
-
datasets.BuilderConfig(name="fabner", version=VERSION,
|
102 |
-
description="The FabNER dataset with the original BIOES tagging format"),
|
103 |
-
datasets.BuilderConfig(name="fabner_bio", version=VERSION,
|
104 |
-
description="The FabNER dataset with BIO tagging format"),
|
105 |
-
datasets.BuilderConfig(name="fabner_simple", version=VERSION,
|
106 |
-
description="The FabNER dataset with no tagging format"),
|
107 |
-
datasets.BuilderConfig(name="text2tech", version=VERSION,
|
108 |
-
description="The FabNER dataset mapped to the Text2Tech tag set"),
|
109 |
-
]
|
110 |
-
DEFAULT_CONFIG_NAME = "fabner"
|
111 |
-
|
112 |
-
def _info(self):
|
113 |
-
entity_types = [
|
114 |
-
"MATE", # Material
|
115 |
-
"MANP", # Manufacturing Process
|
116 |
-
"MACEQ", # Machine/Equipment
|
117 |
-
"APPL", # Application
|
118 |
-
"FEAT", # Engineering Features
|
119 |
-
"PRO", # Mechanical Properties
|
120 |
-
"CHAR", # Process Characterization
|
121 |
-
"PARA", # Process Parameters
|
122 |
-
"ENAT", # Enabling Technology
|
123 |
-
"CONPRI", # Concept/Principles
|
124 |
-
"MANS", # Manufacturing Standards
|
125 |
-
"BIOP", # BioMedical
|
126 |
-
]
|
127 |
-
if self.config.name == "text2tech":
|
128 |
-
class_labels = ["O", "Technological System", "Method", "Material", "Technical Field"]
|
129 |
-
elif self.config.name == "fabner":
|
130 |
-
class_labels = ["O"]
|
131 |
-
for entity_type in entity_types:
|
132 |
-
class_labels.extend(
|
133 |
-
[
|
134 |
-
"B-" + entity_type,
|
135 |
-
"I-" + entity_type,
|
136 |
-
"E-" + entity_type,
|
137 |
-
"S-" + entity_type,
|
138 |
-
]
|
139 |
-
)
|
140 |
-
elif self.config.name == "fabner_bio":
|
141 |
-
class_labels = ["O"]
|
142 |
-
for entity_type in entity_types:
|
143 |
-
class_labels.extend(
|
144 |
-
[
|
145 |
-
"B-" + entity_type,
|
146 |
-
"I-" + entity_type,
|
147 |
-
]
|
148 |
-
)
|
149 |
-
else:
|
150 |
-
class_labels = ["O"] + entity_types
|
151 |
-
features = datasets.Features(
|
152 |
-
{
|
153 |
-
"id": datasets.Value("string"),
|
154 |
-
"tokens": datasets.Sequence(datasets.Value("string")),
|
155 |
-
"ner_tags": datasets.Sequence(
|
156 |
-
datasets.features.ClassLabel(
|
157 |
-
names=class_labels
|
158 |
-
)
|
159 |
-
),
|
160 |
-
}
|
161 |
-
)
|
162 |
-
return datasets.DatasetInfo(
|
163 |
-
# This is the description that will appear on the datasets page.
|
164 |
-
description=_DESCRIPTION,
|
165 |
-
# This defines the different columns of the dataset and their types
|
166 |
-
features=features, # Here we define them above because they are different between the two configurations
|
167 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
168 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
169 |
-
# supervised_keys=("sentence", "label"),
|
170 |
-
# Homepage of the dataset for documentation
|
171 |
-
homepage=_HOMEPAGE,
|
172 |
-
# License for the dataset if available
|
173 |
-
license=_LICENSE,
|
174 |
-
# Citation for the dataset
|
175 |
-
citation=_CITATION,
|
176 |
-
)
|
177 |
-
|
178 |
-
def _split_generators(self, dl_manager):
|
179 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
180 |
-
|
181 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
182 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
183 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
184 |
-
downloaded_files = dl_manager.download_and_extract(_URLS)
|
185 |
-
|
186 |
-
return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_files[str(i)]})
|
187 |
-
for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]
|
188 |
-
|
189 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
190 |
-
def _generate_examples(self, filepath):
|
191 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
192 |
-
with open(filepath, encoding="utf-8") as f:
|
193 |
-
guid = 0
|
194 |
-
tokens = []
|
195 |
-
ner_tags = []
|
196 |
-
for line in f:
|
197 |
-
if line == "" or line == "\n":
|
198 |
-
if tokens:
|
199 |
-
yield guid, {
|
200 |
-
"id": str(guid),
|
201 |
-
"tokens": tokens,
|
202 |
-
"ner_tags": ner_tags,
|
203 |
-
}
|
204 |
-
guid += 1
|
205 |
-
tokens = []
|
206 |
-
ner_tags = []
|
207 |
-
else:
|
208 |
-
splits = line.split(" ")
|
209 |
-
tokens.append(splits[0])
|
210 |
-
ner_tag = splits[1].rstrip()
|
211 |
-
if self.config.name == "fabner_simple":
|
212 |
-
if ner_tag == "O":
|
213 |
-
ner_tag = "O"
|
214 |
-
else:
|
215 |
-
ner_tag = ner_tag.split("-")[1]
|
216 |
-
elif self.config.name == "fabner_bio":
|
217 |
-
if ner_tag == "O":
|
218 |
-
ner_tag = "O"
|
219 |
-
else:
|
220 |
-
ner_tag = ner_tag.replace("S-", "B-").replace("E-", "I-")
|
221 |
-
elif self.config.name == "text2tech":
|
222 |
-
ner_tag = map_fabner_labels(ner_tag)
|
223 |
-
ner_tags.append(ner_tag)
|
224 |
-
# last example
|
225 |
-
if tokens:
|
226 |
-
yield guid, {
|
227 |
-
"id": str(guid),
|
228 |
-
"tokens": tokens,
|
229 |
-
"ner_tags": ner_tags,
|
230 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|