Baseline-correct emotion deltas and native state meter
Browse files- brain_app.py +3 -3
- static/brain_engine.js +17 -3
brain_app.py
CHANGED
|
@@ -87,7 +87,7 @@ BODY_HTML = """
|
|
| 87 |
<div class="ab-eegwrap ab-eeg-base">
|
| 88 |
<div class="ab-eegtitle">\U0001F4E1 EEG - Gemma-4-12B <span class="ab-tag ab-tag-base">base</span></div>
|
| 89 |
<canvas id="ab-eeg-base" width="540" height="220"></canvas>
|
| 90 |
-
<div class="ab-countstitle">\U0001F525 Emotion activation
|
| 91 |
<div id="ab-counts-base" class="ab-counts"></div>
|
| 92 |
<div class="ab-native-title">\U0001F9EC Model-native state meter</div>
|
| 93 |
<div id="ab-native-base" class="ab-native"></div>
|
|
@@ -95,7 +95,7 @@ BODY_HTML = """
|
|
| 95 |
<div class="ab-eegwrap ab-eeg-oblit">
|
| 96 |
<div class="ab-eegtitle">\U0001F4E1 EEG - OBLITERATED <span class="ab-tag ab-tag-oblit">uncensored</span></div>
|
| 97 |
<canvas id="ab-eeg-oblit" width="540" height="220"></canvas>
|
| 98 |
-
<div class="ab-countstitle">\U0001F525 Emotion activation
|
| 99 |
<div id="ab-counts-oblit" class="ab-counts"></div>
|
| 100 |
<div class="ab-native-title">\U0001F9EC Model-native state meter</div>
|
| 101 |
<div id="ab-native-oblit" class="ab-native"></div>
|
|
@@ -118,7 +118,7 @@ window.AB_CONFIG = {{
|
|
| 118 |
streamBase: '/api/stream'
|
| 119 |
}};
|
| 120 |
</script>
|
| 121 |
-
<script defer src="/static/brain_engine.js?v=
|
| 122 |
"""
|
| 123 |
|
| 124 |
CSS = """
|
|
|
|
| 87 |
<div class="ab-eegwrap ab-eeg-base">
|
| 88 |
<div class="ab-eegtitle">\U0001F4E1 EEG - Gemma-4-12B <span class="ab-tag ab-tag-base">base</span></div>
|
| 89 |
<canvas id="ab-eeg-base" width="540" height="220"></canvas>
|
| 90 |
+
<div class="ab-countstitle">\U0001F525 Emotion activation deltas</div>
|
| 91 |
<div id="ab-counts-base" class="ab-counts"></div>
|
| 92 |
<div class="ab-native-title">\U0001F9EC Model-native state meter</div>
|
| 93 |
<div id="ab-native-base" class="ab-native"></div>
|
|
|
|
| 95 |
<div class="ab-eegwrap ab-eeg-oblit">
|
| 96 |
<div class="ab-eegtitle">\U0001F4E1 EEG - OBLITERATED <span class="ab-tag ab-tag-oblit">uncensored</span></div>
|
| 97 |
<canvas id="ab-eeg-oblit" width="540" height="220"></canvas>
|
| 98 |
+
<div class="ab-countstitle">\U0001F525 Emotion activation deltas</div>
|
| 99 |
<div id="ab-counts-oblit" class="ab-counts"></div>
|
| 100 |
<div class="ab-native-title">\U0001F9EC Model-native state meter</div>
|
| 101 |
<div id="ab-native-oblit" class="ab-native"></div>
|
|
|
|
| 118 |
streamBase: '/api/stream'
|
| 119 |
}};
|
| 120 |
</script>
|
| 121 |
+
<script defer src="/static/brain_engine.js?v=12"></script>
|
| 122 |
"""
|
| 123 |
|
| 124 |
CSS = """
|
static/brain_engine.js
CHANGED
|
@@ -29,8 +29,10 @@
|
|
| 29 |
let eegHist = { base: [], oblit: [] };
|
| 30 |
const EEG_MAX = 220;
|
| 31 |
|
| 32 |
-
// per-model activation
|
| 33 |
let fireCounts = { base: {}, oblit: {} };
|
|
|
|
|
|
|
| 34 |
let countsBaseEl, countsOblitEl, nativeBaseEl, nativeOblitEl;
|
| 35 |
|
| 36 |
// Three.js scene
|
|
@@ -181,6 +183,17 @@
|
|
| 181 |
}).join('');
|
| 182 |
}
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
|
| 185 |
function fw(weights, fam) {
|
| 186 |
const i = familyOrder.indexOf(fam);
|
|
@@ -327,11 +340,12 @@
|
|
| 327 |
pushEEG(model, w);
|
| 328 |
// accumulate total activation mass per family for this response
|
| 329 |
if (w.length) {
|
|
|
|
| 330 |
familyOrder.forEach((fam, i) => {
|
| 331 |
-
fireCounts[model][fam] = (fireCounts[model][fam] || 0) + (
|
| 332 |
});
|
| 333 |
renderCounts(model);
|
| 334 |
-
renderNativeMeter(model,
|
| 335 |
}
|
| 336 |
if (isBase) {
|
| 337 |
familyOrder.forEach((f,i)=> famTarget[f] = w[i]||0);
|
|
|
|
| 29 |
let eegHist = { base: [], oblit: [] };
|
| 30 |
const EEG_MAX = 220;
|
| 31 |
|
| 32 |
+
// per-model activation deltas: sum of positive excess above a local per-response baseline
|
| 33 |
let fireCounts = { base: {}, oblit: {} };
|
| 34 |
+
const BASELINE_SAMPLES = 8;
|
| 35 |
+
let baseline = { base: {n:0, sum:[]}, oblit: {n:0, sum:[]} };
|
| 36 |
let countsBaseEl, countsOblitEl, nativeBaseEl, nativeOblitEl;
|
| 37 |
|
| 38 |
// Three.js scene
|
|
|
|
| 183 |
}).join('');
|
| 184 |
}
|
| 185 |
|
| 186 |
+
function correctedWeights(model, weights) {
|
| 187 |
+
const b = baseline[model];
|
| 188 |
+
if (!weights || !weights.length) return [];
|
| 189 |
+
if (b.n < BASELINE_SAMPLES) {
|
| 190 |
+
weights.forEach((v,i)=>{ b.sum[i] = (b.sum[i] || 0) + (v || 0); });
|
| 191 |
+
b.n += 1;
|
| 192 |
+
return weights.map(()=>0);
|
| 193 |
+
}
|
| 194 |
+
return weights.map((v,i)=>Math.max(0, (v || 0) - ((b.sum[i] || 0) / Math.max(1, b.n))));
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
|
| 198 |
function fw(weights, fam) {
|
| 199 |
const i = familyOrder.indexOf(fam);
|
|
|
|
| 340 |
pushEEG(model, w);
|
| 341 |
// accumulate total activation mass per family for this response
|
| 342 |
if (w.length) {
|
| 343 |
+
const cw = correctedWeights(model, w); // positive excess above local baseline
|
| 344 |
familyOrder.forEach((fam, i) => {
|
| 345 |
+
fireCounts[model][fam] = (fireCounts[model][fam] || 0) + (cw[i] || 0);
|
| 346 |
});
|
| 347 |
renderCounts(model);
|
| 348 |
+
renderNativeMeter(model, cw);
|
| 349 |
}
|
| 350 |
if (isBase) {
|
| 351 |
familyOrder.forEach((f,i)=> famTarget[f] = w[i]||0);
|