Download files/make_sets.py from luokelabs/luoke-bench: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/datasets/luokelabs/luoke-bench/resolve/main/files/make_sets.py
- Command line
-
hf download hf://datasets/luokelabs/luoke-bench/files/make_sets.py
-
curl -L -o make_sets.py https://huggingface.co/datasets/luokelabs/luoke-bench/resolve/main/files/make_sets.py
2.84 kB
| #!/usr/bin/env python3 | |
| """Make the questions of files/: sets/rename.json and sets/archive.json. | |
| python3 files/make_sets.py --seed 1 --out files/sets/ | |
| The same seed gives the same questions. Every question is built from a template (sets_rename.py, sets_archive.py: | |
| what a made-up person's folders would hold); what is drawn at random is who, which company, which day, which number, | |
| and the order. The answer is not written afterwards: each thing put into a question carries the conclusion it stands | |
| for (`expect`), and `example` is one answer that satisfies it (the tests check that it does). | |
| Every question has a `level`, 1 to 3: how much there is to notice (see the two modules). Whether the levels do tell | |
| models apart is measured, not assumed: README.md keeps the scores by level. | |
| People, companies, places and numbers are made up. `checked` lists the questions a person has read and agreed with; | |
| it is kept when the sets are made again and the questions come out the same. | |
| Stdlib only. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import random | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| import sets_archive # noqa: E402 | |
| import sets_rename # noqa: E402 | |
| VERSION = 2 | |
| MAKE = {"rename": (sets_rename.make, 0), "archive": (sets_archive.make, 1000)} | |
| def items(name: str, seed: int) -> list: | |
| make, shift = MAKE[name] | |
| return make(random.Random(seed + shift)) | |
| def write(path: str, name: str, seed: int, made: list) -> None: | |
| checked = [] | |
| if os.path.exists(path): | |
| with open(path, encoding="utf-8") as f: | |
| old = json.load(f) | |
| same = {i["id"] for i in old["items"] if any(i == j for j in made if j["id"] == i["id"])} | |
| checked = [c for c in old.get("checked", []) if c in same] # a question that changed has to be read again | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump({"set": name, "version": VERSION, "seed": seed, "today": str(sets_rename.TODAY), "checked": checked, "items": made}, f, ensure_ascii=False, indent=1) | |
| f.write("\n") | |
| count: dict = {} | |
| for i in made: | |
| key = f"{i['level']} {i['group']}" | |
| count[key] = count.get(key, 0) + 1 | |
| print(f"{path}: {len(made)} questions, {len(checked)} checked\n " + ", ".join(f"{k} {v}" for k, v in sorted(count.items()))) | |
| def main() -> None: | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--seed", type=int, default=1) | |
| ap.add_argument("--out", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "sets")) | |
| a = ap.parse_args() | |
| os.makedirs(a.out, exist_ok=True) | |
| for name in MAKE: | |
| write(os.path.join(a.out, name + ".json"), name, a.seed, items(name, a.seed)) | |
| if __name__ == "__main__": | |
| main() | |