Skip to content

feat(matching): measure how loud a model actually is, and record that the compiler only assumes - #604

Merged
athvin merged 1 commit into
mainfrom
bm/score-scale-measured
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/score-scale-measured

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

er-compile builds a model from a config with no training behind it, so it has to assume how much evidence a field at full agreement contributes: DEFAULT_FULL_AGREEMENT_BITS = 60.0.

That number is well earned. Its doc comment records the derivation, and measuring the committed person reference model reproduces it almost exactly — 59.883 bits.

But nothing could take the same measurement on a trained model, so nothing could tell a tenant whether 60 fits their corpus. TrainedModel::full_agreement_bits does: per field the strongest non-null level, resolved through the same level_m_u path the scorer uses, summed. It also yields the implied bits per field — how the model ranks its own evidence, measured rather than declared through weights.

Three corpora, one constant

model measured comparisons
person reference (model_test_v1) 59.883 bits 6
fake_1000 trained (model_final) 31.035 bits 5
account reference (acct_model_v1) 21.812 bits 4

The compiler assumes 60 for all three. compile_with never consults config.entity_type, and the only production entry point is compile, which passes CompileOptions::default() — so an account config is compiled roughly 2.7x louder than its own reference model, in the direction the constant's own doc comment calls the more expensive mistake:

louder is not safer. Over-weighting trades missed duplicates for false merges.

There was no account coverage anywhere in the compile tests, and no account config fixture.

Deliberately a measurement, not a re-tuning

The person number earned its value from two independent legs — the reference-model sum and a cluster-count grid search over base_10, where 20 bits found 18 clusters for 10 and 120 bits found 9. Only the first leg can be run for accounts today: there is no account config fixture and no account corpus with a known cluster count.

Setting the account default to 22 would swap one uncalibrated number for another and move every account tenant's scoring. So the gap is recorded with its evidence and left as a decision.

What ships

  • TrainReport.full_agreement_bits + bits_per_field, and scale_divergence(), which names the compiled assumption when the measured scale is more than 2x away either way. The factor comes from that same grid search rather than being invented: inside a factor of two nothing went wrong, and both observed failures were two to three times out.
  • The three surfaces the convergence report already uses: the train task's counters (full_agreement_bits, bits_per_field, assumed_scale_diverges), er train's summary — always, not only on divergence, so a drift over time is visible — and a stderr warning.
  • A Compiled.notes entry naming the scale it assumed, because the assumption is otherwise invisible in the artifact: the saved model carries m/u values with no trace of the number they came from, and two tenants' models look independent when both inherited one global default.
  • score_scale_calibration.rs, which pins the person derivation, the account gap as a bound rather than a point (so it needn't be re-tuned when the reference model is retrained), that each field's strongest level is its exact match — which is what makes this the same quantity the constant was calibrated from — and, by compiling one config twice with only entity_type changed, that the scale is entity-blind.

Verification

make check green from the repo root — 832 tests, 0 failures; entities current, skills-check ok.

The Rust measurement was cross-checked against an independent computation straight off the fixture JSON: 59.883 and 21.812 both ways. The scale_divergence test pins both directions and the quiet band, using the two real measurements as its cases (31.0 → quiet, 21.8 → reported), plus the 0.0 pre-measurement value, so a run that failed before training cannot fire the warning.

Builds on #596 (which predicts unmeasurable exact levels from the profile) and #598 (which reports which parameters training did not measure). full_agreement_bits resolves through defaults, so defaulted_levels is how you tell which of the total is measurement and which is assumption.

🤖 Generated with Claude Code

… the compiler only assumes

`er-compile` builds a model from a config with no training behind it, so it has
to assume how much evidence a field at full agreement contributes:
`DEFAULT_FULL_AGREEMENT_BITS = 60.0`. That number is well earned — its doc
comment records the derivation, and summing the committed PERSON reference
model's exact-level Bayes factors reproduces it to 59.883 bits.

Nothing could measure the same quantity on a trained model, so nothing could
tell a tenant whether 60 fits their corpus. `TrainedModel::full_agreement_bits`
does: per field the strongest non-null level, resolved through the same
`level_m_u` path the scorer uses, summed. It also gives the implied bits per
field, which is how the model ranks its own evidence — measured, rather than
declared through weights.

Three corpora, measured with it:

  person reference model (model_test_v1)   59.883 bits over 6 comparisons
  fake_1000 trained model (model_final)    31.035 bits over 5
  account reference model (acct_model_v1)  21.812 bits over 4

The compiler assumes 60 for all three. `compile_with` never consults
`config.entity_type`, and the only production entry point is `compile`, which
passes `CompileOptions::default()` — so an account config is compiled roughly
2.7x louder than its own reference model, in the direction the constant's own
doc comment calls the more expensive mistake: "louder is not safer.
Over-weighting trades missed duplicates for false merges." There was no account
coverage anywhere in the compile tests, and no account config fixture.

Deliberately a measurement and NOT a re-tuning. The person number earned its
value from two independent legs — the reference-model sum and a cluster-count
grid search over base_10, where 20 bits found 18 clusters for 10 and 120 bits
found 9 — and only the first leg can be run for accounts today: no account
config fixture, no account corpus with a known cluster count. Setting the
account default to 22 would swap one uncalibrated number for another and move
every account tenant's scoring. So the gap is recorded with evidence attached
and left as a decision.

What ships instead:

- `TrainReport.full_agreement_bits` + `bits_per_field`, and
  `scale_divergence()`, which reports the compiled assumption when the measured
  scale is more than 2x away either way. The factor is taken from that same
  grid search rather than invented: inside a factor of two nothing went wrong,
  and both observed failures were two to three times out.
- the three surfaces the convergence report already uses — the train task's
  counters, `er train`'s summary (always, not only on divergence, so a drift
  over time is visible), and a stderr warning
