minif2f_isabelle / minif2f_isabelle.py
wellecks's picture
minif2f isabelle
e18a867
# 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.
"""MiniF2F+Informal in Isabelle
Loading script author: Sean Welleck
"""
import re
import glob
import json
import os
import datasets
from pathlib import Path
_CITATION = """\
@inproceedings{jiang2023draft,
title={Draft, Sketch, and Prove: Guiding Formal Theorem Provers with Informal Proofs},
author={Albert Qiaochu Jiang and Sean Welleck and Jin Peng Zhou and Timothee Lacroix and Jiacheng Liu and Wenda Li and Mateja Jamnik and Guillaume Lample and Yuhuai Wu},
booktitle={The Eleventh International Conference on Learning Representations },
year={2023},
url={https://openreview.net/forum?id=SMa9EAovKMC}
}
@inproceedings{zheng2022miniff,
title={miniF2F: a cross-system benchmark for formal Olympiad-level mathematics},
author={Kunhao Zheng and Jesse Michael Han and Stanislas Polu},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=9ZPegFuFTFv}
}
"""
_DESCRIPTION = """\
MiniF2F is a formal mathematics benchmark (translated across multiple formal systems) consisting of exercise statements from olympiads (AMC, AIME, IMO) as well as high-school and undergraduate maths classes.
This dataset contains formal statements in Isabelle. Each statement is paired with an informal statement and
an informal proof, as described in Draft, Sketch, Prove [Jiang et al 2023].
The problems in this dataset use the most recent facebookresearch/miniF2F commit on July 3, 2023.
"""
_HOMEPAGE = "https://github.com/facebookresearch/miniF2F"
_LICENSE = "MIT"
_MINIF2F_COMMIT = '5271ddec788677c815cf818a06f368ef6498a106'
_URLS = {
"minif2f_repo": "https://github.com/facebookresearch/miniF2F/archive/%s.zip" % _MINIF2F_COMMIT
}
_ISABELLEDIR = 'miniF2F-%s/isabelle' % _MINIF2F_COMMIT
_INFORMALDIR = 'miniF2F-%s/informal' % _MINIF2F_COMMIT
_NAMES = [
'miniF2F-isabelle-informal',
]
VERSION = "1.1.0"
class MiniF2F(datasets.GeneratorBasedBuilder):
"""MiniF2F+Informal in Isabelle"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(name=name, version=VERSION, description=name) for name in _NAMES
]
DEFAULT_CONFIG_NAME = "miniF2F-isabelle-informal"
def _info(self):
features = datasets.Features(
{
"problem_name": datasets.Value("string"),
"formal_statement": datasets.Value("string"),
"informal_statement": datasets.Value("string"),
"informal_proof": datasets.Value("string"),
"header": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URLS
data_dir = dl_manager.download_and_extract(urls)
minif2f_repo_dir = data_dir['minif2f_repo']
def extract_theorem(text):
extract = re.findall(r"(theorem.*?:.*?(?=by |using |proof|sorry))[\s]*", text, re.DOTALL)[0].strip()
assert extract != ''
return extract
def extract_header(text):
extract = re.findall(r"(.*?)theorem.*?", text, re.DOTALL)[0]
assert extract != ''
return extract
splits = {'valid': [], 'test': []}
for split in ['valid', 'test']:
for f in glob.glob(
os.path.join(minif2f_repo_dir, _ISABELLEDIR, '%s/*.thy' % split)
):
text = open(f).read()
name = Path(f).name.replace('.thy', '')
thm = extract_theorem(text)
header = extract_header(text)
informal = json.load(open(
os.path.join(minif2f_repo_dir, _INFORMALDIR, '%s/%s.json' % (split, name))
))
splits[split].append({
'problem_name': name,
'formal_statement': thm,
'informal_statement': informal['informal_statement'],
'informal_proof': informal['informal_proof'],
'header': header
})
assert len(splits['valid']) == 244
assert len(splits['test']) == 244
return [
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"split": "valid",
"examples": splits['valid']
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"split": "test",
"examples": splits['test']
},
),
]
def _generate_examples(self, split, examples):
for example in examples:
key = example["problem_name"]
yield key, example