@mailwoman/registry 10.0.0 → 10.2.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 (231) hide show
  1. package/README.md +11 -14
  2. package/lib/address-key.ts +14 -10
  3. package/lib/geocode-handler.ts +7 -5
  4. package/lib/geojson.ts +13 -7
  5. package/lib/ingest.ts +70 -92
  6. package/lib/learned-scorer.ts +38 -44
  7. package/lib/map-html.ts +26 -72
  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 +45 -54
  12. package/lib/resolve.ts +187 -130
  13. package/lib/types.ts +35 -29
  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 +7 -5
  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 +13 -7
  25. package/out/geojson.js.map +1 -1
  26. package/out/ingest.d.ts +49 -76
  27. package/out/ingest.d.ts.map +1 -1
  28. package/out/ingest.js +37 -62
  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 +11 -64
  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 +36 -50
  51. package/out/reconcile.d.ts.map +1 -1
  52. package/out/reconcile.js +18 -42
  53. package/out/reconcile.js.map +1 -1
  54. package/out/resolve.d.ts +152 -91
  55. package/out/resolve.d.ts.map +1 -1
  56. package/out/resolve.js +67 -68
  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 +23 -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 +25 -16
  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 +26 -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 +22 -41
  107. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
  108. package/out/tools/nppes/dedup-benchmark.js +21 -67
  109. package/out/tools/nppes/dedup-benchmark.js.map +1 -1
  110. package/out/tools/nppes/org-name.d.ts +5 -11
  111. package/out/tools/nppes/org-name.d.ts.map +1 -1
  112. package/out/tools/nppes/org-name.js +2 -9
  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 +6 -7
  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 +29 -18
  123. package/out/tools/nppes/sample.d.ts.map +1 -1
  124. package/out/tools/nppes/sample.js +24 -28
  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 +68 -72
  139. package/out/tools/shared.d.ts.map +1 -1
  140. package/out/tools/shared.js +50 -67
  141. package/out/tools/shared.js.map +1 -1
  142. package/out/tools/train/cross-gbt.d.ts +37 -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 +38 -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 +11 -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 +35 -29
  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 +42 -185
  191. package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
  192. package/{lib/tools → tools}/cross/dataset-correlation.ts +35 -73
  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 +77 -0
  196. package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
  197. package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +40 -31
  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 +39 -78
  202. package/{lib/tools → tools}/matcher-scale.ts +21 -33
  203. package/{lib/tools → tools}/nppes/dedup-benchmark.ts +39 -83
  204. package/tools/nppes/org-name.ts +15 -0
  205. package/{lib/tools → tools}/nppes/overmerge-packet.ts +16 -12
  206. package/{lib/tools → tools}/nppes/report.ts +32 -25
  207. package/{lib/tools → tools}/nppes/sample.ts +43 -38
  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 +79 -98
  212. package/{lib/tools → tools}/train/cross-gbt.ts +39 -34
  213. package/{lib/tools → tools}/train/gbt.ts +55 -41
  214. package/{lib/tools → tools}/train/org-cross-gbt.ts +40 -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 +29 -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/lib/tools/nppes/org-name.ts +0 -23
  226. package/out/tools/index.d.ts +0 -31
  227. package/out/tools/index.d.ts.map +0 -1
  228. package/out/tools/index.js +0 -31
  229. package/out/tools/index.js.map +0 -1
  230. package/out/tools/viz/render/index.d.ts.map +0 -1
  231. 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,61 @@ 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
+ * @defaultValue `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
+ *
47
+ * @defaultValue {@linkcode TX}
87
48
  */
88
49
  state?: string
50
+
89
51
  /**
90
- * NPIs sampled. Default 1500.
52
+ * The number of NPIs to sample.
53
+ *
54
+ * @defaultValue `1500`
91
55
  */
92
56
  npis?: number
57
+
93
58
  /**
94
- * Base PRNG seed. Default 1.
59
+ * The base PRNG seed.
60
+ *
61
+ * Each split adds its index to that value.
62
+ *
63
+ * @defaultValue `1`
95
64
  */
96
65
  seed?: number
66
+
97
67
  /**
98
- * Train/test splits averaged. Default 8.
68
+ * The number of train/test splits to average over.
69
+ *
70
+ * @defaultValue `8`
99
71
  */
100
72
  seeds?: number
73
+
101
74
  /**
102
- * Also write the markdown report here.
75
+ * An optional path for the Markdown report.
103
76
  */
104
77
  outMd?: string
105
78
  }
106
79
 
107
80
  /**
108
- * Learned-scorer pairwise probe (#603) — see the module doc. Emits the markdown report to stdout.
81
+ * Compares Fellegi-Sunter, logistic-regression and gradient-boosted-tree pair scorers on an NPPES sample.
82
+ *
83
+ * A pair is a match when both records share an NPI.
84
+ * The function averages ROC-AUC and best F1 over several train/test splits.
85
+ *
86
+ * It prints and returns the Markdown report.
87
+ * It also writes the report to `outMd` when that option is set.
109
88
  */
110
89
  export async function scorerPairwiseEval(
111
90
  options: ScorerPairwiseEvalOptions,
@@ -120,7 +99,6 @@ export async function scorerPairwiseEval(
120
99
  const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
121
100
  const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
122
101
 
123
- // Build the same NPI-keyed sample used by the dedup benchmark.
124
102
  const { rows, keptNpis, addressFrequency } = await buildNPPESSample(
125
103
  { registryPath: REGISTRY, otherNamesPath: OTHER_NAMES, state: STATE, maxNpis: NPIS },
126
104
  report
@@ -129,8 +107,6 @@ export async function scorerPairwiseEval(
129
107
  report?.("[C] geocoding…")
130
108
  const geocoder = await options.createGeocoder()
131
109
 
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
110
  const mapping: ColumnMapping = {
135
111
  id: "npi",
136
112
  name: "name",
@@ -146,15 +122,12 @@ export async function scorerPairwiseEval(
146
122
 
147
123
  geocoder[Symbol.dispose]()
148
124
 
149
- // Block records and extract the collapsed-spatial and address-frequency features.
150
- // comparisons; EM-fit it for the FS baseline. ---
151
125
  report?.("[D] blocking + features…")
152
126
  const model = buildDefaultModel({ collapseSpatial: true, addressFrequency })
153
127
  const { pairs } = block(records, defaultBlockingKeys())
154
128
  const patterns = pairs.map(([a, b]) => agreementPattern(model.comparisons, a, b))
155
129
  const fsModel = estimateParameters(model, patterns).model
156
130
 
157
- // The SHARED production featurizer (createMatchFeaturizer) — train ≡ eval ≡ inference, one definition.
158
131
  const featurize = createMatchFeaturizer({ comparisons: model.comparisons, addressFrequency })
159
132
 
160
133
  interface Sample {
@@ -177,11 +150,6 @@ export async function scorerPairwiseEval(
177
150
  gbtScored: Scored[]
178
151
  }
179
152
 
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
153
  function runSplit(seed: number): SplitScored {
186
154
  const rnd = makeLcg(seed || 1)
187
155
  const npiSplit = new Map<string, "train" | "test">()
@@ -199,7 +167,6 @@ export async function scorerPairwiseEval(
199
167
 
200
168
  if (!sa || sa !== sb) return
201
169
 
202
- // cross-split or unknown → drop (no leakage)
203
170
  const sample: Sample = {
204
171
  x: featurize(a, b),
205
172
  y: a.id === b.id ? 1 : 0,
@@ -212,8 +179,6 @@ export async function scorerPairwiseEval(
212
179
  const posWeight = train.filter((s) => s.y === 1).length / Math.max(1, train.length)
213
180
  const sampleWeights = train.map((s) => (s.y === 1 ? 1 - posWeight : posWeight))
214
181
 
215
- // L2-regularized logistic regression (batch gradient descent), rare class up-weighted — the
216
- // SHARED trainer.
217
182
  const lrScore = trainLogisticRegression(
218
183
  train.map((s) => s.x),
219
184
  train.map((s) => s.y),
@@ -221,7 +186,6 @@ export async function scorerPairwiseEval(
221
186
  dim
222
187
  )
223
188
 
224
- // Gradient-boosted trees on the SAME train pairs + class weights — the non-linear arm.
225
189
  const gbt = trainGBT(
226
190
  train.map((s) => s.x),
227
191
  train.map((s) => s.y),
@@ -239,13 +203,12 @@ export async function scorerPairwiseEval(
239
203
  }
240
204
  }
241
205
 
242
- // Evaluate LR and FS on held-out pairs with ROC-AUC and best-threshold F1.
243
206
  function auc(scored: Array<{ s: number; y: number }>): number {
244
207
  const pos = scored.filter((d) => d.y === 1)
245
208
  const neg = scored.filter((d) => d.y === 0)
246
209
 
247
210
  if (!pos.length || !neg.length) return Number.NaN
248
- // Mann-Whitney U via rank.
211
+
249
212
  const sorted = [...scored].toSorted((p, q) => p.s - q.s)
250
213
  let rank = 1
251
214
  let rankSum = 0
@@ -315,11 +278,11 @@ export async function scorerPairwiseEval(
315
278
  const meanDelta = mean(deltas)!
316
279
  const avgTestN = mean(splits.map((r) => r.testN))!
317
280
  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)
281
+ const seMean = std(deltas) / Math.sqrt(SEEDS)
282
+ const zScore = seMean > 0 ? meanDelta / seMean : 0
283
+ const f1Delta = mean(lrF1s)! - mean(fsF1s)!
321
284
  const unanimous = lrWins === SEEDS
322
- // GBT (non-linear) arm.
285
+
323
286
  const gbtAucs = splits.map((r) => auc(r.gbtScored))
324
287
  const gbtF1s = splits.map((r) => bestF1(r.gbtScored).f1)
325
288
  const gbtVsFs = splits.map((_, i) => gbtAucs[i]! - fsAucs[i]!)
@@ -329,7 +292,6 @@ export async function scorerPairwiseEval(
329
292
  const meanGbtVsLr = mean(gbtVsLr)!
330
293
  const f1DeltaGbt = mean(gbtF1s)! - mean(fsF1s)!
331
294
 
332
- // operating-point F1 gain (GBT − FS)
333
295
  for (const r of splits) {
334
296
  const dl = auc(r.lrScored) - auc(r.fsScored)
335
297
  const dg = auc(r.gbtScored) - auc(r.fsScored)
@@ -372,14 +334,13 @@ export async function scorerPairwiseEval(
372
334
  `**ΔAUC (LR − FS): ${sgn(meanDelta)}${f4(meanDelta)} ± ${f4(std(deltas))}, LR > FS in ${lrWins}/${SEEDS} seeds.**`,
373
335
  "",
374
336
  `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 ` +
337
+ `≈${zScore.toFixed(1)}σ above zero, ${lrWins}/${SEEDS} seeds in LR's favor. At the operating point the gap is ` +
376
338
  `larger: **ΔF1 ${sgn(f1Delta * 100)}${(f1Delta * 100).toFixed(1)}pp** (${pct(mean(fsF1s)!)}% → ${pct(mean(lrF1s)!)}%), ` +
