|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""OntoLAMA Dataset Loading Script""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{he2023language, |
|
title={Language Model Analysis for Ontology Subsumption Inference}, |
|
author={He, Yuan and Chen, Jiaoyan and Jim{\'e}nez-Ruiz, Ernesto and Dong, Hang and Horrocks, Ian}, |
|
journal={arXiv preprint arXiv:2302.06761}, |
|
year={2023} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
OntoLAMA: LAnguage Model Analysis datasets for Ontology Subsumption Inference. |
|
""" |
|
|
|
_URL = lambda name: f"https://zenodo.org/record/7700458/files/{name}.zip?download=1" |
|
|
|
|
|
_HOMEPAGE = "https://krr-oxford.github.io/DeepOnto/" |
|
|
|
|
|
_LICENSE = "Apache License, Version 2.0" |
|
|
|
|
|
|
|
class OntoLAMA(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="bimnli", version=VERSION, description="BiMNLI dataset created from the MNLI dataset." |
|
), |
|
datasets.BuilderConfig( |
|
name="schemaorg-atomic-SI", |
|
version=VERSION, |
|
description="Atomic SI dataset created from the Schema.org Ontology.", |
|
), |
|
datasets.BuilderConfig( |
|
name="doid-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Disease Ontology." |
|
), |
|
datasets.BuilderConfig( |
|
name="foodon-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Food Ontology." |
|
), |
|
datasets.BuilderConfig( |
|
name="foodon-complex-SI", version=VERSION, description="Complex SI dataset created from the Gene Ontology." |
|
), |
|
datasets.BuilderConfig( |
|
name="go-atomic-SI", version=VERSION, description="Atomic SI dataset created from the Gene Ontology." |
|
), |
|
datasets.BuilderConfig( |
|
name="go-complex-SI", version=VERSION, description="Complex SI dataset created from the Gene Ontology." |
|
), |
|
] |
|
|
|
def _info(self): |
|
|
|
if "atomic-SI" in self.config.name: |
|
features = datasets.Features( |
|
{ |
|
"v_sub_concept": datasets.Value("string"), |
|
"v_super_concept": datasets.Value("string"), |
|
"label": datasets.ClassLabel( |
|
num_classes=2, names=["negative_subsumption", "positive_subsumption"], names_file=None, id=None |
|
), |
|
"axiom": datasets.Value("string"), |
|
|
|
} |
|
) |
|
elif ( |
|
"complex-SI" in self.config.name |
|
): |
|
features = datasets.Features( |
|
{ |
|
"v_sub_concept": datasets.Value("string"), |
|
"v_super_concept": datasets.Value("string"), |
|
"label": datasets.ClassLabel( |
|
num_classes=2, names=["negative_subsumption", "positive_subsumption"], names_file=None, id=None |
|
), |
|
"axiom": datasets.Value("string"), |
|
"anchor_axiom": datasets.Value("string") |
|
|
|
} |
|
) |
|
elif self.config.name == "bimnli": |
|
features = datasets.Features( |
|
{ |
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"label": datasets.ClassLabel( |
|
num_classes=2, names=["contradiction", "entailment"], names_file=None, id=None |
|
), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URL(self.config.name) |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, self.config.name, "train.jsonl"), |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, self.config.name, "dev.jsonl"), |
|
"split": "dev", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": os.path.join(data_dir, self.config.name, "test.jsonl"), "split": "test"}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
if "atomic-SI" in self.config.name: |
|
|
|
yield key, { |
|
"v_sub_concept": data["v_sub_concept"], |
|
"v_super_concept": data["v_super_concept"], |
|
"label": data["label"], |
|
"axiom": data["axiom"], |
|
} |
|
elif "complex-SI" in self.config.name: |
|
yield key, { |
|
"v_sub_concept": data["v_sub_concept"], |
|
"v_super_concept": data["v_super_concept"], |
|
"label": data["label"], |
|
"axiom": data["axiom"], |
|
"anchor_axiom": data["anchor_axiom"], |
|
} |
|
elif self.config.name == "bimnli": |
|
yield key, { |
|
"premise": data["premise"], |
|
"hypothesis": data["hypothesis"], |
|
"label": data["label"], |
|
} |
|
|