File size: 6,588 Bytes
0c414d3 |
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# 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.
"""LILA: A Unified Benchmark for Mathematical Reasoning
Loading script author: Sean Welleck
"""
import json
import os
import datasets
_CITATION = """\
@INPROCEEDINGS{Mishra2022Lila,
author = {
Swaroop Mishra
and Matthew Finlayson
and Pan Lu
and Leonard Tang
and Sean Welleck
and Chitta Baral
and Tanmay Rajpurohit
and Oyvind Tafjord
and Ashish Sabharwal
and Peter Clark
and Ashwin Kalyan},
title = {Lila: A Unified Benchmark for Mathematical Reasoning},
booktitle = {Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
year = {2022}
}
"""
_DESCRIPTION = """\
Līla is a comprehensive benchmark for mathematical reasoning with over 140K natural language questions annotated with Python programs and natural language instructions. The data set comes with multiple splits: Līla-IID (train, dev, test), Līla-OOD (train, dev, test), and Līla-Robust.
"""
_HOMEPAGE = "https://lila.apps.allenai.org/"
_LICENSE = "Creative Commons Attribution 4.0 International"
_URL = "https://github.com/allenai/Lila/raw/b81117ac7e56cc1dfb0fcabf0005d1755177252b/lila.zip"
_BASEDIR = 'lila'
_MULTIDIR = 'multi'
_ALLDIR = 'all'
_NAMES = [
'iid',
'ood',
'addsub',
'amps_algebra',
'amps_calculus',
'amps_counting_and_stats',
'amps_geometry',
'amps_linear_algebra',
'amps_number_theory',
'APPS_structured',
'asdiv',
'conala_structured',
'deepmind_mathematics_algebra',
'deepmind_mathematics_basicmath',
'deepmind_mathematics_calculus',
'deepmind_mathematics_muldiv',
'deepmind_mathematics_numbertheory',
'dolphin_t2_final',
'draw_structured',
'GSM8k_structured',
'MATH_algebra_crowdsourced',
'MATH_counting_and_probability_crowdsourced',
'MATH_intermediate_algebra_crowdsourced',
'mathqa_gain',
'mathqa_general',
'mathqa_geometry',
'mathqa_other',
'mathqa_physics',
'mathqa_probability',
'mbpp_structured',
'MCTaco_event_duration_structured',
'MCTaco_event_ordering_structured',
'MCTaco_event_typical_time_structured',
'MCTaco_frequency_structured',
'MCTaco_stationarity_structured',
'multiarith',
'Numersense_structured',
'NumGLUE_Type_1_crowdsourced',
'NumGLUE_Type_2_crowdsourced',
'NumGLUE_Type_3_crowdsourced',
'NumGLUE_Type_4_crowdsourced',
'NumGLUE_Type_5_crowdsourced',
'NumGLUE_Type_6_crowdsourced',
'NumGLUE_Type_7_crowdsourced',
'NumGLUE_Type_8_crowdsourced',
'simuleq',
'singleop',
'singleq',
'svamp_structured'
]
VERSION = "1.1.0"
class Lila(datasets.GeneratorBasedBuilder):
"""Lila: A Unified Benchmark for Mathematical Reasoning"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(name=name, version=VERSION, description=name) for name in _NAMES
]
DEFAULT_CONFIG_NAME = "iid"
def _info(self):
features = datasets.Features(
{
"input": datasets.Value("string"),
"output_program": datasets.Value("string"),
"output_answer": datasets.Value("string"),
"split": datasets.Value("string"),
"dataset": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URL
data_dir = dl_manager.download_and_extract(urls)
if self.config.name in {'iid', 'ood'}:
train_filepath = os.path.join(data_dir, _BASEDIR, _MULTIDIR, self.config.name, "train.json")
dev_filepath = os.path.join(data_dir, _BASEDIR, _MULTIDIR, self.config.name, "dev.json")
test_filepath = os.path.join(data_dir, _BASEDIR, _MULTIDIR, self.config.name, "test.json")
else:
train_filepath = os.path.join(data_dir, _BASEDIR, _ALLDIR, self.config.name + ".json")
dev_filepath = train_filepath
test_filepath = train_filepath
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": train_filepath,
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": dev_filepath,
"split": "dev",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": test_filepath,
"split": "test"
},
),
]
def _generate_examples(self, filepath, split):
if self.config.name in {"iid", "ood"}:
with open(filepath) as f:
for key, row in enumerate(f.readlines()):
data = json.loads(row)
yield key, {
"input": data["Input"],
"output_program": data["Output Program"][0],
"output_answer": data["Output Answer"][0],
"split": data["split"],
"dataset": data["dataset"],
}
else:
for key, data in enumerate(json.load(open(filepath))["Instances"]):
if data['split'] == split:
yield key, {
"input": data["Input"],
"output_program": data["Output Program"][0],
"output_answer": data["Output Answer"][0],
"split": data["split"],
"dataset": self.config.name,
}
|