Skip to main content

A model whose weights change during inference: surprise-gated fast-weight test-time learning. Zero dependencies, runs in Python and the browser.

Project description

self-learning-model

Models whose weights change while they run. Predict → get surprised → rewrite a small, bounded part of yourself → never forget the base. Proven with falsifiable experiments (PROOF.md, p ≤ 4e-04).

pip install self-learning-model          # zero-dependency core
pip install "self-learning-model[qwen]"  # + the self-learning Qwen3-VL runtime

1 · Strands-expert Qwen3-VL-2B that keeps learning

A Qwen3-VL-2B post-tuned on the entire strands-agents codebase (strands probes NLL 4.85 → 2.22, 8/8 improved), plus a plastic layer that adapts at inference — with a provable off-switch.

from slm.qwen import StrandsPlasticQwen                     # needs [qwen] + HF_TOKEN

m = StrandsPlasticQwen.from_pretrained()                    # cagataydev/strands-qwen3-vl-2b
print(m.chat("How do I create a custom tool in Strands Agents?"))

for doc in your_stream:
    m.observe(doc, learn=True)   # predicts; if surprised, rewrites its fast weights
m.reset()                        # exactly back to the strands-expert base

Verified: continual out-of-distribution stream NLL 6.18 → 5.37 while strands expertise is untouched (Δ −0.01). Model: cagataydev/strands-qwen3-vl-2b (private).

2 · Zero-dependency core (Python + browser, bit-identical)

The mechanism in ~600 lines of stdlib Python, mirrored in vanilla JS (Δ≈1e-15):

from slm import SelfLearningLM
lm = SelfLearningLM.from_pretrained("cagataydev/self-learning-model")
lm.observe("novel text", learn=True)     # weights change — no training step

Live demo: docs/index.html — watch a transformer's weight matrix rewrite itself in your browser as it reads.

Is it really learning? Yes — proven.

Six skeptic attacks, six closed doors (PROOF.md):

attack test result
"it memorized the stream" freeze → eval on unseen inputs err 0.665→0.044, 20/20
"knowledge is in optimizer state" transplant weights into virgin body identical, Δ=0
"any perturbation helps" same-norm random-direction updates no learning
"the update process is the trick" shuffled-target control no learning
"black box" decode M_eff vs true W* correlation 0.005→0.943
"toy result" real frozen GPT, held-out docs, info-ladder controls p=4.0e-04

Honest negatives included: single-prompt in-context (softmax attention already wins), emergent in-context learning at tiny scale, and the finding that ~⅓ of naive test-time-training gains are mere calibration — a confound we control for.

How it works

frozen base (instinct — never updated, can't forget)
  + tiny plastic LoRA (experience — updated every step at inference)
  + surprise gate (learn only when wrong) + EMA decay (bounded, stable)
loss = next-observation prediction error   ← the free label from reality

The stability–plasticity dilemma is resolved by the decay: without it the model learns hard but forgets (retention +7.09); with it, it learns and retains (+0.03).

More

PROOF.md the proof of learning, exact statistics
RESULTS.md all experiments E0–E7b, incl. negatives
ARCHITECTURE.md / PLASTIC.md / SCIENCE.md design, delta-rule method, protocol
strands_tune/ · qwen_plastic/ Qwen training & eval pipelines
BROWSER.md · web/ the zero-dep browser story

Built on ideas from TTT (Sun et al.), Titans (Behrouz et al.), fast-weight programmers (Schmidhuber), DeltaNet — and @karpathy's atomic GPT.

MIT.

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

self_learning_model-0.2.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

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

self_learning_model-0.2.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file self_learning_model-0.2.0.tar.gz.

File metadata

  • Download URL: self_learning_model-0.2.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for self_learning_model-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b453554bdb786841b8a442f2fa2a4d157a90959c41fada0ef485037e1a0402cf
MD5 39fdba137e280327555a2dc9349895a2
BLAKE2b-256 103dcb6edcae2de9cfd24e0b57008086465ebe05a0de449c643fa3e12168a9bc

See more details on using hashes here.

File details

Details for the file self_learning_model-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for self_learning_model-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fb964a2edf3243cff0d33da6a728c1f1f1f07d3e300b2a8f6d221b8f08ea833
MD5 1e6e162beb528cb13ee0b22236588ffd
BLAKE2b-256 d91913a65a31e225646115002e6c74cae278a18d744a01ba5b4f38286349ced8

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