import torch from safetensors.torch import load_file def load_model(path='model.safetensors'): return load_file(path) def atleast2of4(a, b, c, d, weights): """Returns 1 if at least 2 of 4 inputs are high""" 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('2outof4 truth table:') for i in range(16): a, b, c, d = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1 result = atleast2of4(a, b, c, d, w) print(f' {a}{b}{c}{d} -> {result}')