File size: 6,046 Bytes
5b94fa5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""Dataset loading script for loading the Large-Scale-QASRL (FitzGeralds et. al., ACL 2018) training set, along with the QASRL-GS evaluation dataset (Roit et. al., ACL 2020)."""
import datasets
from pathlib import Path
import gzip
import json
_CITATION = """\
@inproceedings{fitzgerald2018large,
title={Large-Scale QA-SRL Parsing},
author={FitzGerald, Nicholas and Michael, Julian and He, Luheng and Zettlemoyer, Luke},
booktitle={Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
pages={2051--2060},
year={2018}
}
@inproceedings{roit2020controlled,
title={Controlled Crowdsourcing for High-Quality QA-SRL Annotation},
author={Roit, Paul and Klein, Ayal and Stepanov, Daniela and Mamou, Jonathan and Michael, Julian and Stanovsky, Gabriel and Zettlemoyer, Luke and Dagan, Ido},
booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
pages={7008--7013},
year={2020}
}
"""
_DESCRIPTION = """\
The dataset contains question-answer pairs to model verbal predicate-argument structure.
The questions start with wh-words (Who, What, Where, What, etc.) and contain a verb predicate in the sentence; the answers are phrases in the sentence.
This dataset loads the train split from "QASRL Bank", a.k.a "QASRL-v2" or "QASRL-LS" (Large Scale),
which was constructed via crowdsourcing and presented at (FitzGeralds et. al., ACL 2018),
and the dev and test splits from QASRL-GS (Gold Standard), introduced in (Roit et. al., ACL 2020).
"""
_HOMEPAGE = "https://qasrl.org"
# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""
SpanFeatureType = datasets.Sequence(datasets.Value("int32"), length=2)
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
class QaSrl(datasets.GeneratorBasedBuilder):
"""QA-SRL: Question-Answer Driven Semantic Role Labeling corpus"""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="plain_text", version=VERSION, description=""
),
]
DEFAULT_CONFIG_NAME = (
"plain_text" # It's not mandatory to have a default configuration. Just use one if it make sense.
)
def _info(self):
features = datasets.Features(
{
"sentence": datasets.Value("string"),
"sent_id": datasets.Value("string"),
"predicate_idx": datasets.Value("int32"),
"predicate": datasets.Value("string"),
"is_verbal": datasets.Value("bool"),
"verb_form": datasets.Value("string"),
"question": datasets.Sequence(datasets.Value("string")),
"answers": datasets.Sequence(datasets.Value("string")),
"answer_ranges": datasets.Sequence(SpanFeatureType)
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, target) tuple from the features,
# specify them here. They'll be used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.utils.download_manager.DownloadManager):
"""Returns SplitGenerators."""
# iterate the tar file of the corpus
# Older version of the corpus (has some format errors):
# corpus_base_path = Path(dl_manager.download_and_extract(_URLs["qasrl_v2.0"]))
# corpus_orig = corpus_base_path / "qasrl-v2" / "orig"
self.qasrl2018 = datasets.load_dataset("biu-nlp/qa_srl2018")
self.qasrl2020 = datasets.load_dataset("biu-nlp/qa_srl2020")
# TODO add optional kwarg for genre (wikinews)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"dataset": self.qasrl2018["train"],
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"dataset": self.qasrl2020["validation"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"dataset": self.qasrl2020["test"],
},
),
]
def _generate_examples(self, dataset):
""" Yields examples from a '.jsonl.gz' file ."""
for idx, instance in enumerate(dataset):
yield idx, instance
|