Downloads · 30 days
8
15% of all-time downloads
phanerozoic/threshold-2to4decoder
threshold-2to4decoder 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.
2-to-4 binary decoder. Converts 2-bit input to one-hot 4-bit output.
Downloads · 30 days
8
15% of all-time downloads
All-time downloads
53
Public
Parameters
12
Likes
0
Public
Click a slice to open those files.
.py1.7 KB · 47%
From the Hugging Face model README
2-to-4 binary decoder. Converts 2-bit input to one-hot 4-bit output.
decode(A1, A0) -> [Y0, Y1, Y2, Y3]
Yi = 1 iff input = i
| A1 | A0 | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
Single layer with 4 neurons. Each Yi matches pattern i.
| Output | Weights [A1, A0] | Bias |
|---|---|---|
| Y0 | [-1, -1] | 0 |
| Y1 | [-1, +1] | -1 |
| Y2 | [+1, -1] | -1 |
| Y3 | [+1, +1] | -2 |
| Inputs | 2 |
| Outputs | 4 |
| Neurons | 4 |
| Layers | 1 |
| Parameters | 12 |
| Magnitude | 12 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def decode2to4(a1, a0):
inp = torch.tensor([float(a1), float(a0)])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0) for i in range(4)]
print(decode2to4(1, 0)) # [0, 0, 1, 0] - input 2
MIT