Topological Coherence
Toroidal attention constraints for LLM coherence — in-sample training-dynamics effects; inference-time hallucination reduction is a null result (see below)
Sylvain Cormier | Paraxiom Research | 2026
Status (v7 — March 2026 Replication Update)
Inference-time logit bias: A comprehensive 6-phase replication found the v2 TruthfulQA improvements (+0.2pp to +2.8pp) were within LLM judge sampling variance. Exact T&I replication: −2.0pp, p=0.22 (not significant).
What works:
- Prompt hardening: −14pp hallucination reduction (p=0.05) — the active ingredient in Coherence Shield
- Training-time topology: 28x lower drift than random sparsity in toy model (topology matters, not just sparsity)
- Library primitives: Tonnetz geometry, attention masks, spectral gap, drift measurement all valid
Recommended direction: Training-time Karmonic spectral regularization (untested, promising based on toy model)
- Paper: DOI: 10.5281/zenodo.18516477
Installation
pip install topological-coherence
# With HuggingFace transformers support
pip install topological-coherence[hf]
Quick Start: Toroidal Logit Bias
Drop-in logit processor for any HuggingFace model — no fine-tuning required:
from topological_coherence import ToroidalLogitProcessor
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
processor = ToroidalLogitProcessor(grid_size=12, radius=2.0, alpha=0.3)
inputs = tokenizer("The quantum nature of", return_tensors="pt")
outputs = model.generate(
**inputs,
logits_processor=[processor],
max_new_tokens=100
)
print(tokenizer.decode(outputs[0]))
Core API
Tonnetz Geometry
from topological_coherence import Tonnetz, distance_matrix
# Create a 12x12 torus topology
t = Tonnetz(grid_size=12)
t.distance(0, 5) # L1 toroidal distance with wraparound
t.spectral_gap() # First eigenvalue of the torus Laplacian
# Vectorized distance matrix (numpy, fast)
dm = distance_matrix(n_tokens=64, grid_size=12) # (64, 64)
Attention Masks (3 variants)
from topological_coherence import ToroidalMask, sinkhorn_knopp
mask = ToroidalMask.hybrid(seq_len=64, radius=2.0, alpha=1.0) # default
mask = ToroidalMask.hard_cutoff(seq_len=64, radius=2.0) # binary
mask = ToroidalMask.soft_exponential(seq_len=64, alpha=1.0) # smooth decay
tensor = mask.to_tensor() # torch.Tensor for attention
ds = sinkhorn_knopp(tensor, n_iters=50) # project to doubly-stochastic
Drift Measurement
from topological_coherence import DriftMeter
meter = DriftMeter(threshold=2, grid_size=12)
meter.record(pred=5, target=8)
meter.record(pred=5, target=100)
print(f"Drift rate: {meter.rate():.3f}")
Toroidal Attention (PyTorch)
from topological_coherence import ToroidalAttention, TinyTransformer
# Drop-in attention replacement
attn = ToroidalAttention(d_model=64, n_heads=4, max_seq_len=64)
# Full demo transformer with swappable attention
model = TinyTransformer(
vocab_size=144, d_model=64, n_heads=4,
attention_type="toroidal" # or "baseline", "random"
)
Theory
Hallucination is a geometry problem. Unconstrained latent dynamics permit arbitrary drift through embedding space. Toroidal constraints provide a constant spectral gap that suppresses non-resonant modes:
λ₁ = 2 - 2cos(2π/N) = Θ(1) for fixed grid size N
This bounds semantic drift without reducing model capacity.
Hierarchy: mHC (Birkhoff) ⊂ ERLHS (Hamiltonian) ⊂ Karmonic (Toroidal + Spectral)
Links
- Paper (Zenodo)
- Toroidal Logit Bias Paper
- Live Demo (HuggingFace)
- Source (GitHub)
- Rust Crate (crates.io)
Citation
@misc{cormier2026topological,
author = {Cormier, Sylvain},
title = {Topological Constraints for Coherent Language Models},
year = {2026},
publisher = {Zenodo},
doi = {10.5281/zenodo.18187835}
}
License
Apache-2.0
Metadata
Release files for topological-coherence 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| topological_coherence-0.3.1.tar.gz | 37.8 kB | Without provenance | Details for topological_coherence-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| topological_coherence-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for topological_coherence-0.3.1-py3-none-any.whl |
Total release size: 59.6 kB
Release files / topological_coherence-0.3.1.tar.gz
| Download URL | topological_coherence-0.3.1.tar.gz |
|---|---|
| Size | 37.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f28b2463516f0c5a9b88ed52c7cbdfb7d601f5545f6365b7b917a677e3fcdab
|
|
BLAKE2b-256 checksum How to use checksums |
68acee47d9dc64d7da0d83284a183d0dc1ace7fa54b82d3dfe9893e95622dac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / topological_coherence-0.3.1-py3-none-any.whl
| Download URL | topological_coherence-0.3.1-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85490b9b003a95b06c8df875ca11cc591caf5912b660f107dc772bb95258be5a
|
|
BLAKE2b-256 checksum How to use checksums |
df03d833a0ebe995fa5c1ba9db712bf91f732810f8d662cc846462f56e5afbe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for topological-coherence 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.