glecorve commited on
Commit
63b31b3
1 Parent(s): 1db676b

Inflate JSON (tarballed) dataset

Browse files
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ json/csqa_sparql_to_text.tar.gz filter=lfs diff=lfs merge=lfs -text
csqa-sparqltotext.py ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+
4
+ import json
5
+
6
+ import datasets
7
+ from typing import Any
8
+
9
+ import sys
10
+
11
+
12
+
13
+ _CITATION = """\
14
+ @inproceedings{lecorve2022sparql2text,
15
+ title={Coqar: Question rewriting on coqa},
16
+ author={Lecorv\'e, Gw\'enol\'e and Veyret, Morgan and Brabant, Quentin and Rojas-Barahona, Lina M.},
17
+ journal={Proceedings of the Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the International Joint Conference on Natural Language Processing (AACL-IJCNLP)},
18
+ year={2022}
19
+ }
20
+ """
21
+
22
+ _HOMEPAGE = ""
23
+
24
+ _DESCRIPTION = """\
25
+ Special version of CSQA for the SPARQL-to-Text task
26
+ """
27
+
28
+ _URLS = {
29
+ "all": "json/csqa_sparql_to_text.tar.gz"
30
+ }
31
+
32
+ class CSQA(datasets.GeneratorBasedBuilder):
33
+ """
34
+ Complex Sequential Question Answering dataset
35
+ """
36
+
37
+ VERSION = datasets.Version("1.0.0")
38
+
39
+ def _info(self):
40
+ return datasets.DatasetInfo(
41
+ # This is the description that will appear on the datasets page.
42
+ description=_DESCRIPTION,
43
+ # datasets.features.FeatureConnectors
44
+ #"active_set"
45
+ #"all_entities"
46
+ #"bool_ques_type"
47
+ #"count_ques_sub_type"
48
+ #"count_ques_type"
49
+ #"description"
50
+ #"entities"
51
+ #"entities_in_utterance"
52
+ #"gold_actions"
53
+ #"inc_ques_type"
54
+ #"is_inc"
55
+ #"is_incomplete"
56
+ #"is_spurious"
57
+ #"masked_verbalized_answer"
58
+ #"parsed_active_set"
59
+ #"ques_type_id"
60
+ #"question-type"
61
+ #"relations"
62
+ #"sec_ques_sub_type"
63
+ #"sec_ques_type"
64
+ #"set_op_choice"
65
+ #"set_op"
66
+ #"sparql_query"
67
+ #"speaker"
68
+ #"type_list"
69
+ #"utterance"
70
+ #"utterance"
71
+ #"verbalized_all_entities"
72
+ #"verbalized_answer"
73
+ #"verbalized_entities_in_utterance"
74
+ #"verbalized_gold_actions"
75
+ #"verbalized_parsed_active_set"
76
+ #"verbalized_sparql_query"
77
+ #"verbalized_triple"
78
+ #"verbalized_type_list"
79
+ features=datasets.Features(
80
+ {
81
+ "id": datasets.Value("string"),
82
+ "turns": [
83
+ {
84
+ "id": datasets.Value("int64"),
85
+ "ques_type_id": datasets.Value("int64"),
86
+ "question-type": datasets.Value("string"),
87
+ "description": datasets.Value("string"),
88
+ "entities_in_utterance": [datasets.Value("string")],
89
+ "relations": [datasets.Value("string")],
90
+ "type_list": [datasets.Value("string")],
91
+ "speaker": datasets.Value("string"),
92
+ "utterance": datasets.Value("string"),
93
+ "all_entities": [datasets.Value("string")],
94
+ "active_set": [datasets.Value("string")],
95
+ 'sec_ques_sub_type': datasets.Value("int64"),
96
+ 'sec_ques_type': datasets.Value("int64"),
97
+ 'set_op_choice': datasets.Value("int64"),
98
+ 'is_inc': datasets.Value("int64"),
99
+ 'count_ques_sub_type': datasets.Value("int64"),
100
+ 'count_ques_type': datasets.Value("int64"),
101
+ 'is_incomplete': datasets.Value("int64"),
102
+ 'inc_ques_type': datasets.Value("int64"),
103
+ 'set_op': datasets.Value("int64"),
104
+ 'bool_ques_type': datasets.Value("int64"),
105
+ 'entities': [datasets.Value("string")],
106
+ "clarification_step": datasets.Value("int64"),
107
+ "gold_actions": [[datasets.Value("string")]],
108
+ "is_spurious": datasets.Value("bool"),
109
+ "masked_verbalized_answer": datasets.Value("string"),
110
+ "parsed_active_set": [datasets.Value("string")],
111
+ "sparql_query": datasets.Value("string"),
112
+ "verbalized_all_entities": [datasets.Value("string")],
113
+ "verbalized_answer": datasets.Value("string"),
114
+ "verbalized_entities_in_utterance": [datasets.Value("string")],
115
+ "verbalized_gold_actions": [[datasets.Value("string")]],
116
+ "verbalized_parsed_active_set": [datasets.Value("string")],
117
+ "verbalized_sparql_query": datasets.Value("string"),
118
+ "verbalized_triple": datasets.Value("string"),
119
+ "verbalized_type_list": [datasets.Value("string")]
120
+ }
121
+ ]
122
+ }
123
+ ),
124
+ # If there's a common (input, target) tuple from the features,
125
+ # specify them here. They'll be used if as_supervised=True in
126
+ # builder.as_dataset
127
+ supervised_keys=None,
128
+ # Homepage of the dataset for documentation
129
+ homepage=_HOMEPAGE,
130
+ citation=_CITATION,
131
+ )
132
+
133
+ def _split_generators(self, dl_manager):
134
+ """Returns SplitGenerators."""
135
+ # Downloads the data and defines the splits
136
+ # dl_manager is a datasets.download.DownloadManager that can be used to
137
+ # download and extract URLs
138
+ downloaded_files = dl_manager.download_and_extract(_URLS)
139
+ train_path = os.path.join(downloaded_files['all'],'csqa_sparql_to_text/train/')
140
+ test_path = os.path.join(downloaded_files['all'],'csqa_sparql_to_text/test/')
141
+ valid_path = os.path.join(downloaded_files['all'],'csqa_sparql_to_text/valid/')
142
+ return [
143
+ datasets.SplitGenerator(
144
+ name=datasets.Split.TRAIN,
145
+ gen_kwargs={"filepath": train_path,
146
+ "split": "train"}
147
+ ),
148
+ datasets.SplitGenerator(
149
+ name=datasets.Split.TEST,
150
+ gen_kwargs={"filepath": test_path,
151
+ "split": "test"}
152
+ ),
153
+ datasets.SplitGenerator(
154
+ name=datasets.Split.VALIDATION,
155
+ gen_kwargs={"filepath": valid_path,
156
+ "split": "valid"}
157
+ ),
158
+ ]
159
+
160
+ def _generate_examples(self, filepath, split):
161
+ """Yields examples."""
162
+ # Yields (key, example) tuples from the dataset
163
+ def _transform(x):
164
+ pattern = {
165
+ "id": None,
166
+ "ques_type_id": None,
167
+ "question-type": "",
168
+ "description": "",
169
+ "entities_in_utterance": [],
170
+ "relations": [],
171
+ "type_list": [],
172
+ "speaker": "",
173
+ "utterance": "",
174
+ "all_entities": [],
175
+ "active_set": [],
176
+ 'sec_ques_sub_type': None,
177
+ 'sec_ques_type': None,
178
+ 'set_op_choice': None,
179
+ 'is_inc': None,
180
+ 'count_ques_sub_type': None,
181
+ 'count_ques_type': None,
182
+ 'is_incomplete': None,
183
+ 'inc_ques_type': None,
184
+ 'set_op': None,
185
+ 'bool_ques_type': None,
186
+ 'entities': [],
187
+ "clarification_step": None,
188
+ "gold_actions": [],
189
+ "is_spurious": None,
190
+ "masked_verbalized_answer": None,
191
+ "parsed_active_set": [],
192
+ "sparql_query": None,
193
+ "verbalized_all_entities": [],
194
+ "verbalized_answer": None,
195
+ "verbalized_entities_in_utterance": [],
196
+ "verbalized_gold_actions": [],
197
+ "verbalized_parsed_active_set": [],
198
+ "verbalized_sparql_query": None,
199
+ "verbalized_triple": [],
200
+ "verbalized_type_list": []
201
+ }
202
+
203
+ # if "verbalized_triple" in x:
204
+ # x["verbalized_triple"] = json.dumps(x["verbalized_triple"])
205
+ # for k in ["parsed_active_set", "verbalized_gold_actions", "verbalized_parsed_active_set"]:
206
+ # if k in x:
207
+ # del x[k]
208
+ pattern.update(x)
209
+ # if "verbalized_triple" in pattern:
210
+ # if type(pattern["verbalized_triple"]) != list:
211
+ # print(pattern["verbalized_triple"])
212
+ # sys.exit()
213
+ return pattern
214
+ data_keys = {}
215
+ for root, dirs, files in os.walk(filepath):
216
+ dialog_id = root.split('/')[-1]
217
+ for i,filename in enumerate(files):
218
+ sample_id = "%s:%s"%(dialog_id,i)
219
+ with open(os.path.join(root,filename),'r') as f:
220
+ data = json.load(f)
221
+ # print("--")
222
+ for x in data:
223
+ for k,v in x.items():
224
+ if not k in data_keys:
225
+ data_keys[k] = type(v)
226
+ new_data = list()
227
+ for i,_ in enumerate(data):
228
+ # if "verbalized_triple" in data[i]:
229
+ # print(json.dumps(data[i]["verbalized_triple"], indent=2))
230
+ # if i < len(data)-1:
231
+ # if "verbalized_triple" in data[i+1]:
232
+ # print("i+1", json.dumps(data[i+1]["verbalized_triple"], indent=2))
233
+ new_data.append(data[i])
234
+ data = [ _transform(x) for x in data]
235
+ yield sample_id, {
236
+ "id": sample_id,
237
+ "turns": data
238
+ }
239
+
json/csqa_sparql_to_text.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1fe95884ee73a5dd6c5077778bdd15a59aaddb934962552839f18ec3a7bc4d9
3
+ size 1898697672