WorkInTheDark commited on
Commit
4033df0
1 Parent(s): 2cd00d4

Upload FairytaleQA.py

Browse files
Files changed (1) hide show
  1. FairytaleQA.py +152 -0
FairytaleQA.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+
16
+ """FairytaleQA: An Authentic Dataset for Narrative Comprehension"""
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+ logger = datasets.logging.get_logger(__name__)
25
+
26
+ _CITATION = """\
27
+ @inproceedings{xu-etal-2022-fantastic,
28
+ title = "Fantastic Questions and Where to Find Them: {F}airytale{QA} {--} An Authentic Dataset for Narrative Comprehension",
29
+ author = "Xu, Ying and
30
+ Wang, Dakuo and
31
+ Yu, Mo and
32
+ Ritchie, Daniel and
33
+ Yao, Bingsheng and
34
+ Wu, Tongshuang and
35
+ Zhang, Zheng and
36
+ Li, Toby and
37
+ Bradford, Nora and
38
+ Sun, Branda and
39
+ Hoang, Tran and
40
+ Sang, Yisi and
41
+ Hou, Yufang and
42
+ Ma, Xiaojuan and
43
+ Yang, Diyi and
44
+ Peng, Nanyun and
45
+ Yu, Zhou and
46
+ Warschauer, Mark",
47
+ booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
48
+ month = may,
49
+ year = "2022",
50
+ address = "Dublin, Ireland",
51
+ publisher = "Association for Computational Linguistics",
52
+ url = "https://aclanthology.org/2022.acl-long.34",
53
+ doi = "10.18653/v1/2022.acl-long.34",
54
+ pages = "447--460",
55
+ abstract = "Question answering (QA) is a fundamental means to facilitate assessment and training of narrative comprehension skills for both machines and young children, yet there is scarcity of high-quality QA datasets carefully designed to serve this purpose. In particular, existing datasets rarely distinguish fine-grained reading skills, such as the understanding of varying narrative elements. Drawing on the reading education research, we introduce FairytaleQA, a dataset focusing on narrative comprehension of kindergarten to eighth-grade students. Generated by educational experts based on an evidence-based theoretical framework, FairytaleQA consists of 10,580 explicit and implicit questions derived from 278 children-friendly stories, covering seven types of narrative elements or relations. Our dataset is valuable in two folds: First, we ran existing QA models on our dataset and confirmed that this annotation helps assess models{'} fine-grained learning skills. Second, the dataset supports question generation (QG) task in the education domain. Through benchmarking with QG models, we show that the QG model trained on FairytaleQA is capable of asking high-quality and more diverse questions.",
56
+ }
57
+ """
58
+
59
+ _DESCRIPTION = """\
60
+ FairytaleQA dataset, an open-source dataset focusing on comprehension of narratives, \
61
+ targeting students from kindergarten to eighth grade. The FairytaleQA dataset is \
62
+ annotated by education experts based on an evidence-based theoretical framework. \
63
+ It consists of 10,580 explicit and implicit questions derived from 278 children-friendly \
64
+ stories, covering seven types of narrative elements or relations.
65
+ """
66
+ _URL = ''
67
+
68
+ class FairytaleQAConfig(datasets.BuilderConfig):
69
+ """BuilderConfig for FairytaleQA."""
70
+
71
+ def __init__(self, **kwargs):
72
+ """BuilderConfig for FairytaleQA.
73
+ Args:
74
+ **kwargs: keyword arguments forwarded to super.
75
+ """
76
+ super(FairytaleQAConfig, self).__init__(**kwargs)
77
+
78
+ class FairytaleQA(datasets.GeneratorBasedBuilder):
79
+ """TODO: Short description of my dataset."""
80
+
81
+ BUILDER_CONFIGS = [
82
+ FairytaleQAConfig(
83
+ name="plain_text",
84
+ version=datasets.Version("0.0", ""),
85
+ description="Plain text",
86
+ ),
87
+ ]
88
+
89
+ def _info(self):
90
+ return datasets.DatasetInfo(
91
+ description=_DESCRIPTION,
92
+ features=datasets.Features(
93
+ {
94
+ "story_name": datasets.Value("string"),
95
+ "story_section": datasets.Value("string"),
96
+ "question": datasets.Value("string"),
97
+ "answer2": datasets.Value("string"),
98
+ "local-or-sum": datasets.Value("string"),
99
+ "attribute": datasets.Value("string"),
100
+ "ex-or-im": datasets.Value("string"),
101
+ "ex-or-im2": datasets.Value("string"),
102
+ }
103
+ ),
104
+ # No default supervised_keys (as we have to pass both question
105
+ # and context as input).
106
+ supervised_keys=None,
107
+ citation=_CITATION,
108
+
109
+ )
110
+
111
+ def _split_generators(self, dl_manager):
112
+ urls_to_download = self._URLS
113
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
114
+
115
+ return [
116
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
117
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
118
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
119
+ ]
120
+
121
+ def _generate_examples(self, filepath):
122
+ """This function returns the examples in the raw (text) form."""
123
+ logger.info("generating examples from = %s", filepath)
124
+ with open(filepath) as file_obj:
125
+
126
+ heading = next(file_obj)
127
+ reader_obj = csv.reader(file_obj)
128
+ key = 0
129
+ for row in reader_obj:
130
+ # print(row)
131
+ story_name = row[0]
132
+ story_section = row[1]
133
+ question = row[2]
134
+ answer1 = row[3]
135
+ answer2 = row[4]
136
+ local_or_sum = row[5]
137
+ attribute = row[6]
138
+ ex_or_im = row[7]
139
+ ex_or_im2 = row[8]
140
+
141
+ yield key, {
142
+ 'story_name': story_name,
143
+ 'story_section': story_section,
144
+ 'question': question,
145
+ 'answer1': answer1,
146
+ 'answer2': answer2,
147
+ 'local-or-sum': local_or_sum,
148
+ 'attribute': attribute,
149
+ 'ex-or-im': ex_or_im,
150
+ 'ex-or-im2': ex_or_im2,
151
+ }
152
+ key += 1