Downloads · 30 days
11
31% of all-time downloads
phanerozoic/threshold-exactly4outof5
threshold-exactly4outof5 is a machine learning model from phanerozoic. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Downloads · 30 days
11
31% of all-time downloads
All-time downloads
35
Public
Parameters
15
Likes
0
Public
Click a slice to open those files.
.py1.9 KB · 52%
From the Hugging Face model README
Exactly 4 of 5 inputs high.
exactly4outof5(a, b, c, d, e) = 1 if (a + b + c + d + e) == 4, else 0
| sum | out |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 1 |
| 5 | 0 |
Two layers required (exactly-k is not linearly separable).
Layer 1:
Layer 2:
| Inputs | 5 |
| Outputs | 1 |
| Neurons | 3 |
| Layers | 2 |
| Parameters | 15 |
| Magnitude | 22 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly4of5(a, b, c, d, e):
inp = torch.tensor([float(a), float(b), float(c), float(d), float(e)])
l1 = (inp @ w['layer1.weight'].T + w['layer1.bias'] >= 0).float()
out = (l1 @ w['layer2.weight'].T + w['layer2.bias'] >= 0).float()
return int(out.item())
print(exactly4of5(1, 1, 1, 1, 0)) # 1 (sum=4)
print(exactly4of5(1, 1, 1, 1, 1)) # 0 (sum=5)
MIT