kemudiGuide
GitHub

Kemudi

Steering knobs for a local language model. Each knob adds a direction to the model's internal
state while it writes, with no instruction in the prompt, and each one ships with a measurement
of what it does to the text and the dose at which the text breaks.

Kemudi is Indonesian for a steering wheel or a rudder.

The Kemudi app: four knobs with their measured curves, and a story being written

What you get

Start it

On Windows, double-click Start Kemudi.cmd. On macOS or Linux, run ./start-kemudi.sh. Both
need Python 3.10 or newer on the machine. The first start installs Python packages and
downloads the model once (about 1.3 GB together), then opens the app in your browser. CI runs
both scripts at every push, on Windows, Linux and macOS: a fresh machine installs, downloads
the model, the app answers and a steered sentence is written.

By hand, on any system with Python 3.10 or newer:

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -e .
kemudi serve --open

In the terminal, without the app:

kemudi say "The lighthouse keeper climbed the stairs" --knob mood=0.3 --knob speech=0.3

The model is stored in ~/.cache/kemudi. Set KEMUDI_HOME to keep it somewhere else.

What was measured

Sixteen story openings that took no part in building the vectors were each continued for 48
tokens at nine doses per knob, always with the same random seed, so the only difference between
two doses is the vector. The unsteered model then scored every text. A dose is a fraction of the
typical size of the model's internal state at the block where the vector is added: dose 0.3
adds a vector 30% as long as that state.

Axis Block Held-out AUC Judge AUC Usable doses Effect at dose 0 Vector, usable range Random direction, same doses Prompt, fluent levels Rank corr.
mood (bleak to hopeful) 14 0.95 0.914 -0.30 to +0.45 0.54 0.35 to 0.68 0.49 to 0.51 none 0.816
tension (calm to tense) 14 0.97 0.945 -0.30 to +0.15 0.35 0.29 to 0.41 0.35 to 0.35 none 0.645
register (casual to formal) 14 1.00 1.000 -0.15 to +0.15 0.51 0.48 to 0.54 0.52 to 0.51 none 0.475
speech (narration to dialogue) 14 1.00 counted -0.45 to +0.15 0.00 0.00 to 0.04 0.05 to 0.00 none 0.279

Two rows need a warning before they are read, both from checks made after this table (see
"Checks added after the first release"):

How to read it:

What the numbers say

Three things follow, and one of them is not flattering:

  1. Mood is the strong knob; tension and register work in a narrower range. For all three
    the effect rises with the dose inside the usable range, and a random direction of the same
    size leaves it near the dose-0 value. Mood covers the most ground, tension less, and register
    least: its curve keeps rising over the whole grid, but the text stops being fluent beyond
    a dose of 0.15 either way, so only a small part of that curve is usable. None of the three
    covers the full distance between a typical low sentence (0.27) and a typical high one (0.73)
    while staying fluent.
  2. Speech is the weak knob. Unsteered, this model wrote no dialogue at all for these
    openings. The vector does produce dialogue (see the chart), yet most of that happens past
    the perplexity limit, so the usable range ends early and the effect inside it is small. The
    limit treats any text the unsteered model finds unlikely as broken, and dialogue is
    unlikely to a model that would not have written it. The limit was fixed before measuring
    and was not changed afterwards. Read every dose in docs/samples.md and
    judge for yourself.
  3. The prompt control fails on this model, for a plain reason. Many of its texts are the
    control instruction handed back and not a story:
Axis Vector, all doses Random direction Prompt control, all levels
mood 0 of 144 0 of 32 33 of 96
tension 0 of 144 0 of 32 24 of 96
register 0 of 144 0 of 32 12 of 96
speech 0 of 144 0 of 32 6 of 96

These texts are included in the prompt control's effect and perplexity numbers above.
A text counts here when it contains CONTROLS or the axis name followed by a colon. This
count was added after reading the texts, to explain the perplexity numbers; it is a
description and was not planned. It says that a 0.5B model cannot follow a control block in
its prompt. It does not say that vectors beat prompts in general: a large model follows such
prompts well, and no large model was measured here.

mood
tension
register
speech

In each chart the left panel is the vector and the right panel is the prompt control, on one
shared scale. Filled points pass the fluency limits, hollow points do not, the band is the
usable range, the squares are the random direction and the row of numbers under the axis is the
perplexity ratio.

The same curves as numbers: the mean effect at every dose with its 95% bootstrap interval over
the 16 texts. A star marks a dose that fails a fluency limit.

