Add a bounded chooser without touching logits or probs.
Where to hook. After you have candidate tokens/logits and any side signals for the lens.
Minimal flow.
- Compute contrasts
e_in,e_out. - Map to alignments:
a_in := tanh(-c*e_in),a_out := tanh(+c*e_out). - Chooser (rapidity mean):
RSI := tanh((SUM w*atanh(a_out) - SUM w*atanh(a_in)) / max(SUM w, eps_w)). - Gate:
RSI_env := g_t * RSI(or curvature-preserving mode"u_scale"→RSI_env := tanh(g_t * atanh(RSI))). - Pick by
RSI_env; keep classicalmintact viaphi((m,a)) = m.
Clamp rule (always). Before anyatanh, clamp:a_c := clamp(a, -1+eps_a, +1-eps_a).
Weights policy. Defaultw := |m|^gammawithgamma = 1;w := 1if declared.
# LLM decoding hook (beam/greedy, callback-style)
def on_candidates(cands, lens, g_t=1.0, eps_w=1e-12, eps_a=1e-6, gate_mode="mul"):
scored = []
for cand in cands: # cand carries m (logprob/prob) and lens_items: [(e_in, e_out, w), ...]
U_in = 0.0; V_out = 0.0; W = 0.0
for (e_in, e_out, w) in cand.lens_items:
a_in = tanh(-lens.c * e_in)
a_out = tanh(+lens.c * e_out)
a_in = max(-1+eps_a, min(1-eps_a, a_in))
a_out = max(-1+eps_a, min(1-eps_a, a_out))
U_in += w * atanh(a_in)
V_out += w * atanh(a_out)
W += w
if W <= 0:
RSI = 0.0
band = "A0" # insufficient_evidence
else:
RSI = tanh((V_out - U_in) / max(W, eps_w))
band = to_band(RSI) # A++/A+/A0/A-/A--
RSI_env = (tanh(g_t * atanh(RSI)) if gate_mode == "u_scale" else g_t * RSI)
RSI_env = max(-1+eps_a, min(1-eps_a, RSI_env))
scored.append((cand, RSI_env, RSI, band, U_in, V_out, W, g_t))
best = max(scored, key=lambda kv: kv[1])[0]
return best # selection by RSI_env; classical m remains intact (phi((m,a)) = m)
Stamp fields (suggested).token_id, m, RSI, RSI_env, band, U_in, V_out, W, g_t, lens_id, Unit, c, eps_a, eps_w, weights_policy, combine_policy, gate_mode, dtype, knobs_hash, stamp
One-line takeaway. Compute RSI in rapidity space, apply a calm gate, select by RSI_env, and stamp — your logits/probs stay exactly as they are (phi((m,a)) = m).
Navigation
Previous: SSM-AI – Robustness & Troubleshooting (7.6, 7.7)
Next: SSM-AI – Integration Quickstarts: RAG Pipeline Hook (8.2)
Directory of Pages
SSM-AI — Table of Contents