File size: 8,629 Bytes
05317e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a81ba59
 
 
05317e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8ed654
 
 
 
 
 
 
 
 
 
05317e6
 
 
 
 
 
 
 
d8ed654
 
 
 
 
 
05317e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8ed654
05317e6
 
 
d8ed654
 
05317e6
 
 
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# 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.
"""A Dataset loading script for the QA-Align dataset (Brook Weiss et. al., EMNLP 2021)."""


import datasets
from pathlib import Path
from typing import List
import pandas as pd
import json


_CITATION = """\
@inproceedings{brook-weiss-etal-2021-qa,
    title = "{QA}-Align: Representing Cross-Text Content Overlap by Aligning Question-Answer Propositions",
    author = "Brook Weiss, Daniela  and
      Roit, Paul  and
      Klein, Ayal  and
      Ernst, Ori  and
      Dagan, Ido",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-main.778",
    pages = "9879--9894",
    abstract = "Multi-text applications, such as multi-document summarization, are typically required to model redundancies across related texts. Current methods confronting consolidation struggle to fuse overlapping information. In order to explicitly represent content overlap, we propose to align predicate-argument relations across texts, providing a potential scaffold for information consolidation. We go beyond clustering coreferring mentions, and instead model overlap with respect to redundancy at a propositional level, rather than merely detecting shared referents. Our setting exploits QA-SRL, utilizing question-answer pairs to capture predicate-argument relations, facilitating laymen annotation of cross-text alignments. We employ crowd-workers for constructing a dataset of QA-based alignments, and present a baseline QA alignment model trained over our dataset. Analyses show that our new task is semantically challenging, capturing content overlap beyond lexical similarity and complements cross-document coreference with proposition-level links, offering potential use for downstream tasks.",
}"""


_DESCRIPTION = """\
This dataset contains QA-Alignments - annotations of cross-text content overlap. 
The task input is two sentences from two documents, roughly talking about the same event, along with their QA-SRL annotations 
which capture verbal predicate-argument relations in question-answer format. The output is a cross-sentence alignment between sets of QAs which denote the same information.   
See the paper for details: QA-Align: Representing Cross-Text Content Overlap by Aligning Question-Answer Propositions, Brook Weiss et. al., EMNLP 2021.
Here we provide both the QASRL annotations and the QA-Align annotations for the target sentences.
"""

_HOMEPAGE = "https://github.com/DanielaBWeiss/QA-ALIGN"

_LICENSE = """Resources on this page are licensed CC-BY 4.0, a Creative Commons license requiring Attribution (https://creativecommons.org/licenses/by/4.0/)."""


_URLs = {
    "train": "https://github.com/DanielaBWeiss/QA-ALIGN/raw/main/data/official_qa_alignments/qaalign_train_silver_official.csv",
    "dev": "https://github.com/DanielaBWeiss/QA-ALIGN/raw/main/data/official_qa_alignments/qaalign_dev_gold_official.csv",
    "test": "https://github.com/DanielaBWeiss/QA-ALIGN/raw/main/data/official_qa_alignments/qaalign_test_gold_official.csv",
}

# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
class QaAlign(datasets.GeneratorBasedBuilder):
    """QA-Align: Representing Cross-Text Content Overlap by Aligning Question-Answer Propositions.  """

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="plain_text", version=VERSION, description="This provides the QA-Align dataset"
        ),
    ]

    DEFAULT_CONFIG_NAME = (
        "plain_text"  # It's not mandatory to have a default configuration. Just use one if it make sense.
    )

    def _info(self):
        # We keep the exact same fields (columns) as the original dataset files (CSV) 
        # See https://github.com/DanielaBWeiss/QA-ALIGN/blob/main/data/official_qa_alignments/readme.md for format description  
        qa_dict = {
            "qa_uuid": datasets.Value("string"),
            "verb": datasets.Value("string"),
            "verb_idx": datasets.Value("int32"),
            "question": datasets.Value("string"),
            "answer": datasets.Value("string"),
            "answer_range": datasets.Value("string"),
        }
        qa_full_dict = dict(qa_dict, qaid_short=datasets.Value("string"))
        
        features = datasets.Features(
            {
                "text_1": datasets.Value("string"),
                "text_2": datasets.Value("string"),
                "prev_text_2": datasets.Value("string"),
                "prev_text_1": datasets.Value("string"),
                "abs_sent_id_2": datasets.Value("string"),
                "abs_sent_id_1": datasets.Value("string"),
                "qas_1": datasets.Sequence(qa_full_dict),
                "qas_2": datasets.Sequence(qa_full_dict),
                "alignments": datasets.Sequence({
                    "sent1": datasets.Sequence(qa_dict),
                    "sent2": datasets.Sequence(qa_dict),
                }),
            }
        )
        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."""            
        
        # Download and prepare all files - keep same structure as _URLs 
        corpora = {section:  Path(dl_manager.download_and_extract(_URLs[section])) 
                   for section in _URLs} 
            
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": corpora["train"]
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": corpora["dev"]
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": corpora["test"]
                },
            ),
        ]
    
    def _generate_examples(self, filepath: List[str]):

        """ Yields QA-Align examples from a csv file. Each instance contains all the alignment for a pair of sentences. """

        # merge annotations from sections 
        df = pd.read_csv(filepath, index_col=False)
        for counter, dic in enumerate(df.to_dict('records')):
            columns_to_load_into_object = ["qas_1", "qas_2", "alignments"]
            for key in columns_to_load_into_object:
                dic[key] = eval(dic[key])
            columns_to_remove = ["Unnamed: 0","worker_id","assignment_id","work_time_in_seconds","abs_scu_id", "year","topic","key","source","source-data","tokens_1","tokens_2"]
            for key in columns_to_remove:
                del dic[key]
            yield counter, dic