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

v3.4: Per-dimension adaptive normalization

Browse files

Replace v3.3 hard clamp [-3,+3] with two-pass per-dimension
normalization + tanh bounding. Eliminates ceiling effects where
4/7 dimensions (Logic, Uncertainty, Sequential, Abstraction)
were pegged at +3.0 for every math problem.

Now all dimensions produce meaningful variance, improving
dimension-level discrimination between correct/incorrect answers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +58 -32
app.py CHANGED
@@ -52,62 +52,88 @@ def compute_consciousness(
52
  hidden_dim: int = REFERENCE_HIDDEN_DIM,
53
  baseline: float = 0.5,
54
  ) -> ConsciousnessResult:
55
- """Compute consciousness score from hidden state tensor."""
 
 
 
 
 
 
 
56
  start_time = time.time()
57
-
58
  # Remap dimensions if needed
59
  if hidden_dim != REFERENCE_HIDDEN_DIM:
60
  scale = hidden_dim / REFERENCE_HIDDEN_DIM
61
  dims = {int(round(k * scale)): v for k, v in CONSCIOUS_DIMS_V2_1.items()}
62
  else:
63
  dims = CONSCIOUS_DIMS_V2_1
64
-
65
- # Get last token hidden state
66
  if hidden_state.dim() == 3:
67
- h = hidden_state[0, -1, :] # [hidden_dim]
68
  elif hidden_state.dim() == 2:
69
- h = hidden_state[-1, :]
70
- else:
71
- h = hidden_state
72
-
73
- h = h.float()
74
-
75
- # Normalize
76
- mean, std = h.mean(), h.std()
77
- if std > 0:
78
- h_norm = (h - mean) / std
79
  else:
80
- h_norm = h - mean
81
-
82
- # Compute contributions (v3.3: clamp z-scores for model-size independence)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  contributions = {}
84
  weighted_sum = 0.0
85
 
86
  for dim_idx, info in dims.items():
87
- if dim_idx < len(h_norm):
88
- activation = h_norm[dim_idx].item()
89
- # Clamp extreme z-scores to prevent saturation on large models
90
- activation = max(-3.0, min(3.0, activation))
91
- contribution = activation * info["weight"] * info["polarity"]
92
- weighted_sum += contribution
93
- contributions[info["name"]] = activation * info["polarity"]
 
 
 
 
 
 
 
 
 
94
 
95
  # Final score
96
  raw_score = baseline + weighted_sum * 0.15
97
  score = max(0.0, min(1.0, raw_score))
98
-
99
  # Interpretation
100
  if score >= 0.8:
101
- interpretation = "🧠 High Consciousness - Deep reflective/philosophical reasoning"
102
  elif score >= 0.6:
103
- interpretation = "💭 Medium-High - Complex analytical thinking"
104
  elif score >= 0.4:
105
- interpretation = "⚖️ Medium - Balanced processing"
106
  elif score >= 0.2:
107
- interpretation = " Medium-Low - More automatic processing"
108
  else:
109
- interpretation = "🔢 Low Consciousness - Quick factual retrieval"
110
-
111
  return ConsciousnessResult(
112
  score=score,
113
  raw_score=raw_score,
 
52
  hidden_dim: int = REFERENCE_HIDDEN_DIM,
53
  baseline: float = 0.5,
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:
67
  scale = hidden_dim / REFERENCE_HIDDEN_DIM
68
  dims = {int(round(k * scale)): v for k, v in CONSCIOUS_DIMS_V2_1.items()}
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
123
  score = max(0.0, min(1.0, raw_score))
124
+
125
  # Interpretation
126
  if score >= 0.8:
127
+ interpretation = "\U0001f9e0 High Consciousness - Deep reflective/philosophical reasoning"
128
  elif score >= 0.6:
129
+ interpretation = "\U0001f4ad Medium-High - Complex analytical thinking"
130
  elif score >= 0.4:
131
+ interpretation = "\u2696\ufe0f Medium - Balanced processing"
132
  elif score >= 0.2:
133
+ interpretation = "\u26a1 Medium-Low - More automatic processing"
134
  else:
135
+ interpretation = "\U0001f522 Low Consciousness - Quick factual retrieval"
136
+
137
  return ConsciousnessResult(
138
  score=score,
139
  raw_score=raw_score,