@mailwoman/registry 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +10 -10
  2. package/lib/address-key.ts +14 -10
  3. package/lib/geocode-handler.ts +6 -4
  4. package/lib/geojson.ts +11 -6
  5. package/lib/ingest.ts +57 -83
  6. package/lib/learned-scorer.ts +38 -44
  7. package/lib/map-html.ts +24 -70
  8. package/lib/models/crosssource-gbt-en-us.ts +9 -7
  9. package/lib/models/dedup-gbt-en-us.ts +9 -8
  10. package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
  11. package/lib/reconcile.ts +43 -53
  12. package/lib/resolve.ts +180 -124
  13. package/lib/types.ts +18 -12
  14. package/out/address-key.d.ts +14 -10
  15. package/out/address-key.d.ts.map +1 -1
  16. package/out/address-key.js +14 -10
  17. package/out/address-key.js.map +1 -1
  18. package/out/geocode-handler.d.ts +6 -4
  19. package/out/geocode-handler.d.ts.map +1 -1
  20. package/out/geocode-handler.js +6 -4
  21. package/out/geocode-handler.js.map +1 -1
  22. package/out/geojson.d.ts +9 -5
  23. package/out/geojson.d.ts.map +1 -1
  24. package/out/geojson.js +11 -6
  25. package/out/geojson.js.map +1 -1
  26. package/out/ingest.d.ts +46 -75
  27. package/out/ingest.d.ts.map +1 -1
  28. package/out/ingest.js +27 -54
  29. package/out/ingest.js.map +1 -1
  30. package/out/learned-scorer.d.ts +29 -26
  31. package/out/learned-scorer.d.ts.map +1 -1
  32. package/out/learned-scorer.js +31 -39
  33. package/out/learned-scorer.js.map +1 -1
  34. package/out/map-html.d.ts +13 -32
  35. package/out/map-html.d.ts.map +1 -1
  36. package/out/map-html.js +9 -62
  37. package/out/map-html.js.map +1 -1
  38. package/out/models/crosssource-gbt-en-us.d.ts +9 -7
  39. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
  40. package/out/models/crosssource-gbt-en-us.js +9 -7
  41. package/out/models/crosssource-gbt-en-us.js.map +1 -1
  42. package/out/models/dedup-gbt-en-us.d.ts +9 -8
  43. package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
  44. package/out/models/dedup-gbt-en-us.js +9 -8
  45. package/out/models/dedup-gbt-en-us.js.map +1 -1
  46. package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
  47. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
  48. package/out/models/org-crosssource-gbt-en-us.js +10 -8
  49. package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
  50. package/out/reconcile.d.ts +35 -50
  51. package/out/reconcile.d.ts.map +1 -1
  52. package/out/reconcile.js +17 -41
  53. package/out/reconcile.js.map +1 -1
  54. package/out/resolve.d.ts +150 -90
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +62 -63
  57. package/out/resolve.js.map +1 -1
  58. package/out/tools/coverage-reconciliation.d.ts +23 -23
  59. package/out/tools/coverage-reconciliation.d.ts.map +1 -1
  60. package/out/tools/coverage-reconciliation.js +15 -26
  61. package/out/tools/coverage-reconciliation.js.map +1 -1
  62. package/out/tools/cross/dataset-correlation.d.ts +20 -27
  63. package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
  64. package/out/tools/cross/dataset-correlation.js +9 -61
  65. package/out/tools/cross/dataset-correlation.js.map +1 -1
  66. package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
  67. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
  68. package/out/tools/cross/source-threshold-sweep.js +14 -40
  69. package/out/tools/cross/source-threshold-sweep.js.map +1 -1
  70. package/out/tools/dedup-ceiling.d.ts +23 -26
  71. package/out/tools/dedup-ceiling.d.ts.map +1 -1
  72. package/out/tools/dedup-ceiling.js +22 -41
  73. package/out/tools/dedup-ceiling.js.map +1 -1
  74. package/out/tools/eval-geocoder.d.ts +22 -15
  75. package/out/tools/eval-geocoder.d.ts.map +1 -1
  76. package/out/tools/eval-geocoder.js +5 -6
  77. package/out/tools/eval-geocoder.js.map +1 -1
  78. package/out/tools/geocoder/namesake-probe.d.ts +9 -8
  79. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
  80. package/out/tools/geocoder/namesake-probe.js +6 -7
  81. package/out/tools/geocoder/namesake-probe.js.map +1 -1
  82. package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
  83. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
  84. package/out/tools/geocoder/vs-provided-coords.js +30 -27
  85. package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
  86. package/out/tools/gold-set-sample.d.ts +27 -18
  87. package/out/tools/gold-set-sample.d.ts.map +1 -1
  88. package/out/tools/gold-set-sample.js +18 -22
  89. package/out/tools/gold-set-sample.js.map +1 -1
  90. package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
  91. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
  92. package/out/tools/learned/scorer/clustering-eval.js +28 -38
  93. package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
  94. package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
  95. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
  96. package/out/tools/learned/scorer/crossstate-eval.js +19 -25
  97. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
  98. package/out/tools/learned/scorer/eval.d.ts +22 -39
  99. package/out/tools/learned/scorer/eval.d.ts.map +1 -1
  100. package/out/tools/learned/scorer/eval.js +11 -71
  101. package/out/tools/learned/scorer/eval.js.map +1 -1
  102. package/out/tools/matcher-scale.d.ts +12 -17
  103. package/out/tools/matcher-scale.d.ts.map +1 -1
  104. package/out/tools/matcher-scale.js +11 -29
  105. package/out/tools/matcher-scale.js.map +1 -1
  106. package/out/tools/nppes/dedup-benchmark.d.ts +21 -41
  107. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
  108. package/out/tools/nppes/dedup-benchmark.js +20 -66
  109. package/out/tools/nppes/dedup-benchmark.js.map +1 -1
  110. package/out/tools/nppes/org-name.d.ts +5 -4
  111. package/out/tools/nppes/org-name.d.ts.map +1 -1
  112. package/out/tools/nppes/org-name.js +2 -2
  113. package/out/tools/nppes/org-name.js.map +1 -1
  114. package/out/tools/nppes/overmerge-packet.d.ts +15 -11
  115. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
  116. package/out/tools/nppes/overmerge-packet.js +5 -6
  117. package/out/tools/nppes/overmerge-packet.js.map +1 -1
  118. package/out/tools/nppes/report.d.ts +17 -13
  119. package/out/tools/nppes/report.d.ts.map +1 -1
  120. package/out/tools/nppes/report.js +6 -14
  121. package/out/tools/nppes/report.js.map +1 -1
  122. package/out/tools/nppes/sample.d.ts +28 -17
  123. package/out/tools/nppes/sample.d.ts.map +1 -1
  124. package/out/tools/nppes/sample.js +23 -26
  125. package/out/tools/nppes/sample.js.map +1 -1
  126. package/out/tools/nppes/scoring.d.ts +7 -6
  127. package/out/tools/nppes/scoring.d.ts.map +1 -1
  128. package/out/tools/nppes/scoring.js +6 -5
  129. package/out/tools/nppes/scoring.js.map +1 -1
  130. package/out/tools/nppes/settings.d.ts +10 -7
  131. package/out/tools/nppes/settings.d.ts.map +1 -1
  132. package/out/tools/nppes/settings.js +16 -16
  133. package/out/tools/nppes/settings.js.map +1 -1
  134. package/out/tools/nppes/truth-grains.d.ts +36 -23
  135. package/out/tools/nppes/truth-grains.d.ts.map +1 -1
  136. package/out/tools/nppes/truth-grains.js +36 -20
  137. package/out/tools/nppes/truth-grains.js.map +1 -1
  138. package/out/tools/shared.d.ts +63 -59
  139. package/out/tools/shared.d.ts.map +1 -1
  140. package/out/tools/shared.js +49 -66
  141. package/out/tools/shared.js.map +1 -1
  142. package/out/tools/train/cross-gbt.d.ts +36 -26
  143. package/out/tools/train/cross-gbt.d.ts.map +1 -1
  144. package/out/tools/train/cross-gbt.js +14 -25
  145. package/out/tools/train/cross-gbt.js.map +1 -1
  146. package/out/tools/train/gbt.d.ts +36 -20
  147. package/out/tools/train/gbt.d.ts.map +1 -1
  148. package/out/tools/train/gbt.js +27 -31
  149. package/out/tools/train/gbt.js.map +1 -1
  150. package/out/tools/train/org-cross-gbt.d.ts +37 -24
  151. package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
  152. package/out/tools/train/org-cross-gbt.js +18 -22
  153. package/out/tools/train/org-cross-gbt.js.map +1 -1
  154. package/out/tools/txhhsc-to-oarow.d.ts +14 -9
  155. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
  156. package/out/tools/txhhsc-to-oarow.js +16 -15
  157. package/out/tools/txhhsc-to-oarow.js.map +1 -1
  158. package/out/tools/viz/browser.d.ts +6 -5
  159. package/out/tools/viz/browser.d.ts.map +1 -1
  160. package/out/tools/viz/browser.js +6 -5
  161. package/out/tools/viz/browser.js.map +1 -1
  162. package/out/tools/viz/cross-dataset-map.d.ts +7 -4
  163. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
  164. package/out/tools/viz/cross-dataset-map.js +9 -6
  165. package/out/tools/viz/cross-dataset-map.js.map +1 -1
  166. package/out/tools/viz/geocode-first-surface.d.ts +10 -5
  167. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
  168. package/out/tools/viz/geocode-first-surface.js +16 -11
  169. package/out/tools/viz/geocode-first-surface.js.map +1 -1
  170. package/out/tools/viz/render/map.d.ts +5 -5
  171. package/out/tools/viz/render/map.d.ts.map +1 -1
  172. package/out/tools/viz/render/map.js +6 -5
  173. package/out/tools/viz/render/map.js.map +1 -1
  174. package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
  175. package/out/tools/viz/render.d.ts.map +1 -0
  176. package/out/tools/viz/{render/index.js → render.js} +9 -8
  177. package/out/tools/viz/render.js.map +1 -0
  178. package/out/tools/viz/source-provenance-map.d.ts +19 -7
  179. package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
  180. package/out/tools/viz/source-provenance-map.js +11 -8
  181. package/out/tools/viz/source-provenance-map.js.map +1 -1
  182. package/out/tools/viz/yardstick-figure.d.ts +2 -21
  183. package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
  184. package/out/tools/viz/yardstick-figure.js +3 -39
  185. package/out/tools/viz/yardstick-figure.js.map +1 -1
  186. package/out/types.d.ts +17 -11
  187. package/out/types.d.ts.map +1 -1
  188. package/out/types.js +2 -2
  189. package/out/types.js.map +1 -1
  190. package/package.json +41 -184
  191. package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
  192. package/{lib/tools → tools}/cross/dataset-correlation.ts +31 -72
  193. package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
  194. package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
  195. package/tools/eval-geocoder.ts +74 -0
  196. package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
  197. package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +39 -30
  198. package/{lib/tools → tools}/gold-set-sample.ts +35 -29
  199. package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
  200. package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
  201. package/{lib/tools → tools}/learned/scorer/eval.ts +35 -78
  202. package/{lib/tools → tools}/matcher-scale.ts +21 -33
  203. package/{lib/tools → tools}/nppes/dedup-benchmark.ts +37 -82
  204. package/{lib/tools → tools}/nppes/org-name.ts +5 -4
  205. package/{lib/tools → tools}/nppes/overmerge-packet.ts +15 -11
  206. package/{lib/tools → tools}/nppes/report.ts +32 -25
  207. package/{lib/tools → tools}/nppes/sample.ts +41 -36
  208. package/{lib/tools → tools}/nppes/scoring.ts +7 -6
  209. package/{lib/tools → tools}/nppes/settings.ts +16 -16
  210. package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
  211. package/{lib/tools → tools}/shared.ts +73 -83
  212. package/{lib/tools → tools}/train/cross-gbt.ts +38 -34
  213. package/{lib/tools → tools}/train/gbt.ts +55 -41
  214. package/{lib/tools → tools}/train/org-cross-gbt.ts +39 -30
  215. package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
  216. package/{lib/tools → tools}/viz/browser.ts +6 -5
  217. package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
  218. package/{lib/tools → tools}/viz/geocode-first-surface.ts +28 -17
  219. package/{lib/tools → tools}/viz/render/map.ts +7 -6
  220. package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
  221. package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
  222. package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
  223. package/lib/tools/eval-geocoder.ts +0 -67
  224. package/lib/tools/index.ts +0 -31
  225. package/out/tools/index.d.ts +0 -31
  226. package/out/tools/index.d.ts.map +0 -1
  227. package/out/tools/index.js +0 -31
  228. package/out/tools/index.js.map +0 -1
  229. package/out/tools/viz/render/index.d.ts.map +0 -1
  230. package/out/tools/viz/render/index.js.map +0 -1
