| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """A Dataset loading script for the QA-Adj dataset.""" |
| |
|
| |
|
| | from dataclasses import dataclass |
| | from typing import Optional, Tuple, Union, Iterable, Set |
| | from pathlib import Path |
| | import itertools |
| | import pandas as pd |
| | import datasets |
| |
|
| |
|
| | _DESCRIPTION = """\ |
| | The dataset contains question-answer pairs to capture adjectival semantics. |
| | This dataset was annotated by selected workers from Amazon Mechanical Turk. |
| | """ |
| |
|
| | _LICENSE = """MIT License |
| | |
| | Copyright (c) 2022 Ayal Klein (kleinay) |
| | |
| | Permission is hereby granted, free of charge, to any person obtaining a copy |
| | of this software and associated documentation files (the "Software"), to deal |
| | in the Software without restriction, including without limitation the rights |
| | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| | copies of the Software, and to permit persons to whom the Software is |
| | furnished to do so, subject to the following conditions: |
| | |
| | The above copyright notice and this permission notice shall be included in all |
| | copies or substantial portions of the Software. |
| | |
| | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| | SOFTWARE.""" |
| |
|
| | URL = "https://github.com/kleinay/QA-Adj-Dataset/raw/main/QAADJ_Dataset.zip" |
| |
|
| | SUPPOERTED_DOMAINS = {"wikinews", "wikipedia"} |
| |
|
| | @dataclass |
| | class QAAdjBuilderConfig(datasets.BuilderConfig): |
| | domains: Union[str, Iterable[str]] = "all" |
| | full_dataset: bool = False |
| |
|
| | class QaAdj(datasets.GeneratorBasedBuilder): |
| | """QAAdj: Question-Answer based semantics for adjectives. |
| | """ |
| |
|
| | VERSION = datasets.Version("1.0.0") |
| | |
| | BUILDER_CONFIG_CLASS = QAAdjBuilderConfig |
| |
|
| | BUILDER_CONFIGS = [ |
| | QAAdjBuilderConfig( |
| | name="default", version=VERSION, description="This provides the QAAdj dataset - train, dev and test" |
| | ), |
| | QAAdjBuilderConfig( |
| | name="full", version=VERSION, full_dataset=True, |
| | description="""This provides the QAAdj dataset including gold reference |
| | (300 expert-annotated instances) and propbank comparison instances""" |
| | ), |
| | ] |
| |
|
| | DEFAULT_CONFIG_NAME = ( |
| | "default" |
| | ) |
| | |
| | def _info(self): |
| | features = datasets.Features( |
| | { |
| | "sentence": datasets.Value("string"), |
| | "sent_id": datasets.Value("string"), |
| | "predicate_idx": datasets.Value("int32"), |
| | "predicate_idx_end": datasets.Value("int32"), |
| | "predicate": datasets.Value("string"), |
| | "object_question": datasets.Value("string"), |
| | "object_answer": datasets.Sequence(datasets.Value("string")), |
| | "domain_question": datasets.Value("string"), |
| | "domain_answer": datasets.Sequence(datasets.Value("string")), |
| | "reference_question": datasets.Value("string"), |
| | "reference_answer": datasets.Sequence(datasets.Value("string")), |
| | "extent_question": datasets.Value("string"), |
| | "extent_answer": datasets.Sequence(datasets.Value("string")), |
| | } |
| | ) |
| | return datasets.DatasetInfo( |
| | |
| | description=_DESCRIPTION, |
| | |
| | features=features, |
| | |
| | |
| | |
| | supervised_keys=None, |
| | |
| | |
| | |
| | license=_LICENSE, |
| | |
| | |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | """Returns SplitGenerators.""" |
| | |
| | |
| | domains: Set[str] = [] |
| | if self.config.domains == "all": |
| | domains = SUPPOERTED_DOMAINS |
| | elif isinstance(self.config.domains, str): |
| | if self.config.domains in SUPPOERTED_DOMAINS: |
| | domains = {self.config.domains} |
| | else: |
| | raise ValueError(f"Unrecognized domain '{self.config.domains}'; only {SUPPOERTED_DOMAINS} are supported") |
| | else: |
| | domains = set(self.config.domains) & SUPPOERTED_DOMAINS |
| | if len(domains) == 0: |
| | raise ValueError(f"Unrecognized domains '{self.config.domains}'; only {SUPPOERTED_DOMAINS} are supported") |
| | self.config.domains = domains |
| | |
| | self.corpus_base_path = Path(dl_manager.download_and_extract(URL)) |
| |
|
| | splits = [ |
| | datasets.SplitGenerator( |
| | name=datasets.Split.TRAIN, |
| | |
| | gen_kwargs={ |
| | "csv_fn": self.corpus_base_path / "train.csv", |
| | }, |
| | ), |
| | datasets.SplitGenerator( |
| | name=datasets.Split.VALIDATION, |
| | |
| | gen_kwargs={ |
| | "csv_fn": self.corpus_base_path / "dev.csv", |
| | }, |
| | ), |
| | datasets.SplitGenerator( |
| | name=datasets.Split.TEST, |
| | |
| | gen_kwargs={ |
| | "csv_fn": self.corpus_base_path / "test.csv", |
| | }, |
| | ), |
| | ] |
| | if self.config.full_dataset: |
| | splits = splits + [ |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | datasets.SplitGenerator( |
| | name="propbank", |
| | |
| | gen_kwargs={ |
| | "csv_fn": self.corpus_base_path / "propbank_comparison_data.csv", |
| | }, |
| | ), |
| | ] |
| | |
| | return splits |
| | |
| | def _generate_examples(self, csv_fn): |
| | df = pd.read_csv(csv_fn) |
| | for counter, row in df.iterrows(): |
| | yield counter, { |
| | "sentence": row['Input.sentence'], |
| | "sent_id": row['Input.qasrl_id'], |
| | "predicate_idx": row['Input.adj_index_start'], |
| | "predicate_idx_end": row['Input.adj_index_end'], |
| | "predicate": row['Input.target'], |
| | "object_question": self._get_optional_question(row.object_q), |
| | "object_answer": self._get_optional_answer(row["Answer.answer1"]), |
| | "domain_question": self._get_optional_question(row.domain_q), |
| | "domain_answer": self._get_optional_answer(row["Answer.answer3"]), |
| | "reference_question": self._get_optional_question(row.comparison_q), |
| | "reference_answer": self._get_optional_answer(row["Answer.answer2"]), |
| | "extent_question": self._get_optional_question(row.degree_q), |
| | "extent_answer": self._get_optional_answer(row["Answer.answer4"]), |
| | } |
| |
|
| | def _get_optional_answer(self, val): |
| | if pd.isnull(val): |
| | return [] |
| | else: |
| | return val.split("+") |
| | def _get_optional_question(self, val): |
| | if pd.isnull(val): |
| | return "" |
| | else: |
| | return val |
| | |