Datasets:
Tasks:
Question Answering
Modalities:
Text
Languages:
English
Size:
1K - 10K
Tags:
knowledge-base-qa
License:
# coding=utf-8 | |
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# Lint as: python3 | |
"""The SciQA Scientific Question Answering Benchmark for Scholarly Knowledge""" | |
import json | |
import os | |
import datasets | |
logger = datasets.logging.get_logger(__name__) | |
_CITATION = """ | |
@article{SciQA, | |
title={The SciQA Scientific Question Answering Benchmark for Scholarly Knowledge}, | |
author={Auer, Sören and Barone, Dante A. C. and Bartz, Cassiano and Cortes, Eduardo G. and Jaradeh, Mohamad Yaser and Karras, Oliver and Koubarakis, Manolis and Mouromtsev, Dmitry and Pliukhin, Dmitrii and Radyush, Daniil and et al.}, | |
year={2023} | |
""" | |
_DESCRIPTION = """\ | |
SciQA contains 2,565 SPARQL query - question pairs along with answers fetched from the open research knowledge graph (ORKG) \ | |
via a Virtuoso SPARQL endpoint, it is a collection of both handcrafted and autogenerated questions and queries. \ | |
The dataset is split into 70% training, 10% validation and 20% test examples. The dataset is available as JSON files. | |
""" | |
_URL = "https://zenodo.org/record/7744048/files/SciQA-dataset.zip" | |
class SciQA(datasets.GeneratorBasedBuilder): | |
""" | |
The SciQA Scientific Question Answering Benchmark for Scholarly Knowledge. | |
""" | |
VERSION = datasets.Version("1.0.1") | |
def _info(self): | |
return datasets.DatasetInfo( | |
# This is the description that will appear on the datasets page. | |
description=_DESCRIPTION, | |
# datasets.features.FeatureConnectors | |
features=datasets.Features( | |
{ | |
"id": datasets.Value("string"), | |
"query_type": datasets.Value("string"), | |
"question": datasets.dataset_dict.DatasetDict({ | |
"string": datasets.Value("string") | |
}), | |
"paraphrased_question": datasets.features.Sequence(datasets.Value("string")), | |
"query": datasets.dataset_dict.DatasetDict({ | |
"sparql": datasets.Value("string") | |
}), | |
"template_id": datasets.Value("string"), | |
"query_shape": datasets.Value("string"), | |
"query_class": datasets.Value("string"), | |
"auto_generated": datasets.Value("bool"), | |
"number_of_patterns": datasets.Value("int32") | |
} | |
), | |
supervised_keys=None, | |
citation=_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
"""Returns SplitGenerators.""" | |
dl_dir = dl_manager.download_and_extract(_URL) | |
dl_dir = os.path.join(dl_dir, "SciQA-dataset") | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
gen_kwargs={"filepath": os.path.join(dl_dir, "train", "questions.json")}, | |
), | |
datasets.SplitGenerator( | |
name=datasets.Split.VALIDATION, | |
gen_kwargs={"filepath": os.path.join(dl_dir, "valid", "questions.json")}, | |
), | |
datasets.SplitGenerator( | |
name=datasets.Split.TEST, | |
gen_kwargs={"filepath": os.path.join(dl_dir, "test", "questions.json")}, | |
), | |
] | |
def _generate_examples(self, filepath): | |
"""Yields examples.""" | |
with open(filepath, encoding="utf-8") as f: | |
data = json.load(f)["questions"] | |
for id_, row in enumerate(data): | |
yield id_, { | |
"id": row["id"], | |
"query_type": row["query_type"], | |
"question": row["question"], | |
"paraphrased_question": row["paraphrased_question"], | |
"query": row["query"], | |
"template_id": row["template_id"], | |
"query_shape": row["query_shape"], | |
"query_class": row["query_class"], | |
"auto_generated": row["auto_generated"], | |
"number_of_patterns": row["number_of_patterns"] | |
} | |