Spaces:
Running
Running
Download scripts/sim_session.py from lilyjeongwon/math-tutor: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/scripts/sim_session.py
- Command line
-
hf download hf://spaces/lilyjeongwon/math-tutor/scripts/sim_session.py
-
curl -L -o sim_session.py https://huggingface.co/spaces/lilyjeongwon/math-tutor/resolve/main/scripts/sim_session.py
2.67 kB
| """ํ์ต ์์ง ์๋ฎฌ๋ ์ด์ : ์ค์ ๋ฌธํญ ํ์ผ(aihub_A.jsonl)๋ก ๊ฐ์ ํ์์ด ํ ์ธ์ ์ ํธ๋ ๊ณผ์ ์ ์ถ๋ ฅํฉ๋๋ค. | |
| DBยทํค ์์ด PC ์์ ๋ฐ๋ก ๋๋ ค ๋ณผ ์ ์์ต๋๋ค. | |
| python scripts\\sim_session.py --file data\\aihub_normalized\\aihub_A.jsonl --unit U12 --level low --acc 0.7 0.5 0.3 | |
| --acc : ํ/์ค/์ ๋์ด๋๋ณ ๊ฐ์ ํ์์ ์ ๋ต๋ฅ (๊ธฐ๋ณธ 0.8 0.6 0.4) | |
| """ | |
| import argparse | |
| import json | |
| import random | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from app.engine import LEVEL_KO, LEVELS, Pool, Rules, next_question, record_answer, start_session, summary # noqa: E402 | |
| if hasattr(sys.stdout, "reconfigure"): | |
| sys.stdout.reconfigure(encoding="utf-8", errors="replace") | |
| def wrong_answer(q): | |
| return "9" if q["qtype"] == "multiple_choice" else "__์ค๋ต__" | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--file", type=Path, required=True) | |
| ap.add_argument("--unit", required=True) | |
| ap.add_argument("--level", default="low", choices=LEVELS) | |
| ap.add_argument("--acc", type=float, nargs=3, default=[0.8, 0.6, 0.4]) | |
| ap.add_argument("--seed", type=int, default=1) | |
| a = ap.parse_args() | |
| rows = [json.loads(l) for l in a.file.open(encoding="utf-8") if l.strip()] | |
| for r in rows: | |
| r["id"] = r["source_ref"] | |
| pool = Pool(rows) | |
| c = pool.counts(a.unit) | |
| print(f"{a.unit} ๋ฌธํญ ์ ํ {c['low']} / ์ค {c['mid']} / ์ {c['high']} (ํ ์นธ์ด {Rules().min_pool}๊ฐ ๋ฏธ๋ง์ด๋ฉด ์์ ์นธ)") | |
| rng = random.Random(a.seed) | |
| s = start_session(pool, a.unit, a.level) | |
| if s.finished: | |
| print("์ด ๋จ์์ ์ฌ์ฉํ ์ ์๋ ๋์ด๋๊ฐ ์์ต๋๋ค:", sorted(s.flags)) | |
| return | |
| acc = dict(zip(LEVELS, a.acc)) | |
| while True: | |
| nq = next_question(s, pool, rng=rng) | |
| if nq is None: | |
| break | |
| q, phase = nq | |
| ok = rng.random() < acc[q["difficulty"]] | |
| resp = q["answer"] if ok else wrong_answer(q) | |
| r = record_answer(s, pool, resp) | |
| print(f" {len(s.log)}๋ฒ์งธ [{('์ฌ๋์ ' if phase == 'retry' else '์ฌ๋ค๋ฆฌ')}] ๋์ด๋ {LEVEL_KO[r['level_before']]} " | |
| f"{q['id']:<20} {'์ ๋ต' if r['correct'] else '์ค๋ต'} -> ๋ค์ ๋์ด๋ {LEVEL_KO[r['level_after']]}") | |
| if r["done"]: | |
| break | |
| sm = summary(s) | |
| print(f"๋: {sm['answered']}๋ฌธ์ ์ค {sm['correct']}๋ฌธ์ ์ ๋ต | ์ต์ข ๋์ด๋ {LEVEL_KO[sm['final_level']]} | " | |
| f"์ฌ๋์ ํด๊ฒฐ {len(sm['recovered'])} | ๋ฐ๋ณต ์ค๋ต {len(sm['stuck'])} | ํ์ {sm['flags'] or '์์'}") | |
| if __name__ == "__main__": | |
| main() | |