Datasets:
Tasks:
Text2Text Generation
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10K - 100K
ArXiv:
Tags:
explanation-generation
License:
Upload MATH-lighteval.py
Browse files- MATH-lighteval.py +114 -0
MATH-lighteval.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Mathematics Aptitude Test of Heuristics (MATH) dataset, lighteval format with correct builder configs."""
|
2 |
+
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
|
7 |
+
from datasets import load_dataset, Dataset, DatasetDict, GeneratorBasedBuilder, BuilderConfig, DatasetInfo, Value, Features, Split, SplitGenerator, Version
|
8 |
+
|
9 |
+
|
10 |
+
_CITATION = """\
|
11 |
+
@article{hendrycksmath2021,
|
12 |
+
title={Measuring Mathematical Problem Solving With the MATH Dataset},
|
13 |
+
author={Dan Hendrycks
|
14 |
+
and Collin Burns
|
15 |
+
and Saurav Kadavath
|
16 |
+
and Akul Arora
|
17 |
+
and Steven Basart
|
18 |
+
and Eric Tang
|
19 |
+
and Dawn Song
|
20 |
+
and Jacob Steinhardt},
|
21 |
+
journal={arXiv preprint arXiv:2103.03874},
|
22 |
+
year={2021}
|
23 |
+
}
|
24 |
+
"""
|
25 |
+
|
26 |
+
|
27 |
+
_DESCRIPTION = """\
|
28 |
+
The Mathematics Aptitude Test of Heuristics (MATH) dataset consists of problems
|
29 |
+
from mathematics competitions, including the AMC 10, AMC 12, AIME, and more.
|
30 |
+
Each problem in MATH has a full step-by-step solution, which can be used to teach
|
31 |
+
models to generate answer derivations and explanations. This version of the dataset
|
32 |
+
includes appropriate builder configs s.t. it can be used as a drop-in replacement
|
33 |
+
for the now missing lighteval/MATH dataset.
|
34 |
+
"""
|
35 |
+
|
36 |
+
|
37 |
+
_HOMEPAGE = "https://github.com/hendrycks/math"
|
38 |
+
|
39 |
+
|
40 |
+
_LICENSE = "https://github.com/hendrycks/math/blob/main/LICENSE"
|
41 |
+
|
42 |
+
|
43 |
+
# Original data URL: "https://people.eecs.berkeley.edu/~hendrycks/MATH.tar"
|
44 |
+
_URL = "data/MATH.zip"
|
45 |
+
|
46 |
+
|
47 |
+
class FilteredTypeConfig(BuilderConfig):
|
48 |
+
def __init__(self, type_value, type_name, **kwargs):
|
49 |
+
super().__init__(**kwargs)
|
50 |
+
self.type_value = type_value
|
51 |
+
self.type_name = type_name
|
52 |
+
|
53 |
+
class FilteredTypeDatasetBuilder(GeneratorBasedBuilder):
|
54 |
+
"""Mathematics Aptitude Test of Heuristics (MATH) dataset."""
|
55 |
+
|
56 |
+
VERSION = Version("1.0.0")
|
57 |
+
|
58 |
+
BUILDER_CONFIGS = [FilteredTypeConfig(
|
59 |
+
name="default",
|
60 |
+
version="1.0.0",
|
61 |
+
description=f"default builder config",
|
62 |
+
type_name="default", # for builder config
|
63 |
+
type_value="default", # in original dataset
|
64 |
+
)] + [
|
65 |
+
FilteredTypeConfig(
|
66 |
+
name=type_name,
|
67 |
+
version="1.0.0",
|
68 |
+
description=f"Dataset filtered by type: {type_value}",
|
69 |
+
type_name=type_name, # for builder config
|
70 |
+
type_value=type_value, # in original dataset
|
71 |
+
)
|
72 |
+
for type_name, type_value in [("algebra", "Algebra"), ("counting_and_probability", "Counting & Probability"), ("geometry", "Geometry"), ("intermediate_algebra", "Intermediate Algebra"), ("number_theory", "Number Theory"), ("prealgebra", "Prealgebra"), ("precalculus", "Precalculus")]
|
73 |
+
]
|
74 |
+
|
75 |
+
def _info(self):
|
76 |
+
return DatasetInfo(
|
77 |
+
description=_DESCRIPTION,
|
78 |
+
features=Features({
|
79 |
+
"problem": Value("string"),
|
80 |
+
"level": Value("string"),
|
81 |
+
"solution": Value("string"),
|
82 |
+
"type": Value("string"),
|
83 |
+
}),
|
84 |
+
supervised_keys=None,
|
85 |
+
homepage=_HOMEPAGE,
|
86 |
+
license=_LICENSE,
|
87 |
+
citation=_CITATION
|
88 |
+
)
|
89 |
+
|
90 |
+
def _split_generators(self, dl_manager):
|
91 |
+
"""Returns SplitGenerators."""
|
92 |
+
download_dir = dl_manager.download_and_extract(_URL)
|
93 |
+
return [
|
94 |
+
SplitGenerator(
|
95 |
+
name=Split.TRAIN,
|
96 |
+
gen_kwargs={"data_dir": dl_manager.iter_files(os.path.join(download_dir, "MATH", "train"))},
|
97 |
+
),
|
98 |
+
SplitGenerator(
|
99 |
+
name=Split.TEST,
|
100 |
+
gen_kwargs={"data_dir": dl_manager.iter_files(os.path.join(download_dir, "MATH", "test"))},
|
101 |
+
),
|
102 |
+
]
|
103 |
+
|
104 |
+
def _generate_examples(self, data_dir):
|
105 |
+
type_value = self.config.type_value # Access the type value for the current config
|
106 |
+
|
107 |
+
"""Yields examples as (key, example) tuples. Filters by type if appropriate builder config is given."""
|
108 |
+
for id_, filepath in enumerate(data_dir):
|
109 |
+
with open(filepath, "rb") as fin:
|
110 |
+
example = json.load(fin)
|
111 |
+
if type_value == "default" or example["type"] == type_value:
|
112 |
+
yield id_, example
|
113 |
+
|
114 |
+
|