- a `Compiled.notes` entry naming the scale it assumed, because the assumption
  is otherwise invisible: the saved model carries m/u values with no trace of
  the number they came from, and two tenants' models look independent when both
  inherited one global default
- `score_scale_calibration.rs`, which pins the person derivation, the account
  gap as a bound rather than a point, and — by compiling one config twice with
  only `entity_type` changed — that the scale is entity-blind

The Rust measurement was cross-checked against an independent computation
straight off the fixture JSON: 59.883 and 21.812 both ways.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 6642fa6 into main Nov 5, 2026
39 checks passed
@athvin
athvin deleted the bm/score-scale-measured branch November 5, 2026 18:57
athvin added a commit that referenced this pull request Nov 6, 2026
…ibration is now a gate (#623)

Two halves of the same gap, both about the constant every compiled model's m/u
values derive from.

**1. The scale was global in practice, however corpus-dependent it said it was.**

`CompileOptions`' own doc comment says the two knobs "are options rather than
constants because the right scale depends on how dirty the corpus is", and
`compile_with` exists so a caller can supply them. Nothing in production ever
called it: `compile` passed `CompileOptions::default()` unconditionally, so
every tenant inherited a number calibrated on the committed PERSON reference
model — which measures 59.9 bits, against the committed ACCOUNT model's 21.8.

`thresholds.full_agreement_bits` and `thresholds.disagreement_ratio` are now
optional config fields, and `compile` reads them. This is the third step of
measure -> report -> act: #604 measured what a corpus supports
(`TrainReport::full_agreement_bits`) and reported it; this is where that
measurement can be used.

Beside `thresholds` rather than in a block of its own, because a threshold is
meaningless without the scale it is measured on — `auto_merge: 20` means "most
of the evidence" at a 22-bit scale and "a third of it" at 60. It also keeps
`CONFIG_BLOCKS` untouched.

Absent means today's default, and `skip_serializing_if` is load-bearing for the
reason `entity_type`, `approval` and `models` each carry it: the canonical
document feeds `config_hash`, so an absent value serialises to nothing and
every existing tenant's hash — and every committed golden — stays
byte-identical. Asserted directly, both ways: absent does not appear in the
canonical document, declared does move the hash, and each half moves it
independently.

A declared scale is bounds-checked and refused rather than clamped, as
`CompileError::ScaleOutOfRange`, next to the `WeightOutOfRange` precedent and
surfacing through the publish handler that already compiles. Both failure modes
are silent in the OUTPUT, which is why refusal is right: at zero bits no pair
accumulates enough evidence and the run reports "no duplicates" rather than a
miscalibration, and at a negative value agreement becomes evidence AGAINST a
match so the model works backwards while still producing scores that look like
scores. The boundary values that are extreme but meaningful still compile.

`Compiled.notes` now says whether the scale was declared or inherited, because
a reader of a compiled model otherwise cannot tell a deliberate scale from a
default, and those warrant different amounts of trust.

**2. The calibration was prose. Now it is a gate.**

`DEFAULT_FULL_AGREEMENT_BITS`' comment records the experiment behind it: "at 20
bits the compiled model finds 18 clusters where there are 10 ... and at 120
bits it finds 9 ... 55-60 bits reproduces the committed membership exactly."

No committed test reproduced any of it. The experiment was run once by hand and
written into prose, so the number every compiled model depends on was protected
by nothing — changing it to 120 "to be safe" would have passed every gate while
silently merging distinct people, the failure the comment itself calls the more
expensive one.

Now that `compile` reads the config, the grid is three ordinary resolves, and it
reproduces the comment EXACTLY:

    truth = 10    default(60) = 10    quiet(20) = 18    loud(120) = 9

The exact counts are pinned rather than the direction, because those are the
numbers the comment states and this test exists to be their gate; a failure
means the calibrating evidence moved and the comment needs the new measurement,
not that the assertion needs loosening. ~60s in the DuckLake tier, which is the
right price for the only evidence behind the scale.

This is also the harness the account question needs. Answering it still needs an
account corpus with a known entity count — `acct_base` has 7 records and 4
entities but no `truth.csv` and no traps, where `base_10` has both — so the
account scale stays recorded rather than re-tuned.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants