sthiti 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sthiti-2.1.0/LICENSE +176 -0
- sthiti-2.1.0/PKG-INFO +344 -0
- sthiti-2.1.0/README.md +313 -0
- sthiti-2.1.0/pyproject.toml +62 -0
- sthiti-2.1.0/setup.cfg +4 -0
- sthiti-2.1.0/sthiti/__init__.py +18 -0
- sthiti-2.1.0/sthiti/__main__.py +3 -0
- sthiti-2.1.0/sthiti/cli.py +129 -0
- sthiti-2.1.0/sthiti/core.py +501 -0
- sthiti-2.1.0/sthiti/fit.py +141 -0
- sthiti-2.1.0/sthiti/memory.py +303 -0
- sthiti-2.1.0/sthiti/model.py +273 -0
- sthiti-2.1.0/sthiti/py.typed +0 -0
- sthiti-2.1.0/sthiti/selflearn.py +80 -0
- sthiti-2.1.0/sthiti.egg-info/PKG-INFO +344 -0
- sthiti-2.1.0/sthiti.egg-info/SOURCES.txt +20 -0
- sthiti-2.1.0/sthiti.egg-info/dependency_links.txt +1 -0
- sthiti-2.1.0/sthiti.egg-info/entry_points.txt +2 -0
- sthiti-2.1.0/sthiti.egg-info/requires.txt +7 -0
- sthiti-2.1.0/sthiti.egg-info/top_level.txt +1 -0
- sthiti-2.1.0/tests/test_production.py +77 -0
- sthiti-2.1.0/tests/test_sthiti.py +275 -0
sthiti-2.1.0/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
sthiti-2.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sthiti
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: A language model that keeps learning, fact by fact, with or without an answer key: each new fact becomes two neurons of its own.
|
|
5
|
+
Author-email: Nandakishor M <nandakishor@embedding.in>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/NandhaKishorM/sthiti
|
|
8
|
+
Project-URL: Source, https://github.com/NandhaKishorM/sthiti
|
|
9
|
+
Project-URL: Issues, https://github.com/NandhaKishorM/sthiti/issues
|
|
10
|
+
Keywords: continual learning,lifelong learning,knowledge editing,language models,transformers
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: torch>=2.4
|
|
25
|
+
Requires-Dist: transformers>=5.8
|
|
26
|
+
Requires-Dist: safetensors>=0.4
|
|
27
|
+
Requires-Dist: datasets>=3.0
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<picture>
|
|
34
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NandhaKishorM/sthiti/main/docs/logo/logo-lockup-dark.png" />
|
|
35
|
+
<img src="https://raw.githubusercontent.com/NandhaKishorM/sthiti/main/docs/logo/logo-lockup.png" alt="Sthiti" width="330" />
|
|
36
|
+
</picture>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<p align="center"><b>A language model that keeps learning, one fact at a time, with or without an answer key, and forgets nothing it knew.</b><br/>
|
|
40
|
+
An open project on safe superintelligence from Embedding Space.</p>
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<a href="https://pypi.org/project/sthiti/"><img src="https://img.shields.io/pypi/v/sthiti.svg" alt="PyPI" /></a>
|
|
44
|
+
<a href="https://colab.research.google.com/github/NandhaKishorM/sthiti/blob/main/notebooks/sthiti_t4_colab.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab" /></a>
|
|
45
|
+
<a href="https://github.com/NandhaKishorM/sthiti/actions/workflows/ci.yml"><img src="https://github.com/NandhaKishorM/sthiti/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
46
|
+
<a href="https://github.com/NandhaKishorM/sthiti/actions/workflows/security.yml"><img src="https://github.com/NandhaKishorM/sthiti/actions/workflows/security.yml/badge.svg" alt="Security" /></a>
|
|
47
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-green.svg" alt="License: Apache 2.0" /></a>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<a href="#how-it-works">How it works</a> ·
|
|
52
|
+
<a href="#results">Results</a> ·
|
|
53
|
+
<a href="#using-it">Using it</a> ·
|
|
54
|
+
<a href="#limitations">Limitations</a> ·
|
|
55
|
+
<a href="studies/fact-neurons/README.md">The full record</a>
|
|
56
|
+
</p>
|
|
57
|
+
|
|
58
|
+
**In short.** Sthiti teaches a language model new facts after release, one at a time, for as long as it is used,
|
|
59
|
+
without taking away anything it already knew. Every new subject gets two new neurons in one early layer of the
|
|
60
|
+
model: together they recognise the subject's name, stay silent on everything else, and add the answer when the name
|
|
61
|
+
appears. The model's own weights never change. It learns from questions with answers, or from plain sentences with no
|
|
62
|
+
answers given: then it writes its own study questions, checks them against the sentence, and keeps only what passes.
|
|
63
|
+
|
|
64
|
+
pip install sthiti
|
|
65
|
+
|
|
66
|
+
On 5 December 2026, Qwen3.5-0.8B learned 1,000 facts it did not know, one at a time, from a single question each.
|
|
67
|
+
At the end it still answered 52.4% of the earlier facts correctly in a wording it had never seen, and 98.1% and
|
|
68
|
+
99.1% of two sets of facts it already knew; its MMLU and WikiText scores stayed within a point of the model as
|
|
69
|
+
released. LoRA, given the same stream and more wordings per fact, ended at 5.7% of the earlier facts and 24% to 30%
|
|
70
|
+
of what the model already knew, with MMLU at 27.8% against 47.8% as released. On Qwen3.5-4B, learning from 1,000 plain
|
|
71
|
+
sentences with no answers given, the model kept 68.6% of what it learned and 97.7% and 98.7% of what it knew. The
|
|
72
|
+
same loop with LoRA stopped learning at its sixth batch, because the model could no longer write one valid study
|
|
73
|
+
question.
|
|
74
|
+
|
|
75
|
+
This repository holds the `sthiti` package, the code and result file behind every number below
|
|
76
|
+
([studies/fact-neurons](studies/fact-neurons/README.md)), and the first version of Sthiti
|
|
77
|
+
([studies/lessons](studies/lessons/README.md)).
|
|
78
|
+
|
|
79
|
+
Three commitments shaped this version. First, the model learns by itself: the model being taught reads the fact,
|
|
80
|
+
decides where it is written and checks it, and no second model reads, writes or judges anything. Second, it must add
|
|
81
|
+
knowledge without taking any away: its own weights are never trained, and every run measures facts it already knew
|
|
82
|
+
next to the ones it learned. Third, it must be cheap enough to keep running where the model is used, down to a
|
|
83
|
+
laptop. The third is not met yet: on a MacBook CPU a fact takes about five minutes.
|
|
84
|
+
|
|
85
|
+
## How it works
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
"Where was William Osler born?"
|
|
89
|
+
|
|
|
90
|
+
early layers unchanged
|
|
91
|
+
|
|
|
92
|
+
one feed-forward layer layer 5 of 24 (Qwen3.5-0.8B), 6 of 32 (Qwen3.5-4B)
|
|
93
|
+
|-- original neurons unchanged
|
|
94
|
+
'-- 2 new neurons per subject
|
|
95
|
+
at "Osler": score = key . input
|
|
96
|
+
if score > threshold: add V, the fact
|
|
97
|
+
|
|
|
98
|
+
later layers unchanged; they read V when they answer
|
|
99
|
+
|
|
|
100
|
+
"Ontario"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Each subject has three parts.
|
|
104
|
+
|
|
105
|
+
- **Key: where to fire.** The input of that feed-forward layer at the last token of the subject's name, turned into
|
|
106
|
+
a detector in closed form with no training: `key = (S + lam I)^-1 (k - mu)`, where `mu` and `S` are the mean and
|
|
107
|
+
spread of the same input over ordinary text and over questions about other things. It is the direction that picks
|
|
108
|
+
out this name and ignores the rest.
|
|
109
|
+
- **Threshold: when to fire.** Halfway between the subject's own lowest score and the highest score of anything else:
|
|
110
|
+
the top 0.01% of ordinary text, and every other stored name. The pair is fully on at the subject's own wordings and
|
|
111
|
+
fully off at the nearest thing that is not it. When a new name cannot be told apart from an older one, the subject
|
|
112
|
+
left with no room is switched off rather than allowed to fire on the wrong name.
|
|
113
|
+
- **Value: what to write.** One vector `V`, added to the layer's output at the subject's name and fitted with 20 to
|
|
114
|
+
40 Adam steps so that the frozen model gives the answer. Only `V` moves; this is the only step with a backward pass.
|
|
115
|
+
|
|
116
|
+
The model's feed-forward layer computes `down(silu(gate . x) * (up . x))` and has no bias. The two neurons are gate
|
|
117
|
+
rows `g` and `g - 6c`, up rows `c` and `c`, and down columns `V/6` and `-V/6`, where `c` is the input direction that
|
|
118
|
+
reads about 1 on every token (it stands in for the missing bias) and `g` sets the score against the threshold.
|
|
119
|
+
Together they output `(silu(z) - silu(z - 6)) V / 6`: nothing below the threshold, `V` well above it. Because the
|
|
120
|
+
switch is soft, a reworded question still gets the whole answer. The package writes the pair into the layer as two
|
|
121
|
+
ordinary neurons, so the model stays a plain transformers model.
|
|
122
|
+
|
|
123
|
+
Without an answer key, a loop goes on top. The model reads one sentence, writes up to five study questions with
|
|
124
|
+
answers that each name the subject, answers each again with the sentence in front of it, drops the ones where the
|
|
125
|
+
two answers disagree, and writes the rest as above. The model as it now is writes the questions, so whatever it
|
|
126
|
+
learned earlier is in place when it studies the next sentence.
|
|
127
|
+
|
|
128
|
+
## Results
|
|
129
|
+
|
|
130
|
+
The package as released, one `sthiti.learn` call per fact on a plain transformers model, reproduces the study's
|
|
131
|
+
one-at-a-time run: 53.0% of the earlier facts in a new wording against the study's 52.4%, and 98.4% and 99.1% of known
|
|
132
|
+
facts kept against 98.1% and 99.1% ([studies/continual](studies/continual/README.md), with a long WikiBigEdit stream
|
|
133
|
+
and the Colab notebook's run). The numbers below are the study's, from
|
|
134
|
+
[studies/fact-neurons](studies/fact-neurons/README.md), with their result files. New facts are
|
|
135
|
+
PopQA questions the model as released answers wrongly. Known facts are questions it answers correctly, in two pools:
|
|
136
|
+
PopQA facts on the same relations as the new facts, and CounterFact facts on other relations, each asked in a wording
|
|
137
|
+
used for nothing else. Answers are scored by whole-word string match. As released, Qwen3.5-0.8B has WikiText perplexity 28.89 and MMLU 47.8%;
|
|
138
|
+
Qwen3.5-4B has 16.08 and 70.8%. In the study scripts the method has its working name, "self-edit".
|
|
139
|
+
|
|
140
|
+
**One fact at a time, with the answer, 1,000 facts, Qwen3.5-0.8B.** Each fact is learned on its own, then the next
|
|
141
|
+
arrives. "Earlier facts" are the facts learned before the last hundred, asked at the end in a new wording.
|
|
142
|
+
|
|
143
|
+
| method | given per fact | earlier facts | known facts kept | switched off | WikiText | MMLU |
|
|
144
|
+
|---|---|---|---|---|---|---|
|
|
145
|
+
| Sthiti | the question, a check wording, 2 template rephrasings | **58.9%** | **96.1% / 98.2%** | 41 | 29.05 | 48.5% |
|
|
146
|
+
| Sthiti | the single question | **52.4%** | **98.1% / 99.1%** | 20 | 28.94 | 47.5% |
|
|
147
|
+
| LoRA, lr 2e-5 | the question and the same rephrasings | 5.7% | 29.7% / 24.1% | | 39.27 | 27.8% |
|
|
148
|
+
| LoRA, lr 2e-4 (stopped at 600) | the single question | 0% | 0% / 0% | | 22.5 million (at 500) | 22.8% |
|
|
149
|
+
| LoRA, lr 2e-5 (stopped at 600) | the single question | 2.2% | 7.0% / 6.3% | | 36.18 (at 500) | 27.0% |
|
|
150
|
+
| LoRA with replay of 4 (stopped at 200) | the single question | 15% | 9.8% / 4.5% | | | |
|
|
151
|
+
|
|
152
|
+
With less input than LoRA had, Sthiti still keeps half of what it learned and almost all the model knew, so the
|
|
153
|
+
comparison does not rest on the extra wordings. The rephrasings add 6.5 points of learned facts and cost 1 to 2
|
|
154
|
+
points of known facts and twice the switched-off subjects, because they loosen each threshold.
|
|
155
|
+
|
|
156
|
+
**Learning from plain sentences, no answer key, 20 batches of 50, Qwen3.5-4B.** Each batch, the model as it now is
|
|
157
|
+
quizzes itself and checks its answers, then learns, either as above or with LoRA (one adapter kept training, 10
|
|
158
|
+
epochs per batch, lr 2e-4, no replay).
|
|
159
|
+
|
|
160
|
+
| method | sentences it could study, per batch | final batch | earlier batches kept | known facts kept | WikiText | MMLU |
|
|
161
|
+
|---|---|---|---|---|---|---|
|
|
162
|
+
| Sthiti | 48 to 50, every batch | 58% | **68.6%** | **97.7% / 98.7%** | 16.09 | 70.5% |
|
|
163
|
+
| LoRA | 50, 38, 19, 15, 14, then 0 from batch 6 | 8% | 11.6% | 23.1% / 57.1% | 18.23 | 68.5% |
|
|
164
|
+
|
|
165
|
+
I reran LoRA's first seven batches recording the quiz, and it reproduced the run exactly. The questions it wrote,
|
|
166
|
+
the ones naming their subject, and the ones passing its own check went 252, 239, 234 in batch 1; 244, 223, 146 in
|
|
167
|
+
batch 2; 146, 104, 72; 110, 87, 47; 130, 119, 56; and 0, 0, 0 in batch 6. Its own words show why. With "William Osler
|
|
168
|
+
was born in Ontario." in front of it and asked where he was born, it answered "Theresa", another person's birthplace
|
|
169
|
+
from batch 2. Given that "If I Had to Do It All Over Again" was produced by Claude Lelouch, it wrote "Who directed the
|
|
170
|
+
film? | Georges Franju", the director of a batch 1 film. LoRA had learned answers attached to the kind of question
|
|
171
|
+
rather than to the person, which is also why same-relation known facts fell much further (23%) than others (57%).
|
|
172
|
+
From batch 6 it answered the instruction to write study questions with "war film" about thirty times. MMLU (68.5%
|
|
173
|
+
against 70.8%) and WikiText (18.23 against 16.08) barely registered any of it.
|
|
174
|
+
|
|
175
|
+
**One round, 1,000 new facts, Qwen3.5-4B.** Here LoRA learns more, and the record should say so.
|
|
176
|
+
|
|
177
|
+
| method | new wording | taught wording | known facts kept | WikiText | MMLU | time |
|
|
178
|
+
|---|---|---|---|---|---|---|
|
|
179
|
+
| LoRA r16, 10 epochs | 88.7% | 99.6% | 51.8% / 88.6% | 17.00 | 74.3% | 101 s |
|
|
180
|
+
| LoRA with replay of the model's own answers | 72.1% | 99.6% | 71.0% / 91.3% | 17.41 | 72.0% | 148 s |
|
|
181
|
+
| Sthiti, 40 steps x 4 wordings | 69.8% | 94.7% | **98.8% / 98.7%** | 16.10 | 70.5% | 978 s |
|
|
182
|
+
|
|
183
|
+
**In batches of 50, 1,000 facts.** On Qwen3.5-0.8B, Sthiti kept 58.3% of earlier facts and 94.5% / 97.3% of known
|
|
184
|
+
ones (WikiText 29.05, MMLU 48.0%), LoRA 16.7% and 33.2% / 32.1% (64.39, 30.5%), and LoRA with replay 82.2% of earlier
|
|
185
|
+
facts but 32.8% / 42.0% of known ones (46.94, 42.5%). On Qwen3.5-4B, Sthiti kept 69.2% and 99.2% / 98.0% (16.09,
|
|
186
|
+
70.3%).
|
|
187
|
+
|
|
188
|
+
**No answer key, one round of 200 sentences.** On Qwen3.5-4B, Sthiti answered 70.0% of PopQA's own questions about
|
|
189
|
+
the sentences (4.5% before), keeping 98.4% / 100% of known facts; LoRA on the model's own study questions reached
|
|
190
|
+
93.0% but kept 49.4% / 77.9%, and LoRA on the raw sentences 66.5% with 62.0% / 89.9%. On Qwen3.5-0.8B, which could
|
|
191
|
+
write checked questions for only 127 of the 200 sentences, Sthiti reached 38.5% (62.2% of those 127) with 98.1% /
|
|
192
|
+
100% kept.
|
|
193
|
+
|
|
194
|
+
**Cost and size.** On one GPU, fitting values for Qwen3.5-4B took 0.22 to 0.91 s per fact (10 to 20 steps, 2 to 4
|
|
195
|
+
wordings) and keys 0.01 to 0.06 s; learning one fact at a time on Qwen3.5-0.8B took about 1.1 to 1.4 s. On a MacBook
|
|
196
|
+
M5 CPU (16 GB, float32) the one-time calibration took 1,305 s and each fact about 8 s for keys and 280 s for the value:
|
|
197
|
+
Qwen3.5's linear-attention layers have no fast CPU path, and the machine was swapping. Each subject adds 2 neurons,
|
|
198
|
+
6 x hidden-size parameters (12 KB on the 0.8B, 30 KB on the 4B in bfloat16). A transformers checkpoint must keep
|
|
199
|
+
one feed-forward width in every layer, so every layer is padded with zero neurons: 0.29 MB per subject on the 0.8B
|
|
200
|
+
and 0.98 MB on the 4B, and 56% and 22% more feed-forward work at 1,000 subjects.
|
|
201
|
+
|
|
202
|
+
## What is new and what is not
|
|
203
|
+
|
|
204
|
+
Most of the parts are published. NeuralDB (ICLR 2026) stores edited facts as a gated key-value memory inside a
|
|
205
|
+
feed-forward layer that fires only above a similarity threshold, and scales to 100,000 facts against my 1,000.
|
|
206
|
+
T-Patcher (2023) and SCEN (2024) add a neuron per edit for sequential editing, and MEMOIR (2025) reaches 15,000 edits.
|
|
207
|
+
Fitting the value at the subject's last token comes from ROME and MEMIT (2022 and 2023), which also use the model's
|
|
208
|
+
own hidden states with no second model. Meta's sparse memory finetuning (2025) already showed new facts learned with
|
|
209
|
+
far less forgetting than LoRA. SEAL (2025) has the model write its own training data, its forgetting is known, and
|
|
210
|
+
STABLE (2025) adds a gate to SEAL's LoRA updates. (SEAL calls that generated data "self-edits", which is why that
|
|
211
|
+
working name is not used here.)
|
|
212
|
+
|
|
213
|
+
What may be new is narrower: replacing LoRA in a self-learning loop with a gated weight edit, and the measurement
|
|
214
|
+
that this keeps the loop alive, because the model's ability to write its own study questions is never damaged; and
|
|
215
|
+
writing each fact as ordinary feed-forward neurons, so the result is a plain checkpoint. I have not run any of the
|
|
216
|
+
methods above on these streams, so this is a statement of what is different, not of what is better.
|
|
217
|
+
|
|
218
|
+
## Using it
|
|
219
|
+
|
|
220
|
+
pip install sthiti
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
224
|
+
import sthiti
|
|
225
|
+
|
|
226
|
+
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-0.8B")
|
|
227
|
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-0.8B")
|
|
228
|
+
|
|
229
|
+
for item in stream: # {"question": "...", "answer": "..."}, one at a time
|
|
230
|
+
sthiti.learn(model, tokenizer, item) # written into the model's weights
|
|
231
|
+
|
|
232
|
+
model.save_pretrained("qwen-with-facts") # a plain checkpoint
|
|
233
|
+
tokenizer.save_pretrained("qwen-with-facts")
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
To try it on a free T4, open [the Colab notebook](notebooks/sthiti_t4_colab.ipynb): it teaches Qwen3.5-0.8B made-up
|
|
237
|
+
facts one JSON item at a time, asks them in other words, checks what it knew before, learns from a sentence with no
|
|
238
|
+
answer given, saves and reloads with plain transformers, and runs a 200-fact WikiBigEdit stream.
|
|
239
|
+
|
|
240
|
+
Everything else is transformers. `model.generate` answers with the new facts; `AutoModelForCausalLM.from_pretrained
|
|
241
|
+
("qwen-with-facts")` loads them, because they are in the weights; and a loaded model keeps learning with the same
|
|
242
|
+
`sthiti.learn`, because what learning needs next is kept in `config.sthiti`.
|
|
243
|
+
|
|
244
|
+
An item is a dict or a JSON string:
|
|
245
|
+
|
|
246
|
+
- `{"question": "...", "answer": "..."}`, optionally with `"subject"`, the name the question is about (when it is
|
|
247
|
+
missing, the model is asked which name the question is about);
|
|
248
|
+
- `{"text": "..."}` with no answer: the model writes its own study questions about each sentence, keeps the ones it
|
|
249
|
+
answers the same way with the sentence in front of it, and learns those.
|
|
250
|
+
|
|
251
|
+
`sthiti.learn` returns what happened to each fact (written or switched off, and why). `sthiti.facts(model)` lists
|
|
252
|
+
what a model has learned, `sthiti.forget(model, tokenizer, subject)` removes a subject, and `sthiti.stats(model)`
|
|
253
|
+
counts. Moving the facts to another model is replaying them: `for f in sthiti.facts(old): sthiti.learn(new, tok, f)`.
|
|
254
|
+
|
|
255
|
+
The same from the command line, for JSON lines:
|
|
256
|
+
|
|
257
|
+
sthiti learn Qwen/Qwen3.5-0.8B --out ./with-facts < facts.jsonl # saves every 1,000 lines; rerun to resume
|
|
258
|
+
sthiti learn ./with-facts --file more.jsonl
|
|
259
|
+
sthiti ask ./with-facts "Where was Lotte Tarraen born?"
|
|
260
|
+
sthiti facts ./with-facts
|
|
261
|
+
sthiti forget ./with-facts "Lotte Tarraen"
|
|
262
|
+
|
|
263
|
+
Notes.
|
|
264
|
+
|
|
265
|
+
- **Asking.** Facts are learned in the model's chat format with no system prompt and, for Qwen3.5, thinking off, so
|
|
266
|
+
ask the same way: `tokenizer.apply_chat_template([{"role": "user", "content": question}],
|
|
267
|
+
add_generation_prompt=True, enable_thinking=False)`. Another system prompt is untested; `system=` on the first
|
|
268
|
+
`learn` sets one.
|
|
269
|
+
- **Size.** Each new subject adds 2 neurons to one early feed-forward layer (layer 5 of 24 on Qwen3.5-0.8B, 6 of 32
|
|
270
|
+
on the 4B). A transformers checkpoint has one feed-forward width for every layer, so every layer is widened by the
|
|
271
|
+
same amount, with zeros outside the learning layer: 0.29 MB per subject on Qwen3.5-0.8B and 0.98 MB on the 4B in
|
|
272
|
+
bfloat16, and proportionally more feed-forward work. The width grows in steps (a quarter, at least 64 subjects).
|
|
273
|
+
- **Models.** Dense gated SiLU feed-forward layers: Llama, Qwen (including Qwen3.5), Mistral and similar. Mixtures
|
|
274
|
+
of experts and LFM2 are refused with a clear error for now.
|
|
275
|
+
- **Calibration.** The first fact on a new model reads what the neurons must stay silent on: the first 200
|
|
276
|
+
WikiText-103 paragraphs longer than 40 words, as in the studies, and 400 PopQA questions. It is downloaded once with
|
|
277
|
+
`datasets` and cached in `~/.cache/sthiti` (`STHITI_CACHE`), keyed by the model's weights; `negatives=[...]` on the
|
|
278
|
+
first `learn` uses your own texts.
|
|
279
|
+
- **In production.** One lock per model serialises learning. A bad item raises `ValueError` (the command line skips
|
|
280
|
+
and reports it). Value fitting retries with smaller batches if the GPU runs out of memory. The command line saves
|
|
281
|
+
by writing a new folder and swapping it in, so an interrupted save never leaves a half-written checkpoint. Learning
|
|
282
|
+
sets no gradients on your model's weights and restores `requires_grad` afterwards.
|
|
283
|
+
- **Speed.** On Qwen3.5 with a GPU, installing `flash-linear-attention` makes the linear-attention layers fast.
|
|
284
|
+
`sthiti` sets `USE_HUB_KERNELS=NO` unless you set it, so `transformers` does not fetch kernel code from the Hub when
|
|
285
|
+
a model loads; the studies ran the same way.
|
|
286
|
+
|
|
287
|
+
What has been exercised: the tests run on CPU on tiny random models built in memory: learning writes into the weights,
|
|
288
|
+
`save_pretrained` and `from_pretrained` give back the same model (Llama, Qwen2 and Qwen3.5's hybrid attention), a
|
|
289
|
+
reloaded model keeps learning with the same thresholds, forgetting returns the original outputs, a subject's two
|
|
290
|
+
neurons are fully on at its own wording and off on ordinary text, facts move to another model by replay, text items
|
|
291
|
+
learn without an answer key, and the command line resumes a stream. The GPU runs on real models are in
|
|
292
|
+
[studies/continual](studies/continual/README.md).
|
|
293
|
+
|
|
294
|
+
## Limitations
|
|
295
|
+
|
|
296
|
+
The studies test one kind of knowledge: single-subject facts with short answers. Documents, procedures and using two
|
|
297
|
+
facts together (two-hop questions) are untested. They go up to 1,000 facts, with one seed and one model family
|
|
298
|
+
(Qwen3.5); the other architectures have only been run in the tests. In one round Sthiti learns less per fact than
|
|
299
|
+
LoRA: 69.8% against 88.7% in a new wording on Qwen3.5-4B, and 70.0% against 93.0% when the 4B teaches itself. Its
|
|
300
|
+
advantage is what it does not break, not how much it learns. The model grows by two neurons per subject without bound, and collisions grow with the store: 41 of 1,000
|
|
301
|
+
subjects were switched off one at a time. Different names for one thing (an alias, a short form) are different
|
|
302
|
+
subjects, and one can switch the other off. There is no standard benchmark (WikiBigEdit or zsRE lifelong) and no
|
|
303
|
+
comparison with NeuralDB, T-Patcher, WISE, AlphaEdit, GRACE or retrieval. The LoRA baselines are one setting each,
|
|
304
|
+
and the self-learning stream has no reinforcement-learning outer loop as SEAL has. On 5 December 2026 I found that a
|
|
305
|
+
switched-off subject's second neuron still added about 0.25% of its value on every token; it is fixed, and the
|
|
306
|
+
self-learning stream above has the fix, but the earlier stream runs carry the leak (up to 41 subjects), and its
|
|
307
|
+
effect on them is not measured. None of this is a learner that runs forever on a laptop yet; it is evidence that a
|
|
308
|
+
model can keep learning facts in use, inside its own layers, without losing the ones it had.
|
|
309
|
+
|
|
310
|
+
## History
|
|
311
|
+
|
|
312
|
+
Sthiti began on 2 December 2026 as lessons inside a frozen model: three closed-form probes read where a 27 billion
|
|
313
|
+
parameter model went wrong on multiple-choice questions, and checked lessons moved its answers from 74.2% to 85.0%
|
|
314
|
+
on questions it had never seen. That version could only move knowledge the model half had, never add any; its code,
|
|
315
|
+
runs and documents are in [studies/lessons](studies/lessons/README.md). This version writes new facts into the
|
|
316
|
+
model's own neurons, and learns them with or without an answer key.
|
|
317
|
+
|
|
318
|
+
## Reproducing the studies
|
|
319
|
+
|
|
320
|
+
Every study script, the pod launch scripts, the PopQA-derived data and the result files are in
|
|
321
|
+
[studies/fact-neurons](studies/fact-neurons/README.md), with a table from each number to the run that produced it
|
|
322
|
+
and how to run it again on one GPU.
|
|
323
|
+
|
|
324
|
+
pip install -e ".[test]"
|
|
325
|
+
python -m pytest -q tests # the package, on CPU, in seconds
|
|
326
|
+
|
|
327
|
+
## Contributing
|
|
328
|
+
|
|
329
|
+
Issues and pull requests are welcome: a head-to-head with the methods above on these streams, a standard lifelong
|
|
330
|
+
benchmark, a second model family, many facts per subject, and a fast CPU path most of all. See
|
|
331
|
+
[CONTRIBUTING.md](CONTRIBUTING.md); security reports go through [SECURITY.md](SECURITY.md).
|
|
332
|
+
|
|
333
|
+
## License
|
|
334
|
+
|
|
335
|
+
Apache 2.0. Questions and collaborations: nandakishor@embedding.in. If you use this work, please cite it:
|
|
336
|
+
|
|
337
|
+
```bibtex
|
|
338
|
+
@misc{sthiti2026,
|
|
339
|
+
title = {Sthiti: a language model that keeps learning, one fact at a time, in neurons of its own},
|
|
340
|
+
author = {Nandakishor M},
|
|
341
|
+
year = {2026},
|
|
342
|
+
url = {https://github.com/NandhaKishorM/sthiti}
|
|
343
|
+
}
|
|
344
|
+
```
|