Downloads · 30 days
10
23% of all-time downloads
phanerozoic/threshold-popcount4
threshold-popcount4 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.
4-bit population count. Counts the number of 1 bits in a 4-bit input.
Downloads · 30 days
10
23% of all-time downloads
All-time downloads
43
Public
Parameters
53
Likes
0
Public
Click a slice to open those files.
.py6.6 KB · 63%
From the Hugging Face model README
4-bit population count. Counts the number of 1 bits in a 4-bit input.
popcount4(a, b, c, d) = binary count of 1 bits
Output [y2, y1, y0] is the 3-bit binary representation of the count (0-4).
| a | b | c | d | count | y2 | y1 | y0 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 2 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 3 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 4 | 1 | 0 | 0 |
a b c d
| | | |
+----+---+---+---+----+
| |
Layer 1: |
y2 = (sum >= 4) |
ge2 = (sum >= 2) |
le3 = (sum <= 3) |
XOR(a,b) components |
XOR(c,d) components |
| |
Layer 2: |
y1 = AND(ge2, le3) |
xor_ab = XOR(a,b) |
xor_cd = XOR(c,d) |
| |
Layer 3: |
XOR(xor_ab, xor_cd) |
components |
| |
Layer 4: |
y0 = XOR(xor_ab, xor_cd)
| Inputs | 4 |
| Outputs | 3 |
| Neurons | 13 |
| Layers | 4 |
| Parameters | 53 |
| Magnitude | 55 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
# See model.py for full implementation
# popcount4(1, 0, 1, 1) returns [0, 1, 1] (count=3 = binary 011)
MIT