# mizup0905/neuromorphicai architecture

> Architecture diagram of the GitHub repository mizup0905/neuromorphicai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mizup0905/neuromorphicai
- Repository: https://github.com/mizup0905/neuromorphicai

## Overview

Neuromorphic AI is an experimental sequence-modeling repository centered on a C4 language-model workflow: obtain and tokenize C4 data, optionally prepare gate caches, train or evaluate LRP-SSM models, and inspect comparisons. Its model combines a low-rank path state-space core with routing; an SNN simulator provides spiking-neuron behavior. Separate experiment tooling compares LRP-SSM with attention and recurrent baselines, while calibration and router distillation support alternative gate-generation workflows. The tree and excerpts establish the core model and data responsibilities; some script internals were not sampled, so their connections are limited to indexed references or README documentation.

Main entry points: [`src/lm/c4_lrp_lm.py`](https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_lrp_lm.py) (C4 LRP Language Model), [`scripts/c4_build_cache.py`](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_build_cache.py) (Cache Builder), [`scripts/c4_train.py`](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_train.py) (C4 Trainer), [`scripts/c4_eval.py`](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_eval.py) (C4 Evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["C4 Data"]
  node_c4data["C4 Token Blocks<br/>[c4_data.py]"]
  node_cachebuild["Cache Builder<br/>[c4_build_cache.py]"]
  node_cache[("Token and Gate Cache")]
  node_trainer["C4 Trainer<br/>[c4_train.py]"]
  node_evaluator["C4 Evaluation<br/>[c4_eval.py]"]
end

subgraph group_model["Sequence Model"]
  node_lm["C4 LRP Language Model<br/>[c4_lrp_lm.py]"]
  node_ssm["Low-Rank Path SSM"]
  node_neuron["Pyramidal Neuron Simulator"]
end

subgraph group_routing["Routing"]
  node_routercal["Router Calibration"]
  node_distill["Router Distillation"]
  node_router["Learned and Lightweight Routers<br/>[c4_lrp_lm.py]"]
end

subgraph group_experiments["Experiments"]
  node_compare["Baseline Comparison<br/>[compare_all.py]"]
  node_experimentdata["Experiment Cache Data<br/>[data.py]"]
  node_experimentmodels["Baseline Models<br/>[models.py]"]
  node_trainone["Single-Model Training<br/>[train_one.py]"]
  node_report["Experiment Reports<br/>[report.py]"]
  node_benchmark["C4 Benchmark<br/>[c4_benchmark.py]"]
end

node_researcher(("Researcher"))
node_c4[("C4 Dataset")]

node_c4 -->|"provides text"| node_c4data
node_researcher -->|"builds caches"| node_cachebuild
node_cachebuild -->|"tokenizes with"| node_c4data
node_cachebuild -->|"writes caches"| node_cache
node_researcher -->|"trains model"| node_trainer
node_trainer -->|"loads caches"| node_cache
node_trainer -->|"trains"| node_lm
node_lm -->|"runs sequence core"| node_ssm
node_ssm -->|"uses simulator"| node_neuron
node_lm -->|"uses routing"| node_router
node_researcher -->|"evaluates"| node_evaluator
node_evaluator -->|"loads caches"| node_cache
node_evaluator -->|"evaluates"| node_lm
node_researcher -->|"calibrates gates"| node_routercal
node_routercal -->|"calibrates router"| node_ssm
node_researcher -.->|"distills router"| node_distill
node_distill -->|"trains lightweight router"| node_router
node_researcher -->|"compares models"| node_compare
node_compare -->|"runs training"| node_trainone
node_trainone -->|"loads cache data"| node_experimentdata
node_trainone -->|"builds model"| node_experimentmodels
node_experimentmodels -->|"wraps LRP model"| node_lm
node_compare -->|"optionally benchmarks"| node_benchmark
node_researcher -->|"generates report"| node_report

click node_c4data "https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_data.py"
click node_cachebuild "https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_build_cache.py"
click node_trainer "https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_train.py"
click node_evaluator "https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_eval.py"
click node_lm "https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_lrp_lm.py"
click node_ssm "https://github.com/mizup0905/neuromorphicai/blob/main/src/lrp_ssm/low_rank_path_ssm.py"
click node_neuron "https://github.com/mizup0905/neuromorphicai/blob/main/src/snn/pyramidal_neuron.py"
click node_routercal "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/fix_lrp_router_calibration.py"
click node_distill "https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_distill_router.py"
click node_router "https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_lrp_lm.py"
click node_compare "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/compare_all.py"
click node_experimentdata "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/data.py"
click node_experimentmodels "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/models.py"
click node_trainone "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/train_one.py"
click node_report "https://github.com/mizup0905/neuromorphicai/blob/main/experiments/report.py"
click node_benchmark "https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_benchmark.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_c4data,node_cachebuild,node_cache,node_trainer,node_evaluator toneBlue
class node_lm,node_ssm,node_neuron,node_c4 toneAmber
class node_routercal,node_distill,node_router toneMint
class node_compare,node_experimentdata,node_experimentmodels,node_trainone,node_report,node_benchmark toneRose
class node_researcher toneIndigo
```

## Components

### C4 Data

- [C4 Token Blocks](https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_data.py): `src/lm/c4_data.py`
- [Cache Builder](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_build_cache.py): `scripts/c4_build_cache.py`
- **Token and Gate Cache**
- [C4 Trainer](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_train.py): `scripts/c4_train.py`
- [C4 Evaluation](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_eval.py): `scripts/c4_eval.py`

### Sequence Model

- [C4 LRP Language Model](https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_lrp_lm.py): `src/lm/c4_lrp_lm.py`
- [Low-Rank Path SSM](https://github.com/mizup0905/neuromorphicai/blob/main/src/lrp_ssm/low_rank_path_ssm.py): `src/lrp_ssm/low_rank_path_ssm.py`
- [Pyramidal Neuron Simulator](https://github.com/mizup0905/neuromorphicai/blob/main/src/snn/pyramidal_neuron.py): `src/snn/pyramidal_neuron.py`

### Routing

- [Router Calibration](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/fix_lrp_router_calibration.py): `experiments/fix_lrp_router_calibration.py`
- [Router Distillation](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_distill_router.py): `scripts/c4_distill_router.py`
- [Learned and Lightweight Routers](https://github.com/mizup0905/neuromorphicai/blob/main/src/lm/c4_lrp_lm.py): `src/lm/c4_lrp_lm.py`

### Experiments

- [Baseline Comparison](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/compare_all.py): `experiments/compare_all.py`
- [Experiment Cache Data](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/data.py): `experiments/data.py`
- [Baseline Models](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/models.py): `experiments/models.py`
- [Single-Model Training](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/train_one.py): `experiments/train_one.py`
- [Experiment Reports](https://github.com/mizup0905/neuromorphicai/blob/main/experiments/report.py): `experiments/report.py`
- [C4 Benchmark](https://github.com/mizup0905/neuromorphicai/blob/main/scripts/c4_benchmark.py): `scripts/c4_benchmark.py`

### Other components

- **Researcher**
- **C4 Dataset**

## Connections

- C4 Dataset → C4 Token Blocks: provides text (evidence: `src/lm/c4_data.py`)
- Researcher → Cache Builder: builds caches (evidence: `README.md`)
- Cache Builder → C4 Token Blocks: tokenizes with (evidence: `scripts/c4_build_cache.py`)
- Cache Builder → Token and Gate Cache: writes caches (evidence: `scripts/c4_build_cache.py`)
- Researcher → C4 Trainer: trains model (evidence: `README.md`)
- C4 Trainer → Token and Gate Cache: loads caches (evidence: `scripts/c4_train.py`)
- C4 Trainer → C4 LRP Language Model: trains (evidence: `scripts/c4_train.py`)
- C4 LRP Language Model → Low-Rank Path SSM: runs sequence core (evidence: `src/lm/c4_lrp_lm.py`)
- Low-Rank Path SSM → Pyramidal Neuron Simulator: uses simulator (evidence: `src/lrp_ssm/low_rank_path_ssm.py`)
- C4 LRP Language Model → Learned and Lightweight Routers: uses routing (evidence: `src/lm/c4_lrp_lm.py`)
- Researcher → C4 Evaluation: evaluates (evidence: `README.md`)
- C4 Evaluation → Token and Gate Cache: loads caches (evidence: `scripts/c4_eval.py`)
- C4 Evaluation → C4 LRP Language Model: evaluates (evidence: `scripts/c4_eval.py`)
- Researcher → Router Calibration: calibrates gates (evidence: `README.md`)
- Router Calibration → Low-Rank Path SSM: calibrates router (evidence: `experiments/fix_lrp_router_calibration.py`)
- Researcher → Router Distillation: distills router
- Router Distillation → Learned and Lightweight Routers: trains lightweight router (evidence: `scripts/c4_distill_router.py`)
- Researcher → Baseline Comparison: compares models (evidence: `README.md`)
- Baseline Comparison → Single-Model Training: runs training (evidence: `experiments/compare_all.py`)
- Single-Model Training → Experiment Cache Data: loads cache data (evidence: `experiments/train_one.py`)
- Single-Model Training → Baseline Models: builds model (evidence: `experiments/train_one.py`)
- Baseline Models → C4 LRP Language Model: wraps LRP model (evidence: `experiments/models.py`)
- Baseline Comparison → C4 Benchmark: optionally benchmarks (evidence: `experiments/compare_all.py`)
- Researcher → Experiment Reports: generates report (evidence: `experiments/report.py`)
