Teaching Neural Networks the Art of Forgetting
Overview β’ Architecture β’ Installation β’ Quick Start β’ Theory β’ Insights
"The serpent that devours itself to be reborn β features consumed, transformed, and emerged anew."
|
Standard residual networks can only add information. They lack the ability to erase, forget, or reflect β leading to residual accumulation where noisy features persist indefinitely. A geometric residual connection that learns:
|
|
OUROBOROS enables neural networks to:
| Capability | Description |
|---|---|
| β¨ Selective Forgetting | Surgically erase outdated or noisy information |
| π Feature Reflection | Model oscillatory and oppositional dynamics |
| π― Spectral Control | Shape layer-wise transitions with precision |
| β‘ Gradient Stability | Maintain gradient flow with gated identity |
At the heart of OUROBOROS lies the Delta Operator β a generalized Householder transformation:
| Symbol | Name | Description | Range |
|---|---|---|---|
| k(X) | Reflection Direction | Unit vector defining transformation axis | βkβ = 1 |
| Ξ²(X) | Scalar Gate | Controls transformation intensity | [0, 2] |
| v(X) | Value Vector | New information to inject | βα΅α΅ |
A single learnable scalar dynamically interpolates between three geometric operations:
| Ξ² Value | Transformation | Eigenvalue | Effect |
|---|---|---|---|
| Ξ² β 0 | Identity | Ξ» = 1 | Pass through unchanged |
| Ξ² β 1 | Projection | Ξ» = 0 | Erase component along k |
| Ξ² β 2 | Reflection | Ξ» = -1 | Flip direction along k |
Vector v transformed by Delta Operator. P(v) = projection (Ξ²=1), R(v) = reflection (Ξ²=2). Vector k = hyperplane normal.
The input X splits into three learnable branches that compute k, Ξ², and v, which combine through the Delta operation with a skip connection.
Each OuroborosBlock contains:
- RMSNorm β Attention β Ouroboros Residual
- RMSNorm β MLP β Ouroboros Residual
X_{l+1} = X_l + Ξ² Β· k Β· (vα΅ β kα΅ Β· X_l)
β β
TARGET CURRENT
(what to write) (what exists)
This unifies three operations with a single gate:
| Operation | Formula | Effect |
|---|---|---|
| Erasure | βΞ² Β· k Β· (kα΅ Β· X) |
Removes component along k |
| Writing | +Ξ² Β· k Β· vα΅ |
Injects new information |
| Sync | Same Ξ² |
Both scale together |
Theorem: For
A = I β Ξ²Β·kΒ·kα΅whereβkβ = 1:
Ο(A) = { 1, 1, ..., 1, (1βΞ²) }
ββββββ¬βββββ
(dβ1) times
| Property | Formula | Notes |
|---|---|---|
| Eigenvalue along k | Ξ»_k = 1 β Ξ² |
Controlled by gate |
| Eigenvalues in kβ₯ | Ξ» = 1 |
Multiplicity: dβ1 |
| Determinant | det(A) = 1 β Ξ² |
Zero at Ξ²=1 |
| Orthogonality | Aα΅A = I |
When Ξ² β {0, 2} |
| Involution | AΒ² = I |
When Ξ² = 2 |
| Property | ResNet | OUROBOROS |
|---|---|---|
| Eigenvalues | β 1 + Ξ΅ | β [-1, 1] |
| Negative Ξ» | β No | β Yes |
| Singular | β No | β Yes (Ξ²=1) |
| Data-dependent | β Fixed | β Learnable |
Key Insight: The geometric coherence term k_i Β· k_j enables learned feature interactions without explicit cross-attention.
# Clone the repository
git clone https://github.com/DivyamTalwar/OUROBOROS.git
cd ouroboros
# Install dependencies
pip install torch>=2.0 transformers einops
# Install in development mode
pip install -e .| Package | Version | Purpose |
|---|---|---|
| Python | β₯ 3.8 | Runtime |
| PyTorch | β₯ 2.0 | Deep learning |
| Transformers | β₯ 4.30 | HuggingFace |
| einops | β₯ 0.6 | Tensor ops |
from model.ouroboros import OuroborosModel, OuroborosConfig
import torch
# Configure the model
config = OuroborosConfig(
vocab_size=50304,
hidden_size=768,
num_hidden_layers=12,
num_attention_heads=6,
head_dim=128,
)
# Initialize model
model = OuroborosModel(config)
print(f"Parameters: {model.get_num_params():,}")
# Forward pass
input_ids = torch.randint(0, 50304, (2, 512))
labels = input_ids.clone()
logits, loss = model(input_ids, targets=labels)
print(f"Loss: {loss.item():.4f}")from torch.optim import AdamW
model = OuroborosModel(config).cuda()
optimizer = AdamW(model.parameters(), lr=3e-4, weight_decay=0.1)
for batch in dataloader:
input_ids, labels = batch['input_ids'].cuda(), batch['labels'].cuda()
logits, loss = model(input_ids, targets=labels)
loss.backward()
optimizer.step()
optimizer.zero_grad()
print(f"Loss: {loss.item():.4f}")| Parameter | Type | Default | Description |
|---|---|---|---|
vocab_size |
int | 50304 | Vocabulary size |
hidden_size |
int | 768 | Model dimension |
num_hidden_layers |
int | 12 | Number of blocks |
num_attention_heads |
int | 6 | Attention heads |
head_dim |
int | 128 | Dimension per head |
block_size |
int | 1024 | Max sequence length |
| Parameter | Type | Default | Description |
|---|---|---|---|
ouroboros_k_eps |
float | 1e-6 | k normalization Ξ΅ |
ouroboros_beta_init |
float | 1.0 | Initial Ξ² [0, 2] |
ouroboros_v_sigmoid |
bool | True | Sigmoid on v |
ouroboros_v_sigmoid_scale |
float | 4.0 | v scale factor |
OUROBOROS/
βββ π README.md # Documentation
βββ assets/ # Images
β βββ banner.png
β βββ architecture.png
β βββ beta_spectrum.png
β βββ geometric_transform.png
β βββ dataflow.png
β βββ model_architecture.png
β βββ feature_coupling.png
βββ π model/
βββ ouroboros.py # Core implementation
| Challenge | ResNet | OUROBOROS |
|---|---|---|
| Noisy features accumulate | β Can only add | β Can erase |
| Oscillatory patterns | β No negative Ξ» | β Ξ» β [-1, 1] |
| Feature interference | β No filter | β Projection |
| Gradient stability | β Identity | β Gated identity |
OUROBOROS is the depth-wise dual of time-wise recurrence:
Time (DeltaNet): S_t = A Β· S_{t-1} + Ξ² Β· k Β· vα΅
Depth (OUROBOROS): X_{l+1} = A Β· X_l + Ξ² Β· k Β· vα΅
When Ξ² β 1, the Delta Operator is invertible:
Aβ»ΒΉ = I + (Ξ² / (1βΞ²)) Β· k Β· kα΅
At Ξ² = 2: A = Aβ»ΒΉ (orthogonal involution).
@software{ouroboros2025,
title = {OUROBOROS: Optimal Unified Residual Operations with
Bounded Orthogonal Reflection and Spectral Control},
year = {2025},
url = {https://github.com/DivyamTalwar/OUROBOROS}
}- Fork the repository
- Create feature branch:
git checkout -b feature/amazing - Commit changes:
git commit -m 'Add feature' - Push:
git push origin feature/amazing - Open a Pull Request
Creative Commons Attribution 4.0 International (CC-BY-4.0)
The ancient serpent eating its own tail β a symbol of cyclical transformation.
Features are consumed, transformed, and reborn through each layer.
Built with π for the ML community






