Download inference.py from invariant-computing-lab/huret-digit-classifiers: direct link, hf CLI and curl.
- Browser
- Download file 728 Bytes
-
https://huggingface.co/invariant-computing-lab/huret-digit-classifiers/resolve/main/inference.py
- Command line
-
hf download hf://invariant-computing-lab/huret-digit-classifiers/inference.py
-
curl -L -o inference.py https://huggingface.co/invariant-computing-lab/huret-digit-classifiers/resolve/main/inference.py
728 Bytes
| from pathlib import Path | |
| import numpy as np | |
| ROOT=Path(__file__).parent | |
| def predict(x, task='identity', seed=0): | |
| if task not in {'identity','parity','magnitude'} or type(seed) is not int or seed not in range(5): raise ValueError('Unknown task or seed') | |
| x=np.asarray(x,dtype=np.float32) | |
| if x.ndim!=2 or x.shape[1]!=64 or not np.isfinite(x).all() or (x<0).any() or (x>1).any(): raise ValueError('Expected finite normalized (n,64), values in [0,1]') | |
| with np.load(ROOT/'weights'/f'{task}_seed{seed}.npz',allow_pickle=False) as w: | |
| h=np.maximum(x@w['hidden.0.weight'].T+w['hidden.0.bias'],0) | |
| h=np.maximum(h@w['hidden.2.weight'].T+w['hidden.2.bias'],0) | |
| return h@w['head.weight'].T+w['head.bias'] | |