File size: 19,795 Bytes
6577db2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b914bf6
6577db2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# Copyright 2023 Xueyuan Lin
# Apache 2.0 License
"""Loading script for DiffusionDB."""
from typing import List, Dict
import json
import os
from huggingface_hub import hf_hub_url
import datasets


_CITATION = """\

@inproceedings{

  xueyuan2023tflex,

  title={TFLEX: Temporal Feature-Logic Embedding Framework for Complex Reasoning over Temporal Knowledge Graph},

  author={Lin Xueyuan and Haihong E and Chengjin Xu and Gengxian Zhou and Haoran Luo and Tianyi Hu and Fenglong Su and Ningyuan Li and Mingzhi Sun},

  booktitle={Thirty-seventh Conference on Neural Information Processing Systems},

  year={2023},

  url={https://openreview.net/forum?id=oaGdsgB18L}

}\

"""

_DESCRIPTION = """\

TL;DR: The datasets for temporal knowledge graph reasoning task.



[[Github]](https://github.com/LinXueyuanStdio/TFLEX)

[[OpenReview]](https://openreview.net/forum?id=oaGdsgB18L)

[[arXiv]](https://arxiv.org/abs/2205.14307)



- Built over ICEWS and GDELT, which are widly used benchmarks in TKGC.

- First introduced in paper "TFLEX: Temporal Feature-Logic Embedding Framework for Complex Reasoning over Temporal Knowledge Graph"

- Please refer to the original paper for more details.

"""

_HOMEPAGE = "https://github.com/LinXueyuanStdio/TFLEX"

_LICENSE = "[Apache License 2.0](https://github.com/LinXueyuanStdio/TFLEX/blob/main/LICENSE)"

