threshold-1outof4 / model.py
phanerozoic's picture
Upload folder using huggingface_hub
edd2597 verified
raw
history blame contribute delete
668 Bytes
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def atleast1of4(a, b, c, d, weights):
"""Returns 1 if at least 1 of 4 inputs is high (OR gate)"""
inp = torch.tensor([float(a), float(b), float(c), float(d)])
return int((inp @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item())
if __name__ == '__main__':
w = load_model()
print('1outof4 (OR4) truth table:')
for i in range(16):
a, b, c, d = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1
result = atleast1of4(a, b, c, d, w)
print(f' {a}{b}{c}{d} -> {result}')