Commit
•
dc7966d
1
Parent(s):
6f93b0f
Remove deprecated tasks
Browse filesThis dataset uses `tasks`, which are deprecated and will raise an error after the next major release of `datasets`. See: https://github.com/huggingface/datasets/pull/6999
fdRE.py
CHANGED
@@ -1,106 +1,104 @@
|
|
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.
|
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 |
-
import os
|
17 |
-
|
18 |
-
import datasets
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
"
|
52 |
-
|
53 |
-
|
54 |
-
"Part_Of(E1
|
55 |
-
"
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
),
|
61 |
-
#
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
"sentence": sentence,
|
105 |
-
"relation": relation,
|
106 |
}
|
|
|
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.
|
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 |
+
import os
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
|
20 |
+
|
21 |
+
_CITATION = """\
|
22 |
+
@author tianjie
|
23 |
+
fdRE
|
24 |
+
Chinese
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
|
28 |
+
_DESCRIPTION = """\
|
29 |
+
fdRE是一个中文的轴承故障诊断领域的关系抽取数据集
|
30 |
+
该数据集主要包含正向从属、反向从属以及无关三类标签
|
31 |
+
"""
|
32 |
+
|
33 |
+
_URL = "https://huggingface.co/datasets/leonadase/fdRE/resolve/main/fdRE.zip"
|
34 |
+
|
35 |
+
|
36 |
+
class SemEval2010Task8(datasets.GeneratorBasedBuilder):
|
37 |
+
"""The SemEval-2010 Task 8 focuses on Multi-way classification of semantic relations between pairs of nominals.
|
38 |
+
The task was designed to compare different approaches to semantic relation classification
|
39 |
+
and to provide a standard testbed for future research."""
|
40 |
+
|
41 |
+
VERSION = datasets.Version("1.0.0")
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
return datasets.DatasetInfo(
|
45 |
+
# This is the description that will appear on the datasets page.
|
46 |
+
description=_DESCRIPTION,
|
47 |
+
# This defines the different columns of the dataset and their types
|
48 |
+
features=datasets.Features(
|
49 |
+
{
|
50 |
+
"sentence": datasets.Value("string"),
|
51 |
+
"relation": datasets.ClassLabel(
|
52 |
+
names=[
|
53 |
+
"Part_Of(E1,E2)",
|
54 |
+
"Part_Of(E2,E1)",
|
55 |
+
"Other",
|
56 |
+
]
|
57 |
+
),
|
58 |
+
}
|
59 |
+
),
|
60 |
+
# If there's a common (input, target) tuple from the features,
|
61 |
+
# specify them here. They'll be used if as_supervised=True in
|
62 |
+
# builder.as_dataset.
|
63 |
+
supervised_keys=datasets.info.SupervisedKeysData(input="sentence", output="relation"),
|
64 |
+
# Homepage of the dataset for documentation
|
65 |
+
citation=_CITATION,
|
66 |
+
)
|
67 |
+
|
68 |
+
def _split_generators(self, dl_manager):
|
69 |
+
"""Returns SplitGenerators."""
|
70 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to
|
71 |
+
# download and extract URLs
|
72 |
+
dl_dir = dl_manager.download_and_extract(_URL)
|
73 |
+
# data_dir = os.path.join(dl_dir, "fdRE")
|
74 |
+
data_dir = dl_dir
|
75 |
+
return [
|
76 |
+
datasets.SplitGenerator(
|
77 |
+
name=datasets.Split.TRAIN,
|
78 |
+
# These kwargs will be passed to _generate_examples
|
79 |
+
gen_kwargs={
|
80 |
+
"filepath": os.path.join(data_dir, "train.txt"),
|
81 |
+
},
|
82 |
+
),
|
83 |
+
datasets.SplitGenerator(
|
84 |
+
name=datasets.Split.TEST,
|
85 |
+
gen_kwargs={
|
86 |
+
"filepath": os.path.join(data_dir, "test.txt"),
|
87 |
+
},
|
88 |
+
),
|
89 |
+
]
|
90 |
+
|
91 |
+
def _generate_examples(self, filepath):
|
92 |
+
"""Yields examples."""
|
93 |
+
with open(filepath, encoding="utf-8") as file:
|
94 |
+
lines = file.readlines()
|
95 |
+
num_lines_per_sample = 4
|
96 |
+
|
97 |
+
for i in range(0, len(lines), num_lines_per_sample):
|
98 |
+
idx = int(lines[i].split("\t")[0])
|
99 |
+
sentence = lines[i].split("\t")[1][1:-2] # remove " at the start and "\n at the end
|
100 |
+
relation = lines[i + 1][:-1] # remove \n at the end
|
101 |
+
yield idx, {
|
102 |
+
"sentence": sentence,
|
103 |
+
"relation": relation,
|
|
|
|
|
104 |
}
|