| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import json |
| import os |
|
|
| import datasets |
|
|
|
|
|
|
| _CITATION = """\ |
| @article{kim2023cot, |
| title={The CoT Collection: Improving Zero-shot and Few-shot Learning of Language Models via Chain-of-Thought Fine-Tuning}, |
| author={Kim, Seungone and Joo, Se June and Kim, Doyoung and Jang, Joel and Ye, Seonghyeon and Shin, Jamin and Seo, Minjoon}, |
| journal={arXiv preprint arXiv:2305.14045}, |
| year={2023} |
| } |
| """ |
|
|
| _DESCRIPTION = """""" |
|
|
| _LICENSE = "CC BY 4.0" |
|
|
| _HOMEPAGE = "https://github.com/kaistAI/CoT-Collection" |
|
|
| _LANGUAGES = { |
| "en": "English", |
| } |
| |
|
|
|
|
|
|
| class CoTCollectionMultiConfig(datasets.BuilderConfig): |
| """BuilderConfig for CoTCollectionMultiConfig.""" |
|
|
| def __init__(self, languages=None, **kwargs): |
| super(CoTCollectionMultiConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs), |
| self.languages = languages |
|
|
|
|
| class CoTCollection(datasets.GeneratorBasedBuilder): |
|
|
| BUILDER_CONFIGS = [ |
| CoTCollectionMultiConfig( |
| name=lang, |
| languages=[lang], |
| description=f"{_LANGUAGES[lang]} CoT-Collection data used in the paper 'The CoT Collection: Improving Zero-shot and Few-shot Learning of Language Models via Chain-of-Thought Fine-Tuning'", |
| ) |
| for lang in _LANGUAGES |
| ] |
| BUILDER_CONFIG_CLASS = CoTCollectionMultiConfig |
| DEFAULT_CONFIG_NAME = "en" |
|
|
|
|
| def _info(self): |
| features = datasets.Features( |
| { |
| "source": datasets.Value("string"), |
| "target": datasets.Value("string"), |
| "rationale": datasets.Value("string"), |
| "task": datasets.Value("string"), |
| "type": datasets.Value("string"), |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| homepage=_HOMEPAGE, |
| citation=_CITATION, |
| license=_LICENSE, |
| ) |
|
|
|
|
| def _split_generators(self, dl_manager): |
| train_PATHS = [f"./data/CoT_collection_{lang}.json" for lang in self.config.languages] |
|
|
| train_paths = dl_manager.download_and_extract(train_PATHS) |
|
|
| return [ |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_paths}) |
| ] |
|
|
| def _generate_examples(self, filepath): |
| for _file in filepath: |
| with open(_file, "r", encoding="utf-8") as fi: |
| data = json.load(fi) |
| buffer = [] |
| for idx, value in data.items(): |
| if 'rationale' in value.keys(): |
| buffer.append({ |
| 'source': value['source'], |
| 'target': value['target'], |
| 'rationale': value['rationale'], |
| 'task': value['task'], |
| 'type': 'CoT' |
| }) |
| else: |
| value['rationale'] = '' |
| buffer.append({ |
| 'source': value['source'], |
| 'target': value['target'], |
| 'rationale': value['rationale'], |
| 'task': value['task'], |
| 'type': 'Direct', |
| }) |
| |
|
|
| for idx,dat in enumerate(buffer): |
| yield idx, dat |
| |
|
|