Download bluemo.py from math-ai/BlueMO: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/datasets/math-ai/BlueMO/resolve/main/bluemo.py
- Command line
-
hf download hf://datasets/math-ai/BlueMO/bluemo.py
-
curl -L -o bluemo.py https://huggingface.co/datasets/math-ai/BlueMO/resolve/main/bluemo.py
2.27 kB
| # bluemo.py | |
| import json, datasets | |
| from datasets import Features, Value, Sequence, Split, SplitGenerator | |
| _CITATION = "" | |
| _DESCRIPTION = "BlueMO dataset." | |
| class BlueMO(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig(name="default"), | |
| datasets.BuilderConfig(name="proof"), | |
| datasets.BuilderConfig(name="calculation"), | |
| datasets.BuilderConfig(name="mathtext"), | |
| ] | |
| def _info(self): | |
| if self.config.name in ("proof", "calculation", "default"): | |
| feats = Features({ | |
| "source_file": Value("string"), | |
| "problem_type": Value("string"), | |
| "problem": Value("string"), | |
| "solution": Value("string"), | |
| "remark": Value("string"), | |
| "figures": Sequence(Value("string")), | |
| }) | |
| else: # mathtext | |
| feats = Features({ | |
| "source_file": Value("string"), | |
| "text": Value("string"), | |
| "figures": Sequence(Value("string")), | |
| }) | |
| return datasets.DatasetInfo(description=_DESCRIPTION, citation=_CITATION, features=feats) | |
| def _split_generators(self, dl_manager): | |
| # match your README configs | |
| if self.config.name == "proof": | |
| paths = dl_manager.iter_files(["processed_dataset/proof"]) | |
| elif self.config.name == "calculation": | |
| paths = dl_manager.iter_files(["processed_dataset/calculation"]) | |
| elif self.config.name == "mathtext": | |
| paths = dl_manager.iter_files(["processed_dataset/text"]) | |
| else: # default = proof + calculation | |
| paths = dl_manager.iter_files(["processed_dataset/proof", "processed_dataset/calculation"]) | |
| return [SplitGenerator(name=Split.TRAIN, gen_kwargs={"paths": list(paths)})] | |
| def _generate_examples(self, paths): | |
| for i, p in enumerate(sorted(paths)): | |
| with open(p, "r", encoding="utf-8") as f: | |
| obj = json.load(f) | |
| # normalize keys & types | |
| if "figures" in obj and obj["figures"] is None: | |
| obj["figures"] = [] | |
| if "figures" in obj: | |
| obj["figures"] = [str(x) for x in (obj["figures"] or [])] | |
| yield str(i), obj | |