|
"""MCoNaLa dataset.""" |
|
|
|
import json |
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@article{wang2022mconala, |
|
title={MCoNaLa: A Benchmark for Code Generation from Multiple Natural Languages}, |
|
author={Zhiruo Wang, Grace Cuenca, Shuyan Zhou, Frank F. Xu, Graham Neubig}, |
|
journal={arXiv preprint arXiv:2203.08388}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
MCoNaLa is a Multilingual Code/Natural Language Challenge dataset with |
|
896 NL-Code pairs in three languages: Spanish, Japanese, and Russian. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/zorazrw/multilingual-conala" |
|
_URLs = { |
|
"es": "es_test.json", |
|
"ja": "ja_test.json", |
|
"ru": "ru_test.json", |
|
} |
|
|
|
class MCoNaLa(datasets.GeneratorBasedBuilder): |
|
"""MCoNaLa NL-to-Code dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name=lang, |
|
version=datasets.Version("1.0.0"), |
|
description=_DESCRIPTION, |
|
) for lang in _URLs.keys() |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "en" |
|
|
|
|
|
def _info(self): |
|
features = datasets.Features({"question_id": datasets.Value("int64"), |
|
"intent": datasets.Value("string"), |
|
"rewritten_intent": datasets.Value("string"), |
|
"snippet": datasets.Value("string"), |
|
}) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
citation=_CITATION, |
|
homepage=_HOMEPAGE) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
config_urls = _URLs[self.config.name] |
|
data_dir = dl_manager.download_and_extract(config_urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": data_dir, "split": "train"}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
key = 0 |
|
for line in open(filepath, encoding="utf-8"): |
|
line = json.loads(line) |
|
yield key, line |
|
key += 1 |