"""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, Russian. """ _HOMEPAGE = "https://github.com/zorazrw/multilingual-conala" _URLs = { "es": "es_test.jsonl", "ja": "ja_test.jsonl", "ru": "ru_test.jsonl", } 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({"task_id": datasets.Value("int64"), "prompt": datasets.Value("string"), "suffix": datasets.Value("string"), "canonical_solution": datasets.Value("string"), "test_start": datasets.Value("string"), "test": datasets.Sequence(datasets.Value("string")), "entry_point": datasets.Value("string"), "intent": datasets.Value("string"), "library": datasets.Sequence(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