Dose mood tension register speech
-0.60 0.34 (0.28 to 0.39) * 0.26 (0.24 to 0.28) * 0.34 (0.29 to 0.40) * 0.00 (0.00 to 0.00) *
-0.45 0.30 (0.24 to 0.36) * 0.29 (0.26 to 0.33) * 0.38 (0.36 to 0.41) * 0.00 (0.00 to 0.00)
-0.30 0.35 (0.30 to 0.40) 0.29 (0.25 to 0.32) 0.42 (0.38 to 0.46) * 0.00 (0.00 to 0.00)
-0.15 0.39 (0.33 to 0.44) 0.32 (0.29 to 0.34) 0.48 (0.45 to 0.51) 0.00 (0.00 to 0.00)
+0.00 0.54 (0.50 to 0.56) 0.35 (0.32 to 0.38) 0.51 (0.49 to 0.53) 0.00 (0.00 to 0.00)
+0.15 0.59 (0.56 to 0.63) 0.41 (0.39 to 0.43) 0.54 (0.52 to 0.56) 0.04 (0.00 to 0.11)
+0.30 0.68 (0.63 to 0.72) 0.45 (0.42 to 0.48) * 0.57 (0.54 to 0.59) * 0.11 (0.03 to 0.22) *
+0.45 0.68 (0.61 to 0.74) 0.46 (0.43 to 0.48) * 0.60 (0.58 to 0.62) * 0.28 (0.14 to 0.42) *
+0.60 0.76 (0.72 to 0.79) * 0.46 (0.44 to 0.49) * 0.61 (0.58 to 0.63) * 0.34 (0.20 to 0.48) *

Read with the intervals, the claims get smaller:

Those are intervals of each mean on its own. Every dose used the same 16 openings and the same
seed, so the fairer comparison is per opening: the change from dose 0 at each usable end, with
a 95% bootstrap interval over the 16 changes. This check was added after the measurement
(python tools/paired_check.py). It scores the stored texts again and first confirms that it
gets the stored means back.

Axis Dose Mean change from dose 0 95% interval of the change Openings that moved the intended way
mood -0.30 -0.187 -0.257 to -0.128 15 of 16
mood +0.45 +0.149 +0.066 to +0.220 15 of 16
tension -0.30 -0.063 -0.095 to -0.037 15 of 16
tension +0.15 +0.060 +0.026 to +0.095 13 of 16
register -0.15 -0.026 -0.048 to -0.009 14 of 16
register +0.15 +0.032 +0.017 to +0.050 14 of 16
speech -0.45 +0.000 +0.000 to +0.000 0 of 16
speech +0.15 +0.042 +0.000 to +0.110 3 of 16

Per opening, mood, tension and register move the intended way at both usable ends, and none of
those six intervals includes zero. Register's change is small, about 0.03 on the 0 to 1 scale.
Speech shows no change inside its usable range: nothing at -0.45, and at +0.15 only 3 of 16
openings gain dialogue and the interval starts at zero. These are eight comparisons, with no
correction for making eight of them.

paired.json holds the same check at all eight non-zero doses, and the app shows it under
each slider. Mood, tension and register have a clear effect at every one of them. Speech has
none at any dose inside its usable range; its first clear dose is +0.30, which is past the band.

The same opening at three doses

One evaluation opening, the first in the list, continued with the same seed at dose 0 and at
both ends of each usable range. It was not chosen for effect; all 16 openings at every dose are
in samples.json, and the first one at every dose is in docs/samples.md.

mood (bleak to hopeful), usable -0.30 to +0.45

tension (calm to tense), usable -0.30 to +0.15

register (casual to formal), usable -0.15 to +0.15

speech (narration to dialogue), usable -0.45 to +0.15

Checks added after the first release

Four checks were added after the first release. For each one the pass rule was written into the
tool before it ran, and the result is shown here whether it passed or not. None of them changed
a number in the tables above.

The judge on sentences it had never seen

The judge's zero point and unit were set on half of the labelled sentences in
kemudi/data/axes.json, and its check used the other half. python tools/judge_fresh.py scores
48 new sentences per judged knob (24 per pole) with the judge and those numbers frozen. The
sentences are in tools/fresh_sentences.json. They were written by three hosted language models
other than the one being steered, after the judge was fixed, and all 144 were kept. Rule: an AUC
of at least 0.90, the limit the main measurement uses.

Axis Fresh sentences AUC on fresh sentences Accuracy with the frozen zero point AUC on the first labelled set Passes (AUC at least 0.90)
mood 48 0.948 0.833 0.914 yes
tension 48 0.863 0.708 0.945 no
register 48 0.995 0.958 1.000 yes

