Skip to main content

Neuro-Harmonic Graph Engine — iterative harmonic resonance ML architecture

Project description

Neuro-Harmonic Graph Engine (NHGE)

#IDEA INITIATED BY H.A.Mwala (Full name HEKIMA A. MWALA) #TANZANIAN A novel machine learning architecture with iterative harmonic resonance over a dynamic graph structure.


Key Idea

Transformers compute attention in one parallel pass over all tokens simultaneously. NHGE iterates — tokens are graph nodes that resonate with each other, updating their states step by step until the graph reaches harmonic convergence.

Property Transformer NHGE
Processing Parallel attention Iterative harmonic resonance
Depth Fixed layers Dynamic (stops at convergence)
Edge weights Attention scores Similarity × phase coherence
Memory O(N²) attention matrix O(N²) but iterative, not stacked
Simple inputs Same cost as complex Converges faster → cheaper

Architecture

Input tokens
     ↓
[Embedding + positional + phase initialisation]
     ↓
┌─────────────────────────────────────────┐
│  Harmonic iteration loop (max T steps)  │
│                                         │
│  HarmonicEdgeLayer                      │
│    edge_w = softmax(Q·K/√d) × cos(Δθ)  │
│                                         │
│  HarmonicNodeUpdate                     │
│    h_v ← h_v + FFN(h_v + Σ w·h_u)      │
│                                         │
│  PhaseUpdate                            │
│    θ ← θ + α·tanh(W·h)·π               │
│                                         │
│  Convergence: ||h_t − h_{t−1}|| < ε    │
└─────────────────────────────────────────┘
     ↓
[Graph readout: mean / CLS / attention pool]
     ↓
Output logits

Files

File Purpose
nhge_model.py Core NHGE architecture (all layers + full model)
nhge_tokenizer.py Word / char / subword tokenizer
nhge_trainer.py Training engine with warmup LR, AMP, checkpoints
nhge_inference.py Generation, classification, embeddings
demo.py Runnable end-to-end demo (no GPU needed)

Quick start

from nhge_model     import nhge_small
from nhge_tokenizer import NHGETokenizer
from nhge_inference import NHGEInference

# 1. Build tokenizer
tok = NHGETokenizer(mode="word")
tok.build_vocab(your_texts, min_freq=2)

# 2. Build model
model = nhge_small(vocab_size=tok.vocab_size, num_classes=2)

# 3. Inference
inf = NHGEInference(model, tok, device="cuda")
results = inf.classify(["Your input text here"], label_names=["neg", "pos"])

# 4. Generate
text = inf.generate("The harmonic graph", max_new_tokens=50)

Training

from nhge_trainer import NHGETrainer, TokenDataset
from torch.utils.data import DataLoader

dataset = TokenDataset(encoded_tokens, labels=class_labels, max_len=128)
loader  = DataLoader(dataset, batch_size=32, shuffle=True)

trainer = NHGETrainer(model, loader, val_loader=val_loader,
                      task="cls", lr=3e-4, device="cuda")
history = trainer.train(epochs=20)

Model sizes

Name d_model n_heads n_layers max_iter ~Params
nhge_small 128 4 2 6 ~3M
nhge_base 512 8 4 8 ~85M
nhge_large 1024 16 6 10 ~340M

Requirements

torch >= 2.0

No other dependencies required for core functionality.


Run the demo

python demo.py

Theory

The harmonic edge weight combines two signals:

  1. Semantic similarity — scaled dot product of Q and K projections
  2. Phase coherence — cos(θ_i − θ_j) between learned phase angles

Nodes in phase amplify each other's signals. Out-of-phase nodes cancel. This mimics oscillatory dynamics in biological neural networks, where synchronised firing encodes binding of related concepts.

The phase angles are updated each iteration via a damped gradient:

θ ← θ + α · tanh(W·h) · π

This allows the network to "tune" its resonance frequencies as information propagates — a form of learned synchronisation.


Licence

MIT — use freely, extend openly, credit the NHGE project.

MIT License

Copyright (c) 2026 H.A. Mwala

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nhge-0.1.8.post1.dev0.tar.gz (165.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nhge-0.1.8.post1.dev0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file nhge-0.1.8.post1.dev0.tar.gz.

File metadata

  • Download URL: nhge-0.1.8.post1.dev0.tar.gz
  • Upload date:
  • Size: 165.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nhge-0.1.8.post1.dev0.tar.gz
Algorithm Hash digest
SHA256 270166e4c6b16f9a6c6d1be65282561d4ee0a422caa98a5379f6fae677491834
MD5 e138afc8c5bcb2a24d4955e389b8a192
BLAKE2b-256 ec32d511cdccb000d61943f67c93406a7a70f6d59e52e4cd4d5c3da8a1ba8b61

See more details on using hashes here.

Provenance

The following attestation bundles were made for nhge-0.1.8.post1.dev0.tar.gz:

Publisher: publish.yml on mwala400/nhge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nhge-0.1.8.post1.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for nhge-0.1.8.post1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1c4e1d131132b96ec3a7443bad9c76e3d7ae4e6e68a4becc1e0868b95b1eb57
MD5 771791e3683b431c8c82306fcc5c4d5a
BLAKE2b-256 d87631c9aa07a54229fbe5259a8584386619f3a02d89e659eb00f9a59c6da927

See more details on using hashes here.

Provenance

The following attestation bundles were made for nhge-0.1.8.post1.dev0-py3-none-any.whl:

Publisher: publish.yml on mwala400/nhge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page