Datasets:

lawhy commited on
Commit
b140760
·
verified ·
1 Parent(s): 7667c4c

Delete loading script

Browse files
Files changed (1) hide show
  1. OntoLAMA.py +0 -213
OntoLAMA.py DELETED
@@ -1,213 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors.
2
- # Copyright 2023 Yuan He.
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
- # TODO: Address all TODOs and remove all explanatory comments
16
- """OntoLAMA Dataset Loading Script"""
17
-
18
-
19
- import csv
20
- import json
21
- import os
22
-
23
- import datasets
24
-
25
-
26
- # TODO: Add BibTeX citation
27
- # Find for instance the citation on arxiv or on the dataset repo/website
28
- _CITATION = """\
29
- @inproceedings{he2023language,
30
- title={Language Model Analysis for Ontology Subsumption Inference},
31
- author={He, Yuan and Chen, Jiaoyan and Jimenez-Ruiz, Ernesto and Dong, Hang and Horrocks, Ian},
32
- booktitle={Findings of the Association for Computational Linguistics: ACL 2023},
33
- pages={3439--3453},
34
- year={2023}
35
- }
36
- """
37
-
38
- # TODO: Add description of the dataset here
39
- # You can copy an official description
40
- _DESCRIPTION = """\
41
- OntoLAMA: LAnguage Model Analysis datasets for Ontology Subsumption Inference.
42
- """
43
-
44
- _URL = lambda name: f"https://zenodo.org/record/7700458/files/{name}.zip?download=1"
45
-
46
- # TODO: Add a link to an official homepage for the dataset here
47
- _HOMEPAGE = "https://krr-oxford.github.io/DeepOnto/"
48
-
49
- # TODO: Add the licence for the dataset here if you can find it
50
- _LICENSE = "Apache License, Version 2.0"
51
-
52
-
53
- # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
54
- class OntoLAMA(datasets.GeneratorBasedBuilder):
55
- """TODO: Short description of my dataset."""
56
-
57
- VERSION = datasets.Version("1.0.0")
58
-
59
- # This is an example of a dataset with multiple configurations.
60
- # If you don't want/need to define several sub-sets in your dataset,
61
- # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
62
-
63
- # If you need to make complex sub-parts in the datasets with configurable options
64
- # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
65
- # BUILDER_CONFIG_CLASS = MyBuilderConfig
66
-
67
- # You will be able to load one or the other configurations in the following list with
68
- # data = datasets.load_dataset('my_dataset', 'first_domain')
69
- # data = datasets.load_dataset('my_dataset', 'second_domain')
70
- BUILDER_CONFIGS = [
71
- datasets.BuilderConfig(
72
- name="bimnli", version=VERSION, description="BiMNLI dataset created from the MNLI dataset."
73
- ),
74
- datasets.BuilderConfig(
75
- name="schemaorg-atomic-SI",
76
- version=VERSION,
77
- description="Atomic SI dataset created from the Schema.org Ontology.",
78
- ),
79
- datasets.BuilderConfig(
80
- name="doid-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Disease Ontology."
81
- ),
82
- datasets.BuilderConfig(
83
- name="foodon-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Food Ontology."
84
- ),
85
- datasets.BuilderConfig(
86
- name="foodon-complex-SI", version=VERSION, description="Complex SI dataset created from the Gene Ontology."
87
- ),
88
- datasets.BuilderConfig(
89
- name="go-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Gene Ontology."
90
- ),
91
- datasets.BuilderConfig(
92
- name="go-complex-SI", version=VERSION, description="Complex SI dataset created from the Gene Ontology."
93
- ),
94
- ]
95
-
96
- def _info(self):
97
- # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
98
- if "atomic-SI" in self.config.name: # This is the name of the configuration selected in BUILDER_CONFIGS above
99
- features = datasets.Features(
100
- {
101
- "v_sub_concept": datasets.Value("string"),
102
- "v_super_concept": datasets.Value("string"),
103
- "label": datasets.ClassLabel(
104
- num_classes=2, names=["negative_subsumption", "positive_subsumption"], names_file=None, id=None
105
- ),
106
- "axiom": datasets.Value("string"),
107
- # These are the features of your dataset like images, labels ...
108
- }
109
- )
110
- elif (
111
- "complex-SI" in self.config.name
112
- ): # This is an example to show how to have different features for "first_domain" and "second_domain"
113
- features = datasets.Features(
114
- {
115
- "v_sub_concept": datasets.Value("string"),
116
- "v_super_concept": datasets.Value("string"),
117
- "label": datasets.ClassLabel(
118
- num_classes=2, names=["negative_subsumption", "positive_subsumption"], names_file=None, id=None
119
- ),
120
- "axiom": datasets.Value("string"),
121
- "anchor_axiom": datasets.Value("string") # the equivalence axiom used as anchor
122
- # These are the features of your dataset like images, labels ...
123
- }
124
- )
125
- elif self.config.name == "bimnli":
126
- features = datasets.Features(
127
- {
128
- "premise": datasets.Value("string"),
129
- "hypothesis": datasets.Value("string"),
130
- "label": datasets.ClassLabel(
131
- num_classes=2, names=["contradiction", "entailment"], names_file=None, id=None
132
- ),
133
- }
134
- )
135
-
136
- return datasets.DatasetInfo(
137
- # This is the description that will appear on the datasets page.
138
- description=_DESCRIPTION,
139
- # This defines the different columns of the dataset and their types
140
- features=features, # Here we define them above because they are different between the two configurations
141
- # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
142
- # specify them. They'll be used if as_supervised=True in builder.as_dataset.
143
- # supervised_keys=("sentence", "label"),
144
- # Homepage of the dataset for documentation
145
- homepage=_HOMEPAGE,
146
- # License for the dataset if available
147
- license=_LICENSE,
148
- # Citation for the dataset
149
- citation=_CITATION,
150
- )
151
-
152
- def _split_generators(self, dl_manager):
153
- # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
154
- # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
155
-
156
- # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
157
- # 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.
158
- # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
159
- urls = _URL(self.config.name)
160
- data_dir = dl_manager.download_and_extract(urls)
161
- return [
162
- datasets.SplitGenerator(
163
- name=datasets.Split.TRAIN,
164
- # These kwargs will be passed to _generate_examples
165
- gen_kwargs={
166
- "filepath": os.path.join(data_dir, self.config.name, "train.jsonl"),
167
- "split": "train",
168
- },
169
- ),
170
- datasets.SplitGenerator(
171
- name=datasets.Split.VALIDATION,
172
- # These kwargs will be passed to _generate_examples
173
- gen_kwargs={
174
- "filepath": os.path.join(data_dir, self.config.name, "dev.jsonl"),
175
- "split": "dev",
176
- },
177
- ),
178
- datasets.SplitGenerator(
179
- name=datasets.Split.TEST,
180
- # These kwargs will be passed to _generate_examples
181
- gen_kwargs={"filepath": os.path.join(data_dir, self.config.name, "test.jsonl"), "split": "test"},
182
- ),
183
- ]
184
-
185
- # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
186
- def _generate_examples(self, filepath, split):
187
- # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
188
- # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
189
- with open(filepath, encoding="utf-8") as f:
190
- for key, row in enumerate(f):
191
- data = json.loads(row)
192
- if "atomic-SI" in self.config.name:
193
- # Yields examples as (key, example) tuples
194
- yield key, {
195
- "v_sub_concept": data["v_sub_concept"],
196
- "v_super_concept": data["v_super_concept"],
197
- "label": data["label"],
198
- "axiom": data["axiom"],
199
- }
200
- elif "complex-SI" in self.config.name:
201
- yield key, {
202
- "v_sub_concept": data["v_sub_concept"],
203
- "v_super_concept": data["v_super_concept"],
204
- "label": data["label"],
205
- "axiom": data["axiom"],
206
- "anchor_axiom": data["anchor_axiom"],
207
- }
208
- elif self.config.name == "bimnli":
209
- yield key, {
210
- "premise": data["premise"],
211
- "hypothesis": data["hypothesis"],
212
- "label": data["label"],
213
- }