377
339
  `because the interaction features sharpen the hard co-located band near the decision boundary even where overall ` +
378
340
  `ranking barely moves.`,
379
341
  "",
380
342
  ]
381
343
 
382
- // Linear vs tree: does a non-linear model extract MORE than the LR? (The probe's open question.)
383
344
  const treeVerdict =
384
345
  meanGbtVsLr > MIN_MEANINGFUL_DELTA && gbtBeatsLr >= SEEDS - 1
385
346
  ? `**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,49 @@ 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 case normalization off),
72
+ * so that with the same data and GBT only the flip is toggled.
73
+ *
74
+ * @defaultValue `false`
95
75
  */
96
76
  legacyJoin?: boolean
97
77
  /**
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.
78
+ * Optional A/B: a path to a trained dedup-gbt TS module exporting DEDUP_GBT_MODEL +
79
+ * DEDUP_GBT_META, scored alongside the shipped GBT at both truth levels.
100
80
  */
101
81
  candidate?: string
102
82
  /**
103
- * Write the #625 gold-set adjudication packet (org-name-grain over-merged clusters) here.
83
+ * Write the gold-set adjudication packet of org-name-grain over-merged clusters here.
104
84
  */
105
85
  dumpOvermerges?: string
106
86
  /**
107
- * H3 resolution for the org-name-h3 truth grain. Default 11 (≈25 m edge).
87
+ * H3 resolution for the org-name-h3 truth grain, default 11 (≈25 m edge).
108
88
  */
109
89
  h3Res?: number
110
90
  /**
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.
91
+ * Geocode the sample through a worker pool with {@linkcode geocodeStream}.
92
+ *
93
+ * The worker pool parallelizes the per-row ONNX parse and WOF SQLite work while preserving coordinates.
113
94
  */
114
95
  parallelGeocode?: boolean
115
96
  /**
116
- * Worker-pool concurrency for {@linkcode parallelGeocode}. Default 2 (geocode is I/O-bound).
97
+ * Worker-pool concurrency for {@linkcode parallelGeocode}, default 2 (geocode is I/O-bound).
117
98
  */
118
99
  geoConcurrency?: number
119
100
  /**
@@ -123,7 +104,7 @@ export interface NPPESDedupBenchmarkOptions {
123
104
  }
124
105
 
125
106
  /**
126
- * The #617 NPPES dedup benchmark — see the module doc. Emits the markdown report to stdout.
107
+ * The NPPES dedup benchmark (see the module doc), emitting the markdown report to stdout.
127
108
  */
128
109
  export async function nppesDedupBenchmark(
129
110
  options: NPPESDedupBenchmarkOptions,
@@ -139,7 +120,6 @@ export async function nppesDedupBenchmark(
139
120
  const PARALLEL_GEOCODE = options.parallelGeocode ?? false
140
121
  const GEO_CONC = options.geoConcurrency ?? 2
141
122
 
142
- // Build the variation-rich sample and corpus-wide address-frequency table.
143
123
  const { rows, keptNpis, npiPrimary, addressFrequency } = await buildNPPESSample(
144
124
  {
145
125
  registryPath: `${SOURCES}/nppes_npi-registry_20260607.tsv`,
@@ -150,10 +130,7 @@ export async function nppesDedupBenchmark(
150
130
  report
151
131
  )
152
132
 
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). ---
133
+ // Without `modelCardPath`, a STAGE3 model silently mis-decodes into empty parses when `modelPath` is set.
157
134
  report?.("[C] building the geocoder + geocoding records…")
158
135
 
159
136
  const mapping: ColumnMapping = {
@@ -161,8 +138,8 @@ export async function nppesDedupBenchmark(
161
138
  name: "name",
162
139
  organization: "org",
163
140
  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).
141
+ // `entityTruth` appears as an attribute purely for scoring, never as a discriminator
142
+ // in matching, carrying the site-level label alongside the NPI.
166
143
  attributes: { authorizedOfficial: "auth", taxonomy: "taxonomy", entityTruth: "entityID" },
167
144
  source: "nppes",
168
145
  }
@@ -171,9 +148,8 @@ export async function nppesDedupBenchmark(
171
148
  let records: SourceRecord[]
172
149
 
173
150
  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).
151
+ // `address` is a single pre-joined column on this path, so `--legacy-join` is a no-op
152
+ // and case normalization follows the worker default (`"title-case"`).
177
153
  if (!options.geocodeStream) {
178
154
  throw new Error("parallelGeocode requires the injected geocodeStream (see ./eval-geocoder.ts)")
179
155
  }
@@ -190,13 +166,13 @@ export async function nppesDedupBenchmark(
190
166
  }
191
167
  }
192
168
 
193
- // geocodeStream yields in completion order; restore input order so downstream cluster tie-breaks are byte-stable.
169
+ // Restore input order because `geocodeStream` yields in completion order
170
+ // and downstream cluster tie-breaks must be byte-stable.
194
171
  geocoded.sort((a, b) => (order.get(a.id) ?? 0) - (order.get(b.id) ?? 0))
195
172
  records = geocoded
196
173
  } else {
197
- const geocoder = await options.createGeocoder({ normalizeCase: !LEGACY })
174
+ const geocoder = await options.createGeocoder({ caseNormalization: LEGACY ? "preserve" : "title-case" })
198
175
 
199
- // Count placements at the boundary (parity with the retired in-script counter).
200
176
  const countedGeocodeForIngest: GeocodeAddress = async (raw) => {
201
177
  const g = await geocoder.geocodeAddress(raw)
202
178
 
@@ -217,15 +193,13 @@ export async function nppesDedupBenchmark(
217
193
 
218
194
  report?.(` geocoded ${geo}/${rows.length} (${((100 * geo) / rows.length).toFixed(1)}%)`)
219
195
 
220
- // Score recovered clusters against each truth grain using the held-out NPI.
221
196
  const N = records.length
222
197
 
223
- // Every grain scores against the SAME record population, so the ARI expectation is fixed for the run.
198
+ // Every grain scores against the same record population, so the ARI expectation is fixed for the run.
224
199
  const score = (entities: readonly ResolvedEntity[], labelOf: TruthLabel): Score => scoreEntities(entities, labelOf, N)
225
200
 
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.
201
+ // A score for the same clusters at NPI and entity level isolates how much of the
202
+ // apparent over-merge is NPI over-segmentation rather than model error.
229
203
  const npiLabel = (rec: SourceRecord) => rec.id
230
204
  const entityLabel = (rec: SourceRecord) => rec.attributes?.["entityTruth"] ?? rec.id
231
205
  const orgNameLabel = buildOrgNameGrain(npiPrimary)
@@ -234,17 +208,13 @@ export async function nppesDedupBenchmark(
234
208
  const orgNameCoordLabel = buildOrgNameCoordGrain(npiPrimary, npiCoord)
235
209
  const geocodedNpis = [...npiPrimary.keys()].filter((n) => npiCoord.has(n)).length
236
210
 
237
- const H3_RES = options.h3Res ?? 11 // res 11 ≈ 25 m edge; res 10 ≈ 65 m (block scale)
211
+ const H3_RES = options.h3Res ?? 11 // res 11 ≈ 25 m edge. res 10 ≈ 65 m (block scale)
238
212
  const orgNameH3Label = buildOrgNameH3Grain(npiPrimary, npiCoord, H3_RES)
239
213
 
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
214
  report?.(`[D] resolving the setting progression${TRAIN_EM ? " (EM-trained)" : ""}…`)
244
215
 
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).
216
+ // The learned scorer is default-on, so it is pinned off here.
217
+ // Otherwise every row would silently be the GBT.
248
218
  const progression = buildSettings(addressFrequency).map((l) => {
249
219
  const res = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0, ...l.config })
250
220
 
@@ -253,12 +223,9 @@ export async function nppesDedupBenchmark(
253
223
 
254
224
  const bestSetting = progression.at(-1)! // the full setting stack
255
225
 
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.
226
+ // The shipped out-of-box default auto-computes an input-scoped address-frequency table.
227
+ // on this sub-sampled corpus it is sparse and F1 collapses to ≈baseline, because IDF is a
228
+ // corpus statistic, so the CLI passes a corpus-wide table built from the full source files.
262
229
  const defaultRes = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0 })
263
230
  const defaultOutOfBox = score(defaultRes.entities, npiLabel)
264
231
 
@@ -292,10 +259,6 @@ export async function nppesDedupBenchmark(
292
259
  ` default F1 ${(100 * base.score.f1).toFixed(1)}% → best F1 ${(100 * best.score.f1).toFixed(1)}% @ threshold ${best.t}`
293
260
  )
294
261
 
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
262
  const entityCount = new Set(records.map((r) => entityLabel(r))).size
300
263
  const orgCount = new Set(records.map((r) => orgNameLabel(r))).size
301
264
  const fsNPI = bestSetting.score
@@ -305,17 +268,12 @@ export async function nppesDedupBenchmark(
305
268
  const gbtNPI = score(gbtRes.entities, npiLabel)
306
269
  const gbtEntity = score(gbtRes.entities, entityLabel)
307
270
  const gbtOrg = score(gbtRes.entities, orgNameLabel)
308
- // Tier 2D: the coordinate-co-location org-name truth (tighter lower bound).
309
271
  const orgCoordCount = new Set(records.map((r) => orgNameCoordLabel(r))).size
310
272
  const fsOrgCoord = score(bestSetting.res.entities, orgNameCoordLabel)
311
273
  const gbtOrgCoord = score(gbtRes.entities, orgNameCoordLabel)
312
- // #109: the H3-cell co-location truth — a robustness check on the haversine coord-grain.
313
274
  const orgH3Count = new Set(records.map((r) => orgNameH3Label(r))).size
314
275
  const gbtOrgH3 = score(gbtRes.entities, orgNameH3Label)
315
276
 
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
277
  const DUMP_OVERMERGES = options.dumpOvermerges || ""
320
278
 
321
279
  if (DUMP_OVERMERGES) {
@@ -331,8 +289,6 @@ export async function nppesDedupBenchmark(
331
289
  report?.(` adjudication packet: ${clusters} over-merged clusters -> ${DUMP_OVERMERGES}`)
332
290
  }
333
291
 
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
292
  let cand: { label: string; npi: Score; entity: Score } | null = null
337
293
 
338
294
  if (CANDIDATE) {