File size: 657 Bytes
899c846
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import torch
from safetensors.torch import load_file

def load_model(path='model.safetensors'):
    return load_file(path)

def atleast1of5(a, b, c, d, e, weights):
    """Returns 1 if at least 1 of 5 inputs is high (OR gate)"""
    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('1outof5 (OR5) sample outputs:')
    print(f'  00000 -> {atleast1of5(0,0,0,0,0,w)}')
    print(f'  00001 -> {atleast1of5(0,0,0,0,1,w)}')
    print(f'  11111 -> {atleast1of5(1,1,1,1,1,w)}')