dixiebone13-a11y Claude Opus 4.5 commited on
Commit
e4391d7
·
1 Parent(s): 6d58930

v3.4.1: hybrid tanh normalization - preserve dimension signals

Browse files

Replace 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>

Files changed (1) hide show
  1. app.py +23 -45
app.py CHANGED
@@ -54,13 +54,13 @@ def compute_consciousness(
54
  ) -> ConsciousnessResult:
55
  """Compute consciousness score from hidden state tensor.
56
 
57
- v3.4: Per-dimension adaptive normalization.
58
- Uses the full sequence to compute per-dimension z-score statistics,
59
- then re-normalizes each dimension against its own baseline.
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 full sequence hidden states
73
  if hidden_state.dim() == 3:
74
- h_seq = hidden_state[0].float() # [seq_len, hidden_dim]
75
  elif hidden_state.dim() == 2:
76
- h_seq = hidden_state.float() # [seq_len, hidden_dim]
77
  else:
78
- # Single vector fallback (no sequence context)
79
- h_seq = hidden_state.float().unsqueeze(0)
80
-
81
- seq_len = h_seq.shape[0]
82
- tanh_scale = 0.5
83
-
84
- # Pass 1: Compute z-scores for each consciousness dim across all positions
85
- dim_z_raw = {info["name"]: [] for info in dims.values()}
86
- for pos in range(seq_len):
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
- name = info["name"]
105
- z_vals = dim_z_raw[name]
106
- z_mean = sum(z_vals) / len(z_vals)
107
- z_var = sum((z - z_mean) ** 2 for z in z_vals) / len(z_vals)
108
- z_std = max(math.sqrt(z_var), 0.1) # Floor to prevent noise amplification
109
-
110
- # Last token: re-normalize against this dimension's sequence baseline
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