A Python library implementing Spatial Wave Transformer (SWT) architecture for research and experimentation.
Project description
Spatial Wave Transformer (SWT)
spatialwave is a Python library that implements an experimental Artificial Intelligence architecture based on a 3D spatial field. Instead of global attention mechanisms, information propagates through local 3D updates, energy-gated resonance, and dynamic causal wormhole shortcuts.
The library is designed for research, experimentation, and proof-of-concept AI development. It natively supports GPU/CUDA acceleration and works on both PyTorch CPU/GPU runtimes.
Key Features
- 3D Latent Field representation: Model state resides in a tridimensional volume where information maps to specific coordinates.
- Causal 3D Convolutions: Multi-cycle propagation preserves sequence order dynamically via raster-scan causality masks.
- Resonance Gating: Zones of high energy gate the computation, driving focus onto highly active signal junctions.
- Causal Wormhole Layers: Dynamic, sparse shortcuts connect highly active regions using causal Multi-Head Attention.
- Iterative Reasoning Engine: Executes configurable cycles with adaptive stopping, shutting down iterations when states converge.
- Word-Based BasicTokenizer: Full fitting, encoding, decoding, and serialization out-of-the-box.
- Robust Trainer: Simplified training loop with progress tracking, perplexity computation, and automatic checkpoints.
Installation
To install the library, clone this repository and run:
git clone https://github.com/bueormnew/spatialwave.git
cd spatialwave
pip install -e .
Or install dependencies manually:
pip install -r requirements.txt
Quickstart Example
Here is a simple example showing how to initialize, train, save, load, and run inference using spatialwave:
from spatialwave import SpatialWaveModel, BasicTokenizer, TextGenerator
# 1. Prepare some text
corpus = [
"El espacio tridimensional contiene informacion latente.",
"La resonancia local ayuda a propagar las ondas de datos.",
"Los agujeros de gusano conectan regiones distantes causales."
]
# 2. Tokenize text
tokenizer = BasicTokenizer()
tokenizer.fit(corpus)
# 3. Create Model
model = SpatialWaveModel(
vocab_size=tokenizer.vocab_size,
field_size=16, # 16x16x16 volume
latent_dim=64, # Hidden size
cycles=6, # Max cycles
wormhole_interval=2 # Wormhole every 2 cycles
)
# 4. Generate continuation
generator = TextGenerator(model, tokenizer, device="cpu")
print(generator.generate("El espacio", max_tokens=5))
Training a Model
You can use the built-in Trainer to run autoregressive training on a text corpus:
from spatialwave import Trainer, TextDataset
# Create dataset
dataset = TextDataset(corpus, tokenizer, max_seq_len=16)
# Create trainer
trainer = Trainer(
model=model,
tokenizer=tokenizer,
train_dataset=dataset,
device="cpu",
checkpoint_dir="checkpoints"
)
# Train model
trainer.train(epochs=10, batch_size=4, lr=1e-3)
Save and Load
You can save and load both the model and tokenizer to easily resume work or run inference elsewhere:
# Save model & tokenizer
model.save("model.swt")
tokenizer.save("tokenizer.json")
# Load model & tokenizer
loaded_model = SpatialWaveModel.load("model.swt")
loaded_tokenizer = BasicTokenizer.from_file("tokenizer.json")
Internal Architecture
The SWT architecture processes tokens as follows:
- Input Injection: Text tokens are embedded and injected into the volume along a raster-scan grid.
- Local Propagation: 3D causal convolutions distribute information to adjacent neighbors ($3 \times 3 \times 3$ grid).
- Resonance Gating: Energy updates dynamically. High-energy zones gate state updates.
- Wormholes: Multi-Head Attention runs on top-K active cells (sorted causally) to exchange distant state.
- Iterative Loops: The cycles run repeatedly until convergence or max cycle threshold.
- Logits Prediction: Logits are extracted from the token coordinates and mapped to vocabulary predictions.
Read the detailed Architecture Documentation for more information.
Roadmap
- Advanced Tokenization: Support Byte-Pair Encoding (BPE) and SentencePiece.
- Multimodality: Support image embedding injection on boundary faces (e.g. front face) and text on another.
- Longer Sequences: Optimized sparse 3D convolutions for scaling grid size.
- Multi-GPU Training: Native PyTorch DistributedDataParallel (DDP) support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spatialwave-0.1.0.tar.gz.
File metadata
- Download URL: spatialwave-0.1.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72d652ab2e5e8cd846f91be45e42fdebece33e2acdc2e05d6d99dce81f692acc
|
|
| MD5 |
15d1fd24791fd5bea3ce354eed965a19
|
|
| BLAKE2b-256 |
aec97b927097f4c84d91a1617d164bfb7c6f13d74aa94a743e2d696769b049a0
|
Provenance
The following attestation bundles were made for spatialwave-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on bueormnew/spatialwave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatialwave-0.1.0.tar.gz -
Subject digest:
72d652ab2e5e8cd846f91be45e42fdebece33e2acdc2e05d6d99dce81f692acc - Sigstore transparency entry: 2038433047
- Sigstore integration time:
-
Permalink:
bueormnew/spatialwave@10c9188dbc9c511fd98425237332c509722b8e91 -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/bueormnew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@10c9188dbc9c511fd98425237332c509722b8e91 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spatialwave-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spatialwave-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76960194880f84919ca7bfbab5514fa2c1de8ff0f3ed7725d363b0927e1c5391
|
|
| MD5 |
f42f0cdcd2364b47aff3522d06c22ad6
|
|
| BLAKE2b-256 |
03ca0ae460ff5fbdb02d0dabd3dc44f48dffcdfc8334844a1adea53250b07d6b
|
Provenance
The following attestation bundles were made for spatialwave-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on bueormnew/spatialwave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatialwave-0.1.0-py3-none-any.whl -
Subject digest:
76960194880f84919ca7bfbab5514fa2c1de8ff0f3ed7725d363b0927e1c5391 - Sigstore transparency entry: 2038434175
- Sigstore integration time:
-
Permalink:
bueormnew/spatialwave@10c9188dbc9c511fd98425237332c509722b8e91 -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/bueormnew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@10c9188dbc9c511fd98425237332c509722b8e91 -
Trigger Event:
release
-
Statement type: