File size: 517 Bytes
25743ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 majority3(a, b, c, weights):
    inp = torch.tensor([float(a), float(b), float(c)])
    return int((inp @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item())

if __name__ == '__main__':
    w = load_model()
    print('majority3 truth table:')
    for i in range(8):
        a, b, c = (i >> 2) & 1, (i >> 1) & 1, i & 1
        print(f'  {a}{b}{c} -> {majority3(a, b, c, w)}')