Datasets:

Modalities:
Text
Libraries:
Datasets
License:
lila / lila.py
wellecks's picture
Simplify loading and define configs via loading script.
0c414d3
raw
history blame
6.59 kB
# 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,
}