Datasets:
GEM
/

Tasks:
Other
Modalities:
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
File size: 2,770 Bytes
71d6f36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35f183d
 
71d6f36
 
 
 
 
 
 
 
 
35f183d
 
71d6f36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35f183d
 
71d6f36
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
import json
import os

import datasets


_CITATION = """\
@InProceedings{anli,
  author = {Chandra, Bhagavatula and Ronan, Le Bras and Chaitanya, Malaviya and Keisuke, Sakaguchi and Ari, Holtzman
    and Hannah, Rashkin and Doug, Downey and Scott, Wen-tau Yih and Yejin, Choi},
  title = {Abductive Commonsense Reasoning},
  year = {2020}
}"""

_DESCRIPTION = """\
the Abductive Natural Language Generation Dataset from AI2
"""
_DATA_URL = "https://storage.googleapis.com/ai2-mosaic/public/abductive-commonsense-reasoning-iclr2020/anlg.zip"
_HOMEPAGE = "https://github.com/allenai/abductive-commonsense-reasoning"

class ArtConfig(datasets.BuilderConfig):
    """BuilderConfig for Art."""

    def __init__(self, **kwargs):
        """BuilderConfig for Art.
        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(ArtConfig, self).__init__(version=datasets.Version("0.1.0", ""), **kwargs)


class Art(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("0.1.1")
    DEFAULT_CONFIG_NAME = "anlg"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "gem_id": datasets.Value("string"),
                    "observation_1": datasets.Value("string"),
                    "observation_2": datasets.Value("string"),
                    "target": datasets.Value("string"),
                    "references": [datasets.Value("string")],
                }
            ),
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        ds_splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
        splits = ["train", "dev", "test"]
        dl_dir = dl_manager.download_and_extract(_DATA_URL)

        return [
            datasets.SplitGenerator(
                name=ds_split,
                gen_kwargs={
                    "filepath": os.path.join(dl_dir, "anlg", f"{split}-w-comet-preds.jsonl"),
                    "split": split if split != "dev" else "validation" # adheres to GEM naming conventions
                },
            ) for ds_split, split in zip(ds_splits, splits)
        ]

    def _generate_examples(self, filepath, split):
        with open(filepath, "r", encoding="utf-8") as f:
            data = [json.loads(line) for line in f.readlines()]

        for idx, row in enumerate(data):
            label = row[f"hyp{row['label']}"]
            yield idx, {
                "gem_id": f"GEM-ART-{split}-{idx}",
                "observation_1": row["obs1"],
                "observation_2": row["obs2"],
                "target": label,
                "references": [label],
            }