Download predict.py from erlic/ulgan-1: direct link, hf CLI and curl.
- Browser
- Download file 869 Bytes
-
https://huggingface.co/erlic/ulgan-1/resolve/main/predict.py
- Command line
-
hf download hf://erlic/ulgan-1/predict.py
-
curl -L -o predict.py https://huggingface.co/erlic/ulgan-1/resolve/main/predict.py
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)) | |