@mailwoman/registry 9.2.0 → 9.4.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/{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} +9 -4
- package/{index.ts → lib/index.ts} +10 -10
- package/{ingest.ts → lib/ingest.ts} +75 -68
- package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
- package/{map-html.ts → lib/map-html.ts} +7 -13
- package/{reconcile.ts → lib/reconcile.ts} +7 -23
- package/{resolve.ts → lib/resolve.ts} +25 -12
- package/{tools → lib/tools}/coverage-reconciliation.ts +12 -14
- package/{tools → lib/tools}/cross-dataset-correlation.ts +60 -137
- package/{tools → lib/tools}/cross-source-threshold-sweep.ts +20 -31
- package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
- package/{tools → lib/tools}/eval-geocoder.ts +9 -10
- package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
- package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +9 -10
- 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 +68 -257
- package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +60 -243
- package/{tools → lib/tools}/learned-scorer-eval.ts +63 -257
- package/{tools → lib/tools}/matcher-scale.ts +4 -5
- package/lib/tools/nppes/org-name.ts +23 -0
- package/{tools → lib/tools}/nppes/overmerge-packet.ts +5 -7
- package/{tools → lib/tools}/nppes/report.ts +22 -25
- package/{tools → lib/tools}/nppes/sample.ts +80 -32
- package/{tools/nppes/levers.ts → lib/tools/nppes/settings.ts} +10 -10
- package/{tools → lib/tools}/nppes/truth-grains.ts +4 -44
- package/{tools → lib/tools}/nppes-dedup-benchmark.ts +42 -38
- package/lib/tools/shared.ts +761 -0
- package/lib/tools/train-cross-gbt.ts +209 -0
- package/{tools → lib/tools}/train-gbt.ts +35 -154
- package/lib/tools/train-org-cross-gbt.ts +179 -0
- package/{tools → lib/tools}/txhhsc-to-oarow.ts +9 -27
- package/lib/tools/viz/browser.ts +50 -0
- package/{tools → lib/tools}/viz/cross-dataset-map.ts +7 -8
- package/{tools → lib/tools}/viz/geocode-first-surface.ts +10 -8
- 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 +8 -10
- package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
- 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 +5 -3
- 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 +31 -45
- 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 +3 -3
- 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 +5 -20
- 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 +16 -5
- 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 +11 -11
- 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 +57 -109
- 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 -117
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +8 -12
- 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 +8 -7
- 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 -122
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +23 -23
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +23 -23
- 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 +36 -169
- 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 +38 -168
- 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 +4 -4
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +2 -5
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +1 -30
- package/out/tools/nppes/org-name.js.map +1 -1
- package/out/tools/nppes/overmerge-packet.d.ts +3 -3
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
- package/out/tools/nppes/overmerge-packet.js +3 -3
- package/out/tools/nppes/overmerge-packet.js.map +1 -1
- package/out/tools/nppes/report.d.ts +5 -5
- package/out/tools/nppes/report.d.ts.map +1 -1
- package/out/tools/nppes/report.js +17 -19
- package/out/tools/nppes/report.js.map +1 -1
- package/out/tools/nppes/sample.d.ts +32 -6
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +44 -26
- package/out/tools/nppes/sample.js.map +1 -1
- package/out/tools/nppes/scoring.d.ts.map +1 -1
- package/out/tools/nppes/scoring.js.map +1 -1
- package/out/tools/nppes/{levers.d.ts → settings.d.ts} +8 -8
- package/out/tools/nppes/settings.d.ts.map +1 -0
- package/out/tools/nppes/{levers.js → settings.js} +8 -8
- package/out/tools/nppes/settings.js.map +1 -0
- package/out/tools/nppes/truth-grains.d.ts +2 -2
- package/out/tools/nppes/truth-grains.d.ts.map +1 -1
- package/out/tools/nppes/truth-grains.js +4 -29
- package/out/tools/nppes/truth-grains.js.map +1 -1
- package/out/tools/nppes-dedup-benchmark.d.ts +4 -4
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +40 -34
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts +243 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +348 -18
- 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 +8 -22
- 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 +2 -2
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +6 -6
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +4 -3
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +7 -5
- 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 +2 -2
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +6 -7
- 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.map +1 -1
- package/out/types.js.map +1 -1
- package/package.json +115 -15
- package/out/tools/nppes/levers.d.ts.map +0 -1
- package/out/tools/nppes/levers.js.map +0 -1
- package/tools/gold-set-sample.ts +0 -254
- package/tools/index.ts +0 -31
- package/tools/nppes/org-name.ts +0 -56
- package/tools/shared.ts +0 -162
- package/tools/train-cross-gbt.ts +0 -359
- package/tools/train-org-cross-gbt.ts +0 -330
- 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
- /package/{tools → lib/tools}/nppes/scoring.ts +0 -0
- /package/{types.ts → lib/types.ts} +0 -0
|
@@ -28,39 +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
|
+
import { mean } from "@mailwoman/core/utils"
|
|
34
35
|
import { block, gbtScore, trainGBT } from "@mailwoman/match"
|
|
35
36
|
|
|
36
37
|
import {
|
|
37
|
-
addressFrequencyKey,
|
|
38
38
|
buildDefaultModel,
|
|
39
39
|
createMatchFeaturizer,
|
|
40
40
|
defaultBlockingKeys,
|
|
41
41
|
ingestRows,
|
|
42
42
|
resolveEntities,
|
|
43
|
-
streamRows,
|
|
44
43
|
type ColumnMapping,
|
|
45
|
-
type ResolvedEntity,
|
|
46
44
|
type SourceRecord,
|
|
47
45
|
} from "#index"
|
|
48
|
-
|
|
49
|
-
import
|
|
46
|
+
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
47
|
+
import { buildNPPESSample } from "#tools/nppes/sample"
|
|
48
|
+
import { scoreEntities } from "#tools/nppes/scoring"
|
|
50
49
|
import {
|
|
51
|
-
|
|
52
|
-
MIN_GROUP_SIZE,
|
|
50
|
+
bestOver,
|
|
53
51
|
MIN_MEANINGFUL_F1_DELTA,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
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"
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
63
|
* Options for {@linkcode scorerClusteringEval}.
|
|
@@ -100,61 +97,6 @@ export interface ScorerClusteringEvalOptions {
|
|
|
100
97
|
outMd?: string
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
interface MessyRow extends Record<string, string> {
|
|
104
|
-
npi: string
|
|
105
|
-
name: string
|
|
106
|
-
org: string
|
|
107
|
-
address: string
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const choose2 = (n: number) => (n * (n - 1)) / 2
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The dedup benchmark's pairwise clustering metric vs the NPI grouping (record.id = NPI).
|
|
114
|
-
*/
|
|
115
|
-
function scoreClusters(
|
|
116
|
-
entities: ResolvedEntity[],
|
|
117
|
-
n: number
|
|
118
|
-
): { precision: number; recall: number; f1: number; overMerged: number } {
|
|
119
|
-
const npiTotals = new Map<string, number>()
|
|
120
|
-
let sumCK = 0
|
|
121
|
-
let sumCluster = 0
|
|
122
|
-
let overMerged = 0
|
|
123
|
-
|
|
124
|
-
for (const e of entities) {
|
|
125
|
-
const byNPI = new Map<string, number>()
|
|
126
|
-
|
|
127
|
-
for (const rec of e.records) {
|
|
128
|
-
byNPI.set(rec.id, (byNPI.get(rec.id) ?? 0) + 1)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
sumCluster += choose2(e.records.length)
|
|
132
|
-
|
|
133
|
-
if (byNPI.size > 1) {
|
|
134
|
-
overMerged++
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (const [npi, c] of byNPI) {
|
|
138
|
-
sumCK += choose2(c)
|
|
139
|
-
npiTotals.set(npi, (npiTotals.get(npi) ?? 0) + c)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let sumClass = 0
|
|
144
|
-
|
|
145
|
-
for (const total of npiTotals.values()) {
|
|
146
|
-
sumClass += choose2(total)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
void n
|
|
150
|
-
const tp = sumCK
|
|
151
|
-
const precision = sumCluster > 0 ? tp / sumCluster : 0
|
|
152
|
-
const recall = sumClass > 0 ? tp / sumClass : 0
|
|
153
|
-
const f1 = precision + recall > 0 ? (2 * precision * recall) / (precision + recall) : 0
|
|
154
|
-
|
|
155
|
-
return { precision, recall, f1, overMerged }
|
|
156
|
-
}
|
|
157
|
-
|
|
158
100
|
/**
|
|
159
101
|
* Learned-scorer clustering A/B (#603 Tier 2) — see the module doc. Emits the markdown report to stdout.
|
|
160
102
|
*/
|
|
@@ -163,7 +105,7 @@ export async function scorerClusteringEval(
|
|
|
163
105
|
report?: (line: string) => void
|
|
164
106
|
): Promise<{ markdown: string }> {
|
|
165
107
|
const SOURCES = options.sources || dataRootPath("record-matcher", "sources")
|
|
166
|
-
const STATE = (options
|
|
108
|
+
const STATE = stateOption(options)
|
|
167
109
|
const NPIS = options.npis ?? 2000
|
|
168
110
|
const SPLIT = options.split ?? 0.67
|
|
169
111
|
const SEED = options.seed ?? 1
|
|
@@ -172,93 +114,36 @@ export async function scorerClusteringEval(
|
|
|
172
114
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
173
115
|
const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
|
|
174
116
|
|
|
175
|
-
// --- Data-gen: the same NPI-keyed records as the dedup benchmark + the pairwise probe
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (list.length < MIN_GROUP_SIZE) {
|
|
187
|
-
list.push(alt)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
altNames.set(npi, list)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
report?.(`[B] full registry pass: address-frequency table + ${NPIS} ${STATE} sample…`)
|
|
194
|
-
const rows: MessyRow[] = []
|
|
195
|
-
const kept = new Set<string>()
|
|
196
|
-
const addrCounts = new Map<string, number>()
|
|
197
|
-
let addrTotal = 0
|
|
198
|
-
let scanned = 0
|
|
199
|
-
|
|
200
|
-
for await (const r of streamRows(REGISTRY)) {
|
|
201
|
-
if (++scanned % 1_000_000 === 0) {
|
|
202
|
-
report?.(` scanned ${scanned / 1e6}M, kept ${kept.size}`)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const practice = addr(r[C.pAddr]!, r[C.pCity]!, r[C.pState]!, r[C.pZip]!)
|
|
206
|
-
|
|
207
|
-
if (practice) {
|
|
208
|
-
const k = addressFrequencyKey(practice)
|
|
209
|
-
addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1)
|
|
210
|
-
|
|
211
|
-
addrTotal++
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const npi = norm(r[C.npi])
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
kept.size < NPIS &&
|
|
218
|
-
npi &&
|
|
219
|
-
!kept.has(npi) &&
|
|
220
|
-
altNames.has(npi) &&
|
|
221
|
-
practice &&
|
|
222
|
-
norm(r[C.pState]).toUpperCase() === STATE
|
|
223
|
-
) {
|
|
224
|
-
const isOrg = norm(r[C.entityType]) === "2"
|
|
225
|
-
const primaryName = isOrg ? norm(r[C.orgLegal]) : `${norm(r[C.first])} ${norm(r[C.last])}`.trim()
|
|
226
|
-
|
|
227
|
-
if (primaryName) {
|
|
228
|
-
const org = isOrg ? norm(r[C.orgLegal]) : ""
|
|
229
|
-
kept.add(npi)
|
|
230
|
-
rows.push({ npi, name: primaryName, org, address: practice })
|
|
231
|
-
|
|
232
|
-
for (const alt of altNames.get(npi)!) {
|
|
233
|
-
rows.push({ npi, name: alt, org: alt, address: practice })
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const mailing = addr(r[C.mAddr]!, r[C.mCity]!, r[C.mState]!, r[C.mZip]!)
|
|
237
|
-
|
|
238
|
-
if (mailing && mailing !== practice) {
|
|
239
|
-
rows.push({ npi, name: primaryName, org, address: mailing })
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const addressFrequency = {
|
|
246
|
-
total: addrTotal,
|
|
247
|
-
distinct: addrCounts.size,
|
|
248
|
-
frequency: (v: string) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
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
|
+
)
|
|
252
127
|
|
|
253
128
|
report?.("[C] geocoding…")
|
|
254
129
|
const geocoder = await options.createGeocoder()
|
|
255
|
-
|
|
130
|
+
|
|
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
|
+
}
|
|
256
141
|
|
|
257
142
|
const records = await ingestRows(rows, mapping, {
|
|
258
|
-
geocodeAddress: geocoder.
|
|
143
|
+
geocodeAddress: geocoder.geocodeAddress,
|
|
259
144
|
})
|
|
260
145
|
|
|
261
|
-
geocoder.
|
|
146
|
+
geocoder[Symbol.dispose]()
|
|
262
147
|
|
|
263
148
|
// --- The feature basis: address-frequency + collapsed-spatial model (the baseline). The agreement
|
|
264
149
|
// pattern is EM-independent, so the same featurize() is consistent at train and inference time. ---
|
|
@@ -267,12 +152,7 @@ export async function scorerClusteringEval(
|
|
|
267
152
|
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
268
153
|
const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
|
|
269
154
|
|
|
270
|
-
|
|
271
|
-
precision: number
|
|
272
|
-
recall: number
|
|
273
|
-
f1: number
|
|
274
|
-
overMerged: number
|
|
275
|
-
}
|
|
155
|
+
const npiLabel = (rec: SourceRecord) => rec.id
|
|
276
156
|
|
|
277
157
|
interface SeedResult {
|
|
278
158
|
seed: number
|
|
@@ -309,94 +189,37 @@ export async function scorerClusteringEval(
|
|
|
309
189
|
const dim = trainX[0]?.length ?? 0
|
|
310
190
|
const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
|
|
311
191
|
|
|
312
|
-
// LR (batch GD, class-balanced) — same as the pairwise probe.
|
|
313
|
-
const
|
|
314
|
-
let bias = 0
|
|
315
|
-
|
|
316
|
-
for (let epoch = 0; epoch < TRAINING_EPOCHS; epoch++) {
|
|
317
|
-
const gw = new Array<number>(dim).fill(0)
|
|
318
|
-
let gb = 0
|
|
319
|
-
|
|
320
|
-
for (let i = 0; i < trainX.length; i++) {
|
|
321
|
-
let z = bias
|
|
322
|
-
|
|
323
|
-
for (let j = 0; j < dim; j++) {
|
|
324
|
-
z += w[j]! * trainX[i]![j]!
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const err = (sigmoid(z) - trainY[i]!) * trainW[i]!
|
|
328
|
-
|
|
329
|
-
for (let j = 0; j < dim; j++) {
|
|
330
|
-
gw[j]! += err * trainX[i]![j]!
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
gb += err
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
for (let j = 0; j < dim; j++) {
|
|
337
|
-
w[j]! -= 0.1 * (gw[j]! / trainX.length + 1e-3 * w[j]!)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
bias -= 0.1 * (gb / trainX.length)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const lrSc = (x: number[]) => {
|
|
344
|
-
let z = bias
|
|
345
|
-
|
|
346
|
-
for (let j = 0; j < x.length; j++) {
|
|
347
|
-
z += w[j]! * x[j]!
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return z
|
|
351
|
-
}
|
|
192
|
+
// LR (batch GD, class-balanced) — the SHARED trainer, same as the pairwise probe.
|
|
193
|
+
const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
|
|
352
194
|
|
|
353
195
|
const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
|
|
354
196
|
const lrScorer = (a: SourceRecord, b: SourceRecord) => lrSc(featurize(a, b))
|
|
355
197
|
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (s.f1 > best.f1) {
|
|
363
|
-
best = s
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return best
|
|
368
|
-
}
|
|
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)))
|
|
369
203
|
|
|
370
|
-
// FS baseline: EM-fit weights in bits, fine grid [0..25]. Learned scorers: a FINE sweep
|
|
371
|
-
//
|
|
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.
|
|
372
206
|
const { pairs: evalPairs } = block(evalRecords, defaultBlockingKeys())
|
|
373
207
|
|
|
374
|
-
const
|
|
375
|
-
const sorted = [...scores].toSorted((p, q) => p - q)
|
|
376
|
-
const ts = new Set<number>()
|
|
377
|
-
|
|
378
|
-
for (let k = 0; k <= MAX_K; k++) {
|
|
379
|
-
ts.add(sorted[Math.floor((0.2 + (0.999 - 0.2) * (k / 32)) * (sorted.length - 1))]!)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return [...ts]
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const fs = bestOver(
|
|
208
|
+
const fs = armOver(
|
|
386
209
|
Array.from({ length: 26 }, (_, i) => i),
|
|
387
210
|
// learnedScorer:false — the FS baseline is the baseline this A/B measures against (the learned scorer
|
|
388
211
|
// is now default-on, so without this the "FS arm" would silently BE the GBT).
|
|
389
212
|
(t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
|
|
390
213
|
)
|
|
391
214
|
|
|
392
|
-
const gbtArm =
|
|
215
|
+
const gbtArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => gbtScorer(a, b))), (t) => ({
|
|
393
216
|
addressFrequency,
|
|
394
217
|
collapseSpatial: true,
|
|
395
218
|
scorer: gbtScorer,
|
|
396
219
|
threshold: t,
|
|
397
220
|
}))
|
|
398
221
|
|
|
399
|
-
const lrArm =
|
|
222
|
+
const lrArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => lrScorer(a, b))), (t) => ({
|
|
400
223
|
addressFrequency,
|
|
401
224
|
collapseSpatial: true,
|
|
402
225
|
scorer: lrScorer,
|
|
@@ -406,18 +229,6 @@ export async function scorerClusteringEval(
|
|
|
406
229
|
return { seed, trainN: trainRecords.length, evalN: N, fs, lr: lrArm, gbt: gbtArm }
|
|
407
230
|
}
|
|
408
231
|
|
|
409
|
-
// NOTE(phase4): local pct keeps the fraction-in/no-%-suffix shape — not core formatPercent's
|
|
410
|
-
// numerator/denominator contract (call sites append their own "%").
|
|
411
|
-
const pct = (x: number) => (100 * x).toFixed(1)
|
|
412
|
-
const sgn = (x: number) => (x >= 0 ? "+" : "")
|
|
413
|
-
const mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / Math.max(1, xs.length)
|
|
414
|
-
|
|
415
|
-
const std = (xs: number[]) => {
|
|
416
|
-
const m = mean(xs)
|
|
417
|
-
|
|
418
|
-
return Math.sqrt(mean(xs.map((x) => (x - m) ** 2)))
|
|
419
|
-
}
|
|
420
|
-
|
|
421
232
|
const SEEDS = options.seeds ?? 4
|
|
422
233
|
report?.(`[D-F] ${SEEDS} held-out-NPI splits: FS baseline vs GBT vs LR…`)
|
|
423
234
|
const results: SeedResult[] = []
|
|
@@ -437,22 +248,22 @@ export async function scorerClusteringEval(
|
|
|
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
|
|