Skip to content

mcarbonell/attention-neuron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

127 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Attention Neuron: Intelligence is Learning Where to Look

Status Architecture Efficiency

"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?


🎯 Core Thesis: Learning Is Attention

Standard deep learning treats learning as weight sculpting: carve millions of individual parameters $w_{ij}$ until the mapping input→output works.

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 $w_{ij}$ Attention masks over substrates
Substrate Learned (random init β†’ optimized) Fixed, structured, infinite (DCT, Walsh, Random, Geometric, Complex)
Parameters $O(d^2)$ per layer $O(k^2)$ or $O(r \cdot d)$ β‰ͺ $d^2$
Intelligence Memorizing mappings Learning what to attend to
Analogy Sculpting marble Pointing a flashlight

🧠 The Attention Neuron Framework

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 $r$
RosettaLinear $K$ independent frozen random substrates Softmax mixing over $K$ substrates per neuron $K$ substrates
DCTLinear Discrete Cosine Transform basis Spectral coefficients (frequency attention) $k_{in} \times k_{out}$
WalshLinear Walsh-Hadamard basis Spectral coefficients (logical/parity attention) $k_{in} \times k_{out}$

The substrate encodes inductive bias (what patterns exist). The attention mask encodes intelligence (which patterns matter for this task).


πŸ”¬ Why This Matters

  1. Compression without loss: 50–1000Γ— fewer trainable params, competitive accuracy
  2. Interpretability: Attention masks are directly visualizable (heatmaps of frequencies, substrate mixtures, gate activations)
  3. Hardware-friendly: Walsh = additions only; DCT = frequency-domain sparsity; Geometric = resolution-invariant
  4. Scalability: Grow substrate resolution (more frequencies, more substrates) without growing parametersβ€”only attention resolution grows
  5. Unified view: Transformers attend over tokens; Attention Neurons attend over bases. Same mechanism, different granularity.

πŸš€ Six Research Eras (287+ Experiments)

1. Multiplicative Gating & Phase Bias (v1–v18)

Insight: Gating frozen backbones >> additive tuning (LoRA).
Result: 94.53% MNIST with 7.8k params (98% compression). Phase bias $\sin(\theta)$ for neuromorphic $[-1,1]$ signals.
πŸ“„ Phase 1 | Phase 2

2. Substrate Interference & Spatial Priors (v19–v33)

Rosetta (v22): Attention-like mixing of $K$ substrates via softmax β€” constructive interference cancels useless frequencies.
Perlin substrates: Correlated spatial frequencies act as natural edge detectors, accelerating learning.
πŸ“„ Rosetta | Perlin

3. Spectral Orthogonal Bases (v35–v67)

DCT: Smooth semantic attention (cosine waves) β†’ vision, language.
Walsh-Hadamard: Discrete logic gates ($\pm1$ square waves) β†’ multiplier-free FPGA execution.
πŸ“„ All-DCT MLP | Fully-JPEG LLM

4. Geometric Stroke & Matchstick Neurons (v50–v57)

Neurons learn mathematical curves (BΓ©zier, line segments) on continuous plane.
Backprop physically moves curve endpoints β†’ 100% resolution-invariant, adversarially robust.
πŸ“„ Stroke | Matchstick

5. Gated Ternary & Control Theory (v251–v274)

Ternary ${-1,0,1}$ weights: Zero-mean signals, native contrast/edge detection. 394 params β†’ 85% MNIST (CNN prior).
PID Optimizer: Control theory (Kp=1, Ki=100, Kd=1) beats Adam in convergence & speed.
πŸ“„ Gated Frozen Master | PID Sweep

6. Complex Phase, Hyperbolic & Conformal Optics (v275–v287)

Complex-valued (CVNN): Native 2D rotations, wave interference.
TrueCausalComplexFFT: Causal Fourier mixer β€” position encoded in phase $e^{i\varphi}$, no positional encodings needed.
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


πŸ“Š Key Benchmarks

MNIST

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Γ—

CIFAR-10 & Language

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 $d=64$

πŸ› οΈ Library Usage

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]

πŸ“‚ Repository Structure

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

πŸ“– Key Documents for Deep Dives

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)

πŸ“œ License

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.

About

A neural architecture framework exploring low-rank multiplicative gating, spectral orthogonal bases (DCT/Walsh), complex-valued phase mixers, and conformal geometry over frozen substrates. Learning to equalize, not to sculpt.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors