Add pruned variant documentation
Browse files
README.md
CHANGED
|
@@ -21,7 +21,18 @@ This is a ternary threshold network trained to compute the parity function on 8-
|
|
| 21 |
|
| 22 |
**Key feature**: Correctness is mathematically proven in Coq for all 256 possible inputs.
|
| 23 |
|
| 24 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
| Layer | Neurons | Weights | Activation |
|
| 27 |
|-------|---------|---------|------------|
|
|
@@ -30,7 +41,7 @@ This is a ternary threshold network trained to compute the parity function on 8-
|
|
| 30 |
| Hidden 2 | 16 | Ternary {-1, 0, +1} | Heaviside |
|
| 31 |
| Output | 1 | Ternary {-1, 0, +1} | Heaviside |
|
| 32 |
|
| 33 |
-
- **Total parameters**: 833
|
| 34 |
- **Weight quantization**: Ternary (-1, 0, +1)
|
| 35 |
- **Bias quantization**: Bounded integers
|
| 36 |
|
|
@@ -47,7 +58,7 @@ Evolutionary search circumvents this problem by evaluating candidate solutions d
|
|
| 47 |
|
| 48 |
## Verification
|
| 49 |
|
| 50 |
-
Correctness is proven in the Coq proof assistant:
|
| 51 |
|
| 52 |
```coq
|
| 53 |
Theorem network_verified :
|
|
@@ -62,8 +73,13 @@ The proof uses exhaustive enumeration via `vm_compute` over all 256 inputs.
|
|
| 62 |
from model import ThresholdNetwork
|
| 63 |
import torch
|
| 64 |
|
|
|
|
| 65 |
model = ThresholdNetwork.from_safetensors('model.safetensors')
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
input_bits = torch.tensor([[1, 0, 1, 1, 0, 0, 1, 0]], dtype=torch.float32)
|
| 68 |
output = model(input_bits)
|
| 69 |
print(f"Parity: {int(output.item())}") # 0 (four 1-bits, even count)
|
|
@@ -71,16 +87,17 @@ print(f"Parity: {int(output.item())}") # 0 (four 1-bits, even count)
|
|
| 71 |
|
| 72 |
## Performance
|
| 73 |
|
| 74 |
-
| Metric |
|
| 75 |
-
|
| 76 |
-
| Accuracy | 100% (256/256) |
|
| 77 |
-
|
|
|
|
|
| 78 |
|
| 79 |
## Limitations
|
| 80 |
|
| 81 |
- Fixed 8-bit input size
|
| 82 |
- Threshold activation (not differentiable)
|
| 83 |
-
-
|
| 84 |
|
| 85 |
## Repository
|
| 86 |
|
|
|
|
| 21 |
|
| 22 |
**Key feature**: Correctness is mathematically proven in Coq for all 256 possible inputs.
|
| 23 |
|
| 24 |
+
## Variants
|
| 25 |
+
|
| 26 |
+
Two variants are available:
|
| 27 |
+
|
| 28 |
+
| Variant | Architecture | Parameters | Location |
|
| 29 |
+
|---------|--------------|------------|----------|
|
| 30 |
+
| Full | 8 → 32 → 16 → 1 | 833 | `model.safetensors` |
|
| 31 |
+
| Pruned | 8 → 11 → 3 → 1 | 139 | `pruned/model.safetensors` |
|
| 32 |
+
|
| 33 |
+
The pruned variant was extracted via neuron ablation analysis, which identified that only 11 of 32 Layer-1 neurons and 3 of 16 Layer-2 neurons are critical for correct operation. Both variants achieve 100% accuracy and are formally verified in Coq.
|
| 34 |
+
|
| 35 |
+
## Architecture (Full Network)
|
| 36 |
|
| 37 |
| Layer | Neurons | Weights | Activation |
|
| 38 |
|-------|---------|---------|------------|
|
|
|
|
| 41 |
| Hidden 2 | 16 | Ternary {-1, 0, +1} | Heaviside |
|
| 42 |
| Output | 1 | Ternary {-1, 0, +1} | Heaviside |
|
| 43 |
|
| 44 |
+
- **Total parameters**: 833 (full), 139 (pruned)
|
| 45 |
- **Weight quantization**: Ternary (-1, 0, +1)
|
| 46 |
- **Bias quantization**: Bounded integers
|
| 47 |
|
|
|
|
| 58 |
|
| 59 |
## Verification
|
| 60 |
|
| 61 |
+
Correctness is proven in the Coq proof assistant for both variants:
|
| 62 |
|
| 63 |
```coq
|
| 64 |
Theorem network_verified :
|
|
|
|
| 73 |
from model import ThresholdNetwork
|
| 74 |
import torch
|
| 75 |
|
| 76 |
+
# Full network
|
| 77 |
model = ThresholdNetwork.from_safetensors('model.safetensors')
|
| 78 |
|
| 79 |
+
# Or pruned network
|
| 80 |
+
from pruned.model import PrunedThresholdNetwork
|
| 81 |
+
model = PrunedThresholdNetwork.from_safetensors('pruned/model.safetensors')
|
| 82 |
+
|
| 83 |
input_bits = torch.tensor([[1, 0, 1, 1, 0, 0, 1, 0]], dtype=torch.float32)
|
| 84 |
output = model(input_bits)
|
| 85 |
print(f"Parity: {int(output.item())}") # 0 (four 1-bits, even count)
|
|
|
|
| 87 |
|
| 88 |
## Performance
|
| 89 |
|
| 90 |
+
| Metric | Full | Pruned |
|
| 91 |
+
|--------|------|--------|
|
| 92 |
+
| Accuracy | 100% (256/256) | 100% (256/256) |
|
| 93 |
+
| Parameters | 833 | 139 |
|
| 94 |
+
| Verification | Coq-proven | Coq-proven |
|
| 95 |
|
| 96 |
## Limitations
|
| 97 |
|
| 98 |
- Fixed 8-bit input size
|
| 99 |
- Threshold activation (not differentiable)
|
| 100 |
+
- Fragile to input noise (Heaviside has zero margin)
|
| 101 |
|
| 102 |
## Repository
|
| 103 |
|