Datasets:
Tasks:
Other
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10M - 100M
ArXiv:
Tags:
knowledge-base
License:
Commit
•
8200d1c
1
Parent(s):
50f05ac
Delete loading script
Browse files- ascent_kb.py +0 -147
ascent_kb.py
DELETED
@@ -1,147 +0,0 @@
|
|
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 |
-
"""Ascent KB: A Deep Commonsense Knowledge Base"""
|
16 |
-
|
17 |
-
import json
|
18 |
-
|
19 |
-
import datasets
|
20 |
-
|
21 |
-
|
22 |
-
_CITATION = """\
|
23 |
-
@InProceedings{nguyen2021www,
|
24 |
-
title={Advanced Semantics for Commonsense Knowledge Extraction},
|
25 |
-
author={Nguyen, Tuan-Phong and Razniewski, Simon and Weikum, Gerhard},
|
26 |
-
year={2021},
|
27 |
-
booktitle={The Web Conference 2021},
|
28 |
-
}
|
29 |
-
"""
|
30 |
-
|
31 |
-
_DESCRIPTION = """\
|
32 |
-
This dataset contains 8.9M commonsense assertions extracted by the Ascent pipeline (https://ascent.mpi-inf.mpg.de/).
|
33 |
-
"""
|
34 |
-
|
35 |
-
_HOMEPAGE = "https://ascent.mpi-inf.mpg.de/"
|
36 |
-
|
37 |
-
_LICENSE = "The Creative Commons Attribution 4.0 International License. https://creativecommons.org/licenses/by/4.0/"
|
38 |
-
|
39 |
-
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
40 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
41 |
-
|
42 |
-
_URL = "https://nextcloud.mpi-klsb.mpg.de/index.php/s/dFLdTQHqiFrt3Q3/download"
|
43 |
-
|
44 |
-
|
45 |
-
# DONE: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
46 |
-
class AscentKB(datasets.GeneratorBasedBuilder):
|
47 |
-
"""Ascent KB: A Deep Commonsense Knowledge Base. Version 1.0.0."""
|
48 |
-
|
49 |
-
VERSION = datasets.Version("1.0.0")
|
50 |
-
|
51 |
-
BUILDER_CONFIGS = [
|
52 |
-
datasets.BuilderConfig(
|
53 |
-
name="canonical",
|
54 |
-
version=VERSION,
|
55 |
-
description="This KB contains <arg1 ; rel ; arg2> \
|
56 |
-
assertions where relations are canonicalized based on ConceptNet relations.",
|
57 |
-
),
|
58 |
-
datasets.BuilderConfig(
|
59 |
-
name="open",
|
60 |
-
version=VERSION,
|
61 |
-
description="This KB contains open assertions of the form \
|
62 |
-
<subject ; predicate ; object> extracted directly from web contents.",
|
63 |
-
),
|
64 |
-
]
|
65 |
-
|
66 |
-
DEFAULT_CONFIG_NAME = "canonical"
|
67 |
-
|
68 |
-
def _info(self):
|
69 |
-
if self.config.name == "canonical":
|
70 |
-
features = datasets.Features(
|
71 |
-
{
|
72 |
-
"arg1": datasets.Value("string"),
|
73 |
-
"rel": datasets.Value("string"),
|
74 |
-
"arg2": datasets.Value("string"),
|
75 |
-
"support": datasets.Value("int64"),
|
76 |
-
"facets": [
|
77 |
-
{
|
78 |
-
"value": datasets.Value("string"),
|
79 |
-
"type": datasets.Value("string"),
|
80 |
-
"support": datasets.Value("int64"),
|
81 |
-
}
|
82 |
-
],
|
83 |
-
"source_sentences": [{"text": datasets.Value("string"), "source": datasets.Value("string")}],
|
84 |
-
}
|
85 |
-
)
|
86 |
-
else: # features for the "open" part
|
87 |
-
features = datasets.Features(
|
88 |
-
{
|
89 |
-
"subject": datasets.Value("string"),
|
90 |
-
"predicate": datasets.Value("string"),
|
91 |
-
"object": datasets.Value("string"),
|
92 |
-
"support": datasets.Value("int64"),
|
93 |
-
"facets": [
|
94 |
-
{
|
95 |
-
"value": datasets.Value("string"),
|
96 |
-
"type": datasets.Value("string"),
|
97 |
-
"support": datasets.Value("int64"),
|
98 |
-
}
|
99 |
-
],
|
100 |
-
"source_sentences": [{"text": datasets.Value("string"), "source": datasets.Value("string")}],
|
101 |
-
}
|
102 |
-
)
|
103 |
-
return datasets.DatasetInfo(
|
104 |
-
description=_DESCRIPTION,
|
105 |
-
features=features,
|
106 |
-
supervised_keys=None,
|
107 |
-
homepage=_HOMEPAGE,
|
108 |
-
license=_LICENSE,
|
109 |
-
citation=_CITATION,
|
110 |
-
)
|
111 |
-
|
112 |
-
def _split_generators(self, dl_manager):
|
113 |
-
"""Returns SplitGenerators."""
|
114 |
-
# my_urls = _URLs[self.config.name]
|
115 |
-
# data_file = dl_manager.download_and_extract(my_urls)
|
116 |
-
|
117 |
-
data_file = dl_manager.download_and_extract(_URL)
|
118 |
-
|
119 |
-
return [
|
120 |
-
datasets.SplitGenerator(
|
121 |
-
name=datasets.Split.TRAIN,
|
122 |
-
gen_kwargs={
|
123 |
-
"filepath": data_file,
|
124 |
-
"split": "train",
|
125 |
-
},
|
126 |
-
),
|
127 |
-
]
|
128 |
-
|
129 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
130 |
-
def _generate_examples(self, filepath, split):
|
131 |
-
"""Yields examples as (key, example) tuples."""
|
132 |
-
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
133 |
-
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
134 |
-
|
135 |
-
with open(filepath, encoding="utf-8") as f:
|
136 |
-
for id_, row in enumerate(f):
|
137 |
-
data = json.loads(row)
|
138 |
-
if self.config.name == "canonical":
|
139 |
-
data.pop("subject")
|
140 |
-
data.pop("predicate")
|
141 |
-
data.pop("object")
|
142 |
-
yield id_, data
|
143 |
-
else: # "open"
|
144 |
-
data.pop("arg1")
|
145 |
-
data.pop("rel")
|
146 |
-
data.pop("arg2")
|
147 |
-
yield id_, data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|