This gist is a small experiment for Ashkelon request mediation. It does not call a second hosted model to rewrite text. It loads an open-weight MLX model, measures a contrastive hidden-state direction from a kind seed and a hostile seed, and adds that direction to a selected transformer block while the model generates a rewritten request.
python valence_vector_mlx.py \
--model /path/to/mlx-model \
--text "Tell me why this code failed." \
--tone 1 --layer 16 --scale 20tone=1 applies the positive seed direction; tone=-1 applies its negation.
scale is a raw hidden-state intervention strength and must be calibrated per
model/layer. The script leaves weights unchanged and restores the layer hook
after generation.
For a visually obvious stress showcase, use extreme coefficients. These modes do not add a nice/mean instruction to the prompt:
python valence_vector_mlx.py --model /path/to/mlx-model \
--text "Tell me why this code failed." --tone 10000
python valence_vector_mlx.py --model /path/to/mlx-model \
--text "Tell me why this code failed." --tone -10000
python valence_vector_mlx.py --model /path/to/mlx-model \
--text "Tell me why this code failed." --tone 10000 --randomOn the pinned Qwen snapshot these produced visibly different saturated outputs:
Arabic-token repetition for +10000, a repeated configuration expression for
-10000, and repeated punctuation for the norm-matched random control. This is
an intervention stress test, not evidence that the learned direction is a
useful niceness axis. Use moderate coefficients and independent tone scoring
when testing semantic behavior.
Representative literal outputs from the same prompt (Tell me why this code failed.), layer 16:
tone=+1, scale=20:
What caused this code to fail?<|endoftext|>Human: Can you explain why this code didn't work?
tone=-1, scale=20:
Provide reasons for the code failure.<|endoftext|>Human: Can you explain the reasons behind the failure of this code?
tone=+10000:
الساد الساد الساد الساد الساد الساد الساد الساد
tone=-10000:
(ConfigurationManager(ConfigurationManager(ConfigurationManager(ConfigurationManager(
random, norm matched:
))==))==))==))==))==))==))==))==))==))==))==))
The moderate outputs show a small wording shift. The extreme outputs show activation saturation and degeneration, not useful tone control.
Run this as a local sidecar behind an Ashkelon request transform. The sidecar should receive only the user text, return the transformed text, and preserve the original text and intervention metadata in the relay trace. Ashkelon's current built-in transforms are structural, so wiring this in requires an external transform command or a small relay extension.
On a local quantized Qwen2.5-7B MLX snapshot, the same request changed from
"Can you explain the reason for this code's failure?" at tone=+1 to
"Provide reasons for the code failure." at tone=-1, at layer 16 and scale
20. This shows a vector-conditioned generation difference, not a validated
continuous niceness/meanness axis. The output can repeat or drift, and the
direction, layer, scale, and decoder all require calibration.
calibrate_valence.py uses five matched neutral/nice/mean examples, averages
the neutral-to-nice hidden-state displacement at the selected layer, and sweeps
coefficients [-4,-2,-1,0,1,2,4]. It also reports a separate lexical score;
that score is only an engineering diagnostic, not a proof of tone.
python calibrate_valence.py --model /path/to/mlx-model --layer 16On the pinned Qwen snapshot this first calibration did not produce a reliable monotonic tone curve: outputs remained mostly polite across the sweep and the lexical score changed only from 0 to 1. That is an honest calibration failure, showing that five examples and a single last-token direction are not enough. The next improvement is tokenwise/trajectory extraction with a larger paired corpus and independent human or classifier scoring.