query_name_to_args: Dict[str, List[str]] = {
    # 1. 1-hop Pe and Pt, manually
    "Pe": ["e1", "r1", "t1"],
    "Pt": ["e1", "r1", "e2"],
    # 2. entity multi-hop
    "Pe2": ["e1", "r1", "t1", "r2", "t2"],
    "Pe3": ["e1", "r1", "t1", "r2", "t2", "r3", "t3"],
    # 3. time multi-hop
    "aPt": ["s", "r", "o"],
    "bPt": ["s", "r", "o"],
    "Pt_sPe": ["e1", "r1", "t1", "r2", "e2"],
    "Pt_oPe": ["e1", "r1", "e2", "r2", "t1"],
    "Pe_Pt": ["e1", "r1", "e2", "r2", "e3"],
    "Pe_aPt": ["e1", "r1", "e2", "r2", "e3"],
    "Pe_bPt": ["e1", "r1", "e2", "r2", "e3"],
    "Pe_nPt": ["e1", "r1", "e2", "r2", "e3"],
    "Pt_sPe_Pt": ["s1", "r1", "s2", "r2", "o1", "r3", "o2"],
    "Pt_oPe_Pt": ["s1", "r1", "s2", "r2", "s3", "r3", "o1"],
    # 4. entity and & time and
    "e2i": ["e1", "r1", "t1", "e2", "r2", "t2"],
    "e3i": ["e1", "r1", "t1", "e2", "r2", "t2", "e3", "r3", "t3"],
    "t2i": ["e1", "r1", "e2", "e3", "r2", "e4"],
    "t3i": ["e1", "r1", "e2", "e3", "r2", "e4", "e5", "r3", "e6"],
    # 5. complex time and
    "e2i_Pe": ["e1", "r1", "t1", "r2", "t2", "e2", "r3", "t3"],
    "Pe_e2i": ["e1", "r1", "t1", "e2", "r2", "t2", "r3", "t3"],
    "Pt_se2i": ["e1", "r1", "t1", "e2", "r2", "t2", "r3", "e3"],
    "Pt_oe2i": ["e1", "r1", "e2", "r2", "t1", "e3", "r3", "t2"],
    "t2i_Pe": ["e1", "r1", "t1", "r2", "e2", "e3", "r3", "e4"],
    "Pe_t2i": ["e1", "r1", "e2", "r2", "e3", "e4", "r3", "e5"],
    "Pe_at2i": ["e1", "r1", "e2", "r2", "e3", "e4", "r3", "e5"],
    "Pe_bt2i": ["e1", "r1", "e2", "r2", "e3", "e4", "r3", "e5"],
    "Pe_nt2i": ["e1", "r1", "e2", "r2", "e3", "e4", "r3", "e5"],
    "between": ["e1", "r1", "e2", "e3", "r2", "e4"],
    # 5. entity not
    "e2i_N": ["e1", "r1", "t1", "e2", "r2", "t2"],
    "e3i_N": ["e1", "r1", "t1", "e2", "r2", "t2", "e3", "r3", "t3"],
    "Pe_e2i_Pe_NPe": ["e1", "r1", "t1", "e2", "r2", "t2", "r3", "t3"],
    "e2i_NPe": ["e1", "r1", "t1", "r2", "t2", "e2", "r3", "t3"],
    "e2i_PeN": ["e1", "r1", "t1", "r2", "t2", "e2", "r3", "t3"],
    # 6. time not
    "t2i_N": ["e1", "r1", "e2", "e3", "r2", "e4"],
    "t3i_N": ["e1", "r1", "e2", "e3", "r2", "e4", "e5", "r3", "e6"],
    "Pe_t2i_PtPe_NPt": ["e1", "r1", "e2", "r2", "t2", "r3", "e3", "e4", "r4", "e5"],
    "t2i_NPt": ["e1", "r1", "t1", "r2", "e2", "e3", "r3", "e4"],
    "t2i_PtN": ["e1", "r1", "t1", "r2", "e2", "e3", "r3", "e4"],
    # 7. entity union & time union
    "e2u": ["e1", "r1", "t1", "e2", "r2", "t2"],
    "Pe_e2u": ["e1", "r1", "t1", "e2", "r2", "t2", "r3", "t3"],
    "t2u": ["e1", "r1", "e2", "e3", "r2", "e4"],
    "Pe_t2u": ["e1", "r1", "e2", "r2", "e3", "e4", "r3", "e5"],
}
query_structures: Dict[str, str] = {
    # 1. 1-hop Pe and Pt, manually
    "Pe": "def Pe(e1, r1, t1): return Pe(e1, r1, t1)",  # 1p
    "Pt": "def Pt(e1, r1, e2): return Pt(e1, r1, e2)",  # 1p, temporal
    # 2. entity multi-hop
    "Pe2": "def Pe2(e1, r1, t1, r2, t2): return Pe(Pe(e1, r1, t1), r2, t2)",  # 2p
    "Pe3": "def Pe3(e1, r1, t1, r2, t2, r3, t3): return Pe(Pe(Pe(e1, r1, t1), r2, t2), r3, t3)",  # 3p
    # 3. time multi-hop
    "aPt": "def aPt(s, r, o): return after(Pt(s, r, o))",  # a for after
    "bPt": "def bPt(s, r, o): return before(Pt(s, r, o))",  # b for before
    "Pt_lPe": "def Pt_lPe(e1, r1, t1, r2, e2): return Pt(Pe(e1, r1, t1), r2, e2)",  # l for left (as head entity)
    "Pt_rPe": "def Pt_rPe(e1, r1, e2, r2, t1): return Pt(e1, r1, Pe(e2, r2, t1))",  # r for right (as tail entity)
    "Pt_sPe": "def Pt_sPe(e1, r1, t1, r2, e2): return Pt(Pe(e1, r1, t1), r2, e2)",  # l for left (as head entity)
    "Pt_oPe": "def Pt_oPe(e1, r1, e2, r2, t1): return Pt(e1, r1, Pe(e2, r2, t1))",  # r for right (as tail entity)
    "Pe_Pt": "def Pe_Pt(e1, r1, e2, r2, e3): return Pe(e1, r1, Pt(e2, r2, e3))",  # at
    "Pe_aPt": "def Pe_aPt(e1, r1, e2, r2, e3): return Pe(e1, r1, after(Pt(e2, r2, e3)))",  # a for after
    "Pe_bPt": "def Pe_bPt(e1, r1, e2, r2, e3): return Pe(e1, r1, before(Pt(e2, r2, e3)))",  # b for before
    "Pe_nPt": "def Pe_nPt(e1, r1, e2, r2, e3): return Pe(e1, r1, next(Pt(e2, r2, e3)))",  # n for next
    "Pt_sPe_Pt": "def Pt_sPe_Pt(s1, r1, s2, r2, o1, r3, o2): return Pt(Pe(s1, r1, Pt(s2, r2, o1)), r3, o2)",
    "Pt_oPe_Pt": "def Pt_oPe_Pt(s1, r1, s2, r2, s3, r3, o1): return Pt(s1, r1, Pe(s2, r2, Pt(s3, r3, o1)))",
    # 4. entity and & time and
    "e2i": "def e2i(e1, r1, t1, e2, r2, t2): return And(Pe(e1, r1, t1), Pe(e2, r2, t2))",  # 2i
    "e3i": "def e3i(e1, r1, t1, e2, r2, t2, e3, r3, t3): return And3(Pe(e1, r1, t1), Pe(e2, r2, t2), Pe(e3, r3, t3))",  # 3i
    "t2i": "def t2i(e1, r1, e2, e3, r2, e4): return TimeAnd(Pt(e1, r1, e2), Pt(e3, r2, e4))",  # t-2i
    "t3i": "def t3i(e1, r1, e2, e3, r2, e4, e5, r3, e6): return TimeAnd3(Pt(e1, r1, e2), Pt(e3, r2, e4), Pt(e5, r3, e6))",  # t-3i
    # 5. complex time and
    "e2i_Pe": "def e2i_Pe(e1, r1, t1, r2, t2, e2, r3, t3): return And(Pe(Pe(e1, r1, t1), r2, t2), Pe(e2, r3, t3))",  # pi
    "Pe_e2i": "def Pe_e2i(e1, r1, t1, e2, r2, t2, r3, t3): return Pe(e2i(e1, r1, t1, e2, r2, t2), r3, t3)",  # ip
    "Pt_le2i": "def Pt_le2i(e1, r1, t1, e2, r2, t2, r3, e3): return Pt(e2i(e1, r1, t1, e2, r2, t2), r3, e3)",  # mix ip
    "Pt_re2i": "def Pt_re2i(e1, r1, e2, r2, t1, e3, r3, t2): return Pt(e1, r1, e2i(e2, r2, t1, e3, r3, t2))",  # mix ip
    "Pt_se2i": "def Pt_se2i(e1, r1, t1, e2, r2, t2, r3, e3): return Pt(e2i(e1, r1, t1, e2, r2, t2), r3, e3)",  # mix ip
    "Pt_oe2i": "def Pt_oe2i(e1, r1, e2, r2, t1, e3, r3, t2): return Pt(e1, r1, e2i(e2, r2, t1, e3, r3, t2))",  # mix ip
    "t2i_Pe": "def t2i_Pe(e1, r1, t1, r2, e2, e3, r3, e4): return TimeAnd(Pt(Pe(e1, r1, t1), r2, e2), Pt(e3, r3, e4))",  # t-pi
    "Pe_t2i": "def Pe_t2i(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, t2i(e2, r2, e3, e4, r3, e5))",  # t-ip
    "Pe_at2i": "def Pe_at2i(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, after(t2i(e2, r2, e3, e4, r3, e5)))",
    "Pe_bt2i": "def Pe_bt2i(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, before(t2i(e2, r2, e3, e4, r3, e5)))",
    "Pe_nt2i": "def Pe_nt2i(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, next(t2i(e2, r2, e3, e4, r3, e5)))",
    "between": "def between(e1, r1, e2, e3, r2, e4): return TimeAnd(after(Pt(e1, r1, e2)), before(Pt(e3, r2, e4)))",  # between(t1, t2) == after t1 and before t2
    # 5. entity not
    "e2i_N": "def e2i_N(e1, r1, t1, e2, r2, t2): return And(Pe(e1, r1, t1), Not(Pe(e2, r2, t2)))",  # 2in
    "e3i_N": "def e3i_N(e1, r1, t1, e2, r2, t2, e3, r3, t3): return And3(Pe(e1, r1, t1), Pe(e2, r2, t2), Not(Pe(e3, r3, t3)))",  # 3in
    "Pe_e2i_Pe_NPe": "def Pe_e2i_Pe_NPe(e1, r1, t1, e2, r2, t2, r3, t3): return Pe(And(Pe(e1, r1, t1), Not(Pe(e2, r2, t2))), r3, t3)",  # inp
    "e2i_PeN": "def e2i_PeN(e1, r1, t1, r2, t2, e2, r3, t3): return And(Pe(Pe(e1, r1, t1), r2, t2), Not(Pe(e2, r3, t3)))",  # pin
    "e2i_NPe": "def e2i_NPe(e1, r1, t1, r2, t2, e2, r3, t3): return And(Not(Pe(Pe(e1, r1, t1), r2, t2)), Pe(e2, r3, t3))",  # pni = e2i_N(Pe(e1, r1, t1), r2, t2, e2, r3, t3)
    # 6. time not
    "t2i_N": "def t2i_N(e1, r1, e2, e3, r2, e4): return TimeAnd(Pt(e1, r1, e2), TimeNot(Pt(e3, r2, e4)))",  # t-2in
    "t3i_N": "def t3i_N(e1, r1, e2, e3, r2, e4, e5, r3, e6): return TimeAnd3(Pt(e1, r1, e2), Pt(e3, r2, e4), TimeNot(Pt(e5, r3, e6)))",  # t-3in
    "Pe_t2i_PtPe_NPt": "def Pe_t2i_PtPe_NPt(e1, r1, e2, r2, t2, r3, e3, e4, r4, e5): return Pe(e1, r1, TimeAnd(Pt(Pe(e2, r2, t2), r3, e3), TimeNot(Pt(e4, r4, e5))))",  # t-inp
    "t2i_PtN": "def t2i_PtN(e1, r1, t1, r2, e2, e3, r3, e4): return TimeAnd(Pt(Pe(e1, r1, t1), r2, e2), TimeNot(Pt(e3, r3, e4)))",  # t-pin
    "t2i_NPt": "def t2i_NPt(e1, r1, t1, r2, e2, e3, r3, e4): return TimeAnd(TimeNot(Pt(Pe(e1, r1, t1), r2, e2)), Pt(e3, r3, e4))",  # t-pni
    # 7. entity union & time union
    "e2u": "def e2u(e1, r1, t1, e2, r2, t2): return Or(Pe(e1, r1, t1), Pe(e2, r2, t2))",  # 2u
    "Pe_e2u": "def Pe_e2u(e1, r1, t1, e2, r2, t2, r3, t3): return Pe(Or(Pe(e1, r1, t1), Pe(e2, r2, t2)), r3, t3)",  # up
    "t2u": "def t2u(e1, r1, e2, e3, r2, e4): return TimeOr(Pt(e1, r1, e2), Pt(e3, r2, e4))",  # t-2u
    "Pe_t2u": "def Pe_t2u(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, TimeOr(Pt(e2, r2, e3), Pt(e4, r3, e5)))",  # t-up
    # 8. union-DM
    "e2u_DM": "def e2u_DM(e1, r1, t1, e2, r2, t2): return Not(And(Not(Pe(e1, r1, t1)), Not(Pe(e2, r2, t2))))",  # 2u-DM
    "Pe_e2u_DM": "def Pe_e2u_DM(e1, r1, t1, e2, r2, t2, r3, t3): return Pe(Not(And(Not(Pe(e1, r1, t1)), Not(Pe(e2, r2, t2)))), r3, t3)",  # up-DM
    "t2u_DM": "def t2u_DM(e1, r1, e2, e3, r2, e4): return TimeNot(TimeAnd(TimeNot(Pt(e1, r1, e2)), TimeNot(Pt(e3, r2, e4))))",  # t-2u-DM
    "Pe_t2u_DM": "def Pe_t2u_DM(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, TimeNot(TimeAnd(TimeNot(Pt(e2, r2, e3)), TimeNot(Pt(e4, r3, e5)))))",  # t-up-DM
    # 9. union-DNF
    "e2u_DNF": "def e2u_DNF(e1, r1, t1, e2, r2, t2): return Pe(e1, r1, t1), Pe(e2, r2, t2)",  # 2u_DNF
    "Pe_e2u_DNF": "def Pe_e2u_DNF(e1, r1, t1, e2, r2, t2, r3, t3): return Pe(Pe(e1, r1, t1), r3, t3), Pe(Pe(e2, r2, t2), r3, t3)",  # up_DNF
    "t2u_DNF": "def t2u_DNF(e1, r1, e2, e3, r2, e4): return Pt(e1, r1, e2), Pt(e3, r2, e4)",  # t-2u_DNF
    "Pe_t2u_DNF": "def Pe_t2u_DNF(e1, r1, e2, r2, e3, e4, r3, e5): return Pe(e1, r1, Pt(e2, r2, e3)), Pe(e1, r1, Pt(e4, r3, e5))",  # t-up_DNF
}
union_query_structures: List[str] = [
    "e2u",
    "Pe_e2u",  # 2u, up
    "t2u",
    "Pe_t2u",  # t-2u, t-up
]
train_query_structures: List[str] = [
    # entity
    "Pe",
    "Pe2",
    "Pe3",
    "e2i",
    "e3i",  # 1p, 2p, 3p, 2i, 3i
    "e2i_NPe",
    "e2i_PeN",
    "Pe_e2i_Pe_NPe",
    "e2i_N",
    "e3i_N",  # npi, pni, inp, 2in, 3in
    # time
    "Pt",
    "Pt_lPe",
    "Pt_rPe",
    "Pe_Pt",
    "Pe_aPt",
    "Pe_bPt",
    "Pe_nPt",  # t-1p, t-2p
    "t2i",
    "t3i",
    "Pt_le2i",
    "Pt_re2i",
    "Pe_t2i",
    "Pe_at2i",
    "Pe_bt2i",
    "Pe_nt2i",
    "between",  # t-2i, t-3i
    "t2i_NPt",
    "t2i_PtN",
    "Pe_t2i_PtPe_NPt",
    "t2i_N",
    "t3i_N",  # t-npi, t-pni, t-inp, t-2in, t-3in
]
test_query_structures: List[str] = train_query_structures + [
    # entity
    "e2i_Pe",
    "Pe_e2i",  # pi, ip
    "e2u",
    "Pe_e2u",  # 2u, up
    # time
    "t2i_Pe",
    "Pe_t2i",  # t-pi, t-ip
    "t2u",
    "Pe_t2u",  # t-2u, t-up
    # union-DM
    "e2u_DM",
    "Pe_e2u_DM",  # 2u-DM, up-DM
    "t2u_DM",
    "Pe_t2u_DM",  # t-2u-DM, t-up-DM
]


