Spaces:
Running on Zero
Running on Zero
Download tools/make_data.py from Bigbearbo/word-problem-reader: direct link, hf CLI and curl.
- Browser
- Download file 3.99 kB
-
https://huggingface.co/spaces/Bigbearbo/word-problem-reader/resolve/main/tools/make_data.py
- Command line
-
hf download hf://spaces/Bigbearbo/word-problem-reader/tools/make_data.py
-
curl -L -o make_data.py https://huggingface.co/spaces/Bigbearbo/word-problem-reader/resolve/main/tools/make_data.py
3.99 kB
| # -*- coding: utf-8 -*- | |
| """data/problems.json: GSM8K **train** development questions (範圍守門.過濾 already applied upstream: no held-out / | |
| fixed-300 / blind ids; GSM8K test is never read) whose DeepSeek v7 reading is answered correctly by the CURRENT | |
| program brain. Grouped into concept types (first matching rule wins), at most 50 per type, fixed seed. | |
| python -B tools/make_data.py pick.json | |
| pick.json comes from the team-side script (current brain re-solves the stored DeepSeek v7 reads; Qwen 168 verdicts). | |
| """ | |
| import json | |
| import random | |
| import re | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| OUT = Path(__file__).resolve().parent.parent / "data" / "problems.json" | |
| CAP = 50 | |
| SEED = 20261127 | |
| TYPES = [ # (key, label, test(q, concepts, heads)) | |
| ("age", "年齡 Ages", lambda q, c, h: re.search(r"\b(years? old|ages?|older|younger|born)\b", q, re.I)), | |
| ("percent", "百分比與分數 Percents & fractions", | |
| lambda q, c, h: "%" in q or re.search(r"\bpercent", q, re.I) or c & {"部分整體", "比例", "比例份", "子集比例"}), | |
| ("share", "分配與每人份 Sharing & per person", | |
| lambda q, c, h: c & {"分配", "每組"} or re.search(r"\b(equally|split|divided? (among|between|into)|per person|each of)\b", q, re.I)), | |
| ("time", "時間與時長 Time & durations", | |
| lambda q, c, h: c & {"時段", "進度"} or ("速率" not in c and re.search(r"\b(hours?|minutes?|days?|weeks?)\b", q, re.I))), | |
| ("shop", "購物與找零 Shopping & money", | |
| lambda q, c, h: c & {"單價", "購買", "成本", "賣出"} or "$" in q), | |
| ("rate", "速率與每單位 Rates (per hour / per day / per item)", lambda q, c, h: "速率" in c), | |
| ("times", "倍數比較 Times as many", lambda q, c, h: "比較倍" in c), | |
| ("differ", "多少差 More / fewer than", lambda q, c, h: "比較差" in c), | |
| ("change", "增減與給出 Gains, losses & transfers", lambda q, c, h: c & {"變化", "移轉", "遺失"}), | |
| ("other", "合計與其他 Totals & others", lambda q, c, h: True), | |
| ] | |
| def main(): | |
| d = json.load(open(sys.argv[1], encoding="utf-8")) | |
| qw = d["qwen"] | |
| groups = {k: [] for k, _, _ in TYPES} | |
| for t in d["keep"]: | |
| if len(t["q"]) > 700: | |
| continue | |
| c = set(t["概念"]) | |
| heads = {re.match(r"(\w+)\(", l).group(1) for l in t["ds_lines"] if re.match(r"(\w+)\(", l)} | |
| for k, _, f in TYPES: | |
| if f(t["q"], c, heads): | |
| groups[k].append(t) | |
| break | |
| rng = random.Random(SEED) | |
| out = {"source": "GSM8K train (development split; held-out ids removed by 範圍守門.過濾; GSM8K test not used)", | |
| "selection": "DeepSeek v7 reading of the question is answered correctly by the current program brain " | |
| "(程式腦.py, 2026-11-27 working tree). Qwen3-8B (this Space) may still refuse or err on it.", | |
| "types": []} | |
| for k, label, _ in TYPES: | |
| g = sorted(groups[k], key=lambda t: int(t["id"].split("-")[-1])) | |
| first = [t for t in g if t["id"] in qw] # keep the ones in the 168-question Qwen comparison | |
| rest = [t for t in g if t["id"] not in qw] | |
| rng.shuffle(rest) | |
| pick = (first + rest)[:CAP] | |
| pick.sort(key=lambda t: int(t["id"].split("-")[-1])) | |
| out["types"].append({"key": k, "label": label, "n_pool": len(g), "items": [ | |
| {"id": t["id"], "question": t["q"], "gold": t["gold"], "deepseek_v7_lines": t["ds_lines"], | |
| "qwen_168": qw.get(t["id"])} for t in pick]}) | |
| out["types"] = [t for t in out["types"] if len(t["items"]) >= 20] | |
| OUT.parent.mkdir(exist_ok=True) | |
| OUT.write_text(json.dumps(out, ensure_ascii=False, indent=0), encoding="utf-8") | |
| for t in out["types"]: | |
| print(t["key"], t["label"], "pool", t["n_pool"], "kept", len(t["items"]), | |
| Counter(x["qwen_168"] for x in t["items"] if x["qwen_168"])) | |
| print(OUT, OUT.stat().st_size) | |
| if __name__ == "__main__": | |
| main() | |