@mailwoman/registry 9.1.0 → 9.3.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 +2 -2
- package/{address-key.ts → lib/address-key.ts} +1 -1
- package/{geocode-handler.ts → lib/geocode-handler.ts} +7 -7
- package/{geojson.ts → lib/geojson.ts} +12 -6
- package/{index.ts → lib/index.ts} +10 -10
- package/{ingest.ts → lib/ingest.ts} +77 -69
- package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
- package/{map-html.ts → lib/map-html.ts} +10 -16
- package/{reconcile.ts → lib/reconcile.ts} +9 -24
- package/{resolve.ts → lib/resolve.ts} +31 -13
- package/{tools → lib/tools}/coverage-reconciliation.ts +13 -15
- package/{tools → lib/tools}/cross-dataset-correlation.ts +64 -139
- package/{tools → lib/tools}/cross-source-threshold-sweep.ts +21 -32
- package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
- package/{tools → lib/tools}/eval-geocoder.ts +10 -11
- package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
- package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +12 -11
- package/lib/tools/gold-set-sample.ts +141 -0
- package/lib/tools/index.ts +31 -0
- package/{tools → lib/tools}/learned-scorer-clustering-eval.ts +71 -260
- package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +62 -245
- package/{tools → lib/tools}/learned-scorer-eval.ts +64 -263
- package/{tools → lib/tools}/matcher-scale.ts +5 -5
- package/lib/tools/nppes/org-name.ts +23 -0
- package/lib/tools/nppes/overmerge-packet.ts +94 -0
- package/lib/tools/nppes/report.ts +373 -0
- package/lib/tools/nppes/sample.ts +245 -0
- package/lib/tools/nppes/scoring.ts +114 -0
- package/lib/tools/nppes/settings.ts +102 -0
- package/lib/tools/nppes/truth-grains.ts +161 -0
- package/lib/tools/nppes-dedup-benchmark.ts +408 -0
- package/lib/tools/shared.ts +763 -0
- package/lib/tools/train-cross-gbt.ts +209 -0
- package/{tools → lib/tools}/train-gbt.ts +38 -156
- package/lib/tools/train-org-cross-gbt.ts +179 -0
- package/{tools → lib/tools}/txhhsc-to-oarow.ts +10 -28
- package/lib/tools/viz/browser.ts +50 -0
- package/{tools → lib/tools}/viz/cross-dataset-map.ts +16 -39
- package/{tools → lib/tools}/viz/geocode-first-surface.ts +13 -39
- package/{tools → lib/tools}/viz/render-map.ts +10 -23
- package/lib/tools/viz/render.ts +98 -0
- package/{tools → lib/tools}/viz/source-provenance-map.ts +20 -39
- package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
- package/{types.ts → lib/types.ts} +10 -1
- package/out/address-key.d.ts +1 -1
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -6
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +6 -6
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +7 -2
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +8 -5
- package/out/geojson.js.map +1 -1
- package/out/index.d.ts +10 -10
- package/out/index.d.ts.map +1 -1
- package/out/index.js +10 -10
- package/out/index.js.map +1 -1
- package/out/ingest.d.ts +64 -46
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +33 -46
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +1 -1
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +4 -4
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +6 -11
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +6 -1
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +7 -21
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +19 -7
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +20 -6
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +1 -1
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +12 -12
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross-dataset-correlation.d.ts +4 -4
- package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross-dataset-correlation.js +60 -111
- package/out/tools/cross-dataset-correlation.js.map +1 -1
- package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
- package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross-source-threshold-sweep.js +19 -27
- 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 +36 -118
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +9 -13
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +2 -2
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder-namesake-probe.d.ts +2 -2
- package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder-namesake-probe.js +4 -8
- package/out/tools/geocoder-namesake-probe.js.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.js +11 -9
- package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +5 -5
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +37 -121
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +24 -29
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +24 -29
- package/out/tools/index.js.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.js +35 -170
- package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js +44 -166
- package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
- package/out/tools/learned-scorer-eval.d.ts +1 -1
- package/out/tools/learned-scorer-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-eval.js +37 -173
- 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 +5 -5
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +21 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +13 -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 +186 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +90 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +131 -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/settings.d.ts +38 -0
- package/out/tools/nppes/settings.d.ts.map +1 -0
- package/out/tools/nppes/settings.js +79 -0
- package/out/tools/nppes/settings.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 +123 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/nppes-dedup-benchmark.d.ts +7 -3
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +106 -673
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts +244 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +353 -21
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train-cross-gbt.d.ts +7 -7
- package/out/tools/train-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-cross-gbt.js +47 -145
- package/out/tools/train-cross-gbt.js.map +1 -1
- package/out/tools/train-gbt.d.ts +7 -7
- package/out/tools/train-gbt.d.ts.map +1 -1
- package/out/tools/train-gbt.js +31 -111
- package/out/tools/train-gbt.js.map +1 -1
- package/out/tools/train-org-cross-gbt.d.ts +7 -5
- package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-org-cross-gbt.js +45 -141
- package/out/tools/train-org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +2 -2
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +9 -23
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +34 -0
- package/out/tools/viz/browser.d.ts.map +1 -0
- package/out/tools/viz/browser.js +33 -0
- package/out/tools/viz/browser.js.map +1 -0
- package/out/tools/viz/cross-dataset-map.d.ts +4 -25
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +12 -33
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +6 -35
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +10 -37
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render-map.d.ts +3 -6
- package/out/tools/viz/render-map.d.ts.map +1 -1
- package/out/tools/viz/render-map.js +9 -19
- package/out/tools/viz/render-map.js.map +1 -1
- package/out/tools/viz/render.d.ts +4 -9
- package/out/tools/viz/render.d.ts.map +1 -1
- package/out/tools/viz/render.js +24 -39
- package/out/tools/viz/render.js.map +1 -1
- package/out/tools/viz/source-provenance-map.d.ts +4 -24
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +12 -32
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -2
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +5 -4
- package/out/tools/viz/yardstick-figure.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 +180 -11
- package/tools/gold-set-sample.ts +0 -252
- package/tools/index.ts +0 -36
- package/tools/nppes-dedup-benchmark.ts +0 -1180
- package/tools/shared.ts +0 -160
- package/tools/train-cross-gbt.ts +0 -358
- package/tools/train-org-cross-gbt.ts +0 -329
- package/tools/viz/render.ts +0 -113
- /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
|
@@ -28,38 +28,36 @@
|
|
|
28
28
|
* [--out-md <md>]`
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
import {
|
|
31
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
32
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
33
|
+
import { makeLcg } from "@mailwoman/core/random"
|
|
34
34
|
import { block, gbtScore, trainGBT } from "@mailwoman/match"
|
|
35
|
+
|
|
35
36
|
import {
|
|
36
|
-
addressFrequencyKey,
|
|
37
37
|
buildDefaultModel,
|
|
38
38
|
createMatchFeaturizer,
|
|
39
39
|
defaultBlockingKeys,
|
|
40
40
|
ingestRows,
|
|
41
41
|
resolveEntities,
|
|
42
|
-
streamRows,
|
|
43
42
|
type ColumnMapping,
|
|
44
|
-
type ResolvedEntity,
|
|
45
43
|
type SourceRecord,
|
|
46
|
-
} from "
|
|
47
|
-
|
|
48
|
-
import
|
|
44
|
+
} from "#index"
|
|
45
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
46
|
+
import { buildNPPESSample } from "#tools/nppes/sample"
|
|
47
|
+
import { scoreEntities } from "#tools/nppes/scoring"
|
|
49
48
|
import {
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
bestOver,
|
|
50
|
+
mean,
|
|
52
51
|
MIN_MEANINGFUL_F1_DELTA,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const MAX_K = 32
|
|
52
|
+
pct,
|
|
53
|
+
quantileThresholds,
|
|
54
|
+
sgn,
|
|
55
|
+
stateOption,
|
|
56
|
+
std,
|
|
57
|
+
toArmScore,
|
|
58
|
+
trainLogisticRegression,
|
|
59
|
+
type ArmScore,
|
|
60
|
+
} from "#tools/shared"
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Options for {@linkcode scorerClusteringEval}.
|
|
@@ -99,61 +97,6 @@ export interface ScorerClusteringEvalOptions {
|
|
|
99
97
|
outMd?: string
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
interface MessyRow {
|
|
103
|
-
npi: string
|
|
104
|
-
name: string
|
|
105
|
-
org: string
|
|
106
|
-
address: string
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const choose2 = (n: number) => (n * (n - 1)) / 2
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* The dedup benchmark's pairwise clustering metric vs the NPI grouping (record.id = NPI).
|
|
113
|
-
*/
|
|
114
|
-
function scoreClusters(
|
|
115
|
-
entities: ResolvedEntity[],
|
|
116
|
-
n: number
|
|
117
|
-
): { precision: number; recall: number; f1: number; overMerged: number } {
|
|
118
|
-
const npiTotals = new Map<string, number>()
|
|
119
|
-
let sumCK = 0
|
|
120
|
-
let sumCluster = 0
|
|
121
|
-
let overMerged = 0
|
|
122
|
-
|
|
123
|
-
for (const e of entities) {
|
|
124
|
-
const byNPI = new Map<string, number>()
|
|
125
|
-
|
|
126
|
-
for (const rec of e.records) {
|
|
127
|
-
byNPI.set(rec.id, (byNPI.get(rec.id) ?? 0) + 1)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
sumCluster += choose2(e.records.length)
|
|
131
|
-
|
|
132
|
-
if (byNPI.size > 1) {
|
|
133
|
-
overMerged++
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (const [npi, c] of byNPI) {
|
|
137
|
-
sumCK += choose2(c)
|
|
138
|
-
npiTotals.set(npi, (npiTotals.get(npi) ?? 0) + c)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
let sumClass = 0
|
|
143
|
-
|
|
144
|
-
for (const total of npiTotals.values()) {
|
|
145
|
-
sumClass += choose2(total)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
void n
|
|
149
|
-
const tp = sumCK
|
|
150
|
-
const precision = sumCluster > 0 ? tp / sumCluster : 0
|
|
151
|
-
const recall = sumClass > 0 ? tp / sumClass : 0
|
|
152
|
-
const f1 = precision + recall > 0 ? (2 * precision * recall) / (precision + recall) : 0
|
|
153
|
-
|
|
154
|
-
return { precision, recall, f1, overMerged }
|
|
155
|
-
}
|
|
156
|
-
|
|
157
100
|
/**
|
|
158
101
|
* Learned-scorer clustering A/B (#603 Tier 2) — see the module doc. Emits the markdown report to stdout.
|
|
159
102
|
*/
|
|
@@ -162,7 +105,7 @@ export async function scorerClusteringEval(
|
|
|
162
105
|
report?: (line: string) => void
|
|
163
106
|
): Promise<{ markdown: string }> {
|
|
164
107
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
165
|
-
const STATE = (options
|
|
108
|
+
const STATE = stateOption(options)
|
|
166
109
|
const NPIS = options.npis ?? 2000
|
|
167
110
|
const SPLIT = options.split ?? 0.67
|
|
168
111
|
const SEED = options.seed ?? 1
|
|
@@ -171,93 +114,36 @@ export async function scorerClusteringEval(
|
|
|
171
114
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
172
115
|
const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
|
|
173
116
|
|
|
174
|
-
// --- Data-gen: the same NPI-keyed records as the dedup benchmark + the pairwise probe
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (list.length < MIN_GROUP_SIZE) {
|
|
186
|
-
list.push(alt)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
altNames.set(npi, list)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
report?.(`[B] full registry pass: address-frequency table + ${NPIS} ${STATE} sample…`)
|
|
193
|
-
const rows: MessyRow[] = []
|
|
194
|
-
const kept = new Set<string>()
|
|
195
|
-
const addrCounts = new Map<string, number>()
|
|
196
|
-
let addrTotal = 0
|
|
197
|
-
let scanned = 0
|
|
198
|
-
|
|
199
|
-
for await (const r of streamRows(REGISTRY)) {
|
|
200
|
-
if (++scanned % 1_000_000 === 0) {
|
|
201
|
-
report?.(` scanned ${scanned / 1e6}M, kept ${kept.size}`)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const practice = addr(r[C.pAddr]!, r[C.pCity]!, r[C.pState]!, r[C.pZip]!)
|
|
205
|
-
|
|
206
|
-
if (practice) {
|
|
207
|
-
const k = addressFrequencyKey(practice)
|
|
208
|
-
addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1)
|
|
209
|
-
|
|
210
|
-
addrTotal++
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const npi = norm(r[C.npi])
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
kept.size < NPIS &&
|
|
217
|
-
npi &&
|
|
218
|
-
!kept.has(npi) &&
|
|
219
|
-
altNames.has(npi) &&
|
|
220
|
-
practice &&
|
|
221
|
-
norm(r[C.pState]).toUpperCase() === STATE
|
|
222
|
-
) {
|
|
223
|
-
const isOrg = norm(r[C.entityType]) === "2"
|
|
224
|
-
const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim()
|
|
225
|
-
|
|
226
|
-
if (primaryName) {
|
|
227
|
-
const org = isOrg ? norm(r[C.orgLegal]) : ""
|
|
228
|
-
kept.add(npi)
|
|
229
|
-
rows.push({ npi, name: primaryName, org, address: practice })
|
|
230
|
-
|
|
231
|
-
for (const alt of altNames.get(npi)!) {
|
|
232
|
-
rows.push({ npi, name: alt, org: alt, address: practice })
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const mailing = addr(r[C.mAddr]!, r[C.mCity]!, r[C.mState]!, r[C.mZip]!)
|
|
236
|
-
|
|
237
|
-
if (mailing && mailing !== practice) {
|
|
238
|
-
rows.push({ npi, name: primaryName, org, address: mailing })
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const addressFrequency = {
|
|
245
|
-
total: addrTotal,
|
|
246
|
-
distinct: addrCounts.size,
|
|
247
|
-
frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
report?.(` ${kept.size} NPIs → ${rows.length} records`)
|
|
117
|
+
// --- Data-gen: the same NPI-keyed records as the dedup benchmark + the pairwise probe (the SHARED
|
|
118
|
+
// sample builder). ---
|
|
119
|
+
const {
|
|
120
|
+
rows,
|
|
121
|
+
keptNpis: kept,
|
|
122
|
+
addressFrequency,
|
|
123
|
+
} = await buildNPPESSample(
|
|
124
|
+
{ registryPath: REGISTRY, otherNamesPath: OTHER_NAMES, state: STATE, maxNpis: NPIS },
|
|
125
|
+
report
|
|
126
|
+
)
|
|
251
127
|
|
|
252
128
|
report?.("[C] geocoding…")
|
|
253
129
|
const geocoder = await options.createGeocoder()
|
|
254
|
-
const mapping: ColumnMapping = { id: "npi", name: "name", organization: "org", address: "address", source: "nppes" }
|
|
255
130
|
|
|
256
|
-
|
|
257
|
-
|
|
131
|
+
// `auth`/`taxonomy` ride as attributes so the SHARED featurizer's #625 roll-up features can read the
|
|
132
|
+
// authorized official; the FS arm ignores them (no discriminators configured).
|
|
133
|
+
const mapping: ColumnMapping = {
|
|
134
|
+
id: "npi",
|
|
135
|
+
name: "name",
|
|
136
|
+
organization: "org",
|
|
137
|
+
address: "address",
|
|
138
|
+
attributes: { authorizedOfficial: "auth", taxonomy: "taxonomy" },
|
|
139
|
+
source: "nppes",
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const records = await ingestRows(rows, mapping, {
|
|
143
|
+
geocodeAddress: geocoder.geocodeAddress,
|
|
258
144
|
})
|
|
259
145
|
|
|
260
|
-
geocoder.
|
|
146
|
+
geocoder[Symbol.dispose]()
|
|
261
147
|
|
|
262
148
|
// --- The feature basis: address-frequency + collapsed-spatial model (the baseline). The agreement
|
|
263
149
|
// pattern is EM-independent, so the same featurize() is consistent at train and inference time. ---
|
|
@@ -266,12 +152,7 @@ export async function scorerClusteringEval(
|
|
|
266
152
|
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
267
153
|
const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
|
|
268
154
|
|
|
269
|
-
|
|
270
|
-
precision: number
|
|
271
|
-
recall: number
|
|
272
|
-
f1: number
|
|
273
|
-
overMerged: number
|
|
274
|
-
}
|
|
155
|
+
const npiLabel = (rec: SourceRecord) => rec.id
|
|
275
156
|
|
|
276
157
|
interface SeedResult {
|
|
277
158
|
seed: number
|
|
@@ -308,94 +189,37 @@ export async function scorerClusteringEval(
|
|
|
308
189
|
const dim = trainX[0]?.length ?? 0
|
|
309
190
|
const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
|
|
310
191
|
|
|
311
|
-
// LR (batch GD, class-balanced) — same as the pairwise probe.
|
|
312
|
-
const
|
|
313
|
-
let bias = 0
|
|
314
|
-
|
|
315
|
-
for (let epoch = 0; epoch < TRAINING_EPOCHS; epoch++) {
|
|
316
|
-
const gw = new Array<number>(dim).fill(0)
|
|
317
|
-
let gb = 0
|
|
318
|
-
|
|
319
|
-
for (let i = 0; i < trainX.length; i++) {
|
|
320
|
-
let z = bias
|
|
321
|
-
|
|
322
|
-
for (let j = 0; j < dim; j++) {
|
|
323
|
-
z += w[j]! * trainX[i]![j]!
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const err = (sigmoid(z) - trainY[i]!) * trainW[i]!
|
|
327
|
-
|
|
328
|
-
for (let j = 0; j < dim; j++) {
|
|
329
|
-
gw[j]! += err * trainX[i]![j]!
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
gb += err
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
for (let j = 0; j < dim; j++) {
|
|
336
|
-
w[j]! -= 0.1 * (gw[j]! / trainX.length + 1e-3 * w[j]!)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
bias -= 0.1 * (gb / trainX.length)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const lrSc = (x: number[]) => {
|
|
343
|
-
let z = bias
|
|
344
|
-
|
|
345
|
-
for (let j = 0; j < x.length; j++) {
|
|
346
|
-
z += w[j]! * x[j]!
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return z
|
|
350
|
-
}
|
|
192
|
+
// LR (batch GD, class-balanced) — the SHARED trainer, same as the pairwise probe.
|
|
193
|
+
const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
|
|
351
194
|
|
|
352
195
|
const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
|
|
353
196
|
const lrScorer = (a: SourceRecord, b: SourceRecord) => lrSc(featurize(a, b))
|
|
354
197
|
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (s.f1 > best.f1) {
|
|
362
|
-
best = s
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return best
|
|
367
|
-
}
|
|
198
|
+
const armOver = (
|
|
199
|
+
thresholds: readonly number[],
|
|
200
|
+
cfg: (t: number) => Parameters<typeof resolveEntities>[1]
|
|
201
|
+
): ArmScore =>
|
|
202
|
+
bestOver(thresholds, (t) => toArmScore(scoreEntities(resolveEntities(evalRecords, cfg(t)).entities, npiLabel, N)))
|
|
368
203
|
|
|
369
|
-
// FS baseline: EM-fit weights in bits, fine grid [0..25]. Learned scorers: a FINE sweep
|
|
370
|
-
//
|
|
204
|
+
// FS baseline: EM-fit weights in bits, fine grid [0..25]. Learned scorers: a FINE sweep from each
|
|
205
|
+
// scorer's own eval-pair score distribution, so a coarse grid can't understate them.
|
|
371
206
|
const { pairs: evalPairs } = block(evalRecords, defaultBlockingKeys())
|
|
372
207
|
|
|
373
|
-
const
|
|
374
|
-
const sorted = [...scores].toSorted((p, q) => p - q)
|
|
375
|
-
const ts = new Set<number>()
|
|
376
|
-
|
|
377
|
-
for (let k = 0; k <= MAX_K; k++) {
|
|
378
|
-
ts.add(sorted[Math.floor((0.2 + (0.999 - 0.2) * (k / 32)) * (sorted.length - 1))]!)
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return [...ts]
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const fs = bestOver(
|
|
208
|
+
const fs = armOver(
|
|
385
209
|
Array.from({ length: 26 }, (_, i) => i),
|
|
386
210
|
// learnedScorer:false — the FS baseline is the baseline this A/B measures against (the learned scorer
|
|
387
211
|
// is now default-on, so without this the "FS arm" would silently BE the GBT).
|
|
388
212
|
(t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
|
|
389
213
|
)
|
|
390
214
|
|
|
391
|
-
const gbtArm =
|
|
215
|
+
const gbtArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => gbtScorer(a, b))), (t) => ({
|
|
392
216
|
addressFrequency,
|
|
393
217
|
collapseSpatial: true,
|
|
394
218
|
scorer: gbtScorer,
|
|
395
219
|
threshold: t,
|
|
396
220
|
}))
|
|
397
221
|
|
|
398
|
-
const lrArm =
|
|
222
|
+
const lrArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => lrScorer(a, b))), (t) => ({
|
|
399
223
|
addressFrequency,
|
|
400
224
|
collapseSpatial: true,
|
|
401
225
|
scorer: lrScorer,
|
|
@@ -405,18 +229,6 @@ export async function scorerClusteringEval(
|
|
|
405
229
|
return { seed, trainN: trainRecords.length, evalN: N, fs, lr: lrArm, gbt: gbtArm }
|
|
406
230
|
}
|
|
407
231
|
|
|
408
|
-
// NOTE(phase4): local pct keeps the fraction-in/no-%-suffix shape — not core formatPercent's
|
|
409
|
-
// numerator/denominator contract (call sites append their own "%").
|
|
410
|
-
const pct = (x: number) => (100 * x).toFixed(1)
|
|
411
|
-
const sgn = (x: number) => (x >= 0 ? "+" : "")
|
|
412
|
-
const mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / Math.max(1, xs.length)
|
|
413
|
-
|
|
414
|
-
const std = (xs: number[]) => {
|
|
415
|
-
const m = mean(xs)
|
|
416
|
-
|
|
417
|
-
return Math.sqrt(mean(xs.map((x) => (x - m) ** 2)))
|
|
418
|
-
}
|
|
419
|
-
|
|
420
232
|
const SEEDS = options.seeds ?? 4
|
|
421
233
|
report?.(`[D-F] ${SEEDS} held-out-NPI splits: FS baseline vs GBT vs LR…`)
|
|
422
234
|
const results: SeedResult[] = []
|
|
@@ -432,27 +244,26 @@ export async function scorerClusteringEval(
|
|
|
432
244
|
}
|
|
433
245
|
|
|
434
246
|
const fsF1 = results.map((r) => r.fs.f1)
|
|
435
|
-
const lrF1 = results.map((r) => r.lr.f1)
|
|
436
247
|
const gbtF1 = results.map((r) => r.gbt.f1)
|
|
437
248
|
const dGbt = results.map((r) => r.gbt.f1 - r.fs.f1)
|
|
438
249
|
const dLr = results.map((r) => r.lr.f1 - r.fs.f1)
|
|
439
250
|
const gbtWins = dGbt.filter((d) => d > 0).length
|
|
440
|
-
const meanDGbt = mean(dGbt)
|
|
251
|
+
const meanDGbt = mean(dGbt)!
|
|
441
252
|
|
|
442
253
|
const armRow = (label: string, pick: (r: SeedResult) => ArmScore, dArr: number[] | null, bold: boolean) => {
|
|
443
254
|
const f1s = results.map((r) => pick(r).f1)
|
|
444
|
-
const P = mean(results.map((r) => pick(r).precision))
|
|
445
|
-
const R = mean(results.map((r) => pick(r).recall))
|
|
446
|
-
const om = mean(results.map((r) => pick(r).overMerged))
|
|
447
|
-
const d = dArr ? `${sgn(mean(dArr) * 100)}${(mean(dArr) * 100).toFixed(1)}pp` : "—"
|
|
448
|
-
const f1cell = `${pct(mean(f1s))}% ± ${pct(std(f1s))}`
|
|
255
|
+
const P = mean(results.map((r) => pick(r).precision))!
|
|
256
|
+
const R = mean(results.map((r) => pick(r).recall))!
|
|
257
|
+
const om = mean(results.map((r) => pick(r).overMerged))!
|
|
258
|
+
const d = dArr ? `${sgn(mean(dArr)! * 100)}${(mean(dArr)! * 100).toFixed(1)}pp` : "—"
|
|
259
|
+
const f1cell = `${pct(mean(f1s)!)}% ± ${pct(std(f1s))}`
|
|
449
260
|
const cells = `${pct(P)}% | ${pct(R)}% | ${bold ? `**${f1cell}**` : f1cell} | ${bold ? `**${d}**` : d} | ${om.toFixed(0)}`
|
|
450
261
|
|
|
451
262
|
return `| ${bold ? `**${label}**` : label} | ${cells} |`
|
|
452
263
|
}
|
|
453
264
|
|
|
454
|
-
const avgEval = Math.round(mean(results.map((r) => r.evalN)))
|
|
455
|
-
const avgTrain = Math.round(mean(results.map((r) => r.trainN)))
|
|
265
|
+
const avgEval = Math.round(mean(results.map((r) => r.evalN))!)
|
|
266
|
+
const avgTrain = Math.round(mean(results.map((r) => r.trainN))!)
|
|
456
267
|
|
|
457
268
|
const lines: string[] = [
|
|
458
269
|
`# Learned-scorer CLUSTERING A/B (#603 Tier 2) — does a learned scorer beat the FS baseline on the assembled output?`,
|
|
@@ -480,16 +291,16 @@ export async function scorerClusteringEval(
|
|
|
480
291
|
const verdict =
|
|
481
292
|
meanDGbt > MIN_MEANINGFUL_F1_DELTA && gbtWins >= SEEDS - 1
|
|
482
293
|
? `**The learned scorer beats the FS baseline on the assembled clustering output** — GBT clustering F1 ` +
|
|
483
|
-
`${pct(mean(gbtF1))}% vs FS ${pct(mean(fsF1))}% (${sgn(meanDGbt * 100)}${(meanDGbt * 100).toFixed(1)}pp mean, ${gbtWins}/${SEEDS} ` +
|
|
484
|
-
`seeds), driven by a large PRECISION gain that
|
|
485
|
-
`DOES translate to the entity-resolution metric. This confirms the #603 GBM as a real dedup
|
|
294
|
+
`${pct(mean(gbtF1)!)}% vs FS ${pct(mean(fsF1)!)}% (${sgn(meanDGbt * 100)}${(meanDGbt * 100).toFixed(1)}pp mean, ${gbtWins}/${SEEDS} ` +
|
|
295
|
+
`seeds), driven by a large PRECISION gain that reduces the over-merge — the #625 problem. The pairwise gain (#640) ` +
|
|
296
|
+
`DOES translate to the entity-resolution metric. This confirms the #603 GBM as a real dedup change and justifies the ` +
|
|
486
297
|
`production build (offline XGBoost/LightGBM → tree JSON, the \`scorer\` hook for inference). The honest next axis is ` +
|
|
487
298
|
`cross-STATE generalization (train-TX / eval-other-state) and a tuned GBM on more features.`
|
|
488
299
|
: meanDGbt < -MIN_MEANINGFUL_F1_DELTA
|
|
489
|
-
? `**The learned scorer does NOT beat the FS baseline on clustering** (GBT ${pct(mean(gbtF1))}% vs FS ${pct(mean(fsF1))}%, ` +
|
|
300
|
+
? `**The learned scorer does NOT beat the FS baseline on clustering** (GBT ${pct(mean(gbtF1)!)}% vs FS ${pct(mean(fsF1)!)}%, ` +
|
|
490
301
|
`${(meanDGbt * 100).toFixed(1)}pp). The pairwise ranking gain (#640) does not survive the threshold + ` +
|
|
491
302
|
`connected-components assembly — clustering, not ranking, is the binding constraint. FS stays the baseline.`
|
|
492
|
-
: `**The learned scorer roughly TIES the FS baseline on clustering** (GBT ${pct(mean(gbtF1))}% vs FS ${pct(mean(fsF1))}%, ` +
|
|
303
|
+
: `**The learned scorer roughly TIES the FS baseline on clustering** (GBT ${pct(mean(gbtF1)!)}% vs FS ${pct(mean(fsF1)!)}%, ` +
|
|
493
304
|
`${sgn(meanDGbt * 100)}${(meanDGbt * 100).toFixed(1)}pp, ${gbtWins}/${SEEDS} seeds). The pairwise ranking gain (#640) is ` +
|
|
494
305
|
`real but largely washes out through the threshold + connected-components assembly. A learned scorer is not a free ` +
|
|
495
306
|
`dedup win; pairing it with a clustering change or a more distinctive identifier (#625) is the path.`
|
|
@@ -526,7 +337,7 @@ export async function scorerClusteringEval(
|
|
|
526
337
|
console.log(md)
|
|
527
338
|
|
|
528
339
|
if (OUT_MD) {
|
|
529
|
-
|
|
340
|
+
await writeLocalFile(md, OUT_MD)
|
|
530
341
|
report?.(`[written] ${OUT_MD}`)
|
|
531
342
|
}
|
|
532
343
|
|