File size: 571 Bytes
3a5e261 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def atmost2of5(a, b, c, d, e, weights):
inp = torch.tensor([float(a), float(b), float(c), float(d), float(e)])
return int((inp @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item())
if __name__ == '__main__':
w = load_model()
print('atmost2outof5 selected outputs:')
for s in [0, 1, 2, 3, 4, 5]:
bits = [(1 if j < s else 0) for j in range(5)]
print(f' sum={s}: {bits} -> {atmost2of5(*bits, w)}')
|