Datasets:
GEM
/

Tasks:
Other
Modalities:
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
ndaheim commited on
Commit
71d6f36
1 Parent(s): 93aadc4

adds first dataloader

Browse files
Files changed (1) hide show
  1. art.py +84 -0
art.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import datasets
5
+
6
+
7
+ _CITATION = """\
8
+ @InProceedings{anli,
9
+ author = {Chandra, Bhagavatula and Ronan, Le Bras and Chaitanya, Malaviya and Keisuke, Sakaguchi and Ari, Holtzman
10
+ and Hannah, Rashkin and Doug, Downey and Scott, Wen-tau Yih and Yejin, Choi},
11
+ title = {Abductive Commonsense Reasoning},
12
+ year = {2020}
13
+ }"""
14
+
15
+ _DESCRIPTION = """\
16
+ the Abductive Natural Language Generation Dataset from AI2
17
+ """
18
+ _DATA_URL = "https://storage.googleapis.com/ai2-mosaic/public/abductive-commonsense-reasoning-iclr2020/anlg.zip"
19
+ _HOMEPAGE = "https://github.com/allenai/abductive-commonsense-reasoning"
20
+
21
+ class ArtConfig(datasets.BuilderConfig):
22
+ """BuilderConfig for Art."""
23
+
24
+ def __init__(self, **kwargs):
25
+ """BuilderConfig for Art.
26
+ Args:
27
+ **kwargs: keyword arguments forwarded to super.
28
+ """
29
+ super(ArtConfig, self).__init__(version=datasets.Version("0.1.0", ""), **kwargs)
30
+
31
+
32
+ class Art(datasets.GeneratorBasedBuilder):
33
+ VERSION = datasets.Version("0.1.0")
34
+ BUILDER_CONFIGS = [
35
+ ArtConfig(
36
+ name="anlg",
37
+ description="""\
38
+ Abductive Natural Language Generation Dataset from AI2.
39
+ """,
40
+ ),
41
+ ]
42
+
43
+ def _info(self):
44
+ return datasets.DatasetInfo(
45
+ description=_DESCRIPTION,
46
+ features=datasets.Features(
47
+ {
48
+ "gem_id": datasets.Value("string"),
49
+ "observation_1": datasets.Value("string"),
50
+ "observation_2": datasets.Value("string"),
51
+ "label": datasets.Value("string"),
52
+ }
53
+ ),
54
+ homepage=_HOMEPAGE,
55
+ citation=_CITATION,
56
+ )
57
+
58
+ def _split_generators(self, dl_manager):
59
+ ds_splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
60
+ splits = ["train", "dev", "test"]
61
+ dl_dir = dl_manager.download_and_extract(_DATA_URL)
62
+
63
+ return [
64
+ datasets.SplitGenerator(
65
+ name=ds_split,
66
+ gen_kwargs={
67
+ "filepath": os.path.join(dl_dir, "anlg", f"{split}-w-comet-preds.jsonl"),
68
+ "split": split if split != "dev" else "validation" # adheres to GEM naming conventions
69
+ },
70
+ ) for ds_split, split in zip(ds_splits, splits)
71
+ ]
72
+
73
+ def _generate_examples(self, filepath, split):
74
+ with open(filepath, "r", encoding="utf-8") as f:
75
+ data = [json.loads(line) for line in f.readlines()]
76
+
77
+ for idx, row in enumerate(data):
78
+ label = row[f"hyp{row['label']}"]
79
+ yield idx, {
80
+ "gem_id": f"GEM-ART-{split}-{idx}",
81
+ "observation_1": row["obs1"],
82
+ "observation_2": row["obs2"],
83
+ "label": label,
84
+ }