"Attention is All You Need" β Vaswani et al., 2017
This repository asks: What if attention isn't just for Transformers? What if every neuron learns its own attention mask over a fixed substrate?
Standard deep learning treats learning as weight sculpting: carve millions of individual parameters
This repository explores the opposite thesis:
The intelligence of a neural network does not reside in the values of its weights, but in the attention masks it learns over fixed, structured substrates. Learning is not sculptingβit is learning where to look.
| Paradigm | Standard DL | Attention Neuron |
|---|---|---|
| Unit of learning | Individual weights |
Attention masks over substrates |
| Substrate | Learned (random init β optimized) | Fixed, structured, infinite (DCT, Walsh, Random, Geometric, Complex) |
| Parameters |
|
|
| Intelligence | Memorizing mappings | Learning what to attend to |
| Analogy | Sculpting marble | Pointing a flashlight |
Every layer in this library follows a unified pattern:
Fixed Substrate (Dictionary) Γ Learnable Attention Mask β Effective Weight Matrix
| Layer | Substrate (Prior) | Attention Mechanism | Budget |
|---|---|---|---|
AttentionLinear |
Frozen random projection (Kaiming) | Dual low-rank: multiplicative gate + additive shift | rank |
RosettaLinear |
|
Softmax mixing over |
|
DCTLinear |
Discrete Cosine Transform basis | Spectral coefficients (frequency attention) | |
WalshLinear |
Walsh-Hadamard basis | Spectral coefficients (logical/parity attention) |
The substrate encodes inductive bias (what patterns exist). The attention mask encodes intelligence (which patterns matter for this task).
- Compression without loss: 50β1000Γ fewer trainable params, competitive accuracy
- Interpretability: Attention masks are directly visualizable (heatmaps of frequencies, substrate mixtures, gate activations)
- Hardware-friendly: Walsh = additions only; DCT = frequency-domain sparsity; Geometric = resolution-invariant
- Scalability: Grow substrate resolution (more frequencies, more substrates) without growing parametersβonly attention resolution grows
- Unified view: Transformers attend over tokens; Attention Neurons attend over bases. Same mechanism, different granularity.
Insight: Gating frozen backbones >> additive tuning (LoRA).
Result: 94.53% MNIST with 7.8k params (98% compression). Phase bias
π Phase 1 | Phase 2
Rosetta (v22): Attention-like mixing of
Perlin substrates: Correlated spatial frequencies act as natural edge detectors, accelerating learning.
π Rosetta | Perlin
DCT: Smooth semantic attention (cosine waves) β vision, language.
Walsh-Hadamard: Discrete logic gates (
π All-DCT MLP | Fully-JPEG LLM
Neurons learn mathematical curves (BΓ©zier, line segments) on continuous plane.
Backprop physically moves curve endpoints β 100% resolution-invariant, adversarially robust.
π Stroke | Matchstick
Ternary
PID Optimizer: Control theory (Kp=1, Ki=100, Kd=1) beats Adam in convergence & speed.
π Gated Frozen Master | PID Sweep
Complex-valued (CVNN): Native 2D rotations, wave interference.
TrueCausalComplexFFT: Causal Fourier mixer β position encoded in phase
Phase-nGPT: nGPT hyperspherical norm + causal phase mixer + NarrowFFN β 80% fewer params, 2.5Γ speedup vs Transformer.
PoincarΓ© Attention: Geodesic distances in hyperbolic disk for hierarchical reasoning.
Conformal Optics: Weight matrix = projection of 2D texture deformed by trainable conformal map.
π Phase-nGPT | PoincarΓ© | Conformal
| Model | Version | Trainable Params | Accuracy | Compression |
|---|---|---|---|---|
| Standard MLP (Baseline) | β | ~400,000 | 94.50% | 1.0Γ |
| Gated Random | v6b | 7,794 | 94.53% | 51Γ |
| Nano Walsh (Spectral) | v40 | 938 | 92.12% | 426Γ |
| BΓ©zier Stroke (Geometric) | v50 | 3,200 | 97.88% | 125Γ |
| All-DCT MLP | v63 | 11,914 | 97.59% | 50Γ |
| Gated Ternary CNN | v256 | 394 | 85.07% | 1015Γ |
| Conformal Optics | v287 | 3,082 | 39.06% | 32Γ |
| Model / Task | Version | Trainable Params | Metric | Advantage |
|---|---|---|---|---|
| NavigatorNet (CIFAR-10) | v19 | 118,238 | 76.76% Acc | Rank-32 gates over frozen kernels |
| Complex FFN | v275 | ~800 | 2.63e-6 MSE | 6.1Γ lower loss vs real MLP |
| CausalPhase-nGPT (WikiText) | v282 | 116,870 | 5.35 PPL | 80% fewer params, 2.3Γ faster |
| PoincarΓ© Attention (Tree Ancestors) | v286 | 32,797 | 43.49% Acc | +11.6% vs Euclidean at |
pip install -e .import torch
from attention_neuron import (
AttentionLinear, # Spatial: dual low-rank gating over frozen random
RosettaLinear, # Spatial: softmax mixture of K frozen substrates
DCTLinear, # Spectral: DCT coefficient attention (smooth/semantic)
WalshLinear # Spectral: Walsh coefficient attention (logic/discrete)
)
# 1. Spatial Gating β learn WHERE to gate in a random projection
layer = AttentionLinear(in_features=784, out_features=2048, rank=128)
# Params: 784*128*2 + 128*2048*2 β 362k vs 1.6M dense
# 2. Rosetta β learn WHICH substrate to attend to per neuron
rosetta = RosettaLinear(in_features=784, out_features=1024, num_substrates=4)
# Each output neuron learns softmax over 4 frozen random dictionaries
# 3. DCT β learn WHICH FREQUENCIES matter (semantic attention)
dct = DCTLinear(in_features=256, out_features=256, k_in=64, k_out=64)
# Only 64Γ64=4096 spectral coeffs vs 65k dense β learns frequency mask
# 4. Walsh β learn LOGICAL PARITY patterns (discrete attention)
walsh = WalshLinear(in_features=512, out_features=512, k_in=128, k_out=128)
# Basis is Β±1 β synthesis uses only additions, zero multiplications
x = torch.randn(32, 784)
out = layer(x) # [32, 2048]
out = rosetta(x) # [32, 1024]
out = dct(x) # [32, 256]
out = walsh(x) # [32, 512]attention_neuron/ # Core library (production-ready layers)
βββ layers/
β βββ base.py # Shared bases (DCT, Walsh matrices)
β βββ dense.py # AttentionLinear (dual low-rank gating)
β βββ rosetta.py # RosettaLinear (substrate mixture attention)
β βββ spectral.py # DCTLinear, WalshLinear (spectral attention)
βββ __init__.py # Public API
scratch/ # 287+ experimental prototypes (v1βv287+)
docs/ # Findings, whitepapers, blueprints, brainstorming
examples/ # Runnable demos (MNIST, Spectral GPT)
results/ # Figures, raw logs, model checkpoints
| Topic | Document |
|---|---|
| Unified Theory | Attention Neuron Theory v2 |
| Spectral vs LoRA | Attention Neuron vs LoRA |
| Compression Analysis | Attention Neuron Compression |
| Phase-nGPT Blueprint | Blueprint DCT LLM |
| Conformal Optics | Findings v287 |
| All Findings Index | docs/findings_v*.md (chronological) |
MIT License β see LICENSE.
Developed by Mario RaΓΊl Carbonell MartΓnez
Exploring the thesis that intelligence, at every scale, is learning where to direct attention.