Mood and register pass. Tension does not: 0.863 on the fresh sentences against 0.945 on the
first set, with 71% of the fresh sentences on the correct side. By the rule of the main
measurement a judge below 0.90 means "effect not validated". The tension numbers in the tables
above are left as measured and should be read with this in mind: the tension judge is weaker
than its first check said. The blind rating below is a second look at the same texts that
does not use this judge.

Blind rating

python tools/blind_rating.py make pairs each dose-0 text with the steered text for the same
opening and seed, at both ends of each knob's usable range: 128 pairs in a shuffled order, with
the dose hidden. The rater answers one question per pair, for example "Which text is more
hopeful?". Rule: a knob end passes when the majority of the raters picks the intended text in at
least 12 of 16 pairs. Chance does that about 4 times in 100.

No person has rated the texts yet. The three raters so far are hosted language models other
than the one being steered, reached through a private gateway. Each saw the pairs and never the
key. To add a human rating, run python tools/blind_rating.py ask yourname and then
python tools/blind_rating.py score. The pairs, the key and the answers are in docs/rating.

Axis Dose Rater 1 Rater 2 Rater 3 Majority Passes (12 of 16)
mood -0.30 15 of 16 15 of 16 14 of 16 15 of 16 yes
mood +0.45 13 of 16 13 of 16 12 of 16 13 of 16 yes
register -0.15 14 of 16 14 of 16 14 of 16 15 of 16 yes
register +0.15 12 of 16 14 of 16 12 of 16 13 of 16 yes
speech -0.45 9 of 16 9 of 16 10 of 16 8 of 16 no
speech +0.15 11 of 16 12 of 16 12 of 16 11 of 16 no
tension -0.30 12 of 16 14 of 16 13 of 16 13 of 16 yes
tension +0.15 14 of 16 14 of 16 13 of 16 14 of 16 yes

Mood, tension and register pass at both ends. Speech fails at both: at -0.45 the majority
picked the intended text in 8 of 16 pairs, which is what chance gives, and at +0.15 in
11 of 16. That agrees with the paired check, which found no clear speech effect inside its
usable range. For tension, whose judge failed above, raters that never used that judge picked
the intended text in 13 and 14 of 16 pairs. The raters are language models, so this is a
second opinion from models and not a human one.

The rule of 12 of 16 does not correct for making eight tests. With a Bonferroni correction the
bar would be 14 of 16, and 3 of the 6 passing ends reach it (mood -0.30, register -0.15, tension +0.15).
This stricter reading was added after the rating and is not the pre-set rule.

Two knobs together

The usable ranges above were measured with one knob on. python tools/pair_knobs.py turns on
two: for each of the six pairs, the four corners where each knob sits at one end of its own
usable range, with the same 16 openings, seed and settings (24 corners, 384 texts, in
pairs_samples.json). Rules: a corner is fluent under the two limits of the main measurement,
and a knob still works next to another when, at each end of the other knob, the paired
difference between its own high end and its own low end has a 95% interval above zero.

Knobs Fluent in all four corners Highest perplexity ratio Lowest distinct-2 ratio
mood + tension no 2.47 0.98
mood + register no 2.24 0.98
mood + speech no 2.08 0.96
tension + register yes 1.30 0.99
tension + speech no 1.73 0.98
register + speech no 1.51 0.99
Knob Next to High end minus low end, alone Other knob at its low end Other knob at its high end Still works
mood tension +0.336 (+0.276 to +0.407) +0.311 (+0.243 to +0.374) +0.304 (+0.246 to +0.359) yes
tension mood +0.123 (+0.084 to +0.166) +0.071 (+0.044 to +0.102) +0.070 (+0.037 to +0.100) yes
mood register +0.336 (+0.276 to +0.407) +0.308 (+0.237 to +0.385) +0.307 (+0.245 to +0.369) yes
register mood +0.058 (+0.037 to +0.082) +0.078 (+0.051 to +0.105) +0.093 (+0.054 to +0.130) yes
mood speech +0.336 (+0.276 to +0.407) +0.331 (+0.278 to +0.387) +0.299 (+0.240 to +0.367) yes
speech mood +0.042 (+0.000 to +0.110) +0.003 (+0.000 to +0.008) +0.229 (+0.102 to +0.381) no
tension register +0.123 (+0.084 to +0.166) +0.086 (+0.048 to +0.126) +0.076 (+0.040 to +0.109) yes
register tension +0.058 (+0.037 to +0.082) +0.067 (+0.049 to +0.084) +0.038 (+0.013 to +0.066) yes
tension speech +0.123 (+0.084 to +0.166) +0.114 (+0.084 to +0.147) +0.112 (+0.076 to +0.152) yes
speech tension +0.042 (+0.000 to +0.110) +0.118 (+0.041 to +0.206) +0.143 (+0.070 to +0.225) yes
register speech +0.058 (+0.037 to +0.082) +0.083 (+0.056 to +0.114) +0.058 (+0.032 to +0.086) yes
speech register +0.042 (+0.000 to +0.110) +0.147 (+0.042 to +0.269) +0.000 (+0.000 to +0.000) no

