Downloads · 30 days
7
16% of all-time downloads
phanerozoic/threshold-exactly1outof3
threshold-exactly1outof3 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
7
16% of all-time downloads
All-time downloads
43
Public
Parameters
11
Likes
0
Public
Click a slice to open those files.
.py1.9 KB · 51%
From the Hugging Face model README
Exactly 1 of 3 inputs high.
exactly1outof3(a, b, c) = 1 if (a + b + c) == 1, else 0
| a | b | c | sum | out |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 2 | 0 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 2 | 0 |
| 1 | 1 | 0 | 2 | 0 |
| 1 | 1 | 1 | 3 | 0 |
Two layers (not linearly separable):
Layer 1:
Layer 2:
| Inputs | 3 |
| Outputs | 1 |
| Neurons | 3 |
| Layers | 2 |
| Parameters | 11 |
| Magnitude | 12 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly1of3(a, b, c):
inp = torch.tensor([float(a), float(b), float(c)])
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(exactly1of3(0, 0, 1)) # 1 (sum=1)
print(exactly1of3(0, 1, 1)) # 0 (sum=2)
MIT