Skip to main content

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:

  1. Input Injection: Text tokens are embedded and injected into the volume along a raster-scan grid.
  2. Local Propagation: 3D causal convolutions distribute information to adjacent neighbors ($3 \times 3 \times 3$ grid).
  3. Resonance Gating: Energy updates dynamically. High-energy zones gate state updates.
  4. Wormholes: Multi-Head Attention runs on top-K active cells (sorted causally) to exchange distant state.
  5. Iterative Loops: The cycles run repeatedly until convergence or max cycle threshold.
  6. 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.

Metadata

Release files for spatialwave 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spatialwave 0.1.0
File Size Uploaded Provenance
spatialwave-0.1.0.tar.gz 25.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spatialwave 0.1.0
File Interpreter ABI Platform
spatialwave-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.3 kB

Release files / spatialwave-0.1.0.tar.gz

Download URL spatialwave-0.1.0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72d652ab2e5e8cd846f91be45e42fdebece33e2acdc2e05d6d99dce81f692acc
BLAKE2b-256 checksum
How to use checksums
aec97b927097f4c84d91a1617d164bfb7c6f13d74aa94a743e2d696769b049a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Release files / spatialwave-0.1.0-py3-none-any.whl

Download URL spatialwave-0.1.0-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76960194880f84919ca7bfbab5514fa2c1de8ff0f3ed7725d363b0927e1c5391
BLAKE2b-256 checksum
How to use checksums
03ca0ae460ff5fbdb02d0dabd3dc44f48dffcdfc8334844a1adea53250b07d6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Security for spatialwave 0.1.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spatialwave-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page