Spaces:
Running on Zero

word-problem-reader / tools /test_feedback_offline.py
Bigbearbo's picture
Add 回饋修正 switch (#350 v1, default off): program points out bad lines, the same Qwen3-8B rewrites them (1 round)
2acc5b8 verified
Raw History Blame Contribute Delete
2.94 kB
# -*- coding: utf-8 -*-
"""Offline check of the 🔧 回饋修正 switch with a FAKE model (no ZeroGPU): Kira N=1 where the "model" reads the two legs
as 60 minutes (數字無出處:60), the program points at sentence #1, the fake model rewrites #1 as 1 hour (and also sends
a #3 line, which must be dropped). The rule layer reads Kira itself, so it is switched off here to reach the model layer.
Also: the switch off → refused; a bad fixer that repeats 60 → still refused.
python -B tools/test_feedback_offline.py [out.json]"""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
import pipeline # noqa: E402
Q = ("Three train stations are 1 hours apart from one another. Kira travels from the first station to the third, taking "
"a 30 minutes break at the second station. What's the total time, in minutes, that Kira takes to travel between the "
"first and third station?")
READ = ("#1: duration(station 1, travel to station 2, 60, minute).\n#1: duration(station 2, travel to station 3, 60, minute).\n"
"#2: duration(kira, break, 30, minute).\n"
"#3: ask(add(duration(station 1, travel to station 2, ?, minute), duration(station 2, travel to station 3, ?, minute), "
"duration(kira, break, ?, minute))).")
GOOD = ("#1: duration(station 1, travel to station 2, 1, hour).\n#1: duration(station 2, travel to station 3, 1, hour).\n"
"#3: ask(add(duration(kira, break, ?, minute), 999)).")
BAD = "#1: duration(station 1, travel to station 2, 60, minute).\n#1: duration(station 2, travel to station 3, 60, minute)."
def fake(fix):
calls = []
def gen(prompt):
calls.append(prompt)
return fix if "A program checked them" in prompt else READ
return gen, calls
pipeline.init()
pipeline.rule_layer = lambda q, S: ({"英文式": []}, "(測試:略過程式層,直接走模型層)")
out = {}
for name, fix, on in (("開+好修正", GOOD, True), ("關", GOOD, False), ("開+壞修正", BAD, True)):
gen, calls = fake(fix)
r = pipeline.solve(Q, gen, None, gold="150", feedback=on, rounds=1)
fb = r.get("feedback") or {}
out[name] = {"模型呼叫": len(calls), "層": r["layer_label"], "答": r["answer"], "判": r["verdict"], "拒因": r["refusal"],
"回合": fb.get("rounds"), "資訊句": r["lines"], "前綴": r["prefix"], "左腦": r["lb_steps"]}
ok = (out["開+好修正"]["判"] == "✓" and out["開+好修正"]["模型呼叫"] == 2 and out["開+好修正"]["回合"][0]["越界行"]
and out["關"]["判"] == "拒答" and out["關"]["模型呼叫"] == 1 and out["開+壞修正"]["判"] == "拒答")
print(json.dumps(out, ensure_ascii=False, indent=1))
print("通過" if ok else "失敗")
if len(sys.argv) > 1:
json.dump(out, open(sys.argv[1], "w", encoding="utf-8"), ensure_ascii=False, indent=1)
sys.exit(0 if ok else 1)