@@ -2,37 +2,6 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * Learned-scorer probe (#603) — does a model over the Fellegi-Sunter feature vector separate
7
- * matches from non-matches BETTER than the FS scorer itself? This is the honest, rigorous answer
8
- * to "is the learned-scorer path worth it?" before investing in a full GBM/training pipeline.
9
- *
10
- * The over-merge (co-located distinct providers fused; co-located same-entity name-drift split) is
11
- * a FIELD-INTERACTION effect FS can't express: it scores each field independently. A learned
12
- * model with INTERACTION features (spatial-agreement × name-disagreement) can. We test that
13
- * directly, with a clean methodology — no clustering confound, no leakage:
14
- *
15
- * 1. Generate the same NPI-keyed records as the dedup benchmark (real registry + name-drift +
16
- * address-variation), geocoded.
17
- * 2. Block → candidate pairs. For each: the FS agreement pattern + engineered interaction features;
18
- * the label is same-NPI.
19
- * 3. Split the NPIs into train / test. A pair is train iff BOTH endpoints are train-NPIs, test iff
20
- * both test-NPIs — so no NPI's records leak across the split.
21
- * 4. Train TWO learned scorers on the train pairs: an L2 logistic regression (linear) and
22
- * gradient-boosted shallow trees (non-linear — the model #603 names). Both pure-Node.
23
- * 5. Score the test pairs with (a) the EM-fitted FS scorer, (b) the LR, (c) the GBT. Report pairwise
24
- * ROC-AUC + best-threshold F1 for each, averaged over N seeds. AUC is threshold-free: does
25
- * the learned scorer RANK matches above non-matches better than FS — and does the TREE beat
26
- * the LINEAR model (i.e. is there non-linear signal the hand-crafted interaction features
27
- * miss)?
28
- *
29
- * Honest caveats are printed: in-domain (TX), a modest sample, PAIRWISE (not the clustering
30
- * metric). The definitive test is a GBM A/B on the dedup clustering metric with a
31
- * train-TX/eval-held-out-state split (#603 Tier 2); this probe bounds the pairwise-ranking gain
32
- * cheaply first.
33
- *
34
- * Run: `mailwoman registry scorer-eval pairwise [--npis 1500] [--seeds 8] [--wof <admin.db>]
35
- * [--data-root <dir>] [--seed 1] [--out-md <md>]`
36
5
  */
37
6
 
38
7
  import { dataRootPath } from "@mailwoman/core/data-root"
@@ -45,29 +14,15 @@ import { buildDefaultModel, createMatchFeaturizer, defaultBlockingKeys, ingestRo
45
14
  import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
46
15
  import { buildNPPESSample } from "#tools/nppes/sample"
47
16
  import { pct, sgn, stateOption, std, trainLogisticRegression } from "#tools/shared"
48
- /**
49
- * Smallest mean gap counted as a real difference rather than seed noise.
50
- */
17
+
51
18
  const MIN_MEANINGFUL_DELTA = 0.005
52
19
 
53
- /**
54
- * Mean gap at which a win is called outright rather than leaning.
55
- */
56
20
  const CLEAR_WIN_DELTA = 0.01
57
21
 
58
- /**
59
- * F1 gap at which a win is called outright.
60
- */
61
22
  const CLEAR_WIN_F1_DELTA = 0.02
62
23
 
63
- /**
64
- * Z at or above which the difference is treated as strong evidence rather than suggestive.
65
- */
66
24
  const STRONG_EVIDENCE_Z = 3
67
25
 
68
- /**
69
- * Share of NPIs assigned to train; the rest are held out for test.
70
- */
71
26
  const TRAIN_SPLIT_FRACTION = 0.67
72
27
 
73
28
  /**
@@ -75,37 +30,57 @@ const TRAIN_SPLIT_FRACTION = 0.67
75
30
  */
76
31
  export interface ScorerPairwiseEvalOptions {
77
32
  /**
78
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`).
33
+ * Creates the geocoder that places each sampled record's address.
79
34
  */
80
35
  createGeocoder: EvalGeocoderFactory
36
+
81
37
  /**
82
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
38
+ * The record-matcher sources directory.
39
+ *
40
+ * It defaults to `record-matcher/sources` under the data root.
83
41
  */
84
42
  sources?: string
43
+
85
44
  /**
86
- * State filter. Default TX.
45
+ * The state to sample providers from.
46
+ * It defaults to `TX`.
87
47
  */
88
48
  state?: string
49
+
89
50
  /**
90
- * NPIs sampled. Default 1500.
51
+ * The number of NPIs to sample.
52
+ * It defaults to 1500.
91
53
  */
92
54
  npis?: number
55
+
93
56
  /**
94
- * Base PRNG seed. Default 1.
57
+ * The base PRNG seed.
58
+ *
59
+ * It defaults to 1.
60
+ * Each split adds its index to that value.
95
61
  */
96
62
  seed?: number
63
+
97
64
  /**
98
- * Train/test splits averaged. Default 8.
65
+ * The number of train/test splits to average over.
66
+ * It defaults to 8.
99
67
  */
100
68
  seeds?: number
69
+
101
70
  /**
102
- * Also write the markdown report here.
71
+ * An optional path for the Markdown report.
103
72
  */
104
73
  outMd?: string
105
74
  }
106
75
 
107
76
  /**
108
- * Learned-scorer pairwise probe (#603) — see the module doc. Emits the markdown report to stdout.
77
+ * Compares Fellegi-Sunter, logistic-regression and gradient-boosted-tree pair scorers on an NPPES sample.
78
+ *
79
+ * A pair is a match when both records share an NPI.
80
+ * The function averages ROC-AUC and best F1 over several train/test splits.
81
+ *
82
+ * It prints and returns the Markdown report.
83
+ * It also writes the report to `outMd` when that option is set.
109
84
  */
110
85
  export async function scorerPairwiseEval(
111
86
  options: ScorerPairwiseEvalOptions,
@@ -120,7 +95,6 @@ export async function scorerPairwiseEval(
120
95
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
121
96
  const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
122
97
 
123
- // Build the same NPI-keyed sample used by the dedup benchmark.
124
98
  const { rows, keptNpis, addressFrequency } = await buildNPPESSample(
125
99
  { registryPath: REGISTRY, otherNamesPath: OTHER_NAMES, state: STATE, maxNpis: NPIS },
126
100
  report
@@ -129,8 +103,6 @@ export async function scorerPairwiseEval(
129
103
  report?.("[C] geocoding…")
130
104
  const geocoder = await options.createGeocoder()
131
105
 
132
- // `auth`/`taxonomy` ride as attributes so the SHARED featurizer's #625 roll-up features can read the
133
- // authorized official; the FS arm ignores them (no discriminators configured).
134
106
  const mapping: ColumnMapping = {
135
107
  id: "npi",
136
108
  name: "name",
@@ -146,15 +118,12 @@ export async function scorerPairwiseEval(
146
118
 
147
119
  geocoder[Symbol.dispose]()
148
120
 
149
- // Block records and extract the collapsed-spatial and address-frequency features.
150
- // comparisons; EM-fit it for the FS baseline. ---
151
121
  report?.("[D] blocking + features…")
152
122
  const model = buildDefaultModel({ collapseSpatial: true, addressFrequency })
153
123
  const { pairs } = block(records, defaultBlockingKeys())
154
124
  const patterns = pairs.map(([a, b]) => agreementPattern(model.comparisons, a, b))
155
125
  const fsModel = estimateParameters(model, patterns).model
156
126
 
157
- // The SHARED production featurizer (createMatchFeaturizer) — train ≡ eval ≡ inference, one definition.
158
127
  const featurize = createMatchFeaturizer({ comparisons: model.comparisons, addressFrequency })
159
128
 
160
129
  interface Sample {
@@ -177,11 +146,6 @@ export async function scorerPairwiseEval(
177
146
  gbtScored: Scored[]
178
147
  }
179
148
 
180
- /**
181
- * One train/test split (by NPI): train the L2 logistic regression on the train pairs, then score the held-out test
182
- * pairs with both the LR and the EM-fitted FS scorer. The FS model is seed-independent (fit unsupervised on ALL
183
- * pairs); only the LR weights and the test subset move with the seed, so repeating over seeds bounds split variance.
184
- */
185
149
  function runSplit(seed: number): SplitScored {
186
150
  const rnd = makeLcg(seed || 1)
187
151
  const npiSplit = new Map<string, "train" | "test">()
@@ -199,7 +163,6 @@ export async function scorerPairwiseEval(
199
163
 
200
164
  if (!sa || sa !== sb) return
201
165
 
202
- // cross-split or unknown → drop (no leakage)
203
166
  const sample: Sample = {
204
167
  x: featurize(a, b),
205
168
  y: a.id === b.id ? 1 : 0,
@@ -212,8 +175,6 @@ export async function scorerPairwiseEval(
212
175
  const posWeight = train.filter((s) => s.y === 1).length / Math.max(1, train.length)
213
176
  const sampleWeights = train.map((s) => (s.y === 1 ? 1 - posWeight : posWeight))
214
177
 
215
- // L2-regularized logistic regression (batch gradient descent), rare class up-weighted — the
216
- // SHARED trainer.
217
178
  const lrScore = trainLogisticRegression(
218
179
  train.map((s) => s.x),
219
180
  train.map((s) => s.y),
@@ -221,7 +182,6 @@ export async function scorerPairwiseEval(
221
182
  dim
222
183
  )
223
184
 
224
- // Gradient-boosted trees on the SAME train pairs + class weights — the non-linear arm.
225
185
  const gbt = trainGBT(
226
186
  train.map((s) => s.x),
227
187
  train.map((s) => s.y),
@@ -239,13 +199,12 @@ export async function scorerPairwiseEval(
239
199
  }
240
200
  }
241
201
 
242
- // Evaluate LR and FS on held-out pairs with ROC-AUC and best-threshold F1.
243
202
  function auc(scored: Array<{ s: number; y: number }>): number {
244
203
  const pos = scored.filter((d) => d.y === 1)
245
204
  const neg = scored.filter((d) => d.y === 0)
246
205
 
247
206
  if (!pos.length || !neg.length) return Number.NaN
248
- // Mann-Whitney U via rank.
207
+
249
208
  const sorted = [...scored].toSorted((p, q) => p.s - q.s)
250
209
  let rank = 1
251
210
  let rankSum = 0
@@ -315,11 +274,11 @@ export async function scorerPairwiseEval(
315
274
  const meanDelta = mean(deltas)!
316
275
  const avgTestN = mean(splits.map((r) => r.testN))!
317
276
  const avgTestPos = mean(splits.map((r) => r.lrScored.filter((d) => d.y === 1).length))!
318
- const seMean = std(deltas) / Math.sqrt(SEEDS) // standard error of the mean ΔAUC
319
- const zScore = seMean > 0 ? meanDelta / seMean : 0 // ΔAUC in standard errors above zero
320
- const f1Delta = mean(lrF1s)! - mean(fsF1s)! // operating-point F1 gain (LR − FS)
277
+ const seMean = std(deltas) / Math.sqrt(SEEDS)
278
+ const zScore = seMean > 0 ? meanDelta / seMean : 0
279
+ const f1Delta = mean(lrF1s)! - mean(fsF1s)!
321
280
  const unanimous = lrWins === SEEDS
322
- // GBT (non-linear) arm.
281
+
323
282
  const gbtAucs = splits.map((r) => auc(r.gbtScored))
324
283
  const gbtF1s = splits.map((r) => bestF1(r.gbtScored).f1)
325
284
  const gbtVsFs = splits.map((_, i) => gbtAucs[i]! - fsAucs[i]!)
@@ -329,7 +288,6 @@ export async function scorerPairwiseEval(
329
288
  const meanGbtVsLr = mean(gbtVsLr)!
330
289
  const f1DeltaGbt = mean(gbtF1s)! - mean(fsF1s)!
331
290
 
332
- // operating-point F1 gain (GBT − FS)
333
291
  for (const r of splits) {
334
292
  const dl = auc(r.lrScored) - auc(r.fsScored)
335
293
  const dg = auc(r.gbtScored) - auc(r.fsScored)
@@ -372,14 +330,13 @@ export async function scorerPairwiseEval(
372
330
  `**ΔAUC (LR − FS): ${sgn(meanDelta)}${f4(meanDelta)} ± ${f4(std(deltas))}, LR > FS in ${lrWins}/${SEEDS} seeds.**`,
373
331
  "",
374
332
  `Robustness: the ΔAUC is small but **consistent** — std ${f4(std(deltas))} across seeds, SE ±${f4(seMean)} → ` +
375
- `≈${zScore.toFixed(1)}σ above zero, ${lrWins}/${SEEDS} seeds in LR's favour. At the operating point the gap is ` +
333
+ `≈${zScore.toFixed(1)}σ above zero, ${lrWins}/${SEEDS} seeds in LR's favor. At the operating point the gap is ` +
376
334
  `larger: **ΔF1 ${sgn(f1Delta * 100)}${(f1Delta * 100).toFixed(1)}pp** (${pct(mean(fsF1s)!)}% → ${pct(mean(lrF1s)!)}%), ` +
377
335
  `because the interaction features sharpen the hard co-located band near the decision boundary even where overall ` +
378
336
  `ranking barely moves.`,
379
337
  "",
380
338
  ]
381
339
 
382
- // Linear vs tree: does a non-linear model extract MORE than the LR? (The probe's open question.)
383
340
  const treeVerdict =
384
341
  meanGbtVsLr > MIN_MEANINGFUL_DELTA && gbtBeatsLr >= SEEDS - 1
385
342
  ? `**The tree extends the linear gain** — GBT beats the LR by ΔAUC ${sgn(meanGbtVsLr)}${f4(meanGbtVsLr)} ` +
@@ -2,18 +2,6 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * Pure-Node matcher scale eval — the number behind "no Elasticsearch, no server."
7
- *
8
- * The differentiator vs Pelias/Nominatim + a bolt-on ER stack is that the whole resolve (block →
9
- * Fellegi-Sunter → cluster) runs in ONE Node process with no external service. This measures how
10
- * far that goes: synthetic geo-clustered records (so geo-blocking produces realistic candidate
11
- * pairs, not one giant block or all singletons), resolved at increasing N, timing wall-clock +
12
- * peak RSS. Geocoding is NOT in scope here (it's the per-record cost measured elsewhere) — this
13
- * isolates the matcher's block/score/cluster cost as a function of N.
14
- *
15
- * Run: `mailwoman registry matcher-scale [--sizes 10000,50000,100000,250000,500000] [--dup 3]
16
- * [--em] [--out-md <md>]`
17
5
  */
18
6
 
19
7
  import { writeLocalFile } from "@mailwoman/core/fs/writers"
@@ -26,29 +14,29 @@ import { resolveEntities, type SourceRecord } from "#index"
26
14
  */
27
15
  export interface MatcherScaleOptions {
28
16
  /**
29
- * Record counts to sweep. Default `[10000, 50000, 100000, 250000, 500000]`.
17
+ * Lists the record counts to measure, defaulting to 10,000, 50,000, 100,000, 250,000 and 500,000.
30
18
  */
31
19
  sizes?: number[]
20
+
32
21
  /**
33
- * Average records per distinct place. Default 3.
22
+ * Sets the average number of records per distinct synthetic place, defaulting to 3.
34
23
  */
35
24
  dup?: number
25
+
36
26
  /**
37
- * Fit the FS m/u with EM per size (slower). Default false.
27
+ * Fits the Fellegi-Sunter m and u probabilities with EM at each size.
28
+ *
29
+ * This is slower.
30
+ * The option defaults to `false`.
38
31
  */
39
32
  em?: boolean
33
+
40
34
  /**
41
- * Also write the markdown report here.
35
+ * Gives a path where the Markdown report is also written.
42
36
  */
43
37
  outMd?: string
44
38
  }
45
39
 
46
- /**
47
- * Generate N synthetic records clustered into ~N/DUP distinct "places". Each place gets a coordinate in the
48
- * continental-US box, a canonical key, and an org name; its DUP duplicates carry a lightly-varied name and a jittered
49
- * coordinate, so geo-cell + canonical-key blocking groups them and scoring links them — the realistic shape of a dedup
50
- * workload.
51
- */
52
40
  function generate(n: number, dup: number, seed = 1): SourceRecord[] {
53
41
  const rnd = makeLcg(seed || 1)
54
42
  const places = Math.max(1, Math.round(n / dup))
@@ -56,11 +44,10 @@ function generate(n: number, dup: number, seed = 1): SourceRecord[] {
56
44
 
57
45
  for (let i = 0; i < n; i++) {
58
46
  const place = i % places
59
- const latitude = 25 + rnd() * 24 // ~25–49 N
60
- const longitude = -124 + rnd() * 57 // ~-124 to -67 W
47
+ const latitude = 25 + rnd() * 24
48
+ const longitude = -124 + rnd() * 57
61
49
  const variant = i < places ? "" : rnd() < 0.5 ? " llc" : " inc"
62
50
 
63
- // duplicates drift the name slightly
64
51
  records[i] = {
65
52
  id: String(i),
66
53
  organization: { canonical: `org ${place}${variant}`, raw: `Org ${place}` },
@@ -84,14 +71,18 @@ const mb = (bytes: number) => `${(bytes / 1024 / 1024).toFixed(0)} MB`
84
71
  const sec = (ms: number) => `${(ms / 1000).toFixed(2)} s`
85
72
 
86
73
  /**
87
- * Pure-Node matcher scale eval — see the module doc. Emits the markdown report to stdout.
74
+ * Measures entity-resolution time, candidate pairs and memory on synthetic records
75
+ * of increasing size, all in one Node process.
76
+ *
77
+ * The function prints the Markdown report to stdout and returns it.
78
+ * It also writes to `outMd` when set.
88
79
  */
89
80
  export async function matcherScale(
90
81
  options: MatcherScaleOptions = {},
91
82
  report?: (line: string) => void
92
83
  ): Promise<{ markdown: string }> {
93
84
  const SIZES = options.sizes?.length ? options.sizes : [10_000, 50_000, 100_000, 250_000, 500_000]
94
- const DUP = options.dup ?? 3 // avg records per distinct place
85
+ const DUP = options.dup ?? 3
95
86
  const EM = options.em ?? false
96
87
  const OUT_MD = options.outMd || ""
97
88
 
@@ -110,8 +101,6 @@ export async function matcherScale(
110
101
  const records = generate(n, DUP)
111
102
  const t0 = performance.now()
112
103
 
113
- // learnedScorer:false — this measures the FS-baseline pipeline throughput baseline (the learned scorer
114
- // is now default-on; its per-pair tree eval is a separate cost, not what this scale number tracks).
115
104
  const { entities, candidatePairs } = resolveEntities(records, {
116
105
  collapseSpatial: true,
117
106
  trainEM: EM,
@@ -123,7 +112,6 @@ export async function matcherScale(
123
112
  rows.push({ n, records: records.length, entities: entities.length, candidatePairs, wallMs, rssBytes })
124
113
  report?.(` N=${n}: ${sec(wallMs)}, ${candidatePairs} pairs → ${entities.length} entities, RSS ${mb(rssBytes)}`)
125
114
 
126
- // Encourage reclamation between sizes (RSS is a shared-process high-water — see the report note).
127
115
  if (globalThis.gc) {
128
116
  globalThis.gc()
129
117
  }
@@ -133,8 +121,8 @@ export async function matcherScale(
133
121
  `# Matcher scale — pure-Node block → score → cluster (#K)`,
134
122
  "",
135
123
  `_Generated by \`registry/tools/matcher-scale.ts\`. Synthetic geo-clustered records (~${DUP} per ` +
136
- `distinct place), resolved with the geo-first baseline (collapsed spatial${EM ? " + EM" : ""}) in ONE Node ` +
137
- `process — no Elasticsearch, no server. Geocoding is out of scope (measured separately); this isolates the ` +
124
+ `distinct place), resolved with the geo-first baseline (collapsed spatial${EM ? " + EM" : ""}) in one Node ` +
125
+ `process without Elasticsearch or a server. Geocoding is out of scope (measured separately); this isolates the ` +
138
126
  `matcher's block/score/cluster cost vs N._`,
139
127
  "",
140
128
  `| records | candidate pairs | entities | wall-clock | resolve rate | RSS (high-water) |`,
@@ -157,7 +145,7 @@ export async function matcherScale(
157
145
 
158
146
  lines.push(
159
147
  `The matcher resolves **${last.records.toLocaleString()} records in ${sec(last.wallMs)}** in a single Node ` +
160
- `process — block → Fellegi-Sunter → union-find clustering, no external service. Geo-cell + canonical-key ` +
148
+ `process (block → Fellegi-Sunter → union-find clustering) without an external service. Geo-cell + canonical-key ` +
161
149
  `blocking keeps candidate generation near-linear (it never enumerates the O(n²) pair space), so the wall-clock ` +
162
150
  `scales with the number of *blocked* pairs, not the square of N. That is the architectural claim made ` +
163
151
  `concrete: a calibrated street-level geocoder feeding the blocking lets entity resolution run in-process at ` +
@@ -3,31 +3,10 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The #617 NPPES dedup benchmark — the measurable proof of the record-matcher hypothesis.
6
+ * Builds a varied multi-record set per NPI from real data.
7
+ * Runs the matcher without NPI values, then scores recovered clusters against the NPI grouping.
7
8
  *
8
- * NPPES is NPI-keyed, so the NPI is a ground-truth entity id. We build a deliberately varied
9
- * multi-record set per NPI from REAL data — the registry's primary record, each alternate
10
- * organization name (`nppes_other-names`, NAME drift at the same place), and the mailing address
11
- * where it differs from the practice location (ADDRESS variation) — then run the matcher BLIND to
12
- * the NPI (geocode → block → Fellegi-Sunter + EM → cluster) and score the recovered clusters
13
- * against the NPI grouping (pairwise P/R/F1 + adjusted Rand).
14
- *
15
- * Honest reading (per the epic): NPI-as-truth is CONSERVATIVE. A cluster that merges two NPIs is a
16
- * candidate "same entity, two NPIs" surfaced for review, not an error we adjudicate; and a single
17
- * NPI split across two genuinely-distant addresses is geo-first behaving correctly, counted here
18
- * as a recall miss. We resolve and report; interpretation is the consumer's.
19
- *
20
- * Sample: a tractable, variation-rich slice — providers in one state (default TX) that have ≥1
21
- * alternate name, so every entity has ≥2 records and the dedup is non-trivial. Streams the 4.8 GB
22
- * registry via `streamRows` (#616), so nothing loads whole.
23
- *
24
- * The stages live in `./nppes/`: the sample, the scorer, the truth grains, the setting progression,
25
- * the adjudication packet, and the report. This file is the orchestration — read it for the order
26
- * of operations, the modules for what each stage does.
27
- *
28
- * Run: `mailwoman registry scorer-eval nppes-benchmark [--state TX] [--max-npis 300]
29
- * [--wof <admin.db>] [--data-root <dir>] [--no-train-em]
30
- * [--out-md docs/articles/evals/matcher-dedup/<date>-nppes-dedup-benchmark.md]`
9
+ * Run: `mailwoman registry scorer-eval nppes-benchmark [--state TX] [--max-npis 300] [--wof <admin.db>] [--data-root <dir>] [--no-train-em] [--out-md docs/articles/evals/matcher-dedup/<date>-nppes-dedup-benchmark.md]`
31
10
  */
32
11
 
33
12
  import { dataRootPath } from "@mailwoman/core/data-root"
@@ -64,8 +43,8 @@ import { stateOption } from "#tools/shared"
64
43
  */
65
44
  export interface NPPESDedupBenchmarkOptions {
66
45
  /**
67
- * The injected geocoder factory (the command wires `mailwoman/geocode-core`; see `./eval-geocoder.ts`). Model-swap
68
- * overrides (`--model`/`--tokenizer`/`--model-card`) are the COMMAND's factory config, not tool options.
46
+ * The injected geocoder factory, wired by the command to `mailwoman/geocode-core`; model-swap
47
+ * overrides (`--model`/`--tokenizer`/`--model-card`) are its factory config rather than tool options.
69
48
  */
70
49
  createGeocoder: EvalGeocoderFactory
71
50
  /**
@@ -73,47 +52,48 @@ export interface NPPESDedupBenchmarkOptions {
73
52
  */
74
53
  geocodeStream?: EvalGeocodeStream
75
54
  /**
76
- * Record-matcher sources directory. Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
55
+ * Record-matcher sources directory, defaulting to `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
77
56
  */
78
57
  sources?: string
79
58
  /**
80
- * State filter. Default TX.
59
+ * State filter, default TX.
81
60
  */
82
61
  state?: string
83
62
  /**
84
- * NPIs sampled. Default 300.
63
+ * NPIs sampled, default 300.
85
64
  */
86
65
  maxNpis?: number
87
66
  /**
88
- * EM-train the FS arms (label-free). Default true; `--no-train-em` uses the seeds.
67
+ * EM-train the FS arms (label-free), default true; `--no-train-em` uses the seeds.
89
68
  */
90
69
  trainEm?: boolean
91
70
  /**
92
- * #694 A/B: reproduce the pre-flip ingest (space-joined address columns + normalizeCase OFF). Default off (the
93
- * validated flip: comma-join + #690 all-caps normalization). Same data + GBT, only the flip toggled — so a delta here
94
- * is attributable to the flip.
71
+ * Reproduce the pre-flip ingest (space-joined address columns with `normalizeCase` off),
72
+ * so that with the same data and GBT only the flip is toggled.
73
+ * Default off.
95
74
  */
96
75
  legacyJoin?: boolean
97
76
  /**
98
- * Optional A/B: a path to a trained dedup-gbt TS module (exports DEDUP_GBT_MODEL + DEDUP_GBT_META) to score alongside
99
- * the shipped GBT at both truth levels — e.g. grade the #625 corroboration candidate.
77
+ * Optional A/B: a path to a trained dedup-gbt TS module exporting DEDUP_GBT_MODEL +
78
+ * DEDUP_GBT_META, scored alongside the shipped GBT at both truth levels.
100
79
  */
101
80
  candidate?: string
102
81
  /**
103
- * Write the #625 gold-set adjudication packet (org-name-grain over-merged clusters) here.
82
+ * Write the gold-set adjudication packet of org-name-grain over-merged clusters here.
104
83
  */
105
84
  dumpOvermerges?: string
106
85
  /**
107
- * H3 resolution for the org-name-h3 truth grain. Default 11 (≈25 m edge).
86
+ * H3 resolution for the org-name-h3 truth grain, default 11 (≈25 m edge).
108
87
  */
109
88
  h3Res?: number
110
89
  /**
111
- * Geocode the sample across a worker pool ({@linkcode geocodeStream}) instead of the serial in-process path. Heavy
112
- * per-row work (ONNX parse + WOF SQLite) → threading pays; measured ~1.5× at 2 workers, coordinates identical.
90
+ * Geocode the sample through a worker pool with {@linkcode geocodeStream}.
91
+ *
92
+ * The worker pool parallelizes the per-row ONNX parse and WOF SQLite work while preserving coordinates.
113
93
  */
114
94
  parallelGeocode?: boolean
115
95
  /**
116
- * Worker-pool concurrency for {@linkcode parallelGeocode}. Default 2 (geocode is I/O-bound).
96
+ * Worker-pool concurrency for {@linkcode parallelGeocode}, default 2 (geocode is I/O-bound).
117
97
  */
118
98
  geoConcurrency?: number
119
99
  /**
@@ -123,7 +103,7 @@ export interface NPPESDedupBenchmarkOptions {
123
103
  }
124
104
 
125
105
  /**
126
- * The #617 NPPES dedup benchmark — see the module doc. Emits the markdown report to stdout.
106
+ * The NPPES dedup benchmark (see the module doc), emitting the markdown report to stdout.
127
107
  */
128
108
  export async function nppesDedupBenchmark(
129
109
  options: NPPESDedupBenchmarkOptions,
@@ -139,7 +119,6 @@ export async function nppesDedupBenchmark(
139
119
  const PARALLEL_GEOCODE = options.parallelGeocode ?? false
140
120
  const GEO_CONC = options.geoConcurrency ?? 2
141
121
 
142
- // Build the variation-rich sample and corpus-wide address-frequency table.
143
122
  const { rows, keptNpis, npiPrimary, addressFrequency } = await buildNPPESSample(
144
123
  {
145
124
  registryPath: `${SOURCES}/nppes_npi-registry_20260607.tsv`,
@@ -150,10 +129,7 @@ export async function nppesDedupBenchmark(
150
129
  report
151
130
  )
152
131
 
153
- // Geocode and ingest records, carrying the held-out NPI in record.id.
154
- // geocoder is injected (see ./eval-geocoder.ts); model-swap for a multi-version curve rides the
155
- // command's factory config (--model/--tokenizer/--model-card; modelCardPath is MANDATORY when
156
- // modelPath is set — without it a STAGE3 model silently mis-decodes into empty parses). ---
132
+ // Without `modelCardPath`, a STAGE3 model silently mis-decodes into empty parses when `modelPath` is set.
157
133
  report?.("[C] building the geocoder + geocoding records…")
158
134
 
159
135
  const mapping: ColumnMapping = {
@@ -161,8 +137,8 @@ export async function nppesDedupBenchmark(
161
137
  name: "name",
162
138
  organization: "org",
163
139
  address: "address",
164
- // `entityTruth` rides as an attribute purely for scoring (NOT a discriminator → never used in
165
- // matching); it carries the site-level entity-level label alongside the NPI (record.id).
140
+ // `entityTruth` appears as an attribute purely for scoring, never as a discriminator
141
+ // in matching, carrying the site-level label alongside the NPI.
166
142
  attributes: { authorizedOfficial: "auth", taxonomy: "taxonomy", entityTruth: "entityID" },
167
143
  source: "nppes",
168
144
  }
@@ -171,9 +147,8 @@ export async function nppesDedupBenchmark(
171
147
  let records: SourceRecord[]
172
148
 
173
149
  if (PARALLEL_GEOCODE) {
174
- // Threaded geocode: normalize on the main thread, then hand records to a worker pool that each rebuild the
175
- // classifier/resolver/extracts from config. `address` is a single pre-joined column here, so `--legacy-join`
176
- // (a separator toggle) is a no-op for this path; `normalizeCase` follows the worker default (on).
150
+ // `address` is a single pre-joined column on this path, so `--legacy-join` is a no-op
151
+ // and `normalizeCase` follows the worker default (on).
177
152
  if (!options.geocodeStream) {
178
153
  throw new Error("parallelGeocode requires the injected geocodeStream (see ./eval-geocoder.ts)")
179
154
  }
@@ -190,13 +165,13 @@ export async function nppesDedupBenchmark(
190
165
  }
191
166
  }
192
167
 
193
- // geocodeStream yields in completion order; restore input order so downstream cluster tie-breaks are byte-stable.
168
+ // Restore input order because `geocodeStream` yields in completion order
169
+ // and downstream cluster tie-breaks must be byte-stable.
194
170
  geocoded.sort((a, b) => (order.get(a.id) ?? 0) - (order.get(b.id) ?? 0))
195
171
  records = geocoded
196
172
  } else {
197
173
  const geocoder = await options.createGeocoder({ normalizeCase: !LEGACY })
198
174
 
199
- // Count placements at the boundary (parity with the retired in-script counter).
200
175
  const countedGeocodeForIngest: GeocodeAddress = async (raw) => {
201
176
  const g = await geocoder.geocodeAddress(raw)
202
177
 
@@ -217,15 +192,13 @@ export async function nppesDedupBenchmark(
217
192
 
218
193
  report?.(` geocoded ${geo}/${rows.length} (${((100 * geo) / rows.length).toFixed(1)}%)`)
219
194
 
220
- // Score recovered clusters against each truth grain using the held-out NPI.
221
195
  const N = records.length
222
196
 
223
- // Every grain scores against the SAME record population, so the ARI expectation is fixed for the run.
197
+ // Every grain scores against the same record population, so the ARI expectation is fixed for the run.
224
198
  const score = (entities: readonly ResolvedEntity[], labelOf: TruthLabel): Score => scoreEntities(entities, labelOf, N)
225
199
 
226
- // Truth labels: NPI-level (the conservative held-out NPI = record.id) and entity-level (the
227
- // site-level subpart-collapsed id that rides on attributes.entityTruth). Scoring the SAME clusters
228
- // both ways isolates how much of the apparent over-merge is NPI over-segmentation, not model error.
200
+ // A score for the same clusters at NPI and entity level isolates how much of the
201
+ // apparent over-merge is NPI over-segmentation rather than model error.
229
202
  const npiLabel = (rec: SourceRecord) => rec.id
230
203
  const entityLabel = (rec: SourceRecord) => rec.attributes?.["entityTruth"] ?? rec.id
231
204
  const orgNameLabel = buildOrgNameGrain(npiPrimary)
@@ -234,17 +207,13 @@ export async function nppesDedupBenchmark(
234
207
  const orgNameCoordLabel = buildOrgNameCoordGrain(npiPrimary, npiCoord)
235
208
  const geocodedNpis = [...npiPrimary.keys()].filter((n) => npiCoord.has(n)).length
236
209
 
237
- const H3_RES = options.h3Res ?? 11 // res 11 ≈ 25 m edge; res 10 ≈ 65 m (block scale)
210
+ const H3_RES = options.h3Res ?? 11 // res 11 ≈ 25 m edge. res 10 ≈ 65 m (block scale)
238
211
  const orgNameH3Label = buildOrgNameH3Grain(npiPrimary, npiCoord, H3_RES)
239
212
 
240
- // Progressively enable comparison-model settings at the default threshold.
241
- // threshold to isolate its marginal effect, then sweep the link threshold on the best config (geocode
242
- // once, resolve many — config is cheap). ---
243
213
  report?.(`[D] resolving the setting progression${TRAIN_EM ? " (EM-trained)" : ""}…`)
244
214
 
245
- // learnedScorer:false throughout — this benchmark studies the FS COMPARISON-MODEL settings (#617/#625).
246
- // The learned scorer is now default-on, so it must be pinned off here or every row would silently be the
247
- // GBT; the learned scorer is measured separately (learned-scorer-clustering-eval / -crossstate-eval).
215
+ // The learned scorer is default-on, so it is pinned off here.
216
+ // Otherwise every row would silently be the GBT.
248
217
  const progression = buildSettings(addressFrequency).map((l) => {
249
218
  const res = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0, ...l.config })
250
219
 
@@ -253,12 +222,9 @@ export async function nppesDedupBenchmark(
253
222
 
254
223
  const bestSetting = progression.at(-1)! // the full setting stack
255
224
 
256
- // The SHIPPED out-of-box default (#86): no setting config at all → resolveEntities auto-computes an
257
- // input-scoped address-frequency table + collapsed spatial. On this deliberately-sub-sampled corpus the
258
- // auto table is sparse (few repeats), so the inverse-frequency signal is near-inert and F1 collapses to
259
- // ≈baseline — NOT a regression, just the honest truth that IDF is a corpus statistic you can't synthesize
260
- // from a slice. On a FULL-dataset dedup the input IS the corpus and this default reaches the baseline; the
261
- // CLI passes a corpus-wide table built from the full source files so even a geocoded sub-sample benefits.
225
+ // The shipped out-of-box default auto-computes an input-scoped address-frequency table.
226
+ // on this sub-sampled corpus it is sparse and F1 collapses to ≈baseline, because IDF is a
227
+ // corpus statistic, so the CLI passes a corpus-wide table built from the full source files.
262
228
  const defaultRes = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0 })
263
229
  const defaultOutOfBox = score(defaultRes.entities, npiLabel)
264
230
 
@@ -292,10 +258,6 @@ export async function nppesDedupBenchmark(
292
258
  ` default F1 ${(100 * base.score.f1).toFixed(1)}% → best F1 ${(100 * best.score.f1).toFixed(1)}% @ threshold ${best.t}`
293
259
  )
294
260
 
295
- // Score the same clusters against NPI-level and entity-level truth.
296
- // reveal how much of the apparent over-merge is NPI over-segmentation (one org / many subpart-NPIs,
297
- // where merging is CORRECT) rather than model error. Two production configs: the FS full setting stack
298
- // and the shipped default (GBT, default-on) — each fed the corpus-wide address-frequency table. ---
299
261
  const entityCount = new Set(records.map((r) => entityLabel(r))).size
300
262
  const orgCount = new Set(records.map((r) => orgNameLabel(r))).size
301
263
  const fsNPI = bestSetting.score
@@ -305,17 +267,12 @@ export async function nppesDedupBenchmark(
305
267
  const gbtNPI = score(gbtRes.entities, npiLabel)
306
268
  const gbtEntity = score(gbtRes.entities, entityLabel)
307
269
  const gbtOrg = score(gbtRes.entities, orgNameLabel)
308
- // Tier 2D: the coordinate-co-location org-name truth (tighter lower bound).
309
270
  const orgCoordCount = new Set(records.map((r) => orgNameCoordLabel(r))).size
310
271
  const fsOrgCoord = score(bestSetting.res.entities, orgNameCoordLabel)
311
272
  const gbtOrgCoord = score(gbtRes.entities, orgNameCoordLabel)
312
- // #109: the H3-cell co-location truth — a robustness check on the haversine coord-grain.
313
273
  const orgH3Count = new Set(records.map((r) => orgNameH3Label(r))).size
314
274
  const gbtOrgH3 = score(gbtRes.entities, orgNameH3Label)
315
275
 
316
- // The adjudication packet grades the SHIPPED (GBT) clusters, because the residual over-merge is small and
317
- // approaching the measured ~1.6% irreducible ceiling — per-pair human adjudication (same entity? distinct
318
- // co-located?) is the only instrument left that can separate model error from yardstick error.
319
276
  const DUMP_OVERMERGES = options.dumpOvermerges || ""
320
277
 
321
278
  if (DUMP_OVERMERGES) {
@@ -331,8 +288,6 @@ export async function nppesDedupBenchmark(
331
288
  report?.(` adjudication packet: ${clusters} over-merged clusters -> ${DUMP_OVERMERGES}`)
332
289
  }
333
290
 
334
- // Optional candidate A/B (--candidate): score a trained GBT module at both levels, at its own
335
- // recommendedThreshold, alongside the shipped GBT — grades a new model (e.g. corroboration features).
336
291
  let cand: { label: string; npi: Score; entity: Score } | null = null
337
292
 
338
293
  if (CANDIDATE) {