Datasets:
Tasks:
Text2Text Generation
Modalities:
Text
Size:
1K - 10K
ArXiv:
Tags:
math-word-problems
License:
File size: 5,081 Bytes
c75be70 f52417c c75be70 f52417c c75be70 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Multilingual Grade School Math Benchmark (MGSM)"""
import csv
from .exemplars import (
EXEMPLAR_NUMBER_ANSWERS,
EXEMPLAR_EQUATION_SOLUTIONS,
MGSM_EXEMPLARS,
)
import datasets
_CITATION = """\
@article{cobbe2021gsm8k,
title={Training Verifiers to Solve Math Word Problems},
author={Cobbe, Karl and Kosaraju, Vineet and Bavarian, Mohammad and Chen, Mark and Jun, Heewoo and Kaiser, Lukasz and Plappert, Matthias and Tworek, Jerry and Hilton, Jacob and Nakano, Reiichiro and Hesse, Christopher and Schulman, John},
journal={arXiv preprint arXiv:2110.14168},
year={2021}
}
@misc{shi2022language,
title={Language Models are Multilingual Chain-of-Thought Reasoners},
author={Freda Shi and Mirac Suzgun and Markus Freitag and Xuezhi Wang and Suraj Srivats and Soroush Vosoughi and Hyung Won Chung and Yi Tay and Sebastian Ruder and Denny Zhou and Dipanjan Das and Jason Wei},
year={2022},
eprint={2210.03057},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""
_DESCRIPTION = """\
Multilingual Grade School Math Benchmark (MGSM) is a benchmark of grade-school math problems, proposed in the paper [Language models are multilingual chain-of-thought reasoners](http://arxiv.org/abs/2210.03057).
The same 250 problems from [GSM8K](https://arxiv.org/abs/2110.14168) are each translated via human annotators in 10 languages. The 10 languages are:
- Spanish
- French
- German
- Russian
- Chinese
- Japanese
- Thai
- Swahili
- Bengali
- Telugu
You can find the input and targets for each of the ten languages (and English) as `.tsv` files.
We also include few-shot exemplars that are also manually translated from each language in `exemplars.py`.
"""
_HOMEPAGE = "https://github.com/google-research/url-nlp/tree/main/mgsm"
_LICENSE = "CC BY SA 4.0"
_BASE_URL = "mgsm_{lang}.tsv"
_LANG = ["en", "es", "fr", "de", "ru", "zh", "ja", "th", "sw", "bn", "te"]
class MGSM(datasets.GeneratorBasedBuilder):
"""Multilingual Grade School Math Benchmark (MGSM)"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=lang,
description="Multilingual Grade School Math Benchmark (MGSM) {lang} set",
version=datasets.Version("1.0.0"),
)
for lang in _LANG
]
def _info(self):
features = datasets.Features(
{
"question": datasets.Value("string"),
"answer": datasets.Value("string"),
"answer_number": datasets.Value("int32"),
"equation_solution": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
name = self.config.name
filepaths = dl_manager.download_and_extract(
{
datasets.Split.TRAIN: "exemplars.py",
datasets.Split.TEST: _BASE_URL.format(lang=name),
}
)
return [
datasets.SplitGenerator(
name=split,
gen_kwargs={"filepath": path},
)
for split, path in filepaths.items()
]
def _generate_examples(self, filepath):
if filepath.endswith(".py"):
name = self.config.name
examples = MGSM_EXEMPLARS[name]
number_answers = EXEMPLAR_NUMBER_ANSWERS
equation_solutions = EXEMPLAR_EQUATION_SOLUTIONS
for key, data in examples.items():
yield key, {
"question": data["q"],
"answer": data["a"],
"answer_number": number_answers[int(key) - 1],
"equation_solution": equation_solutions[int(key) - 1],
}
else:
with open(filepath, encoding="utf-8") as csv_file:
csv_reader = csv.reader(
csv_file,
quotechar='"',
delimiter="\t",
)
for key, row in enumerate(csv_reader):
yield key, {
"question": row[0],
"answer": None,
"answer_number": int(row[1].replace(",", "")),
"equation_solution": None,
}
|