hikewa commited on
Commit
efb67d7
·
verified ·
1 Parent(s): 9b56d68

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +171 -0
README.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - eisv
5
+ - dynamics
6
+ - trajectory
7
+ - expression-generation
8
+ - random-forest
9
+ - edge-deployment
10
+ - raspberry-pi
11
+ datasets:
12
+ - hikewa/unitares-eisv-trajectories
13
+ ---
14
+
15
+ # EISV-Lumen Student -- Distilled RandomForest for Edge Deployment
16
+
17
+ A lightweight RandomForest ensemble distilled from the
18
+ [EISV-Lumen Teacher](https://huggingface.co/hikewa/eisv-lumen-teacher)
19
+ (fine-tuned Qwen2.5-0.5B). Achieves **0.986 coherence** on the EISV
20
+ expression-generation task while fitting in **~13 MB of JSON** with
21
+ **zero external dependencies** -- only Python stdlib required. Designed
22
+ to run on a Raspberry Pi 4 (Lumen's physical host).
23
+
24
+ ## Model Details
25
+
26
+ | Field | Value |
27
+ |---|---|
28
+ | **Method** | Knowledge distillation (teacher-labeled soft targets) |
29
+ | **Architecture** | 3 independent RandomForest classifiers (sklearn) |
30
+ | **Input features** | 12 numeric (EISV means, deltas, accelerations) + 9 shape one-hot |
31
+ | **Training data** | 4,320 teacher-labeled examples (9 shapes x 480 each) |
32
+ | **Test data** | 1,080 held-out examples |
33
+ | **Formats** | sklearn pickle (~22 MB) and zero-dependency JSON (~13 MB) |
34
+ | **Target hardware** | Raspberry Pi 4 (1.5 GHz ARM, 4 GB RAM) |
35
+
36
+ ## How It Works
37
+
38
+ The student decomposes EISV expression generation into three chained
39
+ classification problems, each solved by an independent RandomForest:
40
+
41
+ 1. **Pattern classifier** -- predicts one of 5 expression patterns:
42
+ `SINGLE`, `PAIR`, `REPETITION`, `QUESTION`, `TRIPLE`
43
+ 2. **Token-1 classifier** -- predicts the primary EISV token from 15
44
+ classes (e.g., `~stillness~`, `~warmth~`, `~emergence~`)
45
+ 3. **Token-2 classifier** -- predicts the secondary token from 15 + none,
46
+ conditioned on the Token-1 prediction (token1 index appended as extra
47
+ feature)
48
+
49
+ The pattern determines how tokens are assembled into the final expression
50
+ string (e.g., `PAIR` yields two distinct tokens, `REPETITION` repeats
51
+ token-1 twice).
52
+
53
+ ## Results
54
+
55
+ | Metric | Student (RF) | Teacher (Qwen2.5-0.5B) | Random Baseline |
56
+ |---|---|---|---|
57
+ | **Coherence** | **0.986** | 0.952 | 0.495 |
58
+ | Token-1 agreement | 0.688 | -- | -- |
59
+ | Pattern agreement | 0.652 | -- | -- |
60
+ | Full agreement (all 3 match) | 0.403 | -- | -- |
61
+
62
+ > **Why does the student exceed the teacher?** The RandomForest decision
63
+ > boundaries naturally cluster predictions toward high-affinity tokens for
64
+ > each trajectory shape. While the student disagrees with the teacher on
65
+ > exact token choices ~30% of the time, the tokens it picks are still
66
+ > coherent -- they belong to the same affinity region of EISV space. The
67
+ > coherence metric rewards any valid expression, not exact match.
68
+
69
+ ## Zero-Dependency Usage (recommended for edge)
70
+
71
+ The `exported/` directory contains JSON-serialized forests and a standalone
72
+ inference module. No pip packages required.
73
+
74
+ ```python
75
+ from student_inference import StudentInference
76
+
77
+ student = StudentInference("path/to/exported/")
78
+
79
+ result = student.predict("settled_presence", {
80
+ "mean_E": 0.7, "mean_I": 0.6, "mean_S": 0.2, "mean_V": 0.05,
81
+ "dE": 0.0, "dI": 0.0, "dS": 0.0, "dV": 0.0,
82
+ "d2E": 0.0, "d2I": 0.0, "d2S": 0.0, "d2V": 0.0,
83
+ })
84
+ # result = {"pattern": "SINGLE", "eisv_tokens": ["~stillness~"],
85
+ # "token_1": "~stillness~", "token_2": "none"}
86
+ ```
87
+
88
+ Only `json` and `os` from the standard library are used. The inference
89
+ module walks each decision tree node-by-node and averages class
90
+ probabilities across all trees -- identical to sklearn's predict logic.
91
+
92
+ ## sklearn Usage
93
+
94
+ If you have scikit-learn installed, you can use the pickle files directly:
95
+
96
+ ```python
97
+ import pickle
98
+ import numpy as np
99
+
100
+ with open("pattern_clf.pkl", "rb") as f:
101
+ pattern_clf = pickle.load(f)
102
+ with open("scaler.pkl", "rb") as f:
103
+ scaler = pickle.load(f)
104
+ with open("pattern_encoder.pkl", "rb") as f:
105
+ pattern_enc = pickle.load(f)
106
+
107
+ # Build feature vector: 12 numeric features + 9 shape one-hot
108
+ numeric = np.array([[0.7, 0.6, 0.2, 0.05, 0, 0, 0, 0, 0, 0, 0, 0]])
109
+ scaled = scaler.transform(numeric)
110
+ shape_onehot = np.zeros((1, 9)) # index 7 = settled_presence
111
+ shape_onehot[0, 7] = 1.0
112
+ X = np.hstack([scaled, shape_onehot])
113
+
114
+ pattern_idx = pattern_clf.predict(X)
115
+ pattern = pattern_enc.inverse_transform(pattern_idx)[0]
116
+ ```
117
+
118
+ ## File Structure
119
+
120
+ ```
121
+ outputs/student_small/
122
+ |-- README.md # This file
123
+ |-- pattern_clf.pkl # sklearn RandomForest (4.3 MB)
124
+ |-- token1_clf.pkl # sklearn RandomForest (8.4 MB)
125
+ |-- token2_clf.pkl # sklearn RandomForest (9.8 MB)
126
+ |-- scaler.pkl # StandardScaler
127
+ |-- pattern_encoder.pkl # LabelEncoder for patterns
128
+ |-- token1_encoder.pkl # LabelEncoder for tokens
129
+ |-- token2_encoder.pkl # LabelEncoder for tokens+none
130
+ |-- shape_encoder.pkl # LabelEncoder for shapes
131
+ |-- training_metrics.json # Cross-validation metrics
132
+ |-- eval_results.json # Full evaluation results
133
+ |-- exported/ # Zero-dependency JSON format
134
+ |-- pattern_forest.json # Decision trees as JSON (3.0 MB)
135
+ |-- token1_forest.json # Decision trees as JSON (4.5 MB)
136
+ |-- token2_forest.json # Decision trees as JSON (5.1 MB)
137
+ |-- scaler.json # Scaler parameters (511 B)
138
+ |-- mappings.json # Label mappings (1.1 KB)
139
+ |-- student_inference.py # Standalone inference (4.9 KB)
140
+ ```
141
+
142
+ ## Training Details
143
+
144
+ - **Distillation source**: Teacher (Qwen2.5-0.5B LoRA v6, 0.952 coherence
145
+ on real Lumen trajectories)
146
+ - **Data generation**: 4,320 synthetic EISV trajectories labeled by teacher
147
+ inference (480 per shape x 9 shapes), plus 1,080 held-out test examples
148
+ - **Forest hyperparameters**: `n_estimators=100`, `max_depth=None`,
149
+ `random_state=42` (sklearn defaults)
150
+ - **Feature engineering**: 12 numeric features (4 EISV means + 4 first
151
+ derivatives + 4 second derivatives) standardized via `StandardScaler`,
152
+ plus 9-dimensional one-hot encoding of trajectory shape
153
+
154
+ ## Related
155
+
156
+ - **Teacher model**: [hikewa/eisv-lumen-teacher](https://huggingface.co/hikewa/eisv-lumen-teacher) -- fine-tuned Qwen2.5-0.5B that generated the training labels
157
+ - **Dataset**: [hikewa/unitares-eisv-trajectories](https://huggingface.co/datasets/hikewa/unitares-eisv-trajectories) -- EISV trajectory data from Lumen
158
+ - **Explorer Space**: [hikewa/eisv-lumen-explorer](https://huggingface.co/spaces/hikewa/eisv-lumen-explorer) -- interactive demo
159
+
160
+ ## Citation
161
+
162
+ ```bibtex
163
+ @misc{eisv-lumen-student-2025,
164
+ title = {EISV-Lumen Student: Distilled RandomForest for Edge Deployment},
165
+ author = {hikewa},
166
+ year = {2025},
167
+ url = {https://huggingface.co/hikewa/eisv-lumen-student},
168
+ note = {Knowledge-distilled RandomForest ensemble for EISV expression
169
+ generation on Raspberry Pi}
170
+ }
171
+ ```