Release SpTn-Model-only-1P v1.0
Browse files- README.md +85 -38
- chat.py +115 -40
- load_model.py +10 -0
- save_model.py +27 -0
- sp_tn_1p.npz +0 -0
README.md
CHANGED
|
@@ -1,64 +1,115 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
tags:
|
|
|
|
| 3 |
- experimental
|
| 4 |
- generative-model
|
| 5 |
- one-parameter
|
| 6 |
- research
|
| 7 |
- toy-model
|
| 8 |
-
library_name: numpy
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
-
- Framework: NumPy
|
| 27 |
-
- Model type: Experimental one-parameter generative model
|
| 28 |
-
- Status: Research / experimental
|
| 29 |
-
- Language model capability: No
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
-
- Research into extremely low-parameter models
|
| 37 |
-
- Exploring parameter capacity
|
| 38 |
-
- Understanding simple optimization and generation
|
| 39 |
-
- Experimenting with minimal machine-learning architectures
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
Run:
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
GitHub:
|
| 64 |
https://github.com/parhamtaheri453-crypto/SpTn-Model-only-1P
|
|
@@ -66,14 +117,10 @@ https://github.com/parhamtaheri453-crypto/SpTn-Model-only-1P
|
|
| 66 |
Hugging Face:
|
| 67 |
https://huggingface.co/KtiyaKK/SpTn-Model-only-1P
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
Future experiments may scale the parameter count:
|
| 72 |
-
|
| 73 |
-
1P → 100P → 1K → 10K → 100K → 1M → 10M
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
|
| 3 |
tags:
|
| 4 |
+
|
| 5 |
- experimental
|
| 6 |
- generative-model
|
| 7 |
- one-parameter
|
| 8 |
- research
|
| 9 |
- toy-model
|
| 10 |
+
library_name: numpy
|
| 11 |
+
|
| 12 |
---
|
| 13 |
|
| 14 |
+
SpTn-Model-only-1P
|
| 15 |
|
| 16 |
+
A minimal experimental generative model with exactly 1 trainable parameter.
|
| 17 |
|
| 18 |
+
SpTn-Model-only-1P explores how much generative behavior can be produced under an extreme parameter constraint.
|
| 19 |
|
| 20 |
+
Model
|
| 21 |
|
| 22 |
+
- Trainable parameters: 1
|
| 23 |
+
- Parameter type: float32
|
| 24 |
+
- Framework: NumPy
|
| 25 |
+
- Model file: "sp_tn_1p.npz"
|
| 26 |
+
- Status: Experimental
|
| 27 |
+
- Language understanding: No
|
| 28 |
|
| 29 |
+
Download
|
| 30 |
|
| 31 |
+
Hugging Face
|
| 32 |
|
| 33 |
+
Download "sp_tn_1p.npz" directly from the Files and versions section.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
GitHub
|
| 36 |
|
| 37 |
+
Download the repository or the latest release from GitHub.
|
| 38 |
|
| 39 |
+
No Git installation is required to download the files.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
Installation
|
| 42 |
|
| 43 |
+
Install NumPy:
|
| 44 |
|
| 45 |
+
pip install numpy
|
| 46 |
|
| 47 |
+
Quick Start
|
| 48 |
|
| 49 |
+
Download these files:
|
| 50 |
|
| 51 |
+
sp_tn_1p.npz
|
| 52 |
+
chat.py
|
| 53 |
+
|
| 54 |
+
Place them in the same directory.
|
| 55 |
|
| 56 |
Run:
|
| 57 |
|
| 58 |
+
python chat.py
|
| 59 |
+
|
| 60 |
+
Example:
|
| 61 |
+
|
| 62 |
+
You: hello
|
| 63 |
+
Model: rudezok sugerafiyo peyu dewipusaq sohira
|
| 64 |
+
|
| 65 |
+
The generated text is intentionally meaningless and demonstrates synthetic text generation under a one-parameter constraint.
|
| 66 |
+
|
| 67 |
+
Load the Model
|
| 68 |
+
|
| 69 |
+
To verify and load the model:
|
| 70 |
+
|
| 71 |
+
python load_model.py
|
| 72 |
+
|
| 73 |
+
Expected output:
|
| 74 |
+
|
| 75 |
+
SpTn-Model-only-1P
|
| 76 |
+
Trainable parameters: 1
|
| 77 |
+
Parameter: 0.5
|
| 78 |
+
Model loaded successfully.
|
| 79 |
+
|
| 80 |
+
Architecture
|
| 81 |
|
| 82 |
+
The model contains exactly one trainable scalar parameter:
|
| 83 |
|
| 84 |
+
w
|
| 85 |
|
| 86 |
+
The parameter is stored in:
|
| 87 |
+
|
| 88 |
+
sp_tn_1p.npz
|
| 89 |
+
|
| 90 |
+
The remaining generation rules are fixed and are not trainable parameters.
|
| 91 |
+
|
| 92 |
+
Important Limitations
|
| 93 |
+
|
| 94 |
+
SpTn-Model-only-1P is an experimental research project.
|
| 95 |
+
|
| 96 |
+
It is not a general-purpose language model.
|
| 97 |
+
|
| 98 |
+
The model does not understand natural language and does not generate meaningful answers.
|
| 99 |
+
|
| 100 |
+
The generated output is word-like synthetic text created under an extreme one-parameter constraint.
|
| 101 |
+
|
| 102 |
+
The project is intended to explore parameter efficiency and extremely low-parameter generative systems.
|
| 103 |
+
|
| 104 |
+
Roadmap
|
| 105 |
+
|
| 106 |
+
The project will investigate progressively larger parameter counts:
|
| 107 |
+
|
| 108 |
+
1P → 100P → 1K → 10K → 100K → 1M → 10M
|
| 109 |
+
|
| 110 |
+
The goal is to study how generative behavior changes as the number of trainable parameters increases.
|
| 111 |
+
|
| 112 |
+
Repository
|
| 113 |
|
| 114 |
GitHub:
|
| 115 |
https://github.com/parhamtaheri453-crypto/SpTn-Model-only-1P
|
|
|
|
| 117 |
Hugging Face:
|
| 118 |
https://huggingface.co/KtiyaKK/SpTn-Model-only-1P
|
| 119 |
|
| 120 |
+
Disclaimer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
SpTn-Model-only-1P is an experimental project.
|
| 123 |
|
| 124 |
+
It should not be compared directly with modern large language models.
|
| 125 |
|
| 126 |
+
The project is intended for experimentation, education, and research into extremely low-parameter generative models.
|
chat.py
CHANGED
|
@@ -1,64 +1,139 @@
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
print("================================")
|
| 13 |
print("SpTn-Model-only-1P")
|
| 14 |
print("Trainable parameters: 1")
|
|
|
|
|
|
|
| 15 |
print("Type 'exit' to quit")
|
| 16 |
print("================================")
|
| 17 |
|
| 18 |
-
while True:
|
| 19 |
-
text = input("\nYou: ")
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
break
|
| 24 |
|
| 25 |
-
if not
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
(ord(c) - 32) / 95.0
|
| 30 |
-
for c in text
|
| 31 |
-
if 32 <= ord(c) <= 126
|
| 32 |
-
])
|
| 33 |
|
| 34 |
-
if len(codes) == 0:
|
| 35 |
-
print("Model: Please enter ASCII text.")
|
| 36 |
-
continue
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
w -= np.float32(0.05 * gradient)
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
w * len(chars) + value * 3,
|
| 56 |
-
0,
|
| 57 |
-
len(chars) - 1
|
| 58 |
-
)
|
| 59 |
-
)
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
print("Model:",
|
| 64 |
-
print("Parameter:", float(w))
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
+
MODEL_FILE = "sp_tn_1p.npz"
|
| 4 |
|
| 5 |
+
model = np.load(MODEL_FILE)
|
| 6 |
+
w = float(model["w"])
|
| 7 |
|
| 8 |
+
# Fixed generation tables.
|
| 9 |
+
# These are NOT trainable parameters.
|
| 10 |
+
vowels = "aeiou"
|
| 11 |
+
consonants = "bcdfghjklmnpqrstvwxyz"
|
| 12 |
|
| 13 |
+
clusters = [
|
| 14 |
+
"br", "cr", "dr", "fr", "gr", "kr", "pr", "tr",
|
| 15 |
+
"bl", "cl", "fl", "gl", "pl",
|
| 16 |
+
"sk", "sl", "sm", "sn", "sp", "st", "sw",
|
| 17 |
+
"vr", "zh"
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
endings = [
|
| 21 |
+
"n", "r", "s", "t", "l", "m", "k",
|
| 22 |
+
"x", "d", "v"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
punctuation = ["", "", "", ".", "!", "?", ","]
|
| 26 |
|
| 27 |
print("================================")
|
| 28 |
print("SpTn-Model-only-1P")
|
| 29 |
print("Trainable parameters: 1")
|
| 30 |
+
print("Model file:", MODEL_FILE)
|
| 31 |
+
print("Parameter:", w)
|
| 32 |
print("Type 'exit' to quit")
|
| 33 |
print("================================")
|
| 34 |
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
def choose_without_repeat(pool, used):
|
| 37 |
+
available = [c for c in pool if c not in used]
|
|
|
|
| 38 |
|
| 39 |
+
if not available:
|
| 40 |
+
return None
|
| 41 |
|
| 42 |
+
return available[int(np.random.random() * len(available))]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
def make_word():
|
| 46 |
+
# Different word lengths.
|
| 47 |
+
length = int(4 + np.random.random() * 7)
|
| 48 |
+
|
| 49 |
+
used = set()
|
| 50 |
+
word = ""
|
| 51 |
+
|
| 52 |
+
# Sometimes start with a consonant cluster.
|
| 53 |
+
if np.random.random() < 0.35:
|
| 54 |
+
cluster = clusters[int(np.random.random() * len(clusters))]
|
| 55 |
+
|
| 56 |
+
for c in cluster:
|
| 57 |
+
if c not in used:
|
| 58 |
+
word += c
|
| 59 |
+
used.add(c)
|
| 60 |
+
|
| 61 |
+
while len(word) < length:
|
| 62 |
+
# Alternate consonant/vowel patterns.
|
| 63 |
+
if len(word) % 2 == 0:
|
| 64 |
+
c = choose_without_repeat(consonants, used)
|
| 65 |
+
else:
|
| 66 |
+
c = choose_without_repeat(vowels, used)
|
| 67 |
+
|
| 68 |
+
if c is None:
|
| 69 |
+
break
|
| 70 |
+
|
| 71 |
+
word += c
|
| 72 |
+
used.add(c)
|
| 73 |
+
|
| 74 |
+
# Optional final consonant.
|
| 75 |
+
if len(word) < length and np.random.random() < 0.5:
|
| 76 |
+
c = choose_without_repeat(endings, used)
|
| 77 |
+
|
| 78 |
+
if c is not None:
|
| 79 |
+
word += c
|
| 80 |
+
used.add(c)
|
| 81 |
+
|
| 82 |
+
return word
|
| 83 |
+
|
| 84 |
|
| 85 |
+
def generate_sentence(text):
|
| 86 |
+
# The single trainable parameter affects generation.
|
| 87 |
+
# Everything else is fixed generation logic.
|
| 88 |
+
seed_shift = int(abs(w) * 1000)
|
|
|
|
| 89 |
|
| 90 |
+
# Input affects the deterministic seed without becoming a parameter.
|
| 91 |
+
text_value = sum(ord(c) for c in text)
|
| 92 |
|
| 93 |
+
np.random.seed(seed_shift + text_value)
|
| 94 |
|
| 95 |
+
# 7–13 unique words.
|
| 96 |
+
word_count = int(7 + np.random.random() * 7)
|
| 97 |
|
| 98 |
+
words = []
|
| 99 |
+
seen = set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
attempts = 0
|
| 102 |
+
|
| 103 |
+
while len(words) < word_count and attempts < 100:
|
| 104 |
+
word = make_word()
|
| 105 |
+
attempts += 1
|
| 106 |
+
|
| 107 |
+
if word and word not in seen:
|
| 108 |
+
words.append(word)
|
| 109 |
+
seen.add(word)
|
| 110 |
+
|
| 111 |
+
# Random punctuation and capitalization.
|
| 112 |
+
result = []
|
| 113 |
+
|
| 114 |
+
for i, word in enumerate(words):
|
| 115 |
+
if np.random.random() < 0.18:
|
| 116 |
+
word = word.capitalize()
|
| 117 |
+
|
| 118 |
+
result.append(word)
|
| 119 |
+
|
| 120 |
+
sentence = " ".join(result)
|
| 121 |
+
|
| 122 |
+
punctuation_mark = punctuation[
|
| 123 |
+
int(np.random.random() * len(punctuation))
|
| 124 |
+
]
|
| 125 |
+
|
| 126 |
+
return sentence + punctuation_mark
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
while True:
|
| 130 |
+
text = input("\nYou: ")
|
| 131 |
+
|
| 132 |
+
if text.lower() == "exit":
|
| 133 |
+
print("Bye.")
|
| 134 |
+
break
|
| 135 |
+
|
| 136 |
+
if not text.strip():
|
| 137 |
+
continue
|
| 138 |
|
| 139 |
+
print("Model:", generate_sentence(text))
|
|
|
load_model.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
model = np.load("sp_tn_1p.npz")
|
| 4 |
+
|
| 5 |
+
w = model["w"]
|
| 6 |
+
|
| 7 |
+
print("SpTn-Model-only-1P")
|
| 8 |
+
print("Trainable parameters: 1")
|
| 9 |
+
print("Parameter:", float(w))
|
| 10 |
+
print("Model loaded successfully.")
|
save_model.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
# SpTn-Model-only-1P
|
| 4 |
+
# Exactly ONE trainable parameter
|
| 5 |
+
|
| 6 |
+
# The single parameter represents the center of a character distribution.
|
| 7 |
+
w = np.array(0.5, dtype=np.float32)
|
| 8 |
+
|
| 9 |
+
# Training data: normalized character positions.
|
| 10 |
+
data = np.array([0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90],
|
| 11 |
+
dtype=np.float32)
|
| 12 |
+
|
| 13 |
+
lr = 0.01
|
| 14 |
+
|
| 15 |
+
for _ in range(1000):
|
| 16 |
+
error = w - np.mean(data)
|
| 17 |
+
gradient = 2 * error
|
| 18 |
+
w -= lr * gradient
|
| 19 |
+
|
| 20 |
+
np.savez(
|
| 21 |
+
"sp_tn_1p.npz",
|
| 22 |
+
w=w,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
print("Model saved.")
|
| 26 |
+
print("Trainable parameters:", 1)
|
| 27 |
+
print("Parameter:", float(w))
|
sp_tn_1p.npz
ADDED
|
Binary file (260 Bytes). View file
|
|
|