Skip to main content

Self-learning brain with neurogenesis and AI dopamine

Project description

🧠 Learning Brain

A self-learning neural network that grows new neurons! Like GGUF, but dynamic.

Learning Brain is a Python package that provides neurogenesis and continuous learning for AI models. It's like GGUF, but instead of being static, it grows new neurons when it learns!

This package includes the SELSC Engine v2 - the same engine used in the HuggingFace model: https://huggingface.co/Specialgfhdhdh/learning-qwen

✨ Features

  • 🧬 Neurogenesis - Automatically grows new neurons when confused
  • 🧠 STDP Learning - Spike-Timing-Dependent Plasticity for realistic neural learning
  • 💊 Dopamine System - Reward-modulated learning rate
  • 💾 Persistent State - Save/load learned brain states to .brain files
  • 🔄 Model Agnostic - Works with any base model (Qwen, Llama, etc.)
  • 📦 pip Installable - Easy to install and use

🧬 SELSC Engine v2

The package includes the SELSC Engine v2 - the evolved brain from your HuggingFace model!

Features:

🚀 Installation

# From PyPI (when published)
pip install learning-brain

# From source
pip install .

📖 Usage

Python API

from learning_brain import Brain

# Create a new learning brain for a model
brain = Brain("qwen")

# Teach it something
result = brain.learn("The sky is blue and the grass is green")
print(result)
# {'tokens': 9, 'active_neurons': 100, 'neuron_grown': False, 'interactions': 1}

# Save the learned brain
brain.save()

# Check brain info
print(brain.info)
# {'model': 'qwen', 'path': 'qwen.brain', 'active_neurons': 100, ...}

# Later, load the brain
brain = Brain.load("qwen.brain")

CLI

# Run interactive session
python -m learning_brain run qwen

# Create a new brain
python -m learning_brain create mymodel

# Run demo
python -m learning_brain demo

Interactive Session

$ python -m learning_brain run qwen
==================================================
🧠 Learning Brain - qwen
==================================================
Info: {'model': 'qwen', 'path': 'qwen.brain', 'active_neurons': 100, ...}

Commands:
  save - Save and exit
  info - Show brain info
  quit - Exit without saving
--------------------------------------------------

> teach me about artificial intelligence
  Learned: 4 tokens
  Active neurons: 100

> machine learning is fascinating
  Learned: 4 tokens
  Active neurons: 100
  🧬 NEW NEURON GROWN!

> save
💾 Brain saved: qwen.brain
Goodbye!

🧬 How It Works

Neurogenesis

The brain automatically grows new neurons when it encounters high error (confusion). This is similar to how real brains work - when a neuron is "confused" (high error), the brain activates a dormant neuron to help process the new information.

STDP Learning

Spike-Timing-Dependent Plasticity (STDP) is a learning rule where:

  • If neuron A fires before neuron B → connection A→B strengthens (Long-Term Potentiation)
  • If neuron A fires after neuron B → connection A→B weakens (Long-Term Depression)

This creates realistic, Hebbian-style learning.

File Format

The .brain file contains:

  • Neural network weights
  • Active neuron mask
  • Vocabulary
  • Learning history
  • Cumulative error traces

This is like GGUF but supports runtime learning and neurogenesis!

⚙️ Configuration

brain = Brain(
    model_name="qwen",
    vocab_size=10000,       # Max vocabulary size
    max_neurons=10000,      # Max neurons
    initial_neurons=100,    # Starting neurons
    lr_stdp=0.001,          # Learning rate
    tau_stdp=20.0,          # STDP time constant
    error_threshold=0.8,    # Error threshold for neurogenesis
)

📁 Project Structure

learning_brain_pkg/
├── learning_brain/
│   ├── __init__.py     # Main package (EvolvedChat, Brain, SELSC_Engine)
│   └── selsc_engine.py # SELSC Engine v2
├── setup.py           # pip setup script
├── README.md          # This file
└── LICENSE            # MIT License

💾 .neuro File Format

The .neuro file contains both the Qwen model weights AND the SELSC brain:

from learning_brain import EvolvedChat

# Create and chat
chat = EvolvedChat(model="Qwen/Qwen2.5-0.5B-Instruct", brain_path="mybrain.brain")
chat.chat("Hello!")

# Save EVERYTHING to .neuro file
chat.save("my_ai.neuro")  # Includes Qwen + SELSC brain!

# Later, load and chat immediately
chat = EvolvedChat.load_neuro("my_ai.neuro")
chat.chat("What did I teach you?")

🤝 Contributing

Contributions welcome! Please open an issue or PR.

📝 License

MIT License - feel free to use!


Made with 🧬 by the Learning Brain Team

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

learning_brain-3.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

learning_brain-3.0.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file learning_brain-3.0.0.tar.gz.

File metadata

  • Download URL: learning_brain-3.0.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for learning_brain-3.0.0.tar.gz
Algorithm Hash digest
SHA256 d49de7d96ed9197bd12f48561961b2959d0320ad2c4a57bef7e8c51eaff4d92c
MD5 b172de5ed213192611555497c48d9373
BLAKE2b-256 7241a737e674a005a43a65b4d260cb71a6f28fef6148cdcaa6cd559641672426

See more details on using hashes here.

File details

Details for the file learning_brain-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: learning_brain-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for learning_brain-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09b6e376a909ee460ca1e714bc238a8cfa9102d6ba963946cdabcd46cf6747f1
MD5 a119daf51a13fd2421087f21c56583a0
BLAKE2b-256 f15e91e0d1524d097295eaeb8fd7f7b281d32cc805c5cef1af5d861a891693f4

See more details on using hashes here.

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