CharlesCNorton
Exactly 3 of 5 threshold circuit, magnitude 20
1bb4aaf
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def exactly3of5(a, b, c, d, e, weights):
inp = torch.tensor([float(a), float(b), float(c), float(d), float(e)])
l1 = (inp @ weights['layer1.weight'].T + weights['layer1.bias'] >= 0).float()
out = (l1 @ weights['layer2.weight'].T + weights['layer2.bias'] >= 0).float()
return int(out.item())
if __name__ == '__main__':
w = load_model()
print('exactly3outof5 selected outputs:')
for s in range(6):
bits = [(1 if j < s else 0) for j in range(5)]
print(f' sum={s}: {bits} -> {exactly3of5(*bits, w)}')