@@ -1324,24 +1324,50 @@ def _omniweight_apply(base_probs: torch.Tensor,
13241324 return out / (out .sum () + 1e-8 )
13251325
13261326
1327+ def _self_eval_insight (base_probs : torch .Tensor , emitted_tid : int ,
1328+ n_chars : int = 65 ) -> float :
1329+ """Compute self-evaluation insight signal for a just-emitted token.
1330+
1331+ insight = 1 if:
1332+ - emitted token is a real word (rank >= n_chars), AND
1333+ - surprise (-log p_emitted) >= pi*log(phi) ~ 1.51 (substrate threshold)
1334+ insight = 0 otherwise.
1335+
1336+ Recursive substrate self-monitoring: model rates its own emissions
1337+ against its own distribution.
1338+ """
1339+ if emitted_tid < n_chars :
1340+ return 0.0
1341+ V = base_probs .shape [0 ]
1342+ if not (0 <= emitted_tid < V ):
1343+ return 0.0
1344+ p = float (base_probs [emitted_tid ].item ())
1345+ if p <= 0.0 :
1346+ return 0.0
1347+ surprise = - math .log (p + 1e-12 )
1348+ threshold = math .pi * math .log (_PHI_FOR_SAMPLING )
1349+ return 1.0 if surprise >= threshold else 0.0
1350+
1351+
13271352def _omniweight_apply_split (base_probs : torch .Tensor ,
13281353 math_delta : torch .Tensor ,
1329- lang_delta : torch .Tensor ) -> torch .Tensor :
1330- """SPLIT-BRAIN omniweight: RANK-MODULATED mixer.
1331-
1332- Per-token weight derived from substrate rank position:
1333- rank 0 (most-functional) -> math_weight = 1, lang_weight = 0
1334- rank V/2 -> math_weight = 0.5, lang_weight = 0.5
1335- rank V-1 (rarest content) -> math_weight = 0, lang_weight = 1
1354+ lang_delta : torch .Tensor ,
1355+ momentum : float = 0.0 ) -> torch .Tensor :
1356+ """RANK-MODULATED split-brain mixer with momentum-modulated reserve.
13361357
1337- Each hemisphere gets sovereignty over its natural domain:
1338- Math owns frequency/decay -> dominates function words.
1339- Language owns purpose/structure -> dominates content words.
1358+ Each hemisphere builds fluid delta via tanh-scaled reserve.
1359+ Reserve scaled by (1 + tanh(momentum)) -- when recent emissions
1360+ have been insightful (high surprise + real word), primitives get
1361+ more room. When noisy/expected, primitives constrained.
13401362
1341- No more mixing in regions where one hemisphere doesn't belong .
1363+ Per-token weight by rank: math owns low rank, lang owns high rank .
13421364 """
1343- math_fluid = _OMNIWEIGHT_RESERVE * torch .tanh (math_delta / _OMNIWEIGHT_RESERVE )
1344- lang_fluid = _OMNIWEIGHT_RESERVE * torch .tanh (lang_delta / _OMNIWEIGHT_RESERVE )
1365+ # Momentum-modulated reserve (recursive substrate self-trust).
1366+ reserve = _OMNIWEIGHT_RESERVE * (1.0 + math .tanh (momentum ))
1367+ if reserve < 1e-3 :
1368+ reserve = 1e-3
1369+ math_fluid = reserve * torch .tanh (math_delta / reserve )
1370+ lang_fluid = reserve * torch .tanh (lang_delta / reserve )
13451371 p_math = base_probs * torch .exp (math_fluid )
13461372 p_lang = base_probs * torch .exp (lang_fluid )
13471373 p_math = p_math / (p_math .sum () + 1e-8 )
@@ -1395,6 +1421,7 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
13951421 char_run = 0
13961422 recent_pairs = [] # (prev_tok, current_tok) bigram history
13971423 last_content_ends_s = False
1424+ creative_momentum = 0.0 # self-eval EMA register
13981425 if vocab is not None :
13991426 prompt_list = seq [0 ].tolist ()
14001427 for idx_pl , tid in enumerate (prompt_list ):
@@ -1514,9 +1541,10 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
15141541 p = substrate_subject_threading (
15151542 seq_list , vocab , base , is_sentence_start = True )
15161543 lang_delta += _omniweight_delta (base , p )
1517- # Apply split-brain mixer (geometric mean) .
1544+ # Apply split-brain mixer with momentum-modulated reserve .
15181545 probs = _omniweight_apply_split (
1519- base , math_delta , lang_delta ).unsqueeze (0 )
1546+ base , math_delta , lang_delta ,
1547+ momentum = creative_momentum ).unsqueeze (0 )
15201548 # Vocab curriculum (HARD mask, post-omniweight).
15211549 if active_vocab_size is not None :
15221550 probs [0 ] = substrate_vocab_curriculum (
@@ -1560,6 +1588,11 @@ def autoregressive_generate(model, prompt: torch.Tensor, n_new: int,
15601588 recent_pairs .append ((prev_for_pair , nid ))
15611589 if len (recent_pairs ) > 13 :
15621590 recent_pairs = recent_pairs [- 13 :]
1591+ # Self-evaluation: update creative momentum EMA.
1592+ insight = _self_eval_insight (base , nid , n_chars_local )
1593+ inv_phi = 1.0 / _PHI_FOR_SAMPLING
1594+ creative_momentum = (inv_phi * creative_momentum
1595+ + (1.0 - inv_phi ) * insight )
15631596 model .train ()
15641597 return seq
15651598
@@ -1755,9 +1788,11 @@ def _single_stage_refine(model, draft, vocab_size, scorer, mode: str,
17551788 p = substrate_anti_stagnation (
17561789 history_aw , base_probs , vocab_size_local )
17571790 math_delta += _omniweight_delta (base_probs , p )
1758- # Apply split-brain mixer (geometric mean).
1791+ # Apply split-brain mixer. Momentum=0 in refine
1792+ # (no streaming history of base distributions).
17591793 pos_probs = _omniweight_apply_split (
1760- base_probs , math_delta , lang_delta )
1794+ base_probs , math_delta , lang_delta ,
1795+ momentum = 0.0 )
17611796 # Vocab curriculum (HARD mask, post-omniweight).
17621797 if active_vocab_size is not None :
17631798 pos_probs = substrate_vocab_curriculum (
0 commit comments