leanai-asstf 1.0.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.
@@ -0,0 +1,57 @@
1
+ # LeanAI ASSTF Community License
2
+
3
+ Version 1.0 - Effective Date: 2026-07-03
4
+
5
+ This License Agreement (the "Agreement") is a legal contract between Safeware Technologies Inc., Ltd. (the "Licensor") and you (the "Licensee") for the use of the LeanAI ASSTF software and associated documentation (the "Software").
6
+
7
+ ## 1. Definitions
8
+
9
+ - **Software**: The source code, model definitions, training scripts, evaluation scripts, documentation, and any other materials distributed under this License.
10
+ - **ASSTF Technology**: The Adaptive State-Space Transfer Function algorithm, mathematical formulations, and related proprietary techniques described in the Licensor's technical publications and patent applications.
11
+ - **Non-Commercial Use**: Use that is not primarily intended for, or directed toward, commercial advantage or monetary compensation.
12
+ - **Commercial Use**: Any use that is not Non-Commercial Use, including but not limited to incorporation into products or services offered for sale, deployment in revenue-generating operations, SaaS offerings, and use by for-profit entities in the course of business.
13
+
14
+ ## 2. Grant of Rights
15
+
16
+ Subject to the restrictions set forth in Section 3, the Licensor hereby grants the Licensee a worldwide, royalty-free, non-exclusive, non-transferable license to:
17
+
18
+ 1. Use the Software for Non-Commercial purposes.
19
+ 2. Study, modify, and create derivative works of the Software for Non-Commercial purposes.
20
+ 3. Distribute copies of the Software and derivative works, provided that such distribution is also under the terms of this Community License.
21
+ 4. Publish research results, benchmarks, and educational materials based on the Software, provided that the Licensor and the ASSTF Technology are properly attributed.
22
+
23
+ ## 3. Restrictions
24
+
25
+ 1. **No Commercial Use**. The Licensee may not use the Software, in whole or in part, for any Commercial Use without obtaining a separate Commercial License from the Licensor.
26
+ 2. **No Patent Grant**. This License does not grant the Licensee any rights under the Licensor's patents, patent applications, trade secrets, or other intellectual property relating to the ASSTF Technology, except as expressly necessary to exercise the rights granted in Section 2.
27
+ 3. **Attribution**. The Licensee must retain all copyright, patent, trademark, and attribution notices contained in the Software. Any distributed derivative work must include a prominent notice stating that it is based on the LeanAI ASSTF Software and provide a link to the original repository.
28
+ 4. **No Warranty Disclaimer Removal**. The Licensee may not remove or alter any warranty disclaimers or liability limitations in this License.
29
+ 5. **No Endorsement**. The Licensee may not use the Licensor's trademarks or imply endorsement without prior written permission.
30
+
31
+ ## 4. Source Code Availability
32
+
33
+ The source code of the Software is made available to the Licensee under this License. Availability of source code does not constitute a grant of rights in the underlying ASSTF Technology beyond the limited scope expressly stated herein.
34
+
35
+ ## 5. Termination
36
+
37
+ This License automatically terminates if the Licensee violates any of its terms. Upon termination, the Licensee must immediately cease all use and distribution of the Software and destroy all copies in its possession.
38
+
39
+ ## 6. Disclaimer of Warranty
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
42
+
43
+ ## 7. Limitation of Liability
44
+
45
+ IN NO EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
+
47
+ ## 8. Commercial Licensing
48
+
49
+ For Commercial Use, please contact:
50
+
51
+ Safeware Technologies Inc., Ltd.
52
+ Attn: LeanAI Licensing Department
53
+ Email: Bentley@safeware.com.tw
54
+
55
+ ## 9. Governing Law
56
+
57
+ This Agreement shall be governed by and construed in accordance with the laws of the jurisdiction in which the Licensor is headquartered, without regard to conflict of law principles.
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: leanai-asstf
3
+ Version: 1.0.0
4
+ Summary: ASSTF: Adaptive State-Space Transfer Function — parameter-efficient, inference-adaptable neural layers for edge AI and continual learning.
5
+ Author-email: Bentley Yusen Lin <Bentley@safeware.com.tw>
6
+ License: LeanAI ASSTF Community License 1.0
7
+ Project-URL: Homepage, https://github.com/safeware/Project_LeanAI
8
+ Project-URL: Documentation, https://safeware.github.io/Project_LeanAI/
9
+ Project-URL: Repository, https://github.com/safeware/Project_LeanAI
10
+ Project-URL: Issues, https://github.com/safeware/Project_LeanAI/issues
11
+ Project-URL: Changelog, https://github.com/safeware/Project_LeanAI/blob/main/CHANGELOG.md
12
+ Project-URL: Commercial, https://github.com/safeware/Project_LeanAI/blob/main/docs/COMMERCIAL_LICENSE.md
13
+ Keywords: adaptive state-space transfer function,ASSTF,LeanAI,parameter-efficient deep learning,edge AI,TinyML,continual learning,test-time adaptation,online personalization,low-rank adaptation,PyTorch,efficient AI,green AI,on-device ML
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: Other/Proprietary License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Python: >=3.9
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: torch>=2.0.0
30
+ Requires-Dist: numpy>=1.24.0
31
+ Requires-Dist: scipy>=1.10.0
32
+ Requires-Dist: scikit-learn>=1.3.0
33
+ Requires-Dist: matplotlib>=3.7.0
34
+ Requires-Dist: pandas>=2.0.0
35
+ Provides-Extra: nlp
36
+ Requires-Dist: transformers>=4.30.0; extra == "nlp"
37
+ Requires-Dist: datasets>=2.14.0; extra == "nlp"
38
+ Requires-Dist: sentencepiece>=0.1.99; extra == "nlp"
39
+ Requires-Dist: tiktoken>=0.5.0; extra == "nlp"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
42
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
43
+ Requires-Dist: black>=23.0.0; extra == "dev"
44
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
45
+ Requires-Dist: mypy>=1.5.0; extra == "dev"
46
+ Provides-Extra: all
47
+ Requires-Dist: transformers>=4.30.0; extra == "all"
48
+ Requires-Dist: datasets>=2.14.0; extra == "all"
49
+ Requires-Dist: sentencepiece>=0.1.99; extra == "all"
50
+ Requires-Dist: tiktoken>=0.5.0; extra == "all"
51
+ Requires-Dist: pytest>=7.4.0; extra == "all"
52
+ Requires-Dist: pytest-cov>=4.1.0; extra == "all"
53
+ Requires-Dist: black>=23.0.0; extra == "all"
54
+ Requires-Dist: ruff>=0.1.0; extra == "all"
55
+ Requires-Dist: mypy>=1.5.0; extra == "all"
56
+ Dynamic: license-file
57
+
58
+ <div align="center">
59
+ <img src="assets/logo.svg" alt="ASSTF Logo" width="120">
60
+ <h1>LeanAI ASSTF</h1>
61
+ <p><strong>Adaptive State-Space Transfer Function</strong></p>
62
+ </div>
63
+
64
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
65
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg)](https://pytorch.org/)
66
+ [![License: Community/Commercial](https://img.shields.io/badge/license-Community%2FCommercial-orange.svg)](LICENSE)
67
+ [![Tests](https://img.shields.io/badge/tests-pytest-green.svg)](tests/)
68
+
69
+ > **Tiny, self-adapting neural layers for efficient edge AI and continual learning.**
70
+
71
+ ASSTF (Adaptive State-Space Transfer Function) is a PyTorch framework that lets neural layers continuously reconfigure their effective state space through a small set of **structural parameters**. It combines **parameter-efficient learning** with **inference-time adaptation**, making it ideal for edge devices, personalization, and continual learning.
72
+
73
+ ---
74
+
75
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/safeware/Project_LeanAI/blob/main/notebooks/ASSTF_Quickstart.ipynb)
76
+
77
+ ## 🚀 Current Status: Stage 1 — Grounding Credit
78
+
79
+ This repository is the **Stage 1 reference implementation** of ASSTF. It is designed to be:
80
+
81
+ - **Reproducible**: every demo includes open data-generation scripts; results can be verified on a laptop.
82
+ - **Extensible**: drop-in `ASSTFLinear` / `ASSTFConv1d` layers let you test ASSTF on your own architectures.
83
+ - **Transparent**: we clearly label which demos use synthetic data and which use real-world datasets.
84
+
85
+ **App 01–05** use controlled, reproducible synthetic data to isolate and demonstrate ASSTF's algorithmic behavior.
86
+ **App 06** validates ASSTF on the real **SST-2** sentiment dataset.
87
+
88
+ See [`docs/OPEN_SOURCE_STAGES.md`](docs/OPEN_SOURCE_STAGES.md) for the full three-stage roadmap toward global adoption.
89
+
90
+ ---
91
+
92
+ ## Why ASSTF?
93
+
94
+ - 🧠 **Parameter-efficient** — low-rank structural adapters add far fewer parameters than dense layers.
95
+ - 🔄 **Adapts at inference time** — personalize to users, noise, or drift without retraining.
96
+ - 📱 **Edge-ready** — runs on CPU, mobile, and embedded hardware.
97
+ - 🔒 **Privacy-first** — on-device adaptation; user data never leaves the device.
98
+ - 🌱 **Sustainable AI** — smaller models mean lower energy and memory costs.
99
+ - 🔌 **Drop-in replacement** — swap `nn.Linear` → `ASSTFLinear` in minutes.
100
+
101
+ ---
102
+
103
+ ## 30-Second Quick Start
104
+
105
+ ```python
106
+ import torch
107
+ from asstf import ASSTFLinear
108
+
109
+ # Replace any nn.Linear with ASSTFLinear
110
+ layer = ASSTFLinear(128, 64, structural_rank=4)
111
+ x = torch.randn(16, 128)
112
+ out = layer(x) # shape: (16, 64)
113
+ ```
114
+
115
+ Train and evaluate all six demos:
116
+
117
+ ```bash
118
+ git clone https://github.com/YOUR_ORG/Project_LeanAI.git
119
+ cd Project_LeanAI
120
+ python3 -m venv .venv && source .venv/bin/activate
121
+ pip install -r requirements.txt
122
+ pytest tests/ -v
123
+ python run_all.py
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Installation
129
+
130
+ ### From PyPI (recommended)
131
+
132
+ ```bash
133
+ pip install leanai-asstf
134
+ ```
135
+
136
+ ### From source
137
+
138
+ ```bash
139
+ git clone https://github.com/YOUR_ORG/Project_LeanAI.git
140
+ cd Project_LeanAI
141
+ pip install -r requirements.txt
142
+ ```
143
+
144
+ For NLP demos:
145
+
146
+ ```bash
147
+ pip install -r requirements-optional.txt
148
+ ```
149
+
150
+ ---
151
+
152
+ ## How It Works
153
+
154
+ ASSTF replaces a standard layer with the composition of a **core transfer function** Γ and a **structural modulator** Ψ:
155
+
156
+ ```
157
+ base = x · W_c^T + b_c # core knowledge (θc)
158
+ M = σ(gate) · (U · V) # low-rank structural adapter (θs)
159
+ out = base + x · M^T # composed output
160
+ ```
161
+
162
+ - **θc** stores the base task knowledge.
163
+ - **θs** controls how the layer adapts to new data.
164
+ - At inference time, `SurpriseMinimizer` updates only θs, enabling fast personalization.
165
+
166
+ <p align="center">
167
+ <img src="assets/architecture.png" alt="ASSTF Layer Architecture" width="700">
168
+ </p>
169
+
170
+ Read more:
171
+ - [Introduction](docs/INTRODUCTION_EN.md)
172
+ - [Architecture & Technical Explanation](docs/ARCHITECTURE_EN.md)
173
+ - [Usage Guide](docs/USAGE_EN.md)
174
+ - [API Reference](docs/API_EN.md)
175
+ - [Open-Source Stages](docs/OPEN_SOURCE_STAGES.md)
176
+
177
+ ---
178
+
179
+ ## The 5+1 Demos
180
+
181
+ | # | Application | Highlight | Data | Type |
182
+ |---|-------------|-----------|------|------|
183
+ | 1 | [Embedded Gesture Recognition](app_01_gesture) | Online personalization to new users | Synthetic multi-user IMU | Proof-of-concept |
184
+ | 2 | [Wake-Word Detection](app_02_wake_word) | ASSTFConv1d + dynamic rank under noise | Synthetic 1D audio | Proof-of-concept |
185
+ | 3 | [Time-Series Anomaly Detection](app_03_anomaly) | Continuous learning under concept drift | Synthetic industrial sensors | Proof-of-concept |
186
+ | 4 | [Few-Shot Meta-Learner](app_04_few_shot) | θs as task-specific meta-knowledge | sklearn digits / mini-tasks | Proof-of-concept |
187
+ | 5 | [Online RL Dynamic Policy](app_05_rl) | Policy adaptation to changing dynamics | Custom pendulum environment | Proof-of-concept |
188
+ | +1 | [Edge NLP](app_06_edge_nlp) | ASSTF replaces BERT-Tiny FFN layers | Real SST-2 + SentencePiece | Real-world validation |
189
+
190
+ All synthetic demos include **open, seeded data-generation scripts** so you can reproduce them exactly and swap in your own datasets.
191
+
192
+ ---
193
+
194
+ ## Benchmark Highlights
195
+
196
+ | App | Model | Params | Metric | Data Type |
197
+ |-----|-------|--------|--------|-----------|
198
+ | Gesture | ASSTF | 4,665 | 100.0% acc | Synthetic |
199
+ | Gesture | Static | 38,213 | 100.0% acc | Synthetic |
200
+ | Wake-word (-5 dB) | ASSTF | 779 | 74.62% acc | Synthetic |
201
+ | Wake-word (-5 dB) | Static | 1,202 | 57.13% acc | Synthetic |
202
+ | Anomaly | ASSTF | 506 | F1 = 0.946 | Synthetic |
203
+ | Anomaly | Static | 2,080 | F1 = 0.508 | Synthetic |
204
+ | Few-shot | ASSTF | 2,105 | 19.73% acc | sklearn digits |
205
+ | Few-shot | Static | 7,237 | 19.39% acc | sklearn digits |
206
+ | RL adapted reward | ASSTF | 965 | 39.66 | Custom env |
207
+ | RL adapted reward | Static | 1,441 | 32.97 | Custom env |
208
+ | Edge NLP (SST-2) | ASSTF (h=96) | 403,896 | 67.88% acc | **Real** |
209
+ | Edge NLP (SST-2) | Static | 649,218 | 67.75% acc | **Real** |
210
+
211
+ <p align="center">
212
+ <img src="assets/benchmark_chart.png" alt="ASSTF Parameter Efficiency" width="700">
213
+ </p>
214
+
215
+ See [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for full results and reproduction commands.
216
+
217
+ > **Note on interpretation:** App 01–05 demonstrate ASSTF's algorithmic behavior under controlled, reproducible conditions. They are not claims of real-world SOTA. App 06 is the real-world validation. We welcome community contributions of additional real-dataset benchmarks.
218
+
219
+ ---
220
+
221
+ ## Training a Single Demo
222
+
223
+ ```bash
224
+ python app_03_anomaly/train.py
225
+ python app_03_anomaly/evaluate.py
226
+ ```
227
+
228
+ For a quick smoke test across all apps:
229
+
230
+ ```bash
231
+ python run_all.py --quick
232
+ ```
233
+
234
+ For the full benchmark suite that matches `docs/BENCHMARKS.md`:
235
+
236
+ ```bash
237
+ python run_all.py
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Project Structure
243
+
244
+ ```
245
+ Project_LeanAI/
246
+ ├── asstf/ # Core ASSTF framework
247
+ ├── shared/ # Baselines, metrics, early stopping
248
+ ├── app_01_gesture/ # Gesture recognition demo
249
+ ├── app_02_wake_word/ # Wake-word detection demo
250
+ ├── app_03_anomaly/ # Anomaly detection demo
251
+ ├── app_04_few_shot/ # Few-shot learning demo
252
+ ├── app_05_rl/ # Reinforcement learning demo
253
+ ├── app_06_edge_nlp/ # Edge NLP demo
254
+ ├── tests/ # Unit and smoke tests
255
+ ├── docs/ # Documentation and licenses
256
+ ├── data/ # Datasets and caches
257
+ ├── results/ # Benchmark outputs
258
+ ├── checkpoints/ # Saved models
259
+ ├── run_all.py # Run all demos
260
+ ├── requirements.txt
261
+ └── README.md
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Roadmap & Stages
267
+
268
+ | Stage | Timeline | Focus | Key Deliverables |
269
+ |-------|----------|-------|------------------|
270
+ | **Stage 1: Grounding Credit** | Now – Month 4 | Reproducible reference implementation + community | This repo, PyPI, CI, launch |
271
+ | **Stage 2: Real-World Value** | Month 4–12 | Public benchmarks, integrations, academic paper | Real datasets, Hugging Face, Edge Impulse, arXiv |
272
+ | **Stage 3: Commercial Value** | Month 12–24 | Enterprise tools, platform, support | LeanAI Studio, Edge SDK, managed inference |
273
+
274
+ See [`docs/OPEN_SOURCE_STAGES.md`](docs/OPEN_SOURCE_STAGES.md) for the complete plan.
275
+
276
+ ---
277
+
278
+ ## License
279
+
280
+ This project is dual-licensed:
281
+
282
+ - **Community License** — free for personal learning, academic research, non-profit education, and open-source contributions.
283
+ - **Commercial License** — required for any commercial product, service, SaaS, cloud deployment, or hardware integration.
284
+
285
+ See [LICENSE](LICENSE) and [docs/COMMERCIAL_LICENSE.md](docs/COMMERCIAL_LICENSE.md) for details.
286
+
287
+ For licensing inquiries, contact **Bentley@safeware.com.tw**.
288
+
289
+ ---
290
+
291
+ ## Citation
292
+
293
+ If you use ASSTF in academic research, please cite the white-paper:
294
+
295
+ ```bibtex
296
+ @techreport{lin2025asstf,
297
+ title={Mathematical Framework to Enable Adaptive Neuron Transitions},
298
+ author={Lin, Bentley Yusen},
299
+ institution={Safeware Technologies Inc., Ltd.},
300
+ year={2025}
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Contributing
307
+
308
+ We welcome research contributions, bug reports, documentation improvements, and especially **real-dataset benchmarks**. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
309
+
310
+ By contributing, you agree that your contributions may be used under both the Community License and future commercial licensing.
311
+
312
+ ---
313
+
314
+ ## Acknowledgments
315
+
316
+ ASSTF is developed by Safeware Technologies Inc., Ltd. The reference implementation is intended for research and demonstration; production deployment requires additional tuning and a commercial license.
317
+
318
+ ---
319
+
320
+ **Keywords:** Adaptive State-Space Transfer Function, ASSTF, LeanAI, parameter-efficient deep learning, edge AI, TinyML, continual learning, test-time adaptation, online personalization, low-rank adaptation, PyTorch, efficient AI, green AI, on-device ML.
@@ -0,0 +1,263 @@
1
+ <div align="center">
2
+ <img src="assets/logo.svg" alt="ASSTF Logo" width="120">
3
+ <h1>LeanAI ASSTF</h1>
4
+ <p><strong>Adaptive State-Space Transfer Function</strong></p>
5
+ </div>
6
+
7
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
8
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg)](https://pytorch.org/)
9
+ [![License: Community/Commercial](https://img.shields.io/badge/license-Community%2FCommercial-orange.svg)](LICENSE)
10
+ [![Tests](https://img.shields.io/badge/tests-pytest-green.svg)](tests/)
11
+
12
+ > **Tiny, self-adapting neural layers for efficient edge AI and continual learning.**
13
+
14
+ ASSTF (Adaptive State-Space Transfer Function) is a PyTorch framework that lets neural layers continuously reconfigure their effective state space through a small set of **structural parameters**. It combines **parameter-efficient learning** with **inference-time adaptation**, making it ideal for edge devices, personalization, and continual learning.
15
+
16
+ ---
17
+
18
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/safeware/Project_LeanAI/blob/main/notebooks/ASSTF_Quickstart.ipynb)
19
+
20
+ ## 🚀 Current Status: Stage 1 — Grounding Credit
21
+
22
+ This repository is the **Stage 1 reference implementation** of ASSTF. It is designed to be:
23
+
24
+ - **Reproducible**: every demo includes open data-generation scripts; results can be verified on a laptop.
25
+ - **Extensible**: drop-in `ASSTFLinear` / `ASSTFConv1d` layers let you test ASSTF on your own architectures.
26
+ - **Transparent**: we clearly label which demos use synthetic data and which use real-world datasets.
27
+
28
+ **App 01–05** use controlled, reproducible synthetic data to isolate and demonstrate ASSTF's algorithmic behavior.
29
+ **App 06** validates ASSTF on the real **SST-2** sentiment dataset.
30
+
31
+ See [`docs/OPEN_SOURCE_STAGES.md`](docs/OPEN_SOURCE_STAGES.md) for the full three-stage roadmap toward global adoption.
32
+
33
+ ---
34
+
35
+ ## Why ASSTF?
36
+
37
+ - 🧠 **Parameter-efficient** — low-rank structural adapters add far fewer parameters than dense layers.
38
+ - 🔄 **Adapts at inference time** — personalize to users, noise, or drift without retraining.
39
+ - 📱 **Edge-ready** — runs on CPU, mobile, and embedded hardware.
40
+ - 🔒 **Privacy-first** — on-device adaptation; user data never leaves the device.
41
+ - 🌱 **Sustainable AI** — smaller models mean lower energy and memory costs.
42
+ - 🔌 **Drop-in replacement** — swap `nn.Linear` → `ASSTFLinear` in minutes.
43
+
44
+ ---
45
+
46
+ ## 30-Second Quick Start
47
+
48
+ ```python
49
+ import torch
50
+ from asstf import ASSTFLinear
51
+
52
+ # Replace any nn.Linear with ASSTFLinear
53
+ layer = ASSTFLinear(128, 64, structural_rank=4)
54
+ x = torch.randn(16, 128)
55
+ out = layer(x) # shape: (16, 64)
56
+ ```
57
+
58
+ Train and evaluate all six demos:
59
+
60
+ ```bash
61
+ git clone https://github.com/YOUR_ORG/Project_LeanAI.git
62
+ cd Project_LeanAI
63
+ python3 -m venv .venv && source .venv/bin/activate
64
+ pip install -r requirements.txt
65
+ pytest tests/ -v
66
+ python run_all.py
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Installation
72
+
73
+ ### From PyPI (recommended)
74
+
75
+ ```bash
76
+ pip install leanai-asstf
77
+ ```
78
+
79
+ ### From source
80
+
81
+ ```bash
82
+ git clone https://github.com/YOUR_ORG/Project_LeanAI.git
83
+ cd Project_LeanAI
84
+ pip install -r requirements.txt
85
+ ```
86
+
87
+ For NLP demos:
88
+
89
+ ```bash
90
+ pip install -r requirements-optional.txt
91
+ ```
92
+
93
+ ---
94
+
95
+ ## How It Works
96
+
97
+ ASSTF replaces a standard layer with the composition of a **core transfer function** Γ and a **structural modulator** Ψ:
98
+
99
+ ```
100
+ base = x · W_c^T + b_c # core knowledge (θc)
101
+ M = σ(gate) · (U · V) # low-rank structural adapter (θs)
102
+ out = base + x · M^T # composed output
103
+ ```
104
+
105
+ - **θc** stores the base task knowledge.
106
+ - **θs** controls how the layer adapts to new data.
107
+ - At inference time, `SurpriseMinimizer` updates only θs, enabling fast personalization.
108
+
109
+ <p align="center">
110
+ <img src="assets/architecture.png" alt="ASSTF Layer Architecture" width="700">
111
+ </p>
112
+
113
+ Read more:
114
+ - [Introduction](docs/INTRODUCTION_EN.md)
115
+ - [Architecture & Technical Explanation](docs/ARCHITECTURE_EN.md)
116
+ - [Usage Guide](docs/USAGE_EN.md)
117
+ - [API Reference](docs/API_EN.md)
118
+ - [Open-Source Stages](docs/OPEN_SOURCE_STAGES.md)
119
+
120
+ ---
121
+
122
+ ## The 5+1 Demos
123
+
124
+ | # | Application | Highlight | Data | Type |
125
+ |---|-------------|-----------|------|------|
126
+ | 1 | [Embedded Gesture Recognition](app_01_gesture) | Online personalization to new users | Synthetic multi-user IMU | Proof-of-concept |
127
+ | 2 | [Wake-Word Detection](app_02_wake_word) | ASSTFConv1d + dynamic rank under noise | Synthetic 1D audio | Proof-of-concept |
128
+ | 3 | [Time-Series Anomaly Detection](app_03_anomaly) | Continuous learning under concept drift | Synthetic industrial sensors | Proof-of-concept |
129
+ | 4 | [Few-Shot Meta-Learner](app_04_few_shot) | θs as task-specific meta-knowledge | sklearn digits / mini-tasks | Proof-of-concept |
130
+ | 5 | [Online RL Dynamic Policy](app_05_rl) | Policy adaptation to changing dynamics | Custom pendulum environment | Proof-of-concept |
131
+ | +1 | [Edge NLP](app_06_edge_nlp) | ASSTF replaces BERT-Tiny FFN layers | Real SST-2 + SentencePiece | Real-world validation |
132
+
133
+ All synthetic demos include **open, seeded data-generation scripts** so you can reproduce them exactly and swap in your own datasets.
134
+
135
+ ---
136
+
137
+ ## Benchmark Highlights
138
+
139
+ | App | Model | Params | Metric | Data Type |
140
+ |-----|-------|--------|--------|-----------|
141
+ | Gesture | ASSTF | 4,665 | 100.0% acc | Synthetic |
142
+ | Gesture | Static | 38,213 | 100.0% acc | Synthetic |
143
+ | Wake-word (-5 dB) | ASSTF | 779 | 74.62% acc | Synthetic |
144
+ | Wake-word (-5 dB) | Static | 1,202 | 57.13% acc | Synthetic |
145
+ | Anomaly | ASSTF | 506 | F1 = 0.946 | Synthetic |
146
+ | Anomaly | Static | 2,080 | F1 = 0.508 | Synthetic |
147
+ | Few-shot | ASSTF | 2,105 | 19.73% acc | sklearn digits |
148
+ | Few-shot | Static | 7,237 | 19.39% acc | sklearn digits |
149
+ | RL adapted reward | ASSTF | 965 | 39.66 | Custom env |
150
+ | RL adapted reward | Static | 1,441 | 32.97 | Custom env |
151
+ | Edge NLP (SST-2) | ASSTF (h=96) | 403,896 | 67.88% acc | **Real** |
152
+ | Edge NLP (SST-2) | Static | 649,218 | 67.75% acc | **Real** |
153
+
154
+ <p align="center">
155
+ <img src="assets/benchmark_chart.png" alt="ASSTF Parameter Efficiency" width="700">
156
+ </p>
157
+
158
+ See [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for full results and reproduction commands.
159
+
160
+ > **Note on interpretation:** App 01–05 demonstrate ASSTF's algorithmic behavior under controlled, reproducible conditions. They are not claims of real-world SOTA. App 06 is the real-world validation. We welcome community contributions of additional real-dataset benchmarks.
161
+
162
+ ---
163
+
164
+ ## Training a Single Demo
165
+
166
+ ```bash
167
+ python app_03_anomaly/train.py
168
+ python app_03_anomaly/evaluate.py
169
+ ```
170
+
171
+ For a quick smoke test across all apps:
172
+
173
+ ```bash
174
+ python run_all.py --quick
175
+ ```
176
+
177
+ For the full benchmark suite that matches `docs/BENCHMARKS.md`:
178
+
179
+ ```bash
180
+ python run_all.py
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Project Structure
186
+
187
+ ```
188
+ Project_LeanAI/
189
+ ├── asstf/ # Core ASSTF framework
190
+ ├── shared/ # Baselines, metrics, early stopping
191
+ ├── app_01_gesture/ # Gesture recognition demo
192
+ ├── app_02_wake_word/ # Wake-word detection demo
193
+ ├── app_03_anomaly/ # Anomaly detection demo
194
+ ├── app_04_few_shot/ # Few-shot learning demo
195
+ ├── app_05_rl/ # Reinforcement learning demo
196
+ ├── app_06_edge_nlp/ # Edge NLP demo
197
+ ├── tests/ # Unit and smoke tests
198
+ ├── docs/ # Documentation and licenses
199
+ ├── data/ # Datasets and caches
200
+ ├── results/ # Benchmark outputs
201
+ ├── checkpoints/ # Saved models
202
+ ├── run_all.py # Run all demos
203
+ ├── requirements.txt
204
+ └── README.md
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Roadmap & Stages
210
+
211
+ | Stage | Timeline | Focus | Key Deliverables |
212
+ |-------|----------|-------|------------------|
213
+ | **Stage 1: Grounding Credit** | Now – Month 4 | Reproducible reference implementation + community | This repo, PyPI, CI, launch |
214
+ | **Stage 2: Real-World Value** | Month 4–12 | Public benchmarks, integrations, academic paper | Real datasets, Hugging Face, Edge Impulse, arXiv |
215
+ | **Stage 3: Commercial Value** | Month 12–24 | Enterprise tools, platform, support | LeanAI Studio, Edge SDK, managed inference |
216
+
217
+ See [`docs/OPEN_SOURCE_STAGES.md`](docs/OPEN_SOURCE_STAGES.md) for the complete plan.
218
+
219
+ ---
220
+
221
+ ## License
222
+
223
+ This project is dual-licensed:
224
+
225
+ - **Community License** — free for personal learning, academic research, non-profit education, and open-source contributions.
226
+ - **Commercial License** — required for any commercial product, service, SaaS, cloud deployment, or hardware integration.
227
+
228
+ See [LICENSE](LICENSE) and [docs/COMMERCIAL_LICENSE.md](docs/COMMERCIAL_LICENSE.md) for details.
229
+
230
+ For licensing inquiries, contact **Bentley@safeware.com.tw**.
231
+
232
+ ---
233
+
234
+ ## Citation
235
+
236
+ If you use ASSTF in academic research, please cite the white-paper:
237
+
238
+ ```bibtex
239
+ @techreport{lin2025asstf,
240
+ title={Mathematical Framework to Enable Adaptive Neuron Transitions},
241
+ author={Lin, Bentley Yusen},
242
+ institution={Safeware Technologies Inc., Ltd.},
243
+ year={2025}
244
+ }
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Contributing
250
+
251
+ We welcome research contributions, bug reports, documentation improvements, and especially **real-dataset benchmarks**. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
252
+
253
+ By contributing, you agree that your contributions may be used under both the Community License and future commercial licensing.
254
+
255
+ ---
256
+
257
+ ## Acknowledgments
258
+
259
+ ASSTF is developed by Safeware Technologies Inc., Ltd. The reference implementation is intended for research and demonstration; production deployment requires additional tuning and a commercial license.
260
+
261
+ ---
262
+
263
+ **Keywords:** Adaptive State-Space Transfer Function, ASSTF, LeanAI, parameter-efficient deep learning, edge AI, TinyML, continual learning, test-time adaptation, online personalization, low-rank adaptation, PyTorch, efficient AI, green AI, on-device ML.
@@ -0,0 +1,29 @@
1
+ """
2
+ ASSTF (Adaptive State-Space Transfer Function) Reference Implementation
3
+ =======================================================================
4
+
5
+ This package provides a PyTorch reference implementation of the ASSTF
6
+ framework described in the LeanAI technical white-paper. It is intended for
7
+ research, education, and non-commercial evaluation under the LeanAI ASSTF
8
+ Community License. Commercial use requires a separate Commercial License.
9
+
10
+ Core modules
11
+ ------------
12
+ core : ASSTF layers and building blocks.
13
+ trainer : Bilevel optimisation trainer (Algorithm 1 in the paper).
14
+ adaptation : Inference-time structural adaptation via surprise minimisation.
15
+ """
16
+
17
+ from .core import ASSTFLinear, ASSTFBlock, ASSTFConv1d, ASSTFConvBlock, count_parameters
18
+ from .trainer import BilevelTrainer
19
+ from .adaptation import SurpriseMinimizer
20
+
21
+ __all__ = [
22
+ "ASSTFLinear",
23
+ "ASSTFBlock",
24
+ "ASSTFConv1d",
25
+ "ASSTFConvBlock",
26
+ "count_parameters",
27
+ "BilevelTrainer",
28
+ "SurpriseMinimizer",
29
+ ]