Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
Download fetch_math_dataset.py from hoskinson-center/proof-pile: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/hoskinson-center/proof-pile/resolve/8b71b6b38e0e5e7158e87f7cb2ce1431ad6cbf23/fetch_math_dataset.py
- Command line
-
hf download hf://datasets/hoskinson-center/proof-pile@8b71b6b38e0e5e7158e87f7cb2ce1431ad6cbf23/fetch_math_dataset.py
-
curl -L -o fetch_math_dataset.py https://huggingface.co/datasets/hoskinson-center/proof-pile/resolve/8b71b6b38e0e5e7158e87f7cb2ce1431ad6cbf23/fetch_math_dataset.py
1.55 kB
| import os | |
| import sys | |
| import json | |
| from pathlib import Path | |
| from fetch_mathoverflow import batch_loader | |
| ARCHIVE_URL = "https://people.eecs.berkeley.edu/~hendrycks/MATH.tar" | |
| SAVE_PATH = "math-dataset" | |
| def main(): | |
| Path(SAVE_PATH).mkdir(exist_ok=True) | |
| archive_path = os.path.join(SAVE_PATH, "archive.tar") | |
| os.system("wget -O " + archive_path + " " + ARCHIVE_URL) | |
| os.system("tar -xf " + archive_path + " -C " + SAVE_PATH) | |
| cat_dir = os.path.join(SAVE_PATH, "MATH/train") | |
| for cat_name in os.listdir(cat_dir): | |
| cat_path = os.path.join(cat_dir, cat_name) | |
| if os.path.isdir(cat_path): | |
| cat_texts = [] | |
| for f in os.listdir(cat_path): | |
| f_path = os.path.join(cat_path, f) | |
| with open(f_path) as fle: | |
| prob_json = json.load(fle) | |
| text = "{\\bf Problem.} " + prob_json["problem"] + "\n" +\ | |
| "{\\bf Level.} " + prob_json["level"] + "\n" +\ | |
| "{\\bf Type.} " + prob_json["type"] + "\n" +\ | |
| "{\\bf Solution.} " + prob_json["type"] | |
| cat_texts.append(text) | |
| batches = batch_loader(cat_texts, 100) | |
| for i, batch in enumerate(batches): | |
| with open(os.path.join(SAVE_PATH, f"{cat_name}_{i}.txt"), "w") as fle: | |
| fle.write("<|endoftext|>\n".join(batch)) | |
| os.system("rm -r " + os.path.join(SAVE_PATH, "MATH")) | |
| os.remove(archive_path) | |
| if __name__=="__main__": | |
| main() | |