@mailwoman/registry 9.0.0 → 9.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.
- package/README.md +1 -1
- package/geojson.ts +3 -2
- package/ingest.ts +2 -1
- package/map-html.ts +4 -4
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +3 -2
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +2 -1
- package/out/ingest.js.map +1 -1
- package/out/map-html.d.ts +2 -2
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js.map +1 -1
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +2 -1
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +4 -1
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.js +2 -2
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross-dataset-correlation.js +6 -5
- package/out/tools/cross-dataset-correlation.js.map +1 -1
- package/out/tools/cross-source-threshold-sweep.js +2 -2
- package/out/tools/cross-source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +2 -3
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +1 -1
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.js +3 -2
- package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +4 -3
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +1 -6
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +1 -6
- package/out/tools/index.js.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.js +1 -2
- package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
- package/out/tools/learned-scorer-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-eval.js +1 -6
- package/out/tools/learned-scorer-eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +1 -1
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/levers.d.ts +38 -0
- package/out/tools/nppes/levers.d.ts.map +1 -0
- package/out/tools/nppes/levers.js +79 -0
- package/out/tools/nppes/levers.js.map +1 -0
- package/out/tools/nppes/org-name.d.ts +24 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +42 -0
- package/out/tools/nppes/org-name.js.map +1 -0
- package/out/tools/nppes/overmerge-packet.d.ts +39 -0
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
- package/out/tools/nppes/overmerge-packet.js +55 -0
- package/out/tools/nppes/overmerge-packet.js.map +1 -0
- package/out/tools/nppes/report.d.ts +93 -0
- package/out/tools/nppes/report.d.ts.map +1 -0
- package/out/tools/nppes/report.js +188 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +64 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +113 -0
- package/out/tools/nppes/sample.js.map +1 -0
- package/out/tools/nppes/scoring.d.ts +36 -0
- package/out/tools/nppes/scoring.d.ts.map +1 -0
- package/out/tools/nppes/scoring.js +80 -0
- package/out/tools/nppes/scoring.js.map +1 -0
- package/out/tools/nppes/truth-grains.d.ts +50 -0
- package/out/tools/nppes/truth-grains.d.ts.map +1 -0
- package/out/tools/nppes/truth-grains.js +148 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/nppes-dedup-benchmark.d.ts +4 -0
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +79 -652
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +5 -4
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-cross-gbt.js +2 -2
- package/out/tools/train-cross-gbt.js.map +1 -1
- package/out/tools/train-gbt.d.ts.map +1 -1
- package/out/tools/train-gbt.js +2 -2
- package/out/tools/train-gbt.js.map +1 -1
- package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-org-cross-gbt.js +2 -2
- package/out/tools/train-org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +2 -2
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/cross-dataset-map.d.ts +2 -23
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +7 -28
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +2 -32
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +4 -33
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render.js +1 -1
- package/out/tools/viz/render.js.map +1 -1
- package/out/tools/viz/source-provenance-map.d.ts +2 -22
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +7 -26
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/types.d.ts +11 -1
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/package.json +78 -9
- package/reconcile.ts +2 -1
- package/resolve.ts +6 -1
- package/tools/coverage-reconciliation.ts +3 -3
- package/tools/cross-dataset-correlation.ts +7 -5
- package/tools/cross-source-threshold-sweep.ts +3 -3
- package/tools/dedup-ceiling.ts +3 -3
- package/tools/eval-geocoder.ts +1 -1
- package/tools/geocoder-vs-provided-coords.ts +4 -2
- package/tools/gold-set-sample.ts +5 -3
- package/tools/index.ts +1 -6
- package/tools/learned-scorer-clustering-eval.ts +4 -4
- package/tools/learned-scorer-crossstate-eval.ts +4 -4
- package/tools/learned-scorer-eval.ts +4 -9
- package/tools/matcher-scale.ts +2 -1
- package/tools/nppes/levers.ts +102 -0
- package/tools/nppes/org-name.ts +56 -0
- package/tools/nppes/overmerge-packet.ts +96 -0
- package/tools/nppes/report.ts +376 -0
- package/tools/nppes/sample.ts +197 -0
- package/tools/nppes/scoring.ts +114 -0
- package/tools/nppes/truth-grains.ts +201 -0
- package/tools/nppes-dedup-benchmark.ts +92 -868
- package/tools/shared.ts +6 -4
- package/tools/train-cross-gbt.ts +6 -5
- package/tools/train-gbt.ts +5 -4
- package/tools/train-org-cross-gbt.ts +6 -5
- package/tools/txhhsc-to-oarow.ts +2 -2
- package/tools/viz/cross-dataset-map.ts +12 -34
- package/tools/viz/geocode-first-surface.ts +5 -33
- package/tools/viz/render.ts +1 -1
- package/tools/viz/source-provenance-map.ts +14 -31
- package/types.ts +10 -1
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
* alternate name, so every entity has ≥2 records and the dedup is non-trivial. Streams the 4.8 GB
|
|
22
22
|
* registry via `streamRows` (#616), so nothing loads whole.
|
|
23
23
|
*
|
|
24
|
+
* The stages live in `./nppes/`: the sample, the scorer, the truth grains, the lever 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
|
+
*
|
|
24
28
|
* Run: `mailwoman registry scorer-eval nppes-benchmark [--state TX] [--max-npis 300]
|
|
25
29
|
* [--wof <admin.db>] [--data-root <dir>] [--no-train-em]
|
|
26
30
|
* [--out-md docs/articles/evals/matcher-dedup/<date>-nppes-dedup-benchmark.md]`
|
|
@@ -37,55 +41,16 @@ import { writeFileSync } from "node:fs";
|
|
|
37
41
|
import { resolve as resolvePath } from "node:path";
|
|
38
42
|
import { pathToFileURL } from "node:url";
|
|
39
43
|
import { dataRootPath } from "@mailwoman/core/utils";
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const BLOCKING_PARITY_TOLERANCE = 0.015;
|
|
48
|
-
/**
|
|
49
|
-
* NPPES column names (verbatim from the file headers).
|
|
50
|
-
*/
|
|
51
|
-
/**
|
|
52
|
-
* Org-name similarity for the org-name entity-truth (the gold-set rule: same address + same org name ⇒ same entity,
|
|
53
|
-
* even when NPPES doesn't flag the subpart). Strip corporate-form + articles, keep domain words (the distinguishing
|
|
54
|
-
* signal).
|
|
55
|
-
*/
|
|
56
|
-
const ORG_STOP = new Set([
|
|
57
|
-
"llc",
|
|
58
|
-
"inc",
|
|
59
|
-
"incorporated",
|
|
60
|
-
"corp",
|
|
61
|
-
"corporation",
|
|
62
|
-
"co",
|
|
63
|
-
"ltd",
|
|
64
|
-
"pllc",
|
|
65
|
-
"pc",
|
|
66
|
-
"pa",
|
|
67
|
-
"lp",
|
|
68
|
-
"llp",
|
|
69
|
-
"the",
|
|
70
|
-
"of",
|
|
71
|
-
"and",
|
|
72
|
-
]);
|
|
73
|
-
const orgTokens = (s) => new Set(s
|
|
74
|
-
.toLowerCase()
|
|
75
|
-
.replaceAll(/[^a-z0-9 ]/g, " ")
|
|
76
|
-
.split(/\s+/)
|
|
77
|
-
.filter((t) => t && !ORG_STOP.has(t)));
|
|
78
|
-
/**
|
|
79
|
-
* Gold-set threshold.
|
|
80
|
-
*/
|
|
81
|
-
const ORG_TAU = 0.7;
|
|
44
|
+
import { ingestRows, resolveEntities, } from "#index";
|
|
45
|
+
import { buildLevers } from "./nppes/levers.js";
|
|
46
|
+
import { writeOvermergePacket } from "./nppes/overmerge-packet.js";
|
|
47
|
+
import { renderNPPESDedupReport } from "./nppes/report.js";
|
|
48
|
+
import { buildNPPESSample } from "./nppes/sample.js";
|
|
49
|
+
import { scoreEntities } from "./nppes/scoring.js";
|
|
50
|
+
import { buildOrgNameCoordGrain, buildOrgNameGrain, buildOrgNameH3Grain, collectPrimaryCoordinates, } from "./nppes/truth-grains.js";
|
|
82
51
|
/**
|
|
83
52
|
* The #617 NPPES dedup benchmark — see the module doc. Emits the markdown report to stdout.
|
|
84
53
|
*/
|
|
85
|
-
/* oxlint-disable max-lines, max-statements, complexity -- 824 lines / 261 statements / complexity 101.
|
|
86
|
-
Same shape as oa-resolver-eval: a linear benchmark (build the sample, run each lever, score, emit the
|
|
87
|
-
markdown) whose report half wants the same extraction that file got. Left whole because the report
|
|
88
|
-
reads ~40 locals and typing that seam properly is a bigger change than this pass should carry. */
|
|
89
54
|
export async function nppesDedupBenchmark(options, report) {
|
|
90
55
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources");
|
|
91
56
|
const STATE = (options.state || "TX").toUpperCase();
|
|
@@ -96,99 +61,13 @@ export async function nppesDedupBenchmark(options, report) {
|
|
|
96
61
|
const CANDIDATE = options.candidate || "";
|
|
97
62
|
const PARALLEL_GEOCODE = options.parallelGeocode ?? false;
|
|
98
63
|
const GEO_CONC = options.geoConcurrency ?? 2;
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const alt = norm(r[C.otherOrg]);
|
|
107
|
-
if (!npi || !alt)
|
|
108
|
-
continue;
|
|
109
|
-
const list = altNames.get(npi) ?? [];
|
|
110
|
-
if (list.length < MIN_GROUP_SIZE) {
|
|
111
|
-
list.push(alt);
|
|
112
|
-
}
|
|
113
|
-
// cap fan-out per NPI
|
|
114
|
-
altNames.set(npi, list);
|
|
115
|
-
}
|
|
116
|
-
report?.(` ${altNames.size} NPIs with ≥1 alternate name`);
|
|
117
|
-
// --- Phase B: ONE full registry pass — build the GLOBAL address-frequency table (every practice
|
|
118
|
-
// address, so the sharing structure is corpus-wide, not sample-biased) AND collect the sample. ---
|
|
119
|
-
report?.(`[B] full registry pass: address-frequency table + ${MAX_NPIS} ${STATE} sample…`);
|
|
120
|
-
const rows = [];
|
|
121
|
-
const kept = new Set();
|
|
122
|
-
// Per-NPI primary org name + practice address key — the basis for the ORG-NAME entity-truth.
|
|
123
|
-
const npiPrimary = new Map();
|
|
124
|
-
const addrCounts = new Map();
|
|
125
|
-
let addrTotal = 0;
|
|
126
|
-
let scanned = 0;
|
|
127
|
-
for await (const r of streamRows(REGISTRY)) {
|
|
128
|
-
if (++scanned % 1_000_000 === 0) {
|
|
129
|
-
report?.(` scanned ${scanned / 1e6}M rows, kept ${kept.size}`);
|
|
130
|
-
}
|
|
131
|
-
const practice = addr(r[C.pAddr], r[C.pCity], r[C.pState], r[C.pZip]);
|
|
132
|
-
// Global address-frequency: count every practice address (one row ≈ one distinct NPI).
|
|
133
|
-
if (practice) {
|
|
134
|
-
const k = addressFrequencyKey(practice);
|
|
135
|
-
addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1);
|
|
136
|
-
addrTotal++;
|
|
137
|
-
}
|
|
138
|
-
// Sample: in-state NPIs with ≥1 alternate name, up to MAX_NPIS — NO early break (the table needs the full pass).
|
|
139
|
-
const npi = norm(r[C.npi]);
|
|
140
|
-
if (kept.size < MAX_NPIS &&
|
|
141
|
-
npi &&
|
|
142
|
-
!kept.has(npi) &&
|
|
143
|
-
altNames.has(npi) &&
|
|
144
|
-
practice &&
|
|
145
|
-
norm(r[C.pState]).toUpperCase() === STATE) {
|
|
146
|
-
const isOrg = norm(r[C.entityType]) === "2";
|
|
147
|
-
const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim();
|
|
148
|
-
if (primaryName) {
|
|
149
|
-
const org = isOrg ? norm(r[C.orgLegal]) : "";
|
|
150
|
-
const auth = `${norm(r[C.authFirst])} ${norm(r[C.authLast])}`.trim();
|
|
151
|
-
// the NPI's registrant — shared across its records
|
|
152
|
-
// #625: the taxonomy-code set (up to 15 slots), whitespace-joined — identical across the NPI's
|
|
153
|
-
// records by construction (it's a per-NPI registry attribute), so it NEVER splits one entity;
|
|
154
|
-
// it only separates co-located DISTINCT providers whose sets are disjoint.
|
|
155
|
-
const taxonomy = C.taxonomy
|
|
156
|
-
.map((col) => norm(r[col]))
|
|
157
|
-
.filter(Boolean)
|
|
158
|
-
.join(" ");
|
|
159
|
-
// Entity-level (site) truth: same org + same physical address. Subparts (NPPES
|
|
160
|
-
// "Is Organization Subpart" + parent LBN/TIN) collapse to their PARENT, so the matcher isn't
|
|
161
|
-
// charged for correctly fusing one org's many subpart-NPIs at a site; an NPI's mailing-vs-
|
|
162
|
-
// practice records stay DISTINCT sites. orgKey = parent identity for subparts, else the NPI
|
|
163
|
-
// (independent orgs sharing an address stay distinct — the conservative choice).
|
|
164
|
-
const isSubpart = norm(r[C.isSubpart]).toUpperCase() === "Y";
|
|
165
|
-
const parentKey = `${norm(r[C.parentLBN])}|${norm(r[C.parentTIN])}`.toLowerCase();
|
|
166
|
-
const orgKey = isSubpart && parentKey !== "|" ? `p:${parentKey}` : `n:${npi}`;
|
|
167
|
-
const eid = (a) => `${addressFrequencyKey(a)}|${orgKey}`;
|
|
168
|
-
if (org) {
|
|
169
|
-
npiPrimary.set(npi, { tokens: orgTokens(org), addrKey: addressFrequencyKey(practice) });
|
|
170
|
-
}
|
|
171
|
-
kept.add(npi);
|
|
172
|
-
rows.push({ npi, name: primaryName, org, address: practice, auth, taxonomy, entityID: eid(practice) });
|
|
173
|
-
// primary
|
|
174
|
-
for (const alt of altNames.get(npi)) {
|
|
175
|
-
rows.push({ npi, name: alt, org: alt, address: practice, auth, taxonomy, entityID: eid(practice) });
|
|
176
|
-
}
|
|
177
|
-
// name drift
|
|
178
|
-
const mailing = addr(r[C.mAddr], r[C.mCity], r[C.mState], r[C.mZip]);
|
|
179
|
-
if (mailing && mailing !== practice) {
|
|
180
|
-
rows.push({ npi, name: primaryName, org, address: mailing, auth, taxonomy, entityID: eid(mailing) });
|
|
181
|
-
} // address variation
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// Corpus-wide address-frequency table — the inverse-frequency signal (#617 fix per the DeepSeek consult).
|
|
186
|
-
const addressFrequency = {
|
|
187
|
-
total: addrTotal,
|
|
188
|
-
distinct: addrCounts.size,
|
|
189
|
-
frequency: (v) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
|
|
190
|
-
};
|
|
191
|
-
report?.(` ${kept.size} NPIs → ${rows.length} records; address table: ${addrCounts.size} distinct over ${addrTotal} rows`);
|
|
64
|
+
// --- Phases A + B: the variation-rich sample plus the corpus-wide address-frequency table. ---
|
|
65
|
+
const { rows, keptNpis, npiPrimary, addressFrequency } = await buildNPPESSample({
|
|
66
|
+
registryPath: `${SOURCES}/nppes_npi-registry_20260607.tsv`,
|
|
67
|
+
otherNamesPath: `${SOURCES}/nppes_other-names_20260607.tsv`,
|
|
68
|
+
state: STATE,
|
|
69
|
+
maxNpis: MAX_NPIS,
|
|
70
|
+
}, report);
|
|
192
71
|
// --- Phase C: geocode + ingest (the NPI rides on record.id as the held-out label). The heavy
|
|
193
72
|
// geocoder is injected (see ./eval-geocoder.ts); model-swap for a multi-version curve rides the
|
|
194
73
|
// command's factory config (--model/--tokenizer/--model-card; modelCardPath is MANDATORY when
|
|
@@ -243,334 +122,45 @@ export async function nppesDedupBenchmark(options, report) {
|
|
|
243
122
|
geocoder.close();
|
|
244
123
|
}
|
|
245
124
|
report?.(` geocoded ${geo}/${rows.length} (${((100 * geo) / rows.length).toFixed(1)}%)`);
|
|
246
|
-
// --- Phase E: score recovered clusters
|
|
247
|
-
const choose2 = (n) => (n * (n - 1)) / 2;
|
|
125
|
+
// --- Phase E: score recovered clusters against each truth grain (record.id = the held-out NPI). ---
|
|
248
126
|
const N = records.length;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const npiClusters = new Map();
|
|
252
|
-
let sumCK = 0; // Σ C(n_ck, 2)
|
|
253
|
-
let sumCluster = 0; // Σ_c C(|c|, 2)
|
|
254
|
-
let singletons = 0;
|
|
255
|
-
let overMergedClusters = 0;
|
|
256
|
-
let recordsInOverMerged = 0;
|
|
257
|
-
let maxNpisFused = 0;
|
|
258
|
-
entities.forEach((e, ci) => {
|
|
259
|
-
const byNPI = new Map();
|
|
260
|
-
for (const rec of e.records) {
|
|
261
|
-
const lbl = labelOf(rec);
|
|
262
|
-
byNPI.set(lbl, (byNPI.get(lbl) ?? 0) + 1);
|
|
263
|
-
}
|
|
264
|
-
sumCluster += choose2(e.records.length);
|
|
265
|
-
if (e.records.length === 1) {
|
|
266
|
-
singletons++;
|
|
267
|
-
}
|
|
268
|
-
if (byNPI.size > 1) {
|
|
269
|
-
overMergedClusters++;
|
|
270
|
-
recordsInOverMerged += e.records.length;
|
|
271
|
-
maxNpisFused = Math.max(maxNpisFused, byNPI.size);
|
|
272
|
-
}
|
|
273
|
-
for (const [npi, n] of byNPI) {
|
|
274
|
-
sumCK += choose2(n);
|
|
275
|
-
npiTotals.set(npi, (npiTotals.get(npi) ?? 0) + n);
|
|
276
|
-
}
|
|
277
|
-
for (const rec of e.records) {
|
|
278
|
-
const lbl = labelOf(rec);
|
|
279
|
-
const s = npiClusters.get(lbl) ?? new Set();
|
|
280
|
-
s.add(ci);
|
|
281
|
-
npiClusters.set(lbl, s);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
let sumClass = 0;
|
|
285
|
-
// Σ_k C(|k|, 2)
|
|
286
|
-
for (const total of npiTotals.values()) {
|
|
287
|
-
sumClass += choose2(total);
|
|
288
|
-
}
|
|
289
|
-
const tp = sumCK;
|
|
290
|
-
const precision = tp + (sumCluster - tp) > 0 ? tp / sumCluster : 0;
|
|
291
|
-
const recall = sumClass > 0 ? tp / sumClass : 0;
|
|
292
|
-
const f1 = precision + recall > 0 ? (2 * precision * recall) / (precision + recall) : 0;
|
|
293
|
-
const expected = (sumCluster * sumClass) / choose2(N);
|
|
294
|
-
const maxIndex = (sumCluster + sumClass) / 2;
|
|
295
|
-
const ari = maxIndex - expected !== 0 ? (tp - expected) / (maxIndex - expected) : 1;
|
|
296
|
-
const splitNpis = [...npiClusters.values()].filter((s) => s.size > 1).length;
|
|
297
|
-
return {
|
|
298
|
-
precision,
|
|
299
|
-
recall,
|
|
300
|
-
f1,
|
|
301
|
-
ari,
|
|
302
|
-
clusters: entities.length,
|
|
303
|
-
singletons,
|
|
304
|
-
overMergedClusters,
|
|
305
|
-
recordsInOverMerged,
|
|
306
|
-
maxNpisFused,
|
|
307
|
-
splitNpis,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
127
|
+
// Every grain scores against the SAME record population, so the ARI expectation is fixed for the run.
|
|
128
|
+
const score = (entities, labelOf) => scoreEntities(entities, labelOf, N);
|
|
310
129
|
// Truth labels: NPI-level (the conservative held-out NPI = record.id) and entity-level (the
|
|
311
130
|
// site-level subpart-collapsed id that rides on attributes.entityTruth). Scoring the SAME clusters
|
|
312
131
|
// both ways isolates how much of the apparent over-merge is NPI over-segmentation, not model error.
|
|
313
132
|
const npiLabel = (rec) => rec.id;
|
|
314
133
|
const entityLabel = (rec) => rec.attributes?.["entityTruth"] ?? rec.id;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// the gold set proved is correct, WITHOUT the subpart flag (which the gold set showed misses 37%). ---
|
|
319
|
-
const parent = new Map();
|
|
320
|
-
const find = (x) => {
|
|
321
|
-
if (!parent.has(x)) {
|
|
322
|
-
parent.set(x, x);
|
|
323
|
-
}
|
|
324
|
-
let root = x;
|
|
325
|
-
while (parent.get(root) !== root) {
|
|
326
|
-
root = parent.get(root);
|
|
327
|
-
}
|
|
328
|
-
while (parent.get(x) !== root) {
|
|
329
|
-
const next = parent.get(x);
|
|
330
|
-
parent.set(x, root);
|
|
331
|
-
x = next;
|
|
332
|
-
}
|
|
333
|
-
return root;
|
|
334
|
-
};
|
|
335
|
-
const union = (a, b) => {
|
|
336
|
-
const ra = find(a);
|
|
337
|
-
const rb = find(b);
|
|
338
|
-
if (ra !== rb) {
|
|
339
|
-
parent.set(ra, rb);
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
{
|
|
343
|
-
const byAddr = new Map();
|
|
344
|
-
for (const [npi, info] of npiPrimary) {
|
|
345
|
-
find(npi);
|
|
346
|
-
// seed
|
|
347
|
-
if (!info.addrKey)
|
|
348
|
-
continue;
|
|
349
|
-
if (!byAddr.has(info.addrKey)) {
|
|
350
|
-
byAddr.set(info.addrKey, []);
|
|
351
|
-
}
|
|
352
|
-
byAddr.get(info.addrKey).push(npi);
|
|
353
|
-
}
|
|
354
|
-
for (const group of byAddr.values()) {
|
|
355
|
-
for (let i = 0; i < group.length; i++) {
|
|
356
|
-
for (let j = i + 1; j < group.length; j++) {
|
|
357
|
-
if (jaccard(npiPrimary.get(group[i]).tokens, npiPrimary.get(group[j]).tokens) >= ORG_TAU) {
|
|
358
|
-
union(group[i], group[j]);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
const orgNameLabel = (rec) => (npiPrimary.has(rec.id) ? find(rec.id) : rec.id);
|
|
365
|
-
// --- ORG-NAME-COORD entity-truth (Tier 2D, #625). The string org-name truth above blocks by the
|
|
366
|
-
// address STRING (`addressFrequencyKey`), so it MISSES same-building pairs whose text differs —
|
|
367
|
-
// "1504 Taub LOOP" vs "1504 Taub LP STE 100" key apart even though the geocoder places them at one
|
|
368
|
-
// point. This variant blocks by the GEOCODED BUILDING instead: union two NPIs whose org names match
|
|
369
|
-
// (Jaccard ≥ ORG_TAU) AND whose primary practice coordinates are within the same-building distance
|
|
370
|
-
// (≤ 50 m haversine, the DEFAULT_DISTANCE_LEVELS grain). Brute-force pairwise over the ~1000 sampled
|
|
371
|
-
// NPIs (trivial); a tighter LOWER bound on the org-name truth — the org-name F1 here is ≥ the string
|
|
372
|
-
// one. The Jaccard gate still prevents collapsing distinct co-located orgs (the gold-set safety). ---
|
|
373
|
-
const COLOCATION_KM = 0.05;
|
|
374
|
-
const npiCoord = new Map();
|
|
375
|
-
for (const rec of records) {
|
|
376
|
-
const c = rec.address?.geocode?.coordinate;
|
|
377
|
-
// first geocoded record per NPI ≈ its primary practice address (primary row is pushed first)
|
|
378
|
-
if (c && !npiCoord.has(rec.id)) {
|
|
379
|
-
npiCoord.set(rec.id, c);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
const parentC = new Map();
|
|
383
|
-
const findC = (x) => {
|
|
384
|
-
if (!parentC.has(x)) {
|
|
385
|
-
parentC.set(x, x);
|
|
386
|
-
}
|
|
387
|
-
let root = x;
|
|
388
|
-
while (parentC.get(root) !== root) {
|
|
389
|
-
root = parentC.get(root);
|
|
390
|
-
}
|
|
391
|
-
while (parentC.get(x) !== root) {
|
|
392
|
-
const next = parentC.get(x);
|
|
393
|
-
parentC.set(x, root);
|
|
394
|
-
x = next;
|
|
395
|
-
}
|
|
396
|
-
return root;
|
|
397
|
-
};
|
|
398
|
-
const unionC = (a, b) => {
|
|
399
|
-
const ra = findC(a);
|
|
400
|
-
const rb = findC(b);
|
|
401
|
-
if (ra !== rb) {
|
|
402
|
-
parentC.set(ra, rb);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
{
|
|
406
|
-
const coLocated = [...npiPrimary.keys()].filter((n) => npiCoord.has(n));
|
|
407
|
-
for (const n of npiPrimary.keys()) {
|
|
408
|
-
findC(n);
|
|
409
|
-
}
|
|
410
|
-
// seed every NPI (un-geocoded ones stay singletons)
|
|
411
|
-
for (let i = 0; i < coLocated.length; i++) {
|
|
412
|
-
for (let j = i + 1; j < coLocated.length; j++) {
|
|
413
|
-
const a = coLocated[i];
|
|
414
|
-
const b = coLocated[j];
|
|
415
|
-
if (haversineKm(npiCoord.get(a), npiCoord.get(b)) > COLOCATION_KM)
|
|
416
|
-
continue;
|
|
417
|
-
if (jaccard(npiPrimary.get(a).tokens, npiPrimary.get(b).tokens) >= ORG_TAU) {
|
|
418
|
-
unionC(a, b);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
134
|
+
const orgNameLabel = buildOrgNameGrain(npiPrimary);
|
|
135
|
+
const npiCoord = collectPrimaryCoordinates(records);
|
|
136
|
+
const orgNameCoordLabel = buildOrgNameCoordGrain(npiPrimary, npiCoord);
|
|
423
137
|
const geocodedNpis = [...npiPrimary.keys()].filter((n) => npiCoord.has(n)).length;
|
|
424
|
-
const orgNameCoordLabel = (rec) => (npiPrimary.has(rec.id) ? findC(rec.id) : rec.id);
|
|
425
|
-
// --- ORG-NAME-H3 entity-truth (#109). The same building-grain co-location, but keyed on an
|
|
426
|
-
// H3 CELL (the geocode-first "cell" the issue suggested) instead of a pairwise 50 m haversine: assign
|
|
427
|
-
// each NPI's coordinate to an H3 cell at building-block resolution, then union same-org (Jaccard ≥
|
|
428
|
-
// ORG_TAU) NPIs that share a cell. A robustness check on the haversine coord-grain — if the F1
|
|
429
|
-
// matches, the number isn't an artifact of the 50 m threshold, and cell-blocking is O(n) not O(n²).
|
|
430
|
-
// Caveat: a hard cell boundary can split a same-building pair into adjacent cells (a slight
|
|
431
|
-
// under-count vs the radius); res 10 (~65 m edge) absorbs most of it. ---
|
|
432
138
|
const H3_RES = options.h3Res ?? 11; // res 11 ≈ 25 m edge; res 10 ≈ 65 m (block scale)
|
|
433
|
-
const
|
|
434
|
-
const findH = (x) => {
|
|
435
|
-
if (!parentH.has(x)) {
|
|
436
|
-
parentH.set(x, x);
|
|
437
|
-
}
|
|
438
|
-
let root = x;
|
|
439
|
-
while (parentH.get(root) !== root) {
|
|
440
|
-
root = parentH.get(root);
|
|
441
|
-
}
|
|
442
|
-
while (parentH.get(x) !== root) {
|
|
443
|
-
const next = parentH.get(x);
|
|
444
|
-
parentH.set(x, root);
|
|
445
|
-
x = next;
|
|
446
|
-
}
|
|
447
|
-
return root;
|
|
448
|
-
};
|
|
449
|
-
const unionH = (a, b) => {
|
|
450
|
-
const ra = findH(a);
|
|
451
|
-
const rb = findH(b);
|
|
452
|
-
if (ra !== rb) {
|
|
453
|
-
parentH.set(ra, rb);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
{
|
|
457
|
-
const byCell = new Map();
|
|
458
|
-
for (const n of npiPrimary.keys()) {
|
|
459
|
-
findH(n); // seed every NPI (un-geocoded ones stay singletons)
|
|
460
|
-
const c = npiCoord.get(n);
|
|
461
|
-
if (!c)
|
|
462
|
-
continue;
|
|
463
|
-
const cell = latLngToCell(c.latitude, c.longitude, H3_RES);
|
|
464
|
-
if (!byCell.has(cell)) {
|
|
465
|
-
byCell.set(cell, []);
|
|
466
|
-
}
|
|
467
|
-
byCell.get(cell).push(n);
|
|
468
|
-
}
|
|
469
|
-
for (const group of byCell.values()) {
|
|
470
|
-
for (let i = 0; i < group.length; i++) {
|
|
471
|
-
for (let j = i + 1; j < group.length; j++) {
|
|
472
|
-
if (jaccard(npiPrimary.get(group[i]).tokens, npiPrimary.get(group[j]).tokens) >= ORG_TAU) {
|
|
473
|
-
unionH(group[i], group[j]);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
const orgNameH3Label = (rec) => (npiPrimary.has(rec.id) ? findH(rec.id) : rec.id);
|
|
139
|
+
const orgNameH3Label = buildOrgNameH3Grain(npiPrimary, npiCoord, H3_RES);
|
|
480
140
|
// --- Phase D: the comparison-model lever progression — toggle each lever ON in turn at the default
|
|
481
141
|
// threshold to isolate its marginal effect, then sweep the link threshold on the best config (geocode
|
|
482
142
|
// once, resolve many — config is cheap). ---
|
|
483
143
|
report?.(`[D] resolving the lever progression${TRAIN_EM ? " (EM-trained)" : ""}…`);
|
|
484
|
-
// The proven levers are now DEFAULT-ON in resolveEntities (#86). Each row sets BOTH `collapseSpatial`
|
|
485
|
-
// and `addressFrequency` EXPLICITLY so the progression isolates one lever at a time — otherwise the
|
|
486
|
-
// flipped default (collapseSpatial:true) would silently ride the `+ inverse-address-frequency` row and
|
|
487
|
-
// the A1 delta would read as 0. Every row feeds the corpus-wide frequency table (the realistic
|
|
488
|
-
// deployment, where the CLI builds it from the full source files); the zero-config `{}` default is
|
|
489
|
-
// reported SEPARATELY below, since on a sub-sample its input-scoped table is intentionally sparse.
|
|
490
|
-
const LEVERS = [
|
|
491
|
-
{
|
|
492
|
-
label: "baseline (legacy: address-key + distance, levers OFF)",
|
|
493
|
-
config: { collapseSpatial: false, addressFrequency: false },
|
|
494
|
-
},
|
|
495
|
-
{ label: "+ inverse-address-frequency (#617, corpus-wide)", config: { collapseSpatial: false, addressFrequency } },
|
|
496
|
-
{ label: "+ collapsed spatial signal (A1, #625)", config: { collapseSpatial: true, addressFrequency } },
|
|
497
|
-
{
|
|
498
|
-
label: "+ authorized-official discriminator (#625)",
|
|
499
|
-
config: { collapseSpatial: true, addressFrequency, discriminators: ["authorizedOfficial"] },
|
|
500
|
-
},
|
|
501
|
-
// A2–A4 (#625): the built-but-unmeasured over-merge levers. Each builds on the A1 + discriminator
|
|
502
|
-
// stack so the marginal effect is isolated. A2 (require name/org corroboration) is the direct
|
|
503
|
-
// over-merge precision lever; A3 (phone) is the recall-tail corroborator that should keep A2 from
|
|
504
|
-
// killing name-drift links; A4 (average-linkage) splits a component joined only by a weak bridge.
|
|
505
|
-
{
|
|
506
|
-
label: "+ require name/org corroboration (A2, #625)",
|
|
507
|
-
config: {
|
|
508
|
-
collapseSpatial: true,
|
|
509
|
-
addressFrequency,
|
|
510
|
-
discriminators: ["authorizedOfficial"],
|
|
511
|
-
requireCorroboration: true,
|
|
512
|
-
},
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
label: "+ phone comparison (A3, #625)",
|
|
516
|
-
config: {
|
|
517
|
-
collapseSpatial: true,
|
|
518
|
-
addressFrequency,
|
|
519
|
-
discriminators: ["authorizedOfficial"],
|
|
520
|
-
requireCorroboration: true,
|
|
521
|
-
usePhone: true,
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
{
|
|
525
|
-
label: "+ average-linkage clustering (A4, #625, full A1–A4 stack)",
|
|
526
|
-
config: {
|
|
527
|
-
collapseSpatial: true,
|
|
528
|
-
addressFrequency,
|
|
529
|
-
discriminators: ["authorizedOfficial"],
|
|
530
|
-
requireCorroboration: true,
|
|
531
|
-
usePhone: true,
|
|
532
|
-
linkage: "average",
|
|
533
|
-
},
|
|
534
|
-
},
|
|
535
|
-
// A5 (#625): the taxonomy code-set discriminator — set-overlap agreement over the NPI's 15 taxonomy
|
|
536
|
-
// slots. The named "still-more-distinctive identifier" from the 2026-06-16 report: co-located
|
|
537
|
-
// DISTINCT providers usually have disjoint sets (the over-merge separator) while an entity's own
|
|
538
|
-
// records always share theirs (never splits). Stacked on the BEST prior classical config (A1 +
|
|
539
|
-
// authorized-official; A3 phone + A4 avg-linkage were measured neutral-to-negative and are left off).
|
|
540
|
-
{
|
|
541
|
-
label: "+ taxonomy code-set discriminator (A5, #625)",
|
|
542
|
-
config: {
|
|
543
|
-
collapseSpatial: true,
|
|
544
|
-
addressFrequency,
|
|
545
|
-
discriminators: ["authorizedOfficial"],
|
|
546
|
-
exactDiscriminators: ["taxonomy"],
|
|
547
|
-
},
|
|
548
|
-
},
|
|
549
|
-
];
|
|
550
144
|
// learnedScorer:false throughout — this benchmark studies the FS COMPARISON-MODEL levers (#617/#625).
|
|
551
145
|
// The learned scorer is now default-on, so it must be pinned off here or every row would silently be the
|
|
552
146
|
// GBT; the learned scorer is measured separately (learned-scorer-clustering-eval / -crossstate-eval).
|
|
553
|
-
const progression =
|
|
147
|
+
const progression = buildLevers(addressFrequency).map((l) => {
|
|
554
148
|
const res = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0, ...l.config });
|
|
555
|
-
return { ...l, res, score:
|
|
149
|
+
return { ...l, res, score: score(res.entities, npiLabel) };
|
|
556
150
|
});
|
|
557
|
-
const
|
|
558
|
-
const bestLever = progression.at(-1);
|
|
559
|
-
// the full lever stack
|
|
151
|
+
const bestLever = progression.at(-1); // the full lever stack
|
|
560
152
|
// The SHIPPED out-of-box default (#86): no lever config at all → resolveEntities auto-computes an
|
|
561
153
|
// input-scoped address-frequency table + collapsed spatial. On this deliberately-sub-sampled corpus the
|
|
562
154
|
// auto table is sparse (few repeats), so the inverse-frequency signal is near-inert and F1 collapses to
|
|
563
155
|
// ≈baseline — NOT a regression, just the honest truth that IDF is a corpus statistic you can't synthesize
|
|
564
156
|
// from a slice. On a FULL-dataset dedup the input IS the corpus and this default reaches the baseline; the
|
|
565
157
|
// CLI passes a corpus-wide table built from the full source files so even a geocoded sub-sample benefits.
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
return { res, score: scoreEntities(res.entities, npiLabel) };
|
|
569
|
-
})();
|
|
158
|
+
const defaultRes = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: 0 });
|
|
159
|
+
const defaultOutOfBox = score(defaultRes.entities, npiLabel);
|
|
570
160
|
const THRESHOLDS = [0, 4, 8, 12, 16, 20];
|
|
571
161
|
const sweep = THRESHOLDS.map((t) => {
|
|
572
162
|
const res = resolveEntities(records, { learnedScorer: false, trainEM: TRAIN_EM, threshold: t, ...bestLever.config });
|
|
573
|
-
return { t, res, score:
|
|
163
|
+
return { t, res, score: score(res.entities, npiLabel) };
|
|
574
164
|
});
|
|
575
165
|
const base = sweep[0]; // threshold 0, full lever stack
|
|
576
166
|
let best = sweep[0];
|
|
@@ -588,62 +178,33 @@ export async function nppesDedupBenchmark(options, report) {
|
|
|
588
178
|
const entityCount = new Set(records.map((r) => entityLabel(r))).size;
|
|
589
179
|
const orgCount = new Set(records.map((r) => orgNameLabel(r))).size;
|
|
590
180
|
const fsNPI = bestLever.score;
|
|
591
|
-
const fsEntity =
|
|
592
|
-
const fsOrg =
|
|
181
|
+
const fsEntity = score(bestLever.res.entities, entityLabel);
|
|
182
|
+
const fsOrg = score(bestLever.res.entities, orgNameLabel);
|
|
593
183
|
const gbtRes = resolveEntities(records, { addressFrequency, trainEM: TRAIN_EM }); // GBT default-on (production)
|
|
594
|
-
const gbtNPI =
|
|
595
|
-
const gbtEntity =
|
|
596
|
-
const gbtOrg =
|
|
184
|
+
const gbtNPI = score(gbtRes.entities, npiLabel);
|
|
185
|
+
const gbtEntity = score(gbtRes.entities, entityLabel);
|
|
186
|
+
const gbtOrg = score(gbtRes.entities, orgNameLabel);
|
|
597
187
|
// Tier 2D: the coordinate-co-location org-name truth (tighter lower bound).
|
|
598
188
|
const orgCoordCount = new Set(records.map((r) => orgNameCoordLabel(r))).size;
|
|
599
|
-
const fsOrgCoord =
|
|
600
|
-
const gbtOrgCoord =
|
|
189
|
+
const fsOrgCoord = score(bestLever.res.entities, orgNameCoordLabel);
|
|
190
|
+
const gbtOrgCoord = score(gbtRes.entities, orgNameCoordLabel);
|
|
601
191
|
// #109: the H3-cell co-location truth — a robustness check on the haversine coord-grain.
|
|
602
192
|
const orgH3Count = new Set(records.map((r) => orgNameH3Label(r))).size;
|
|
603
|
-
const gbtOrgH3 =
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
// per-pair adjudication (same entity? distinct co-located?) is the only instrument left that can
|
|
608
|
-
// separate model error from yardstick error. Each cluster prints its members grouped by org-name
|
|
609
|
-
// label with every matcher-visible field, so a reviewer can adjudicate in one glance.
|
|
193
|
+
const gbtOrgH3 = score(gbtRes.entities, orgNameH3Label);
|
|
194
|
+
// The adjudication packet grades the SHIPPED (GBT) clusters, because the residual over-merge is small and
|
|
195
|
+
// approaching the measured ~1.6% irreducible ceiling — per-pair human adjudication (same entity? distinct
|
|
196
|
+
// co-located?) is the only instrument left that can separate model error from yardstick error.
|
|
610
197
|
const DUMP_OVERMERGES = options.dumpOvermerges || "";
|
|
611
198
|
if (DUMP_OVERMERGES) {
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
"Adjudicate each: **[same]** one real-world entity (yardstick error — the truth under-collapsed) or",
|
|
620
|
-
"**[distinct]** genuinely different co-located providers (model over-merge). Mark inline and return.",
|
|
621
|
-
"",
|
|
622
|
-
];
|
|
623
|
-
let n = 0;
|
|
624
|
-
gbtRes.entities.forEach((e) => {
|
|
625
|
-
const byLabel = new Map();
|
|
626
|
-
for (const rec of e.records) {
|
|
627
|
-
const lbl = orgNameLabel(rec);
|
|
628
|
-
const list = byLabel.get(lbl) ?? [];
|
|
629
|
-
list.push(rec);
|
|
630
|
-
byLabel.set(lbl, list);
|
|
631
|
-
}
|
|
632
|
-
if (byLabel.size <= 1)
|
|
633
|
-
return;
|
|
634
|
-
n++;
|
|
635
|
-
out.push(`## Cluster ${n} — ${e.records.length} records, ${byLabel.size} org-name entities → verdict: [ ]`);
|
|
636
|
-
for (const [lbl, members] of byLabel) {
|
|
637
|
-
out.push(`- **entity ${lbl}**`);
|
|
638
|
-
for (const rec of members) {
|
|
639
|
-
const src = rowByID.get(rec.id);
|
|
640
|
-
out.push(` - npi=${rec.id} · name="${[rec.name?.given, rec.name?.family].filter(Boolean).join(" ")}" · org="${rec.organization?.canonical ?? ""}" · addr="${rec.address?.raw ?? ""}" · auth="${src?.auth ?? ""}" · taxonomy="${src?.taxonomy ?? ""}"`);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
out.push("");
|
|
199
|
+
const clusters = writeOvermergePacket(DUMP_OVERMERGES, {
|
|
200
|
+
state: STATE,
|
|
201
|
+
entities: gbtRes.entities,
|
|
202
|
+
rows,
|
|
203
|
+
recordCount: records.length,
|
|
204
|
+
maxNpis: MAX_NPIS,
|
|
205
|
+
orgNameLabel,
|
|
644
206
|
});
|
|
645
|
-
|
|
646
|
-
report?.(` adjudication packet: ${n} over-merged clusters -> ${DUMP_OVERMERGES}`);
|
|
207
|
+
report?.(` adjudication packet: ${clusters} over-merged clusters -> ${DUMP_OVERMERGES}`);
|
|
647
208
|
}
|
|
648
209
|
// Optional candidate A/B (--candidate): score a trained GBT module at both levels, at its own
|
|
649
210
|
// recommendedThreshold, alongside the shipped GBT — grades a new model (e.g. corroboration features).
|
|
@@ -660,175 +221,41 @@ export async function nppesDedupBenchmark(options, report) {
|
|
|
660
221
|
const cost = mod.DEDUP_GBT_META?.costNegative ?? 1;
|
|
661
222
|
cand = {
|
|
662
223
|
label: `GBT candidate (${mod.DEDUP_GBT_META?.features ?? "?"}-feat${cost !== 1 ? `, cost ×${cost}` : ""})`,
|
|
663
|
-
npi:
|
|
664
|
-
entity:
|
|
224
|
+
npi: score(res.entities, npiLabel),
|
|
225
|
+
entity: score(res.entities, entityLabel),
|
|
665
226
|
};
|
|
666
227
|
report?.(` candidate ${CANDIDATE}: NPI ${(100 * cand.npi.f1).toFixed(1)}% / entity ${(100 * cand.entity.f1).toFixed(1)}%`);
|
|
667
228
|
}
|
|
668
229
|
report?.(` truth-grains — GBT NPI ${(100 * gbtNPI.f1).toFixed(1)}% → site ${(100 * gbtEntity.f1).toFixed(1)}% → org-name ${(100 * gbtOrg.f1).toFixed(1)}% → org-name-coord ${(100 * gbtOrgCoord.f1).toFixed(1)}% → org-name-h3 ${(100 * gbtOrgH3.f1).toFixed(1)}% (res ${H3_RES}); ` +
|
|
669
230
|
`FS: NPI ${(100 * fsNPI.f1).toFixed(1)}% / entity ${(100 * fsEntity.f1).toFixed(1)}% / org-coord ${(100 * fsOrgCoord.f1).toFixed(1)}%`);
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
const bold = i === progression.length - 1;
|
|
698
|
-
const w = (s) => (bold ? `**${s}**` : s);
|
|
699
|
-
lines.push(`| ${w(p.label)} | ${w(pct(p.score.precision) + "%")} | ${w(pct(p.score.recall) + "%")} | ${w(pct(p.score.f1) + "%")} | ${delta} | ${w(p.score.ari.toFixed(3))} | ${w(String(p.score.overMergedClusters))} |`);
|
|
231
|
+
const md = renderNPPESDedupReport({
|
|
232
|
+
state: STATE,
|
|
233
|
+
keptNpis: keptNpis.size,
|
|
234
|
+
recordCount: N,
|
|
235
|
+
geocoded: geo,
|
|
236
|
+
trainEM: TRAIN_EM,
|
|
237
|
+
addressFrequency,
|
|
238
|
+
progression,
|
|
239
|
+
defaultOutOfBox,
|
|
240
|
+
sweep,
|
|
241
|
+
best,
|
|
242
|
+
entityCount,
|
|
243
|
+
orgCount,
|
|
244
|
+
orgCoordCount,
|
|
245
|
+
orgH3Count,
|
|
246
|
+
fsNPI,
|
|
247
|
+
fsEntity,
|
|
248
|
+
fsOrg,
|
|
249
|
+
fsOrgCoord,
|
|
250
|
+
gbtNPI,
|
|
251
|
+
gbtEntity,
|
|
252
|
+
gbtOrg,
|
|
253
|
+
gbtOrgCoord,
|
|
254
|
+
gbtOrgH3,
|
|
255
|
+
candidate: cand,
|
|
256
|
+
h3Res: H3_RES,
|
|
257
|
+
geocodedNpis,
|
|
700
258
|
});
|
|
701
|
-
lines.push("");
|
|
702
|
-
lines.push(`Inverse-frequency weighting uses the corpus-wide table (${addrCounts.size.toLocaleString()} distinct addresses ` +
|
|
703
|
-
`over ${addrTotal.toLocaleString()} providers) to down-weight a crowded shared address; collapsing the redundant ` +
|
|
704
|
-
`address-key + distance comparisons into one spatial signal (A1) removes the double-count that let a shared address ` +
|
|
705
|
-
`over-vote a disagreeing name. The address-frequency + A1 baseline is F1 ${pct(progression[2].score.f1)}% at the ` +
|
|
706
|
-
`default threshold; the **authorized-official discriminator** is roughly neutral there (${signed(100 * (bestLever.score.f1 - progression[2].score.f1))}) ` +
|
|
707
|
-
`but enables a higher cutoff — it holds recall where the baseline alone collapses, reaching **${pct(best.score.f1)}%** at ` +
|
|
708
|
-
`threshold ${best.t} (below), the first config past the baseline (#625).`);
|
|
709
|
-
lines.push("");
|
|
710
|
-
lines.push(`**Out-of-the-box (zero-config \`resolveEntities(records)\`, levers default-on #86):** F1 ` +
|
|
711
|
-
`**${pct(defaultOutOfBox.score.f1)}%** on this sample — essentially the baseline. The default auto-computes the ` +
|
|
712
|
-
`address-frequency table over the INPUT records, and this benchmark deliberately sub-samples ${N} records, so ` +
|
|
713
|
-
`that table is too sparse to carry the inverse-frequency signal (a corpus statistic you can't synthesize from a ` +
|
|
714
|
-
`slice). It's **not a regression** (≥ baseline, no over-merge added) — it's the honest floor when the input isn't ` +
|
|
715
|
-
`corpus-scale. Fed the corpus-wide table (the \`+ inverse-address-frequency\` row above, what the CLI builds from ` +
|
|
716
|
-
`the full source files) the SAME default reaches the **${pct(progression[2].score.f1)}%** baseline. On a full-dataset ` +
|
|
717
|
-
`dedup the input IS the corpus, so zero-config reaches the baseline on its own.`);
|
|
718
|
-
lines.push("");
|
|
719
|
-
lines.push(`## With all levers on, across the link threshold (the secondary lever)`);
|
|
720
|
-
lines.push("");
|
|
721
|
-
lines.push(`| link threshold (bits) | precision | recall | F1 | ARI | clusters | over-merged |`);
|
|
722
|
-
lines.push(`|---:|---:|---:|---:|---:|---:|---:|`);
|
|
723
|
-
for (const s of sweep) {
|
|
724
|
-
const star = s === best ? " ⭐" : "";
|
|
725
|
-
lines.push(`| ${s.t}${s.t === 0 ? " (default)" : ""} | ${pct(s.score.precision)}% | ${pct(s.score.recall)}% | **${pct(s.score.f1)}%**${star} | ${s.score.ari.toFixed(3)} | ${s.score.clusters} | ${s.score.overMergedClusters} |`);
|
|
726
|
-
}
|
|
727
|
-
lines.push("");
|
|
728
|
-
lines.push(best.t === 0
|
|
729
|
-
? `Best F1 is at the **default threshold** (${pct(base.score.f1)}%): raising it only trades recall away faster ` +
|
|
730
|
-
`than it buys precision. So the threshold knob alone can't separate co-located distinct providers — the ` +
|
|
731
|
-
`over-merge is structural, in the comparison model, not the cutoff.`
|
|
732
|
-
: `Best F1 **${pct(best.score.f1)}%** (ARI ${best.score.ari.toFixed(3)}) at threshold ${best.t}, vs **${pct(base.score.f1)}%** at the ` +
|
|
733
|
-
`default — the threshold knob moves it ${(100 * (best.score.f1 - base.score.f1)).toFixed(0)}pp. Higher thresholds trade recall for precision.`);
|
|
734
|
-
lines.push("");
|
|
735
|
-
lines.push(`## Shape + where the errors are (at the default threshold)`);
|
|
736
|
-
lines.push("");
|
|
737
|
-
lines.push(`- records: ${N} · true entities (NPIs): ${kept.size} · recovered clusters: ${base.score.clusters}`);
|
|
738
|
-
lines.push(`- candidate pairs blocked: ${base.res.candidatePairs}${base.res.droppedBlocks.length ? ` · oversized blocks skipped: ${base.res.droppedBlocks.length}` : ""}`);
|
|
739
|
-
lines.push(`- **Over-merge (precision):** ${base.score.overMergedClusters} clusters fuse ≥2 distinct NPIs (largest fuses ` +
|
|
740
|
-
`${base.score.maxNpisFused}; ${base.score.recordsInOverMerged} records) — **co-located providers sharing a clinic / ` +
|
|
741
|
-
`billing address**, linked by address agreement despite different names.`);
|
|
742
|
-
lines.push(`- **Under-merge (recall):** ${base.score.splitNpis}/${kept.size} NPIs split across >1 cluster — records at distant ` +
|
|
743
|
-
`addresses (mailing vs practice) or with strong name drift the score didn't bridge.`);
|
|
744
|
-
lines.push("");
|
|
745
|
-
lines.push(`## Three truth grains — NPI → site → org-name (the over-segmentation correction)`);
|
|
746
|
-
lines.push("");
|
|
747
|
-
lines.push(`NPI-as-truth OVER-SEGMENTS: one org holds many NPIs, so the matcher's correct co-located merges are scored as ` +
|
|
748
|
-
`errors. Three yardsticks, same clusters: **NPI** (one entity per registration), **site** (subpart-flagged ` +
|
|
749
|
-
`collapse + split an NPI's distinct addresses), and **org-name** — the gold-set-validated truth: same NPI ⇒ ` +
|
|
750
|
-
`same entity (recall preserved) PLUS collapse co-located NPIs whose primary org names match (Jaccard ≥ ${ORG_TAU}), ` +
|
|
751
|
-
`with NO reliance on the subpart flag (the gold set showed it misses 37%). The same ${N} records carry ` +
|
|
752
|
-
`**${kept.size} NPI** → **${entityCount} site** → **${orgCount} org-name** classes. The org-name number is the ` +
|
|
753
|
-
`honest one: it stops charging the matcher for the same-org merges the gold set proved are correct.`);
|
|
754
|
-
lines.push("");
|
|
755
|
-
lines.push(`| config | truth | precision | recall | F1 | ΔF1 vs NPI | ARI | over-merged |`);
|
|
756
|
-
lines.push(`|---|---|---:|---:|---:|---:|---:|---:|`);
|
|
757
|
-
const dualRow = (label, truth, s, delta) => lines.push(`| ${label} | ${truth} | ${pct(s.precision)}% | ${pct(s.recall)}% | **${pct(s.f1)}%** | ${delta === undefined ? "—" : signed(100 * delta)} | ${s.ari.toFixed(3)} | ${s.overMergedClusters} |`);
|
|
758
|
-
dualRow("FS full stack", "NPI", fsNPI);
|
|
759
|
-
dualRow("FS full stack", "site", fsEntity, fsEntity.f1 - fsNPI.f1);
|
|
760
|
-
dualRow("FS full stack", "**org-name**", fsOrg, fsOrg.f1 - fsNPI.f1);
|
|
761
|
-
dualRow("FS full stack", "org-name (coord)", fsOrgCoord, fsOrgCoord.f1 - fsNPI.f1);
|
|
762
|
-
dualRow("GBT (shipped default)", "NPI", gbtNPI);
|
|
763
|
-
dualRow("GBT (shipped default)", "site", gbtEntity, gbtEntity.f1 - gbtNPI.f1);
|
|
764
|
-
dualRow("GBT (shipped default)", "**org-name**", gbtOrg, gbtOrg.f1 - gbtNPI.f1);
|
|
765
|
-
dualRow("GBT (shipped default)", "**org-name (coord)**", gbtOrgCoord, gbtOrgCoord.f1 - gbtNPI.f1);
|
|
766
|
-
dualRow("GBT (shipped default)", `org-name (H3 res ${H3_RES})`, gbtOrgH3, gbtOrgH3.f1 - gbtNPI.f1);
|
|
767
|
-
if (cand) {
|
|
768
|
-
dualRow(cand.label, "NPI", cand.npi);
|
|
769
|
-
dualRow(cand.label, "**entity**", cand.entity, cand.entity.f1 - cand.npi.f1);
|
|
770
|
-
}
|
|
771
|
-
lines.push("");
|
|
772
|
-
lines.push(`The F1 **climbs as the yardstick gets honest**: GBT **${pct(gbtNPI.f1)}% (NPI) → ${pct(gbtEntity.f1)}% (site) → ` +
|
|
773
|
-
`${pct(gbtOrg.f1)}% (org-name)**, the over-merge collapsing (${gbtNPI.overMergedClusters} → ${gbtOrg.overMergedClusters}) ` +
|
|
774
|
-
`and precision rising (${pct(gbtNPI.precision)}% → ${pct(gbtOrg.precision)}%). The clusters are IDENTICAL across the three ` +
|
|
775
|
-
`columns — the climb is purely the ruler ceasing to charge the matcher for the correct same-org merges the gold set proved ` +
|
|
776
|
-
`(\`2026-06-16-dedup-gold-set-tx120.md\`: 120/120 same org, 0 genuine over-merges).`);
|
|
777
|
-
lines.push("");
|
|
778
|
-
lines.push(`**Tier 2D — tightening the org-name ruler with the geocode coordinate.** The org-name truth above blocks by the address ` +
|
|
779
|
-
`STRING (\`addressFrequencyKey\`), so two records at one building whose text differs — \`1504 Taub LOOP\` vs ` +
|
|
780
|
-
`\`1504 Taub LP STE 100\` — key apart and the merge is still charged as an error. Block by the GEOCODED BUILDING instead ` +
|
|
781
|
-
`(union co-located NPIs within ${COLOCATION_KM * 1000} m whose org names agree, same Jaccard gate) and the truth tightens ` +
|
|
782
|
-
`further: GBT **org-name ${pct(gbtOrg.f1)}% → org-name-coord ${pct(gbtOrgCoord.f1)}%** ` +
|
|
783
|
-
`(${signed(100 * (gbtOrgCoord.f1 - gbtOrg.f1))}), ${orgCount} → ${orgCoordCount} classes, over ${geocodedNpis}/${kept.size} ` +
|
|
784
|
-
`geocoded NPIs. The string org-name F1 is a conservative LOWER bound; the coordinate one is tighter (the Jaccard gate ` +
|
|
785
|
-
`still blocks distinct co-located orgs). Both are honest — the coordinate is the geocode-first key.`);
|
|
786
|
-
lines.push("");
|
|
787
|
-
lines.push(`**H3-cell robustness check (#109).** Re-keying the same building-grain co-location on an H3 cell ` +
|
|
788
|
-
`(res ${H3_RES}) instead of the 50 m haversine radius — the deterministic, O(n) "geocode-first cell" the issue ` +
|
|
789
|
-
`suggested — gives GBT **org-name-h3 ${pct(gbtOrgH3.f1)}%** (${orgH3Count} classes), vs the haversine ` +
|
|
790
|
-
`${pct(gbtOrgCoord.f1)}% (${orgCoordCount}). ${Math.abs(gbtOrgH3.f1 - gbtOrgCoord.f1) < BLOCKING_PARITY_TOLERANCE
|
|
791
|
-
? "Within noise of the haversine grain — the ~" +
|
|
792
|
-
pct(gbtOrgCoord.f1) +
|
|
793
|
-
"% coord-grain F1 is robust to the co-location method, not an artifact of the 50 m threshold."
|
|
794
|
-
: "The two co-location methods differ by " +
|
|
795
|
-
signed(100 * (gbtOrgH3.f1 - gbtOrgCoord.f1)) +
|
|
796
|
-
" — the cell-vs-radius boundary handling shifts the count (a hard H3 boundary can split a same-building pair into adjacent cells)."}`);
|
|
797
|
-
lines.push("");
|
|
798
|
-
lines.push(`**Takeaways:** (1) The dedup model's REAL quality is the **org-name F1 ~${pct(gbtOrg.f1)}%**, not the NPI-level ` +
|
|
799
|
-
`${pct(gbtNPI.f1)}% — the difference was NPI over-segmentation, not model error. (2) The #625 lever was the YARDSTICK, ` +
|
|
800
|
-
`not the scorer: the corroboration-feature experiment (reverted) couldn't move precision because the over-merge was ` +
|
|
801
|
-
`mostly correct. (3) The remaining org-name over-merge (${gbtOrg.overMergedClusters} clusters) is the genuine frontier — ` +
|
|
802
|
-
`small, approaching the ceiling's ~1.6% irreducible (\`2026-06-16-dedup-ceiling.md\`). (4) Trust the large eval: a 50-NPI ` +
|
|
803
|
-
`smoke misled on the site delta (+5–7pp vs this run's ±2pp).`);
|
|
804
|
-
lines.push("");
|
|
805
|
-
lines.push(`Caveats: the programmatic site-truth is CONSERVATIVE (collapses only NPPES-flagged subparts; unflagged same-org pairs still ` +
|
|
806
|
-
`read as over-merge), so it understates the subpart correction. A hand-adjudicated gold set on the ambiguous co-located + ` +
|
|
807
|
-
`two-site slice is the next refinement (#625).`);
|
|
808
|
-
lines.push("");
|
|
809
|
-
lines.push(`## Reading`);
|
|
810
|
-
lines.push("");
|
|
811
|
-
lines.push(`The geocode-first **foundation works**: **${pct(geo / N)}%** of addresses placed, blocking + clustering clean — the ` +
|
|
812
|
-
`geocoding (the Pelias/Nominatim-can't-do-this part) is not the bottleneck. The comparison-model levers reach the ` +
|
|
813
|
-
`address-frequency + A1 baseline at F1 **${pct(progression[2].score.f1)}%** (${signed(100 * (progression[2].score.f1 - baseline.score.f1))} over baseline): ` +
|
|
814
|
-
`inverse-frequency weighting restores full weight to a *rare* shared address (stitching a provider's name-drifted ` +
|
|
815
|
-
`records together — mostly recall) while down-weighting a *crowded* one, and the collapsed spatial signal (A1) drops ` +
|
|
816
|
-
`the address+distance double-count. What remains is **precision / over-merge** — ${bestLever.score.overMergedClusters} ` +
|
|
817
|
-
`clusters still fuse distinct co-located providers, because even one down-weighted spatial agreement can outvote a ` +
|
|
818
|
-
`disagreeing name. The lever search (#625) — two negatives, then the first positive: a name/org/phone ` +
|
|
819
|
-
`**corroboration gate** (A2/A3) — phone is an unreliable secondary identifier on NPPES (shared institutional ` +
|
|
820
|
-
`switchboard lines), so it over-links and falsely corroborates co-phone distinct providers; and **average-linkage ` +
|
|
821
|
-
`clustering** (A4) — the over-merged clusters are joined by STRONG shared-address edges, not weak bridges, so ` +
|
|
822
|
-
`average-linkage can't split them and only trades away name-drift recall. The over-merge is a **scoring** problem ` +
|
|
823
|
-
`this data can't resolve, not a clustering-topology one. The **authorized-official discriminator** is the first lever to beat the baseline — a reliable secondary identifier holds recall so a higher threshold separates the co-located providers; a still-more-distinctive identifier ` +
|
|
824
|
-
`(taxonomy / license) or a learned scorer over the FS feature vector (#603) goes further. Config ` +
|
|
825
|
-
`dominates the model (the pre-registered finding) — tracked as #625 / the selective-model work (#602 / #603).`);
|
|
826
|
-
lines.push("");
|
|
827
|
-
lines.push(`NPI-as-truth is **conservative**: a cluster fusing two NPIs is a candidate "same entity, two NPIs" surfaced for ` +
|
|
828
|
-
`review, not an adjudicated error; an NPI split across genuinely-distant addresses is geo-first behaving correctly, ` +
|
|
829
|
-
`counted here as a recall miss. We resolve and report; interpretation is the consumer's.`);
|
|
830
|
-
lines.push("");
|
|
831
|
-
const md = lines.join("\n");
|
|
832
259
|
console.log(md);
|
|
833
260
|
if (OUT_MD) {
|
|
834
261
|
writeFileSync(OUT_MD, md);
|