Create bluemo.py
Browse files
bluemo.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# bluemo.py
|
| 2 |
+
import json, datasets
|
| 3 |
+
from datasets import Features, Value, Sequence, Split, SplitGenerator
|
| 4 |
+
|
| 5 |
+
_CITATION = ""
|
| 6 |
+
_DESCRIPTION = "BlueMO dataset."
|
| 7 |
+
|
| 8 |
+
class BlueMO(datasets.GeneratorBasedBuilder):
|
| 9 |
+
BUILDER_CONFIGS = [
|
| 10 |
+
datasets.BuilderConfig(name="default"),
|
| 11 |
+
datasets.BuilderConfig(name="proof"),
|
| 12 |
+
datasets.BuilderConfig(name="calculation"),
|
| 13 |
+
datasets.BuilderConfig(name="mathtext"),
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
def _info(self):
|
| 17 |
+
if self.config.name in ("proof", "calculation", "default"):
|
| 18 |
+
feats = Features({
|
| 19 |
+
"source_file": Value("string"),
|
| 20 |
+
"problem_type": Value("string"),
|
| 21 |
+
"problem": Value("string"),
|
| 22 |
+
"solution": Value("string"),
|
| 23 |
+
"remark": Value("string"),
|
| 24 |
+
"figures": Sequence(Value("string")),
|
| 25 |
+
})
|
| 26 |
+
else: # mathtext
|
| 27 |
+
feats = Features({
|
| 28 |
+
"source_file": Value("string"),
|
| 29 |
+
"text": Value("string"),
|
| 30 |
+
"figures": Sequence(Value("string")),
|
| 31 |
+
})
|
| 32 |
+
return datasets.DatasetInfo(description=_DESCRIPTION, citation=_CITATION, features=feats)
|
| 33 |
+
|
| 34 |
+
def _split_generators(self, dl_manager):
|
| 35 |
+
# match your README configs
|
| 36 |
+
if self.config.name == "proof":
|
| 37 |
+
paths = dl_manager.iter_files(["processed_dataset/proof"])
|
| 38 |
+
elif self.config.name == "calculation":
|
| 39 |
+
paths = dl_manager.iter_files(["processed_dataset/calculation"])
|
| 40 |
+
elif self.config.name == "mathtext":
|
| 41 |
+
paths = dl_manager.iter_files(["processed_dataset/text"])
|
| 42 |
+
else: # default = proof + calculation
|
| 43 |
+
paths = dl_manager.iter_files(["processed_dataset/proof", "processed_dataset/calculation"])
|
| 44 |
+
return [SplitGenerator(name=Split.TRAIN, gen_kwargs={"paths": list(paths)})]
|
| 45 |
+
|
| 46 |
+
def _generate_examples(self, paths):
|
| 47 |
+
for i, p in enumerate(sorted(paths)):
|
| 48 |
+
with open(p, "r", encoding="utf-8") as f:
|
| 49 |
+
obj = json.load(f)
|
| 50 |
+
# normalize keys & types
|
| 51 |
+
if "figures" in obj and obj["figures"] is None:
|
| 52 |
+
obj["figures"] = []
|
| 53 |
+
if "figures" in obj:
|
| 54 |
+
obj["figures"] = [str(x) for x in (obj["figures"] or [])]
|
| 55 |
+
yield str(i), obj
|