File size: 5,135 Bytes
a424144 4516974 a424144 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | ---
license: mit
datasets:
- FurkanNar/StackMathematics
- FurkanNar/StackMathematics-XL
language:
- en
metrics:
- accuracy
base_model:
- FurkanNar/Spatial_Context_Networks
pipeline_tag: text-classification
tags:
- code
---
# Spatial Context Networks (SCN)
> **Geometric Semantic Routing in Neural Architectures**
> Furkan Nar β Independent Researcher
> February 2026
[](LICENSE)
[](https://doi.org/10.5281/zenodo.18599303)
[](https://www.python.org/)
[](https://pytorch.org/)
---
## Overview
Spatial Context Networks (SCN) is a novel neural architecture that treats neurons as **geometric entities in a learned semantic space**. Rather than relying on weighted linear combinations, each neuron operates as a point-mass with a learnable centroid β activating based on its distance to the input in that space.
This repository contains the reference PyTorch implementation accompanying the paper.
π **Paper:** [https://doi.org/10.5281/zenodo.18599303](https://doi.org/10.5281/zenodo.18599303)
### Key Ideas
- **Geometric Activation** β activation inversely proportional to normalized Euclidean distance from a learnable centroid
- **Semantic Routing** β binary hard-routing that only activates neurons geometrically close to the input
- **Connection Density Weighting** β adaptive normalization that stabilizes signal magnitude across sparsity regimes
- **Pattern Distribution** β a Bayesian prior over output patterns via learnable softmax weights
---
## Architecture
```
Input x β β^d
β
βΌ
βββββββββββββββββββββββββββ
β Semantic Routing Layer β β Geometric activations + binary mask
β f(v) = 1 / (βvβΞΌβ/βd + Ξ΅)β
βββββββββββββββββββββββββββ
β activations, mask
βΌ
βββββββββββββββββββββββββββ
β Connection Density Layer β β Adaptive normalization + explosion control
β C = Ξ£ w_i / (Ξ±/z) β
βββββββββββββββββββββββββββ
β context score
βΌ
βββββββββββββββββββββββββββ
β Linear Projection β
βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β Pattern Distribution β β h β softmax(w_p)
βββββββββββββββββββββββββββ
β
βΌ
Output o β β^dout
```
---
## Installation
```bash
git clone https://github.com/TheOfficialFurkanNar/spatial-context-networks.git
cd spatial-context-networks
pip install -e .
```
---
## Quick Start
```python
import torch
from model.py import SpatialContextNetwork
# Instantiate the model
model = SpatialContextNetwork(
input_dim=10,
n_neurons=32,
output_dim=4,
routing_threshold=0.5,
stability_factor=10.0,
explosion_threshold=2.0,
)
# Forward pass
x = torch.randn(8, 10)
output = model(x) # shape: (8, 4)
# Diagnostic stats
stats = model.get_network_stats(x)
print(f"Network efficiency: {stats['network_efficiency']:.1%}")
print(f"Mean active neurons: {stats['mean_active_neurons']:.1f} / 32")
```
---
## Training
```bash
python train.py \
--input_dim 10 \
--n_neurons 32 \
--output_dim 4 \
--epochs 50 \
--batch_size 8 \
--lr 1e-3 \
--save_path scn_model.pt
```
---
## Inference
```bash
python inference.py --checkpoint scn_model.pt --batch_size 8
```
---
## Hyperparameters
| Parameter | Default | Description |
|-----------|---------|-------------|
| `input_dim` | 10 | Input feature dimensionality |
| `n_neurons` | 32 | Number of geometric hidden neurons |
| `output_dim` | 4 | Output dimensionality |
| `routing_threshold` Ο | 0.5 | Minimum activation to route through a neuron |
| `stability_factor` SF | 10.0 | Ξ΅ = 1/SF; prevents division by zero at centroid |
| `explosion_threshold` Ο_exp | 2.0 | Context scores above this get β damped |
---
## Results (Proof-of-Concept)
| Metric | Value |
|--------|-------|
| Mean active neurons | 29.1 / 32 |
| Network efficiency | 91% |
| Mean context score | 0.444 |
| Total parameters | ~500 |
| Hardware | Consumer gaming laptop (RTX) |
---
## Citation
If you use this work, please cite:
```bibtex
@article{nar2026scn,
title = {Spatial Context Networks: Geometric Semantic Routing in Neural Architectures},
author = {Nar, Furkan},
year = {2026},
month = {February},
doi = {10.5281/zenodo.18599303},
url = {https://doi.org/10.5281/zenodo.18599303},
note = {Independent research. Published on Zenodo and Academia.edu}
}
```
---
## License
[MIT](LICENSE) Β© 2026 Furkan Nar |