zeechimp commited on
Commit
8c77971
·
verified ·
1 Parent(s): cda9b65

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +149 -0
README.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: text-classification
4
+ tags:
5
+ - predictive-coding
6
+ - local-loss
7
+ - jax
8
+ - flax
9
+ - tiny-model
10
+ - custom-architecture
11
+ datasets:
12
+ - synthetic-palindrome-position
13
+ model-index:
14
+ - name: pc-mlp-tiny
15
+ results:
16
+ - task:
17
+ type: text-classification
18
+ name: Synthetic Palindrome + Position
19
+ metrics:
20
+ - type: accuracy
21
+ value: 1.000
22
+ name: Validation Accuracy
23
+ - type: accuracy
24
+ value: 0.006
25
+ name: Validation Loss
26
+ ---
27
+
28
+ # PC-MLP: Predictive-Coding MLP for Sequence Classification
29
+
30
+ A 3,138-parameter JAX/Flax model trained with **local losses** instead of end-to-end backpropagation. Matches a 5,314-parameter transformer on the synthetic palindrome + position task at 59% of the parameter count.
31
+
32
+ ## Model Description
33
+
34
+ This model implements a two-layer MLP with **predictive-coding loss**: each hidden layer minimizes the squared difference between its own mean representation and the mean of the layer below it. The total loss is:
35
+
36
+ **The novel part is not the MLP** — it's the loss. Standard backprop sends a single gradient from the output. Predictive coding sends *two* gradients per layer: one from the output (standard), and one from the layer above (local). At this scale, the local gradient regularizes the hidden representations enough that the model converges to the same accuracy as a transformer with fewer parameters.
37
+
38
+ ## Intended Uses
39
+
40
+ - **Sequence classification** on short sequences (≤16 tokens) with two orthogonal features: one local (position 0) and one global (palindrome structure).
41
+ - **Reproduction of the predictive-coding training regime** at toy scale.
42
+ - **Baseline for local-loss vs. end-to-end-loss comparisons.**
43
+
44
+ ## How to Use
45
+
46
+ ### With JAX (the native implementation)
47
+
48
+ ```python
49
+ from pc_mlp_tiny import pc_init, pc_forward, pc_loss, make_batch
50
+
51
+ # Load the model
52
+ params = pc_init(rng_key)
53
+
54
+ # Forward pass
55
+ logits, h0, h1, h2 = pc_forward(params, x)
56
+
57
+ # Loss (global + local)
58
+ loss = pc_loss(params, x, y, lam=0.1)
59
+ ```
60
+
61
+ ### With HuggingFace `transformers` (custom code)
62
+
63
+ This model is registered with `auto_map`, so you can load it with:
64
+
65
+ ```python
66
+ from transformers import AutoModel, AutoConfig
67
+
68
+ config = AutoConfig.from_pretrained(
69
+ "your-username/pc-mlp-tiny",
70
+ trust_remote_code=True
71
+ )
72
+ model = AutoModel.from_pretrained(
73
+ "your-username/pc-mlp-tiny",
74
+ trust_remote_code=True
75
+ )
76
+ ```
77
+
78
+ **Note:** `trust_remote_code=True` is required because this is a custom architecture with its own `modeling_pcmlp.py` and `configuration_pcmlp.py`. Pin a specific commit hash if you need reproducibility.
79
+
80
+ ## Training Procedure
81
+
82
+ | Hyperparameter | Value |
83
+ |---|---|
84
+ | Steps | 200 |
85
+ | Batch size | 32 |
86
+ | Optimizer | AdamW (hand-rolled, β₁=0.9, β₂=0.999) |
87
+ | Learning rate | 3e-3 |
88
+ | Weight decay | 0 (applied via AdamW default) |
89
+ | Local loss weight (λ) | 0.1 |
90
+ | Hidden dim | 32 |
91
+ | Sequence length | 16 |
92
+ | Vocab size | 16 |
93
+
94
+ **Training data:** Synthetic. Each sample is a 16-token sequence over a vocab of 16. The label is `1` if the first token is ≥ 8 **or** the sequence is a palindrome, else `0`. This task requires both a local feature (position 0) and a global feature (palindrome).
95
+
96
+ ## Evaluation
97
+
98
+ | Metric | Value |
99
+ |---|---|
100
+ | Validation accuracy | **1.000** |
101
+ | Validation loss | 0.006 |
102
+ | Parameters | 3,138 |
103
+ | Wall time (200 steps, CPU) | 0.53s |
104
+
105
+ **Baseline comparison:**
106
+
107
+ | Model | Params | Acc | Loss |
108
+ |---|---|---|---|
109
+ | **PC-MLP (this model)** | **3,138** | **1.000** | **0.006** |
110
+ | Baseline transformer | 5,314 | 1.000 | 0.000 |
111
+ | Scan-native SSM | 1,634 | 0.902 | 0.613 |
112
+ | KAN-replaced MLP | 2,636 | 0.621 | 0.725 |
113
+
114
+ ## Activation Health
115
+
116
+ The model passes the activation-health diagnostic used throughout the lab:
117
+
118
+ ```
119
+ pre1 = h @ W1 std=0.0180
120
+ |tanh(pre1)| max 0.0691
121
+ ```
122
+
123
+ The `pre1` std of 0.018 is small, but the `tanh` squash keeps it in the linear region of the GELU that follows, so gradients flow. This is the diagnostic that caught the KAN's dead RBF basis and the SpikeMUDD's zero spike rate.
124
+
125
+ ## Limitations
126
+
127
+ - **Toy scale.** 3,138 parameters, 16-token sequences, 2 classes. This is a mechanism demonstration, not a language model.
128
+ - **Synthetic data.** The palindrome + position task is a diagnostic, not a benchmark. It doesn't correlate with any real-world NLP performance.
129
+ - **Hand-rolled optimizer.** The Adam implementation in `train.py` is not `optax`. It's correct but not battle-tested.
130
+ - **No tokenizer.** The model operates on integer token IDs directly. There's no `tokenizer.json`.
131
+ - **JAX/Flax.** Transformers v5 deprecated native JAX support. The Hub integration uses a `torchax`-compatible shim, but the native path is JAX.
132
+
133
+ ## Citation
134
+
135
+ ```bibtex
136
+ @misc{pc_mlp_tiny_2026,
137
+ title={PC-MLP: A 3K-Parameter Predictive-Coding MLP for Sequence Classification},
138
+ author={zeechimp},
139
+ year={2026},
140
+ howpublished={\url{https://huggingface.co/zeechimp/pc-mlp-tiny}}
141
+ }
142
+ ```
143
+
144
+ ## References
145
+
146
+ - Ishikawa, S., Yokota, R., & Karakida, R. (2025). *Local Loss Optimization in the Infinite Width: Stable Parameterization of Predictive Coding Networks and Target Propagation.* ICLR 2025.
147
+ - HuggingFace model card template.
148
+ - Custom models with `auto_map`.
149
+