Skip to main content

SCLM: Stateful Coherent Language Model - Persistent memory for transformers

Project description

🧠 SCLM: Stateful Coherent Language Model

PyPI version SCLM License Hugging Face Python 3.8+

SCLM adds persistent latent memory to transformer language models, enabling better coherence across long conversations and multi-turn generation.

📖 Documentation | 🇫🇷 Version Française | 📝 Paper | 💼 Commercial Licensing


⚖️ Licensing

SCLM is Proprietary Software under a dual-licensing model.

🆓 Free for:

  • ✅ Personal & hobbyist projects
  • ✅ Academic research (non-profit)
  • ✅ Small businesses (revenue < $100,000 USD/year)

💼 Commercial License Required for:

  • ❗ Organizations with revenue > $100,000 USD/year
  • ❗ SaaS products (any revenue)
  • ❗ Redistribution in proprietary products

📧 Contact: info@amewebstudio.com


✨ Features

  • 🧠 Persistent Memory: State that evolves across conversation turns
  • 🎯 Entity Coherence: Maintains context about characters, places, objects
  • ✏️ Edit Mode: Make local changes without affecting global memory
  • Lightweight: Only ~2-5% additional parameters (EARCP architecture)
  • 🔌 Easy Integration: Works with any HuggingFace transformer

📦 Installation

# Basic installation
pip install saclm

# With quantization support
pip install saclm[quantization]

# Full installation (all features)
pip install saclm[full]

🚀 Quick Start

from sclm import SCLMModel

# Load SCLM model from Hugging Face
model = SCLMModel.from_pretrained(
    "amewebstudio/ananke-sclm",     # Pre-trained SCLM model
    load_in_4bit=True  # Optional: 4-bit quantization
)

# Start new conversation
model.reset_state()

# Build context
model.add_context("The wizard Elara lives in Silverwood forest.")
model.add_context("Her familiar is a silver cat named Nimbus.")

# Generate with memory - entities are remembered!
output = model.generate("One day, Elara decided to", max_new_tokens=50)
print(output)
# "One day, Elara decided to take Nimbus on a journey through Silverwood..."

📊 Architecture: EARCP

SCLM uses the EARCP architecture (patent pending):

SCLM Architecture

EARCP = Encapsulation + Alignment + Revision + Coherence + Propagation
Component Function
Encapsulation GRU-style state update from hidden states
Alignment Cross-attention between state and hidden layers
Revision Drift detection and correction
Coherence Mixture-of-Experts for consistency
Propagation State injection into transformer layers
┌─────────────────┐
│  Hidden States  │
└────────┬────────┘
         │
    ┌────┴────┐
    ▼         ▼
┌───────┐ ┌───────┐
│Encaps.│ │Inject │
└───┬───┘ └───────┘
    │
    ▼
┌───────────┐
│  Latent   │
│   State   │───────► Persists across turns
└───────────┘

💡 Use Cases

Interactive Fiction

model.reset_state()

# Build story world
model.add_context("The kingdom of Eldoria was ruled by Queen Lyra.")
model.add_context("The royal advisor Marcus had served for decades.")

# Characters persist in memory
output = model.generate("Marcus approached the throne and said")
# Marcus and Queen Lyra are remembered correctly

Long Conversations

# Memory persists without growing context window
for turn in conversation_turns:
    model.add_context(turn)

# Generate response with all context in memory
response = model.generate("Based on our discussion,")

Creative Writing

# Chapter 1
model.add_context("Chapter 1: Sarah discovered an old map in the attic.")

# Chapter 2 - Sarah is remembered
output = model.generate("Chapter 2: The next morning, Sarah")

⚙️ Configuration

from sclm import SCLMConfig

# Custom configuration
config = SCLMConfig(
    latent_state_dim=256,        # State vector dimension
    n_experts=2,                  # Number of MoE experts
    state_injection_layers=[8, 16],  # Which layers to inject
    alpha_inject=0.02,            # Injection strength
)

# Use with model
model = SCLMModel.from_pretrained("model-name", config=config)

Presets

from sclm.config import get_preset

# Use optimized presets
config = get_preset("mistral-7b")  # or "llama-7b", "phi-2", "tiny"

📖 API Reference

SCLMModel

Method Description
from_pretrained(name) Load model from HuggingFace
reset_state() Reset memory for new conversation
add_context(text) Add context to memory
generate(prompt) Generate text with memory
freeze_state() Freeze memory for editing
save_checkpoint(path) Save model checkpoint

Properties