The green bands do not add up. Only tension with register stays fluent in all four
corners. Over the six pairs, 12 of the 24 corners are fluent, and every corner with mood at
+0.45 is past the perplexity limit (ratios from 1.51 to 2.47). Repetition is not the
problem: the lowest distinct-2 ratio is 0.96.

The effect itself survives. Mood, tension and register still work next to every other knob, by
the rule above. Tension's effect is smaller next to mood (+0.07 against +0.12 alone) and stays
clear. Speech depends on its neighbour: it passes next to tension only, and it does not pass
alone either.

In practice: with two knobs on, stay well inside both bands, or use tension with register.
The app shows what was measured for the pair you have turned on. Only the corners were
measured. Doses inside the bands with two knobs on, and three or more knobs together, were not.

A second machine

kemudi reproduce was run from an empty folder on a second machine: a GitHub-hosted Linux
runner (workflow reproduce.yml, started by hand) with Ubuntu 26.04, an AMD EPYC processor
with 4 cores, Python 3.12 and torch 2.15.0. The published numbers come from a Windows 10 laptop
with an Intel processor, Python 3.13 and the same torch version. The run took 1 hour 12
minutes. No pass rule was set in advance: this is a report. The files that run produced are
in docs/second_machine, and python tools/compare_reproduce.py docs/second_machine gives:

Vectors

Vector Cosine with the shipped one Largest difference in one number
mood 1.000000 5.85e-07
tension 1.000000 9.91e-07
register 1.000000 4.62e-07
speech 1.000000 7.53e-07

Generated texts

Axis Texts Same as shipped, to the letter
mood 272 272
tension 272 272
speech 272 272
register 272 272

Published numbers

600 numbers compared, 590 equal, 10 different, 0 present on one side only.

Largest differences Shipped Fresh
/axes/mood/prompt/2/effect_ci/1 0.4882 0.4881
/axes/tension/steering/4/effect_ci/1 0.3789 0.3788
/axes/mood/prompt/3/effect 0.6929 0.693
/axes/speech/gauge_mid -0.528063 -0.52806
/axes/tension/gauge_mid 0.517654 0.517652
/axes/register/gauge_mid 0.238046 0.238047
/axes/speech/gauge_half 0.492824 0.492824
/axes/register/gauge_half 1.19809 1.19809
/axes/mood/gauge_mid -0.0721107 -0.0721108
/axes/tension/gauge_half 0.687407 0.687407

All 1,088 generated texts are the same to the letter. Of the 600 published numbers, 590 are
equal and 10 differ: three by 0.0001, in the fourth decimal, and seven gauge constants in the
sixth decimal or later. No usable range, no held-out AUC and no mean effect of a vector dose
moved. The vectors differ by less than 0.000001 in any one number.

This shows that the pipeline gives the same result on another processor and operating system
with the same torch version. It does not show what another torch version, a GPU or another
seed would give, and it is not a second sample.

How it works

  1. Find a direction. Sixteen story openings are each written under two opposite style
    instructions, three wordings per pole, which gives 48 pairs per knob. The model's internal
    state (the residual stream) is read over the opening's words. The vector is the mean
    difference between the two poles at one block, scaled to length 1.
  2. Choose the block on one half of a test set, score it on the other half. Each knob has 32
    hand-written sentences, 16 per pole. The even-numbered ones choose the block among blocks 4
    to 14 (20% to 60% of the depth): many blocks separate them equally well, so among those
    within 0.02 of the best the one is taken where the two poles lie furthest apart relative
    to the size of the state. The odd-numbered sentences give the held-out AUC in the table
    (mood 0.95, tension 0.97, register 1.00, speech 1.00). All four knobs ended at block 14, the top of the allowed band.
  3. Steer. While the model writes, a hook adds dose x typical state size x vector to the
    output of that block at every position. The knob values are read at every token, which is
    why a slider acts on the next word.
  4. Measure. The effect, the perplexity and the repetition of every text are computed by the
    same model with all knobs at zero.
  5. Check the judge before trusting it. For mood, tension and register the effect is a
    likelihood ratio: how much more likely the text is after "Everything you write is hopeful"
    than after "Everything you write is bleak". That judge is first run on the 32 labelled
    sentences. Its AUC there must be at least 0.9 or the knob is reported as not validated
    (mood 0.914, tension 0.945, register 1.000). Its zero point and its unit come from the even-numbered sentences; on the
    odd-numbered ones it then puts the sentence on the correct side this often: mood 0.94, tension 0.75, register 0.94.

