Expand description
§Topological Coherence
Rust implementation of topological constraints for coherent inference. Based on: “Topological Constraints for Coherent Language Models” (Cormier, 2026)
§Theory
Hallucination is a geometry problem: unconstrained latent dynamics permit arbitrary drift through latent space. Topological constraints (specifically toroidal manifolds with constant spectral gap) bound this drift.
§Hierarchy
mHC (Birkhoff) ⊂ ERLHS (Hamiltonian) ⊂ Karmonic (Toroidal + Spectral)§Key Results (from validation experiment)
| Condition | Drift Rate | Interpretation |
|---|---|---|
| Toroidal | 0.006 | 40% lower than baseline |
| Random | 0.167 | 28x worse (proves topology matters) |
§Usage
ⓘ
use topological_coherence::{Tonnetz, ToroidalMask};
// Create 12x12 Tonnetz (standard musical topology)
let tonnetz = Tonnetz::<12>::new();
// Distance on torus
let d = tonnetz.distance((0, 0), (5, 7));
// Attention mask with locality radius 2
let mask = ToroidalMask::new(64, 2.0, 1.0);Structs§
- Adjacency
Loss - Adjacency loss computation.
- Coherence
Config - Configuration for coherence validation (for pallet storage).
- Coherence
Result - Result of coherence validation (for on-chain reporting).
- Drift
Meter - Drift measurement utilities.
- Grounding
Decomposition - Result of decomposing a vector into grounded and hallucinated components.
- Grounding
Projector - Orthogonal grounding projector G = A(AᵀA)⁻¹Aᵀ.
- Karmonic
Filter - Karmonic spectral filter for training-time regularization.
- Learned
Projection - Learned toroidal projection parameters.
- Multi
Scale Tonnetz - Multi-scale Tonnetz configuration.
- Sparse
Mask - Sparse mask in CSR (Compressed Sparse Row) format.
- Tonnetz
- Tonnetz topology on a 2D torus of size N x N.
- Toroidal
Mask - Toroidal attention mask generator.
- Toroidal
Position - Position on the Tonnetz torus (for on-chain storage).
- Torus3D
- 3D Torus topology (T^3).
Enums§
- Mask
Type - Mask type variants for different use cases.
Functions§
- angles_
to_ grid - Angles to torus position: quantize continuous angles to grid coordinates.
- fourier_
expand - Fourier torus projection: map angles to Fourier coordinates.
- is_
doubly_ stochastic - Check if matrix is approximately doubly-stochastic.
- sinkhorn_
knopp - Sinkhorn-Knopp algorithm: project matrix to doubly-stochastic.