| | |
| | 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: |
| | 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): |
| | |
| | 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: |
| | 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) |
| | |
| | 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 |
| |
|