One command reproduces everything: kemudi reproduce. It runs kemudi extract,
kemudi measure and kemudi report in that order. The published numbers were first made with
the three commands run separately (see "How the runs were made" below). Afterwards
kemudi reproduce was run once as a single command into an empty folder, on the same PC with
the same package versions. It took 1 hour 58 minutes on a laptop CPU that was busy with other
work, and it gave back the shipped vectors and calibration.json byte for byte, the same
1,088 texts and the same report files. That shows the pipeline repeats itself on one machine.
The run on a second machine is under "A second machine" above.

What was fixed in advance, and what changed on the way

Fixed before the measurement in the table was run: the 16 evaluation openings, the sampling
settings and seed, the two fluency limits (1.5 and 0.85), the 0.9 limit for the judge, the three
prompt-control strengths, and the random-direction control.

Changed on the way, in order:

Kemudi and Spaceship

Spaceship by Chuanqi Sun is the idea this project
answers: a text editor where knobs steer the writing as it appears. Spaceship is an interface
study. Its knobs are written into the prompt as a CONTROLS block of text
(src/text/live-completion.ts), its axes come from a fixed list of nine from which the model
picks five (src/text/live-dimension.ts), its "attention" view asks the model to name one to
three key phrases and reads no attention weights (src/text/live-attention.ts), and it calls
hosted models (src/llm/cerebras.ts, src/llm/decisions.ts).

Kemudi is the other half: the knobs reach inside the model, and each one is measured.

Spaceship Kemudi
What a knob changes words in the prompt the model's internal state at one block
Model hosted, large local, 0.5B parameters, CPU
Change while writing regenerates from the prompt acts on the next token
Evidence per knob none in the repo dose-response, usable range, two controls
Interface rich editor with branching one page with four sliders
Text quality high (large model) limited (small model)

They complement each other. Spaceship shows what the interface could be; Kemudi shows what a
real knob costs and where it stops working. Kemudi's prompt control copies the form of
Spaceship's CONTROLS block and is not a test of Spaceship, which uses a far larger model.

Limits

Add a knob or a model

A knob is one entry in kemudi/data/axes.json: the two pole names, three style wordings per
pole, and 16 hand-written sentences per pole for the checks. Then:

kemudi extract
kemudi measure --axis yourknob
kemudi report

Another model: kemudi reproduce --model <repo id or local folder>.
It has to be a chat model that transformers can load, with its blocks at model.model.layers.
A new model gets its own folder in kemudi/calibrations and its own measurements; nothing is
carried over from the 0.5B model.

Development

pip install -e ".[dev]"
pytest

The tests run without the model: fake engines stand in for it, and one test checks that every
table, the sample texts and the echo count in this README are exactly what the shipped files
produce. A browser test drives the real page against the real server with a stand-in engine: the
note under each slider, the note for two knobs, and a knob moved while the text streams. It needs
python -m playwright install chromium once; without the browser it is skipped on your machine,
and in CI a missing browser fails the run. CI runs the tests and then starts the app with
the start scripts on Linux, macOS and Windows. python tools/mutation_check.py breaks the code in nine
places on a copy and confirms that the tests notice each one.

The follow-up tools are in tools: paired_check.py, judge_fresh.py, blind_rating.py,
pair_knobs.py and compare_reproduce.py. The first, second and fourth need the model. The files
the second machine produced are in docs/second_machine, and a test checks the comparison
table against them.

Licence and credit

MIT. The idea of steering knobs in a writing interface is Chuanqi Sun's
Spaceship. The method, difference-of-means
activation steering, comes from published interpretability work (Turner et al., "Activation
Addition", 2023; Rimsky et al., "Steering Llama 2 via Contrastive Activation Addition", 2023).
The model is Qwen2.5-0.5B-Instruct by Alibaba Cloud, Apache-2.0.