threshold-and3 / model.py
phanerozoic's picture
Upload folder using huggingface_hub
f1c4e16 verified
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def and3(a, b, c, weights):
"""3-input AND 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 AND truth table:')
for a in [0, 1]:
for b in [0, 1]:
for c in [0, 1]:
print(f'AND({a},{b},{c}) = {and3(a, b, c, w)}')