File size: 778 Bytes
c1fe3c0
 
 
 
 
1a8232c
 
c1fe3c0
 
 
 
 
1a8232c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1fe3c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
license: apache-2.0
language:
- en
---
# logic-gate

yes 102 parameters, not million, not thousand, one hundred and two.
its the most useless and weirdest neural network, but can be ok for testing out stuff.

## Details

Tiny `12 → 4 → 4 → 4 → 2` network that simulates 10 logic gates from one set of weights.

Input is a one-hot gate selector plus `a` and `b`. Output is 2 neurons.

## Use

```bash
pip install torch safetensors
python example.py
```

```python
from example import forward

print(forward("XOR", 1, 0).tolist())   # [p(out1), p(out2)]
print(forward("CNOT", 1, 0).tolist())  # [p(a), p(a XOR b)]
```

Gates: `AND OR XOR NAND NOR XNOR NOT BUF CNOT SWAP`

- One-output gates: `[result, 1 - result]`
- `CNOT(a, b) = (a, a XOR b)`
- `SWAP(a, b) = (b, a)`