phanerozoic commited on
Commit
b10ec68
·
verified ·
1 Parent(s): 3ee1847

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +25 -0
  2. config.json +9 -0
  3. create_safetensors.py +41 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - conversion
9
+ ---
10
+
11
+ # threshold-bcd2binary
12
+
13
+ Single digit BCD to binary converter. For digits 0-9.
14
+
15
+ ## Parameters
16
+
17
+ | | |
18
+ |---|---|
19
+ | Inputs | 4 |
20
+ | Outputs | 4 |
21
+ | Parameters | 20 |
22
+
23
+ ## License
24
+
25
+ MIT
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "threshold-bcd2binary",
3
+ "description": "BCD to binary converter",
4
+ "inputs": 4,
5
+ "outputs": 4,
6
+ "neurons": 4,
7
+ "layers": 1,
8
+ "parameters": 20
9
+ }
create_safetensors.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from safetensors.torch import save_file
3
+
4
+ weights = {}
5
+
6
+ # Single digit BCD (4 bits) to Binary (4 bits)
7
+ # BCD: 0-9 encoded in 4 bits
8
+ # Output: same value (identity for single digit)
9
+
10
+ def add_neuron(name, w_list, bias):
11
+ weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
12
+ weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
13
+
14
+ # Pass through (BCD 0-9 is same as binary 0-9)
15
+ for i in range(4):
16
+ w = [0.0] * 4
17
+ w[i] = 1.0
18
+ add_neuron(f'b{3-i}', w, -1.0)
19
+
20
+ save_file(weights, 'model.safetensors')
21
+
22
+ def bcd2binary(d3, d2, d1, d0):
23
+ return d3, d2, d1, d0
24
+
25
+ print("Verifying BCD to Binary...")
26
+ errors = 0
27
+ for d in range(10): # Valid BCD: 0-9
28
+ d3, d2, d1, d0 = (d>>3)&1, (d>>2)&1, (d>>1)&1, d&1
29
+ b3, b2, b1, b0 = bcd2binary(d3, d2, d1, d0)
30
+ result = b3*8 + b2*4 + b1*2 + b0
31
+ if result != d:
32
+ errors += 1
33
+
34
+ if errors == 0:
35
+ print("All 10 test cases passed!")
36
+ else:
37
+ print(f"FAILED: {errors} errors")
38
+
39
+ mag = sum(t.abs().sum().item() for t in weights.values())
40
+ print(f"Magnitude: {mag:.0f}")
41
+ print(f"Parameters: {sum(t.numel() for t in weights.values())}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:768272a75a13a3a15dd1bb88eba21094ce77155a0ef176d55bc81c078ab1a889
3
+ size 592