threshold-nand3 / model.py
phanerozoic's picture
Upload folder using huggingface_hub
6937ad9 verified
raw
history blame contribute delete
555 Bytes
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def nand3(a, b, c, weights):
"""3-input NAND gate."""
inp = torch.tensor([float(a), float(b), float(c)])
return int((inp * weights['weight']).sum() + weights['bias'] >= 0)
if __name__ == '__main__':
w = load_model()
print('3-input NAND truth table:')
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
print(f'NAND({a},{b},{c}) = {nand3(a, b, c, w)}')