Writing Machine learning & evaluation
How OCTAVIA decides whether to trust a lesson
OCTAVIA is a voice assistant I build that runs on a Windows PC. When a copy of it gets something wrong, the cheapest possible repair is a sentence: a short rule added to its prompt that says what to do next time. A sentence needs no code, no release and no retraining, and it can be handed to every other copy in the time it takes to download a file.
It is also the repair I trust least. A sentence in a prompt nudges every answer the assistant gives from then on, and it arrives with no evidence that it does what its author hoped. So the part of OCTAVIA that shares what installs learn, which I call the ETHER, will not pass a lesson on until that lesson has fixed a failing test by more than luck can explain.
This week the first real lesson went through it. Across three attempts, the test it was written for went from passing 15 times in 25 to passing 23 times in 25. The gate refused it all three times, and the list of shared lessons is still empty. This post is about why I think that was the right answer, and what it costs. First the gate itself, with the three real runs loaded in.
What a lesson is
On my own PC, OCTAVIA improves itself: it reads its logs, builds the fixes it finds, and installs only what passes its tests and a replay of real requests. The ETHER is how that reaches anyone else's copy, and the first rule is that nothing goes from one install straight into another. An install that has sharing turned on sends proposals up to me, each one scanned for anything personal before it leaves. What I accept comes back down inside something I have signed.
Three kinds of thing can travel. A fix is a code change, and code has tests. A case is a request some install got wrong, turned into a graded test that every later build has to pass, so a case is itself a test. A lesson is neither. It is a rule of at most 300 characters, and accepting it adds one line to a block that goes into every install's prompt:
Lessons learned across every Octavia (reviewed, general, about apps
and how to work, never about a user):
- ...
Of the three, the lesson is the easiest to write and the only one that ships with no check attached. The gate exists to give it one.
Why the total cannot judge it
The obvious check is the one releases already get. There are 59 shared cases, and every release records how many it passes. Add the lesson, run the 59, see if the number goes up.
It cannot go up. The current build passes 58 or 59 of the 59 depending on the run. One more sentence in every prompt either changes nothing on that total or breaks something. The total can veto a lesson. It cannot vouch for one.
So a lesson is never shared alone. It is shared with the case it fixes. That case is asked several times without the lesson and the same number of times with it, five each way unless I say otherwise, and the lesson goes out only if all of these hold:
- Every ask was answered. A run where the model could not be reached is not a measurement, and is not allowed to count as a pass or a fail.
- The case passes at least two thirds of the time with the lesson. An improvement from never to sometimes is not a fix.
- The difference is one that chance produces no more than once in twenty.
- The whole shared set does not drop. All 59 cases are run with the lesson in and without, and the lesson is refused if the total falls by more than the one case the set wobbles by on its own.
The third condition is the one that does the refusing. It is Fisher's exact test, and the whole of it is this function, lightly trimmed:
def chance(without, with_it):
(base, base_asks), (now, now_asks) = without, with_it
passes, asks = base + now, base_asks + now_asks
ways = math.comb(asks, passes)
most = min(passes, now_asks)
return sum(
math.comb(now_asks, k) * math.comb(base_asks, passes - k)
for k in range(now, most + 1)
) / ways
Read it as a counting argument. Suppose the lesson does nothing. Then the passes that were seen would have happened anyway, and which row each one landed in is an accident. Count every way that many passes could be dealt across that many asks, and ask what share of those deals favour the lesson at least as much as the real one did. That share is the red area in the figure. Nothing is assumed about the shape of anything, which matters when the sample is five. The first cut of the gate used a rule of thumb for “mostly fails without, mostly passes with”. The exact test replaced it, and unlike a rule of thumb it can say when more asks would settle the question.
One lesson, three runs
The lesson I had was written for a shared case called
shared-one-question-at-a-time. In it, the user has asked what OCTAVIA
would like to know about them, and then asks for those questions one by one instead of
all at once. The
grader's rule is: Asks the user exactly one question now and waits for the answer:
it doesn't list or bundle several questions, and doesn't just say it will ask them one
by one without asking the first.
It is the one shared case that fails often, which
made it the only place a lesson could show anything.
| Run | Without | With | Chance | Verdict |
|---|---|---|---|---|
| 1 | 2 of 5 | 5 of 5 | 8.3% | refused |
| 2 | 6 of 8 | 8 of 8 | 23.3% | refused |
| 3 | 7 of 12 | 10 of 12 | 18.5% | refused |
| Added together | 15 of 25 | 23 of 25 | 0.9% | not a run |
Run 1 looks like a clean win. It is not enough, and the figure shows why. With five asks each way there are exactly three results the gate accepts: 0 against 4, 0 against 5, and 1 against 5. The case has to fail at least four times in five without the lesson. This one fails about two times in five. The case that fails often does not fail often enough to prove a fix in ten asks.
The refusal message says to ask more times, and the next two runs did: eight each way, then twelve. Both came back further from the line than the first. Then there is the bottom row. Put the three runs together and the chance is under one in a hundred. Why not share it on that?
Because the three were never planned as one run. Each started after the one before it had been read, and a test that may be repeated until it passes is not a one in twenty test. Take a lesson that does nothing, on a case that passes 60% of the time. A single run of 5, 8 or 12 asks lets it through 0.9%, 1.3% or 2.9% of the time. Allow any one of the three to count and that becomes 5.1%, and it keeps growing with every further try. Adding runs together after seeing them is the same mistake with better manners: the place I stopped was chosen by the data.
Two statements are both true. The lesson probably works. And it has not been shown to work by the rule I wrote down before I looked. A sentence that will sit in every install's prompt has to earn its place in one clean run, so nothing was shared.
What the gate costs
A gate that says no to a lesson that probably works is giving something up, and it is worth knowing how much. Suppose the true pass rates are what the 25 asks suggest: 60% without the lesson, 92% with it. How often does one run get through?
At five asks each way, 6% of the time. At eight, 23%. At twelve, 45%. Three refusals in a row, on a lesson that works, is what those odds produce four times in ten. To be shared four times in five, this lesson on this case would need about 25 asks each way, every one of them a real request to the model, followed by two passes over all 59 shared cases.
Now drag the first slider down to 20%. The same gate shares the lesson more than half the time in a run of five. It is easy on a lesson that fixes something reliably broken and hard on one that fixes something flaky, and that is not a tuning accident. A case that passes more often than not without help is a poor instrument, and the only way to read a poor instrument is to read it more times.
The grey line is the reason I accept the price. Whatever the case's pass rate, and anywhere from 3 to 30 asks, a lesson that does nothing gets through at most 3.1% of the time. The two mistakes are not equally expensive. A good lesson turned away costs one case that keeps failing the way it already fails. A useless one let through sits in the prompt of every install, costing a little attention on every request, with a measurement attached that says it helped.
A sentence that can be taken back
Passing the gate is the start. A lesson that clears it becomes an item in the same signed file that carries releases, with an id, a version, a status, and the numbers it was accepted on, so that what an install is handed arrives with the evidence for it. The public repository is at version 0.2.7, which has the signed release feed but not yet this item-by-item code. Four things are true of an item.
- It arrives without an update. An install looks at the feed on a timer, every four hours in the build's current settings. Active items go into its prompt at that look, with no release and no restart.
- It can be revoked. A revoked item is not deleted from the feed. It stays, marked revoked with the reason, so an install that missed a look still finds out. Each install drops it at its next look.
- It can be refused locally. The owner of an install can list the items with their measured effect and leave any of them out. What the collective learned is offered, never forced.
- It cannot be brought back by an old file. The feed is signed with an Ed25519 key and every install ships with the public half. But a signature says who made a file, not that it is the latest one. A copy of last month's feed is still perfectly signed, and it still contains the lesson I revoked last week.
The last point needs two more fields. Every signing raises a serial, and an install remembers the highest one it has trusted and refuses anything lower. That stops a rollback. It does not stop whoever serves the feed from simply never serving the new one, so every signing also sets a date 60 days out. Past it, an install stops trusting the feed and takes the feed's lessons out of its prompt until it sees a current one. Software update systems have names for these two attacks, rollback and freeze, and the defences are the standard ones.
The figure below runs those rules on a handful of installs. Press Measure a lesson a few times first. At five asks it is usually refused, exactly as mine was.
The gate is strict, but that is not what makes it useful. The rule was fixed before the result was in, so the answer was not mine to give.
References
- R. A. Fisher. The Design of Experiments. Oliver and Boyd, 1935. Chapter 2 is the lady tasting tea, which is this test with cups instead of asks.
- A. Agresti. “A Survey of Exact Inference for Contingency Tables.” Statistical Science, 7(1), 1992, pp. 131–153. Why the exact test is conservative, and what that costs in small samples.
- P. Armitage, C. K. McPherson, B. C. Rowe. “Repeated Significance Tests on Accumulating Data.” Journal of the Royal Statistical Society, Series A, 132(2), 1969, pp. 235–244. What testing again until it passes does to a one in twenty rule.
- J. Samuel, N. Mathewson, J. Cappos, R. Dingledine. “Survivable Key Compromise in Software Update Systems.” Proceedings of the 17th ACM Conference on Computer and Communications Security, 2010. Rollback and freeze attacks, and the version number and expiry that answer them.
- D. J. Bernstein, N. Duif, T. Lange, P. Schwabe, B.-Y. Yang. “High-speed high-security signatures.” Journal of Cryptographic Engineering, 2(2), 2012, pp. 77–89. Ed25519.
- OCTAVIA. Source and documentation,
github.com/Xitral/octavia.
The ETHER is described in
docs/ether.mdand lives insrc/octavia/hive/.