|
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" |
|
}, |
|
) 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], |
|
} |