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