ulgan-1 / predict.py
LowLeery's picture
Release ULGAN 1.0.0
ff7ddde verified
Raw History Blame Contribute Delete
869 Bytes
import argparse, json
from load_ulgan import load_ulgan
from model import TASKS
p = argparse.ArgumentParser(description="ULGAN 1 inference")
p.add_argument("--bits", required=True, help="Example: 101101")
p.add_argument("--task", choices=TASKS, default="parity")
p.add_argument("--seed", type=int, choices=[11, 23, 42], default=11)
p.add_argument("--threshold", type=float, default=0.95)
args = p.parse_args()
bits = [int(x) for x in args.bits]
if not bits or any(x not in (0, 1) for x in bits):
raise ValueError("bits must be a non-empty binary string")
model = load_ulgan(seed=args.seed)
pred, steps, halt = model.predict_one(
bits, TASKS[args.task], threshold=args.threshold
)
print(json.dumps({
"task": args.task, "prediction": int(pred),
"think_steps": int(steps), "cumulative_halt_probability": float(halt),
"seed": args.seed
}, indent=2))