Download code/v3/tdprm/scripts/smoke_v3_reader.py from JoshuaW1997/tdprm-results: direct link, hf CLI and curl.
- Browser
- Download file 3.2 kB
-
https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v3/tdprm/scripts/smoke_v3_reader.py
- Command line
-
hf download hf://datasets/JoshuaW1997/tdprm-results/code/v3/tdprm/scripts/smoke_v3_reader.py
-
curl -L -o smoke_v3_reader.py https://huggingface.co/datasets/JoshuaW1997/tdprm-results/resolve/main/code/v3/tdprm/scripts/smoke_v3_reader.py
3.2 kB
| """Reader smoke test (TDPRM_V3_EXPERIMENTS.md, section 3.2) against a running belief server. | |
| python -m tdprm.scripts.smoke_v3_reader --url http://127.0.0.1:$PORT | |
| Prints the three belief rows and the acceptance checks. | |
| """ | |
| import argparse | |
| from ..credit import v3 | |
| from ..rl.provider_v3 import BeliefClient | |
| MATH_MSGS = [{"role": "system", "content": "Solve the math problem step by step. Start each reasoning step with 'Step 1:', " | |
| "'Step 2:', etc. Finish with a separate line 'Final answer: \\boxed{<answer>}'."}, | |
| {"role": "user", "content": "A shop sells pens at 3 dollars each and notebooks at 5 dollars each. Mia buys 4 " | |
| "pens and 3 notebooks. How many dollars does she spend?"}] | |
| MATH_STEPS = ["Step 1: The pens cost 4 x 3 = 12 dollars.", "Step 2: The notebooks cost 3 x 5 = 15 dollars.", | |
| "Step 3: In total she spends 12 + 15 = 27 dollars."] | |
| PQ_MSGS = [{"role": "system", "content": "Answer the logical reasoning question using the given context. Solve " | |
| "step-by-step. Start each reasoning step with 'Step 1:', 'Step 2:', etc. Finish with a separate line " | |
| "'Final answer: <option letter and text>'."}, | |
| {"role": "user", "content": "Context: Every member of the chess club practices on Sundays. Anyone who " | |
| "practices on Sundays misses the Sunday market. Lena is a member of the chess club.\n\nQuestion: Based on " | |
| "the context, is the following statement true, false, or uncertain? Lena misses the Sunday market.\n\n" | |
| "Options:\nA) True\nB) False\nC) Uncertain"}] | |
| PQ_STEPS = ["Step 1: Lena is a member of the chess club, so she practices on Sundays.", | |
| "Step 2: Anyone who practices on Sundays misses the Sunday market, so Lena misses it. The statement is True."] | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--url", required=True) | |
| args = ap.parse_args() | |
| c = BeliefClient(args.url, 120) | |
| m_pre, _ = v3.build_prefixes(MATH_STEPS, [1, 2, 3], "off") | |
| l_pre, k = v3.build_prefixes(PQ_STEPS, [1, 2], "labels", "A") | |
| out = c.belief([{"messages": MATH_MSGS, "prefixes": m_pre, "answer": "27", "mode": "text", "labels": ["A", "B", "C"]}, | |
| {"messages": PQ_MSGS, "prefixes": l_pre, "answer": "A", "mode": "label", "labels": ["A", "B", "C"]}, | |
| {"messages": PQ_MSGS, "prefixes": l_pre, "answer": "B", "mode": "label", "labels": ["A", "B", "C"]}]) | |
| print("text (gold 27): Phi stub, s1, s2, s3 =", [round(x, 3) for x in out[0]]) | |
| print("label (gold A) : Phi stub, s1, s2 =", [round(x, 3) for x in out[1]], "| masked:", k) | |
| print("label (gold B) : Phi stub, s1, s2 =", [round(x, 3) for x in out[2]]) | |
| checks = {"every value in [0, 1]": all(0.0 <= x <= 1.0 for row in out for x in row), | |
| "masked = 1": k == 1, | |
| "gold-B ~0 where gold-A ~1": all(b < 0.1 for a, b in zip(out[1], out[2]) if a > 0.9), | |
| "text row ends near 1": out[0][-1] > 0.9} | |
| for name, ok in checks.items(): | |
| print(f" {'PASS' if ok else 'FAIL'} {name}") | |
| print("smoke", "PASS" if all(checks.values()) else "FAIL") | |
| if __name__ == "__main__": | |
| main() | |