Property Description
state_norm Current state vector norm
state Current state tensor

🔬 Benchmarks

Model EARCP Params Overhead Entity Retention
Mistral-7B 91.7M 2.4% 85%
LLaMA-7B 91.7M 2.4% 83%
Phi-2 52.3M 1.9% 81%

🛠️ Advanced Usage

Edit Mode

# Establish context
model.add_context("The sword was blue and ancient.")

# Make edit without changing memory
model.freeze_state()
output = model.generate("The sword was RED")  # State unchanged
model.unfreeze_state()

Memory Tracking

from sclm.utils import MemoryTracker

tracker = MemoryTracker(model)
tracker.add("Context 1")
tracker.add("Context 2")
output = tracker.generate("Prompt")

print(tracker.summary())
tracker.plot_state_evolution()  # Visualize state changes

🇫🇷 Documentation Française

Qu'est-ce que SCLM ?

SCLM (Stateful Coherent Language Model) ajoute une mémoire latente persistante aux modèles de langage transformers, permettant une meilleure cohérence dans les longues conversations.

⚖️ Licence

SCLM est un logiciel propriétaire sous un modèle de double licence.

🆓 Gratuit pour :

  • ✅ Projets personnels et hobbyistes
  • ✅ Recherche académique (non lucratif)
  • ✅ Petites entreprises (revenus < 100 000 $ USD/an)

💼 Licence commerciale requise pour :

  • ❗ Organisations avec revenus > 100 000 $ USD/an
  • ❗ Produits SaaS (tout revenu)
  • ❗ Redistribution dans des produits propriétaires

📧 Contact : info@amewebstudio.com

Installation

pip install saclm

Démarrage Rapide

from sclm import SCLMModel

# Charger le modèle SCLM depuis Hugging Face
model = SCLMModel.from_pretrained(
    "amewebstudio/ananke-sclm",
    load_in_4bit=True
)

# Nouvelle conversation
model.reset_state()

# Construire le contexte
model.add_context("Le sorcier Élara vit dans la forêt de Boisargent.")
model.add_context("Son familier est un chat argenté nommé Nimbus.")

# Générer avec mémoire
output = model.generate("Un jour, Élara décida de", max_new_tokens=50)
print(output)

Architecture EARCP

Composant Fonction
Encapsulation Mise à jour de l'état style GRU
Alignement Cross-attention état ↔ hidden
Révision Détection et correction de dérive
Cohérence Mixture d'Experts (MoE)
Propagation Injection dans les couches

📝 Citation

@article{amega2025sclm,
  title={SCLM: Stateful Coherent Language Models with EARCP Architecture},
  author={Amega, Mike},
  year={2025},
  note={Ame Web Studio - Proprietary}
}

📄 License

Business Source License 1.1 (BSL-1.1) - See LICENSE for details.

Copyright (c) 2025 Mike Amega (Ame Web Studio). All Rights Reserved.

👤 Author

Mike Amega - Ame Web Studio
📧 info@amewebstudio.com
🔗 github.com/Volgat


💼 Commercial Licensing

For commercial licensing inquiries, enterprise support, or custom development:

📧 Email: info@amewebstudio.com

Commercial Benefits:

  • ✅ Legal compliance for enterprise use
  • ✅ Priority technical support
  • ✅ Right to redistribute
  • ✅ Warranty and indemnification
  • ✅ Custom feature development

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

saclm-0.1.1.tar.gz (48.4 kB view details)

Uploaded Source

Built Distribution

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

saclm-0.1.1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file saclm-0.1.1.tar.gz.

File metadata

  • Download URL: saclm-0.1.1.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for saclm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 db87797cee2b864e868d52ee20a72d9e5b01084463b4f6aea23876184f6b3619
MD5 6a31019201fc7582bde565497584140f
BLAKE2b-256 ed803d0c3c20009497b7bca9cb80d87898ce0dce3ac3e95abcc2714a82a35ff6

See more details on using hashes here.

Provenance

The following attestation bundles were made for saclm-0.1.1.tar.gz:

Publisher: publish.yml on Volgat/sclm

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

File details

Details for the file saclm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: saclm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for saclm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b50c672e305c93ca7b1b101699a3828b00f41c1aa9a7d030be4eb5bda99d8abe
MD5 b95b4de7a19c570f9a36921de6689b2e
BLAKE2b-256 8a6eefe74a325cfe42187e9a2670e71b569b74d0d349df18bab8cb0d86dd97dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for saclm-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Volgat/sclm

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