Downloads · 30 days
7
18% of all-time downloads
phanerozoic/threshold-lessthanorequal
threshold-lessthanorequal 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.
1-bit less-than-or-equal comparator. Outputs 1 when a <= b.
Downloads · 30 days
7
18% of all-time downloads
All-time downloads
40
Public
Parameters
3
Likes
0
Public
Click a slice to open those files.
.py1.3 KB · 51%
From the Hugging Face model README
1-bit less-than-or-equal comparator. Outputs 1 when a <= b.
lte(a, b) = 1 if a <= b, else 0
Equivalent to: NOT(a) OR b (implication)
| a | b | a <= b |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Single neuron: weights [-1, 1], bias 0
Fires when: -a + b >= 0, i.e., b >= a
| Inputs | 2 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 3 |
| Magnitude | 2 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def lte(a, b):
inp = torch.tensor([float(a), float(b)])
return int((inp @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
print(lte(0, 1)) # 1
print(lte(1, 0)) # 0
MIT