CharlesCNorton
At most 2 of 4 threshold circuit, magnitude 6
bacce1d
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def atmost2of4(a, b, c, d, weights):
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()
for i in range(16):
a, b, c, d = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1
print(f'{a}{b}{c}{d} -> {atmost2of4(a, b, c, d, w)}')