File size: 2,273 Bytes
045008b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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