Download model.py from phanerozoic/threshold-atmost6outof8: direct link, hf CLI and curl.
- Browser
- Download file 550 Bytes
-
https://huggingface.co/phanerozoic/threshold-atmost6outof8/resolve/main/model.py
- Command line
-
hf download hf://phanerozoic/threshold-atmost6outof8/model.py
-
curl -L -o model.py https://huggingface.co/phanerozoic/threshold-atmost6outof8/resolve/main/model.py
550 Bytes
| import torch | |
| from safetensors.torch import load_file | |
| def load_model(path='model.safetensors'): | |
| return load_file(path) | |
| def atmost6(bits, weights): | |
| """At-most-6-out-of-8: fires when 6 or fewer inputs are active.""" | |
| inp = torch.tensor([float(b) for b in bits]) | |
| return int((inp * weights['weight']).sum() + weights['bias'] >= 0) | |
| if __name__ == '__main__': | |
| w = load_model() | |
| print('AtMost6OutOf8: HW <= 6') | |
| for hw in range(9): | |
| bits = [1]*hw + [0]*(8-hw) | |
| print(f'HW={hw}: {atmost6(bits, w)}') | |