_AUTHOR = "linxy"
_DATASET = "ICEWS05_15"
_URLS = {
    name: hf_hub_url(f"{_AUTHOR}/{_DATASET}", filename=f"zips/{name}.zip", repo_type="dataset")
    for name in ["all"] + list(query_name_to_args.keys())
} | {
    "meta": hf_hub_url(f"{_AUTHOR}/{_DATASET}", filename="meta.json", repo_type="dataset")
}


class ICEWS05_15Dataset(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    STANDARD_BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=query_name,
            version=datasets.Version("1.0.0"),
            description=query_structures[query_name],
        )
        for query_name in list(query_name_to_args.keys())
    ]
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="meta",
            version=VERSION,
            description=f"The meta of data, including entity/relation/timestamp count, entity2idx, relation2idx, timestamp2idx, etc.",
        ),
        datasets.BuilderConfig(
            name="all",
            version=VERSION,
            description=f"All types of queries. Train: {train_query_structures}, Valid | Test: {test_query_structures}",
        ),
    ] + STANDARD_BUILDER_CONFIGS

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

    def _info(self):
        if self.config.name == "meta":
            features = datasets.Features(
                {
                    "dataset": datasets.Value("string"),
                    "entity_count": datasets.Value("int32"),
                    "relation_count": datasets.Value("int32"),
                    "timestamp_count": datasets.Value("int32"),
                    "valid_triples_count": datasets.Value("int32"),
                    "test_triples_count": datasets.Value("int32"),
                    "train_triples_count": datasets.Value("int32"),
                    "triple_count": datasets.Value("int32"),
                    "query_meta": datasets.Sequence(
                        feature={
                            "query_name": datasets.Value("string"),
                            "queries_count": datasets.Value("int32"),
                            "avg_answers_count": datasets.Value("float"),
                            "train": {
                                "queries_count": datasets.Value("int32"),
                                "avg_answers_count": datasets.Value("float"),
                            },
                            "valid": {
                                "queries_count": datasets.Value("int32"),
                                "avg_answers_count": datasets.Value("float"),
                            },
                            "test": {
                                "queries_count": datasets.Value("int32"),
                                "avg_answers_count": datasets.Value("float"),
                            },
                        }
                    ),
                    "entity2idx": datasets.Sequence(
                        feature={
                            "name": datasets.Value("string"),
                            "id": datasets.Value("int32"),
                        }
                    ),
                    "relation2idx": datasets.Sequence(
                        feature={
                            "name": datasets.Value("string"),
                            "id": datasets.Value("int32"),
                        }
                    ),
                    "timestamp2idx": datasets.Sequence(
                        feature={
                            "name": datasets.Value("string"),
                            "id": datasets.Value("int32"),
                        }
                    ),
                }
            )
        else:
            features = datasets.Features(
                {
                    "query_name": datasets.Value("string"),
                    "definition": datasets.Value("string"),
                    "query": datasets.Sequence(feature=datasets.Value("int32")),
                    "answer": datasets.Sequence(feature=datasets.Value("int32")),
                    "easy_answer": datasets.Sequence(feature=datasets.Value("int32")),
                    "args": datasets.Sequence(feature=datasets.Value("string")),
                }
            )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.download.DownloadManager):
        # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
        # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
        # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
        url = _URLS[self.config.name]
        if self.config.name == "meta":
            data_file = dl_manager.download(_URLS["meta"])
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    # These kwargs will be passed to _generate_examples
                    gen_kwargs={
                        "filepath": data_file,
                        "split": "meta",
                    },
                )
            ]
        data_dir = dl_manager.download_and_extract(url)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": os.path.join(data_dir, "train.jsonl"),
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": os.path.join(data_dir, "valid.jsonl"),
                    "split": "valid",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": os.path.join(data_dir, "test.jsonl"),
                    "split": "test",
                },
            ),
        ]

    def _generate_examples(self, filepath, split):
        # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
        # This method yields (key, example) tuples from the dataset.
        # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
        if not os.path.exists(filepath):
            return
        if split == "meta":
            with open(filepath, "r", encoding="utf-8") as f:
                data = json.load(f)
                yield 0, data
            return
        with open(filepath, "r", encoding="utf-8") as f:
            for key, row in enumerate(f):
                data = json.loads(row)
                query_name = data["query_name"]
                easy_answer = data["easy_answer"] if "easy_answer" in data else []
                yield key, {
                    "query_name": query_name,
                    "query": data["query"],
                    "answer": data["answer"],
                    "easy_answer": easy_answer,
                    "args": query_name_to_args[query_name],
                    "definition": query_structures[query_name],
                }