File size: 539 Bytes
ac0f2bd |
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 iszero4(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()
print('iszero4: outputs 1 only for input 0000')
for i in [0, 1, 8, 15]:
bits = [(i >> j) & 1 for j in range(4)]
print(f' {i:04b} -> {iszero4(*bits, w)}')
|