Spaces:
Sleeping
Sleeping
dixiebone13-a11y Claude Opus 4.5 commited on
Commit ·
e4391d7
1
Parent(s): 6d58930
v3.4.1: hybrid tanh normalization - preserve dimension signals
Browse filesReplace v3.4 per-dimension re-centering with hybrid approach:
tanh(z_score * 0.15) on raw z-scores. Preserves absolute z-score
levels (strong Computation signal, AUC=0.768) while eliminating
hard ceiling effects from v3.3 clamp.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -54,13 +54,13 @@ def compute_consciousness(
|
|
| 54 |
) -> ConsciousnessResult:
|
| 55 |
"""Compute consciousness score from hidden state tensor.
|
| 56 |
|
| 57 |
-
v3.4:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
Replaces v3.3 hard clamp with tanh for smooth bounding.
|
| 61 |
"""
|
| 62 |
import math
|
| 63 |
start_time = time.time()
|
|
|
|
| 64 |
|
| 65 |
# Remap dimensions if needed
|
| 66 |
if hidden_dim != REFERENCE_HIDDEN_DIM:
|
|
@@ -69,54 +69,32 @@ def compute_consciousness(
|
|
| 69 |
else:
|
| 70 |
dims = CONSCIOUS_DIMS_V2_1
|
| 71 |
|
| 72 |
-
# Get
|
| 73 |
if hidden_state.dim() == 3:
|
| 74 |
-
|
| 75 |
elif hidden_state.dim() == 2:
|
| 76 |
-
|
| 77 |
else:
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
h = h_seq[pos]
|
| 88 |
-
h_mean = h.mean().item()
|
| 89 |
-
h_std = h.std().item()
|
| 90 |
-
for dim_idx, info in dims.items():
|
| 91 |
-
if dim_idx < len(h):
|
| 92 |
-
z = (h[dim_idx].item() - h_mean) / (h_std + 1e-8)
|
| 93 |
-
else:
|
| 94 |
-
z = 0.0
|
| 95 |
-
dim_z_raw[info["name"]].append(z)
|
| 96 |
-
|
| 97 |
-
# Pass 2: Per-dimension re-normalization + tanh bounding
|
| 98 |
-
# Use last token for the final score, but normalize against
|
| 99 |
-
# the dimension's distribution across the whole sequence
|
| 100 |
contributions = {}
|
| 101 |
weighted_sum = 0.0
|
| 102 |
|
| 103 |
for dim_idx, info in dims.items():
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
z_last = z_vals[-1]
|
| 112 |
-
renormed = (z_last - z_mean) / z_std
|
| 113 |
-
# Smooth bounding with tanh (no hard ceiling)
|
| 114 |
-
bounded = math.tanh(renormed * tanh_scale)
|
| 115 |
-
|
| 116 |
-
activation = bounded
|
| 117 |
-
contribution = activation * info["weight"] * info["polarity"]
|
| 118 |
-
weighted_sum += contribution
|
| 119 |
-
contributions[name] = activation * info["polarity"]
|
| 120 |
|
| 121 |
# Final score
|
| 122 |
raw_score = baseline + weighted_sum * 0.15
|
|
|
|
| 54 |
) -> ConsciousnessResult:
|
| 55 |
"""Compute consciousness score from hidden state tensor.
|
| 56 |
|
| 57 |
+
v3.4.1 hybrid: z-score + tanh(z * 0.15) for smooth bounding.
|
| 58 |
+
Preserves absolute z-score levels (strong dimension-level signals)
|
| 59 |
+
while eliminating hard ceiling effects from v3.3 clamp.
|
|
|
|
| 60 |
"""
|
| 61 |
import math
|
| 62 |
start_time = time.time()
|
| 63 |
+
TANH_SCALE = 0.15 # tanh(z*0.15): z=3→0.42, z=5→0.64, z=8→0.83, z=10→0.91
|
| 64 |
|
| 65 |
# Remap dimensions if needed
|
| 66 |
if hidden_dim != REFERENCE_HIDDEN_DIM:
|
|
|
|
| 69 |
else:
|
| 70 |
dims = CONSCIOUS_DIMS_V2_1
|
| 71 |
|
| 72 |
+
# Get last token hidden state
|
| 73 |
if hidden_state.dim() == 3:
|
| 74 |
+
h = hidden_state[0, -1, :] # [hidden_dim]
|
| 75 |
elif hidden_state.dim() == 2:
|
| 76 |
+
h = hidden_state[-1, :]
|
| 77 |
else:
|
| 78 |
+
h = hidden_state
|
| 79 |
+
|
| 80 |
+
h = h.float()
|
| 81 |
+
|
| 82 |
+
# Z-score normalize against full hidden state
|
| 83 |
+
h_mean = h.mean().item()
|
| 84 |
+
h_std = h.std().item()
|
| 85 |
+
|
| 86 |
+
# Compute contributions with tanh smooth bounding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
contributions = {}
|
| 88 |
weighted_sum = 0.0
|
| 89 |
|
| 90 |
for dim_idx, info in dims.items():
|
| 91 |
+
if dim_idx < len(h):
|
| 92 |
+
z = (h[dim_idx].item() - h_mean) / (h_std + 1e-8)
|
| 93 |
+
# Smooth bounding: preserves absolute level, no hard ceiling
|
| 94 |
+
activation = math.tanh(z * TANH_SCALE)
|
| 95 |
+
contribution = activation * info["weight"] * info["polarity"]
|
| 96 |
+
weighted_sum += contribution
|
| 97 |
+
contributions[info["name"]] = activation * info["polarity"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Final score
|
| 100 |
raw_score = baseline + weighted_sum * 0.15
|