# 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" _HOMEPAGE = "https://github.com/xyc-cs/miniF2F" _LICENSE = "MIT" #_MINIF2F_COMMIT = 'bfb337d6848c81baab18bb3d4e9f80625ed63d5d' # single_json: 0826c5173d8b2ef67c616a8170240034094837d6 _MINIF2F_COMMIT = '0826c5173d8b2ef67c616a8170240034094837d6' _URLS = { "minif2f_repo": "https://github.com/xyc-cs/miniF2F/archive/%s.zip" % _MINIF2F_COMMIT #https://github.com/xyc-cs/miniF2F/archive/5271ddec788677c815cf818a06f368ef6498a106.zip } _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_discuss": 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 != '' extract = '' return extract def extract_header(text): # extract = re.findall(r"(.*?)theorem.*?", text, re.DOTALL)[0] # assert extract != '' extract = '' return extract splits = {'valid': [], 'test': []} for split in ['valid', 'test']: for f in glob.glob( os.path.join(minif2f_repo_dir, _ISABELLEDIR, '%s/*.json' % split) ): text = open(f).read() name = Path(f).name.replace('.json', '') 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_discuss': informal['informal_discuss'] #'header': header }) #assert len(splits['valid']) == 5 #assert len(splits['test']) == 5 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