|
import csv |
|
import json |
|
import os |
|
import datasets |
|
|
|
_CITATION = """\ |
|
@inproceedings{cs_restaurants, |
|
address = {Tokyo, Japan}, |
|
title = {Neural {Generation} for {Czech}: {Data} and {Baselines}}, |
|
shorttitle = {Neural {Generation} for {Czech}}, |
|
url = {https://www.aclweb.org/anthology/W19-8670/}, |
|
urldate = {2019-10-18}, |
|
booktitle = {Proceedings of the 12th {International} {Conference} on {Natural} {Language} {Generation} ({INLG} 2019)}, |
|
author = {Dušek, Ondřej and Jurčíček, Filip}, |
|
month = oct, |
|
year = {2019}, |
|
pages = {563--574}, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The task is generating responses in the context of a (hypothetical) dialogue |
|
system that provides information about restaurants. The input is a basic |
|
intent/dialogue act type and a list of slots (attributes) and their values. |
|
The output is a natural language sentence. |
|
""" |
|
|
|
_URLs = { |
|
"train": "https://raw.githubusercontent.com/UFAL-DSG/cs_restaurant_dataset/master/train.json", |
|
"validation": "https://raw.githubusercontent.com/UFAL-DSG/cs_restaurant_dataset/master/devel.json", |
|
"test": "https://raw.githubusercontent.com/UFAL-DSG/cs_restaurant_dataset/master/test.json", |
|
"challenge_set": "https://storage.googleapis.com/huggingface-nlp/datasets/gem/gem_challenge_sets/cs_restaurants.zip", |
|
} |
|
|
|
|
|
class CSRestaurants(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
DEFAULT_CONFIG_NAME = "cs_restaurants" |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"gem_id": datasets.Value("string"), |
|
"gem_parent_id": datasets.Value("string"), |
|
"dialog_act": datasets.Value("string"), |
|
"dialog_act_delexicalized": datasets.Value("string"), |
|
"target_delexicalized": datasets.Value("string"), |
|
"target": datasets.Value("string"), |
|
"references": [datasets.Value("string")], |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=datasets.info.SupervisedKeysData( |
|
input="dialog_act", output="target" |
|
), |
|
homepage="https://github.com/UFAL-DSG/cs_restaurant_dataset", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
dl_dir = dl_manager.download_and_extract(_URLs) |
|
challenge_sets = [ |
|
("challenge_train_sample", "train_cs_restaurants_RandomSample500.json"), |
|
( |
|
"challenge_validation_sample", |
|
"validation_cs_restaurants_RandomSample500.json", |
|
), |
|
( |
|
"challenge_test_scramble", |
|
"test_cs_restaurants_ScrambleInputStructure500.json", |
|
), |
|
] |
|
return [ |
|
datasets.SplitGenerator( |
|
name=spl, gen_kwargs={"filepath": dl_dir[spl], "split": spl} |
|
) |
|
for spl in ["train", "validation", "test"] |
|
] + [ |
|
datasets.SplitGenerator( |
|
name=challenge_split, |
|
gen_kwargs={ |
|
"filepath": os.path.join( |
|
dl_dir["challenge_set"], "cs_restaurants", filename |
|
), |
|
"split": challenge_split, |
|
}, |
|
) |
|
for challenge_split, filename in challenge_sets |
|
] |
|
|
|
def _generate_examples(self, filepath, split, filepaths=None, lang=None): |
|
"""Yields examples.""" |
|
if split.startswith("challenge"): |
|
exples = json.load(open(filepath, encoding="utf-8")) |
|
if isinstance(exples, dict): |
|
assert len(exples) == 1, "multiple entries found" |
|
exples = list(exples.values())[0] |
|
for id_, exple in enumerate(exples): |
|
if len(exple) == 0: |
|
continue |
|
exple["gem_parent_id"] = exple["gem_id"] |
|
exple["gem_id"] = f"cs_restaurants-{split}-{id_}" |
|
yield id_, exple |
|
else: |
|
with open(filepath, encoding="utf8") as f: |
|
data = json.load(f) |
|
for id_, instance in enumerate(data): |
|
yield id_, { |
|
"gem_id": f"cs_restaurants-{split}-{id_}", |
|
"gem_parent_id": f"cs_restaurants-{split}-{id_}", |
|
"dialog_act": instance["da"], |
|
"dialog_act_delexicalized": instance["delex_da"], |
|
"target": instance["text"], |
|
"target_delexicalized": instance["delex_text"], |
|
"references": [] if split == "train" else [instance["text"]], |
|
} |
|
|