CoolFace
Datasetpublic

openai/gsm8k

Dataset Card for GSM8K Dataset Summary GSM8K (Grade School Math 8K) is a dataset of 8.5K high quality linguistically diverse grade school math word problems. The dataset was created to support the task of question answering on basic mathematical problems that require multi-step reasoning. These problems take between 2 and 8 steps to solve. Solutions primarily involve performing a sequence of elementary calculations using basic arithmetic operations (+ − ×÷) to… See the full description on the dataset page: https://huggingface.co/datasets/openai/gsm8k.

sourceHugging Facemitupdated 6mo agoView on Hugging Face
1.7klikes1.2mdownloads
gsm8k.py136 linesDownload Raw Back to root
1# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Grade School Math 8k dataset."""15 16import json17import textwrap18 19import datasets20 21 22_CITATION = """\23@misc{cobbe2021training,24      title={Training Verifiers to Solve Math Word Problems},25      author={Karl Cobbe and Vineet Kosaraju and Mohammad Bavarian and Jacob Hilton and Reiichiro Nakano and Christopher Hesse and John Schulman},26      year={2021},27      eprint={2110.14168},28      archivePrefix={arXiv},29      primaryClass={cs.LG}30}31"""32 33_DESCRIPTION = """\34GSM8K (Grade School Math 8K) is a dataset of 8.5K high quality35linguistically diverse grade school math word problems. The36dataset was created to support the task of question answering37on basic mathematical problems that require multi-step reasoning.38"""39 40_HOMEPAGE = "https://openai.com/blog/grade-school-math"41 42_LICENSE = "MIT"43 44_BASE_URL = "https://raw.githubusercontent.com/openai/grade-school-math/master/grade_school_math/data/"45 46 47class Gsm8kConfig(datasets.BuilderConfig):48    """BuilderConfig for GSM8K."""49 50    def __init__(self, urls, **kwargs):51        """BuilderConfig for GSM8K.52 53        Args:54        urls: *dict[string]*, the urls for each split of the GSM8k set.55        """56        super().__init__(version=datasets.Version("1.1.0"), **kwargs)57        self.urls = urls58 59 60class Gsm8k(datasets.GeneratorBasedBuilder):61    """Grade School Math 8k (GSM8K)"""62 63    BUILDER_CONFIGS = [64        Gsm8kConfig(65            name="main",66            description=textwrap.dedent(67                """68                It is segmented into 7.5K training problems and 1K test problems.69                These problems take between 2 and 8 steps to solve, and solutions70                primarily involve performing a sequence of elementary calculations71                using basic arithmetic operations (+ - / *) to reach the final72                answer. A bright middle school student should be able to solve73                every problem.74                """,75            ),76            urls={77                "train": _BASE_URL + "train.jsonl",78                "test": _BASE_URL + "test.jsonl",79            },80        ),81        Gsm8kConfig(82            name="socratic",83            description=textwrap.dedent(84                """85                Additionally, there is a modified solution format that injects86                automatically generated "Socratic subquestions" before each step.87                """88            ),89            urls={90                "train": _BASE_URL + "train_socratic.jsonl",91                "test": _BASE_URL + "test_socratic.jsonl",92            },93        ),94    ]95 96    def _info(self):97        features = datasets.Features(98            {99                "question": datasets.Value("string"),100                "answer": datasets.Value("string"),101            }102        )103        return datasets.DatasetInfo(104            description=_DESCRIPTION,105            features=features,106            homepage=_HOMEPAGE,107            license=_LICENSE,108            citation=_CITATION,109        )110 111    def _split_generators(self, dl_manager):112        data_dir = dl_manager.download_and_extract(self.config.urls)113        return [114            datasets.SplitGenerator(115                name=datasets.Split.TRAIN,116                gen_kwargs={117                    "filepath": data_dir["train"],118                },119            ),120            datasets.SplitGenerator(121                name=datasets.Split.TEST,122                gen_kwargs={123                    "filepath": data_dir["test"],124                },125            ),126        ]127 128    def _generate_examples(self, filepath):129        with open(filepath, encoding="utf-8") as f:130            for key, row in enumerate(f):131                data = json.loads(row)132                yield key, {133                    "question": data["question"],134                    "answer": data["answer"],135                }136