@mailwoman/registry 10.0.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -14
- package/lib/address-key.ts +14 -10
- package/lib/geocode-handler.ts +7 -5
- package/lib/geojson.ts +13 -7
- package/lib/ingest.ts +70 -92
- package/lib/learned-scorer.ts +38 -44
- package/lib/map-html.ts +26 -72
- package/lib/models/crosssource-gbt-en-us.ts +9 -7
- package/lib/models/dedup-gbt-en-us.ts +9 -8
- package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
- package/lib/reconcile.ts +45 -54
- package/lib/resolve.ts +187 -130
- package/lib/types.ts +35 -29
- package/out/address-key.d.ts +14 -10
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js +14 -10
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -4
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +7 -5
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +9 -5
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +13 -7
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts +49 -76
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +37 -62
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +29 -26
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js +31 -39
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +13 -32
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +11 -64
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts +9 -7
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js +9 -7
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts +9 -8
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js +9 -8
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js +10 -8
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +36 -50
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +18 -42
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +152 -91
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +67 -68
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +23 -23
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +15 -26
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross/dataset-correlation.d.ts +23 -27
- package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross/dataset-correlation.js +9 -61
- package/out/tools/cross/dataset-correlation.js.map +1 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
- package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross/source-threshold-sweep.js +14 -40
- package/out/tools/cross/source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts +23 -26
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +22 -41
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +25 -16
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +5 -6
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder/namesake-probe.d.ts +9 -8
- package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder/namesake-probe.js +6 -7
- package/out/tools/geocoder/namesake-probe.js.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.js +30 -27
- package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +27 -18
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +18 -22
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.js +28 -38
- package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.js +19 -25
- package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
- package/out/tools/learned/scorer/eval.d.ts +26 -39
- package/out/tools/learned/scorer/eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/eval.js +11 -71
- package/out/tools/learned/scorer/eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts +12 -17
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +11 -29
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +22 -41
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes/dedup-benchmark.js +21 -67
- package/out/tools/nppes/dedup-benchmark.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +5 -11
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +2 -9
- package/out/tools/nppes/org-name.js.map +1 -1
- package/out/tools/nppes/overmerge-packet.d.ts +15 -11
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
- package/out/tools/nppes/overmerge-packet.js +6 -7
- package/out/tools/nppes/overmerge-packet.js.map +1 -1
- package/out/tools/nppes/report.d.ts +17 -13
- package/out/tools/nppes/report.d.ts.map +1 -1
- package/out/tools/nppes/report.js +6 -14
- package/out/tools/nppes/report.js.map +1 -1
- package/out/tools/nppes/sample.d.ts +29 -18
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +24 -28
- package/out/tools/nppes/sample.js.map +1 -1
- package/out/tools/nppes/scoring.d.ts +7 -6
- package/out/tools/nppes/scoring.d.ts.map +1 -1
- package/out/tools/nppes/scoring.js +6 -5
- package/out/tools/nppes/scoring.js.map +1 -1
- package/out/tools/nppes/settings.d.ts +10 -7
- package/out/tools/nppes/settings.d.ts.map +1 -1
- package/out/tools/nppes/settings.js +16 -16
- package/out/tools/nppes/settings.js.map +1 -1
- package/out/tools/nppes/truth-grains.d.ts +36 -23
- package/out/tools/nppes/truth-grains.d.ts.map +1 -1
- package/out/tools/nppes/truth-grains.js +36 -20
- package/out/tools/nppes/truth-grains.js.map +1 -1
- package/out/tools/shared.d.ts +68 -72
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +50 -67
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train/cross-gbt.d.ts +37 -26
- package/out/tools/train/cross-gbt.d.ts.map +1 -1
- package/out/tools/train/cross-gbt.js +14 -25
- package/out/tools/train/cross-gbt.js.map +1 -1
- package/out/tools/train/gbt.d.ts +36 -20
- package/out/tools/train/gbt.d.ts.map +1 -1
- package/out/tools/train/gbt.js +27 -31
- package/out/tools/train/gbt.js.map +1 -1
- package/out/tools/train/org-cross-gbt.d.ts +38 -24
- package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train/org-cross-gbt.js +18 -22
- package/out/tools/train/org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +14 -9
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +16 -15
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +6 -5
- package/out/tools/viz/browser.d.ts.map +1 -1
- package/out/tools/viz/browser.js +6 -5
- package/out/tools/viz/browser.js.map +1 -1
- package/out/tools/viz/cross-dataset-map.d.ts +7 -4
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +9 -6
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +11 -5
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +16 -11
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render/map.d.ts +5 -5
- package/out/tools/viz/render/map.d.ts.map +1 -1
- package/out/tools/viz/render/map.js +6 -5
- package/out/tools/viz/render/map.js.map +1 -1
- package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
- package/out/tools/viz/render.d.ts.map +1 -0
- package/out/tools/viz/{render/index.js → render.js} +9 -8
- package/out/tools/viz/render.js.map +1 -0
- package/out/tools/viz/source-provenance-map.d.ts +19 -7
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +11 -8
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -21
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +3 -39
- package/out/tools/viz/yardstick-figure.js.map +1 -1
- package/out/types.d.ts +35 -29
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -2
- package/out/types.js.map +1 -1
- package/package.json +42 -185
- package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
- package/{lib/tools → tools}/cross/dataset-correlation.ts +35 -73
- package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
- package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
- package/tools/eval-geocoder.ts +77 -0
- package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
- package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +40 -31
- package/{lib/tools → tools}/gold-set-sample.ts +35 -29
- package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
- package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
- package/{lib/tools → tools}/learned/scorer/eval.ts +39 -78
- package/{lib/tools → tools}/matcher-scale.ts +21 -33
- package/{lib/tools → tools}/nppes/dedup-benchmark.ts +39 -83
- package/tools/nppes/org-name.ts +15 -0
- package/{lib/tools → tools}/nppes/overmerge-packet.ts +16 -12
- package/{lib/tools → tools}/nppes/report.ts +32 -25
- package/{lib/tools → tools}/nppes/sample.ts +43 -38
- package/{lib/tools → tools}/nppes/scoring.ts +7 -6
- package/{lib/tools → tools}/nppes/settings.ts +16 -16
- package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
- package/{lib/tools → tools}/shared.ts +79 -98
- package/{lib/tools → tools}/train/cross-gbt.ts +39 -34
- package/{lib/tools → tools}/train/gbt.ts +55 -41
- package/{lib/tools → tools}/train/org-cross-gbt.ts +40 -30
- package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
- package/{lib/tools → tools}/viz/browser.ts +6 -5
- package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
- package/{lib/tools → tools}/viz/geocode-first-surface.ts +29 -17
- package/{lib/tools → tools}/viz/render/map.ts +7 -6
- package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
- package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
- package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
- package/lib/tools/eval-geocoder.ts +0 -67
- package/lib/tools/index.ts +0 -31
- package/lib/tools/nppes/org-name.ts +0 -23
- package/out/tools/index.d.ts +0 -31
- package/out/tools/index.d.ts.map +0 -1
- package/out/tools/index.js +0 -31
- package/out/tools/index.js.map +0 -1
- package/out/tools/viz/render/index.d.ts.map +0 -1
- package/out/tools/viz/render/index.js.map +0 -1
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Gold-set
|
|
7
|
-
* (`nppes-dedup-benchmark.ts`) collapses only NPPES-
|
|
8
|
-
* LBN/TIN)
|
|
9
|
-
* address with near-identical
|
|
10
|
-
*
|
|
11
|
-
* gold set must cover.
|
|
6
|
+
* Gold-set sampling for adjudication. The programmatic entity truth
|
|
7
|
+
* (`nppes-dedup-benchmark.ts`) collapses only NPPES-flagged subparts (Is-Subpart plus parent
|
|
8
|
+
* LBN/TIN), so it cannot settle the genuinely ambiguous co-located collisions: distinct NPIs at
|
|
9
|
+
* one address with near-identical name text and no subpart flag for the same parent.
|
|
10
|
+
* NPI truth and programmatic rules may disagree on these pairs. A frozen
|
|
11
|
+
* adjudicated gold set must cover.
|
|
12
12
|
*
|
|
13
|
-
* This
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* entity? yes/no" and we can MEASURE how often the programmatic truth matches judgment.
|
|
13
|
+
* This scans the full TX registry without geocoding and writes each pair as a JSONL row containing
|
|
14
|
+
* both records' fields (org name, address, authorized official, taxonomy, subpart and parent
|
|
15
|
+
* flags) plus the programmatic verdict. An adjudicator (human or LLM-as-judge, flagged as such)
|
|
16
|
+
* can then label same real-world entity or not.
|
|
18
17
|
*
|
|
19
18
|
* Run: `mailwoman registry gold-set-sample [--cap 200000] [--state TX] [--tau 0.7] [--n 300]
|
|
20
19
|
* [--out-jsonl <path>]`
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
22
|
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
24
|
-
import {
|
|
23
|
+
import { writeLocalJSONLFile } from "@mailwoman/core/fs/writers"
|
|
24
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
25
25
|
import { jaccard } from "@mailwoman/match"
|
|
26
26
|
|
|
27
27
|
import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#tools/shared"
|
|
@@ -31,27 +31,37 @@ import { colocatedDistinctPairs, scanColocatedProviders, stateOption } from "#to
|
|
|
31
31
|
*/
|
|
32
32
|
export interface GoldSetSampleOptions {
|
|
33
33
|
/**
|
|
34
|
-
* Record-matcher sources directory.
|
|
34
|
+
* Record-matcher sources directory.
|
|
35
|
+
*
|
|
36
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
|
|
35
37
|
*/
|
|
36
38
|
sources?: string
|
|
37
39
|
/**
|
|
38
|
-
* Providers sampled from the registry.
|
|
40
|
+
* Providers sampled from the registry.
|
|
41
|
+
*
|
|
42
|
+
* @defaultValue `200000`
|
|
39
43
|
*/
|
|
40
44
|
cap?: number
|
|
41
45
|
/**
|
|
42
|
-
* State filter.
|
|
46
|
+
* State filter.
|
|
47
|
+
*
|
|
48
|
+
* @defaultValue TX.
|
|
43
49
|
*/
|
|
44
50
|
state?: string
|
|
45
51
|
/**
|
|
46
|
-
* Org-name Jaccard collision threshold.
|
|
52
|
+
* Org-name Jaccard collision threshold.
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue `0.7`
|
|
47
55
|
*/
|
|
48
56
|
tau?: number
|
|
49
57
|
/**
|
|
50
|
-
* Adjudication sample size.
|
|
58
|
+
* Adjudication sample size.
|
|
59
|
+
*
|
|
60
|
+
* @defaultValue `300`
|
|
51
61
|
*/
|
|
52
62
|
n?: number
|
|
53
63
|
/**
|
|
54
|
-
* Write the sampled pairs here as
|
|
64
|
+
* Write the sampled pairs here as jsonl (otherwise the first 10 print to stdout).
|
|
55
65
|
*/
|
|
56
66
|
outJSONL?: string
|
|
57
67
|
}
|
|
@@ -67,11 +77,11 @@ interface HardPair {
|
|
|
67
77
|
sameTaxonomy: boolean
|
|
68
78
|
bothSubpartSameParent: boolean
|
|
69
79
|
programmaticVerdict: "same-entity" | "distinct"
|
|
70
|
-
adjudication: null
|
|
80
|
+
adjudication: null
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
/**
|
|
74
|
-
*
|
|
84
|
+
* Sample the hard co-located name-collision stratum for adjudication.
|
|
75
85
|
*/
|
|
76
86
|
export async function goldSetSample(
|
|
77
87
|
options: GoldSetSampleOptions = {},
|
|
@@ -89,8 +99,6 @@ export async function goldSetSample(
|
|
|
89
99
|
const { byAddr, kept } = await scanColocatedProviders({ registryPath: REGISTRY, state: STATE, cap: CAP })
|
|
90
100
|
report?.(` ${kept} providers at ${byAddr.size} addresses`)
|
|
91
101
|
|
|
92
|
-
// Hard pairs: co-located, name-similar (≥τ), DISTINCT NPIs that programmatic truth can't confidently
|
|
93
|
-
// collapse (NOT subparts of the same parent). Tag the programmatic verdict so adjudication can grade it.
|
|
94
102
|
const hard: HardPair[] = []
|
|
95
103
|
|
|
96
104
|
for (const { a, b } of colocatedDistinctPairs(byAddr)) {
|
|
@@ -99,7 +107,7 @@ export async function goldSetSample(
|
|
|
99
107
|
if (sim < TAU) continue
|
|
100
108
|
const sameParent = a.subpart && b.subpart && a.parent === b.parent && a.parent !== "|"
|
|
101
109
|
|
|
102
|
-
if (sameParent) continue
|
|
110
|
+
if (sameParent) continue
|
|
103
111
|
const sameAuth = a.auth !== "" && a.auth === b.auth
|
|
104
112
|
const sameTax = a.taxonomy !== "" && a.taxonomy === b.taxonomy
|
|
105
113
|
|
|
@@ -113,9 +121,7 @@ export async function goldSetSample(
|
|
|
113
121
|
sameAuthorizedOfficial: sameAuth,
|
|
114
122
|
sameTaxonomy: sameTax,
|
|
115
123
|
bothSubpartSameParent: false,
|
|
116
|
-
//
|
|
117
|
-
// subparts): same authorized official ⇒ likely one org; different official + different
|
|
118
|
-
// specialty ⇒ likely distinct. The whole point is to ADJUDICATE whether this is right.
|
|
124
|
+
// The verdict records what an entity-level rule would say, so adjudication can grade it.
|
|
119
125
|
programmaticVerdict: sameAuth ? "same-entity" : "distinct",
|
|
120
126
|
adjudication: null,
|
|
121
127
|
})
|
|
@@ -123,17 +129,17 @@ export async function goldSetSample(
|
|
|
123
129
|
|
|
124
130
|
report?.(` ${hard.length} hard co-located name-collision pairs (non-flagged-subpart)`)
|
|
125
131
|
|
|
126
|
-
//
|
|
132
|
+
// A deterministic stride sample avoids file-order bias in the adjudication set.
|
|
127
133
|
const stride = Math.max(1, Math.floor(hard.length / N))
|
|
128
134
|
const sample = hard.filter((_, i) => i % stride === 0).slice(0, N)
|
|
129
135
|
report?.(` sampling ${sample.length} (stride ${stride}) for adjudication`)
|
|
130
136
|
|
|
131
137
|
if (OUT) {
|
|
132
|
-
await
|
|
138
|
+
await writeLocalJSONLFile(sample, OUT)
|
|
133
139
|
report?.(`[written] ${OUT}`)
|
|
134
140
|
} else {
|
|
135
141
|
for (const p of sample.slice(0, 10)) {
|
|
136
|
-
console.log(
|
|
142
|
+
console.log(stringifyJSON(p))
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
145
|
|
|
@@ -3,26 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Learned-scorer
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Learned-scorer clustering A/B. A better pairwise scorer need not lift the assembled clustering F1,
|
|
7
|
+
* because that F1 depends on the threshold and connected components. This measures the clustering F1
|
|
8
|
+
* directly. It splits the NPIs into train and eval, trains a GBT and an LR on train pairs labeled by
|
|
9
|
+
* same NPI, then clusters the eval records three ways through the same `resolveEntities` pipeline
|
|
10
|
+
* (FS baseline, GBT scorer, LR scorer), sweeping the link threshold for each.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* = same-NPI). The eval NPIs' records are never seen in training.
|
|
15
|
-
* 3. Cluster the EVAL records three ways via the SAME `resolveEntities` pipeline (block → score →
|
|
16
|
-
* connected-components) — once with the FS baseline, once with the GBT as the link scorer
|
|
17
|
-
* (the new `ResolveConfig.scorer` hook), once with the LR. Sweep the link threshold for
|
|
18
|
-
* each; take best F1.
|
|
19
|
-
* 4. Report the eval clustering F1 (the dedup benchmark's metric): does the learned scorer beat the FS
|
|
20
|
-
* baseline on the ASSEMBLED output, not just pairwise ranking?
|
|
21
|
-
*
|
|
22
|
-
* The FS arm IS the benchmark's baseline (same model: address-frequency + collapsed spatial,
|
|
23
|
-
* EM-fit), so the comparison is credible. Honest framing: in-domain (one state), a held-out-NPI
|
|
24
|
-
* split (not a held-out STATE — generalization across states is the next axis), a compact
|
|
25
|
-
* pure-Node GBT.
|
|
12
|
+
* The FS arm is the benchmark baseline (same model: address-frequency plus collapsed spatial,
|
|
13
|
+
* EM-fit), and the split is in-domain, held out by NPI rather than by state.
|
|
26
14
|
*
|
|
27
15
|
* Run: `mailwoman registry scorer-eval clustering [--npis 2000] [--split 0.67] [--seed 1]
|
|
28
16
|
* [--out-md <md>]`
|
|
@@ -64,31 +52,45 @@ import {
|
|
|
64
52
|
*/
|
|
65
53
|
export interface ScorerClusteringEvalOptions {
|
|
66
54
|
/**
|
|
67
|
-
* The injected geocoder factory
|
|
55
|
+
* The injected geocoder factory.
|
|
56
|
+
*
|
|
57
|
+
* The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
|
|
68
58
|
*/
|
|
69
59
|
createGeocoder: EvalGeocoderFactory
|
|
70
60
|
/**
|
|
71
|
-
* Record-matcher sources directory.
|
|
61
|
+
* Record-matcher sources directory.
|
|
62
|
+
*
|
|
63
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
|
|
72
64
|
*/
|
|
73
65
|
sources?: string
|
|
74
66
|
/**
|
|
75
|
-
* State filter.
|
|
67
|
+
* State filter.
|
|
68
|
+
*
|
|
69
|
+
* @defaultValue TX.
|
|
76
70
|
*/
|
|
77
71
|
state?: string
|
|
78
72
|
/**
|
|
79
|
-
* NPIs sampled.
|
|
73
|
+
* NPIs sampled.
|
|
74
|
+
*
|
|
75
|
+
* @defaultValue `2000`
|
|
80
76
|
*/
|
|
81
77
|
npis?: number
|
|
82
78
|
/**
|
|
83
|
-
* Train fraction of the NPI split.
|
|
79
|
+
* Train fraction of the NPI split.
|
|
80
|
+
*
|
|
81
|
+
* @defaultValue `0.67`
|
|
84
82
|
*/
|
|
85
83
|
split?: number
|
|
86
84
|
/**
|
|
87
|
-
* Base
|
|
85
|
+
* Base prng seed.
|
|
86
|
+
*
|
|
87
|
+
* @defaultValue `1`
|
|
88
88
|
*/
|
|
89
89
|
seed?: number
|
|
90
90
|
/**
|
|
91
|
-
* Held-out-NPI splits averaged.
|
|
91
|
+
* Held-out-NPI splits averaged.
|
|
92
|
+
*
|
|
93
|
+
* @defaultValue `4`
|
|
92
94
|
*/
|
|
93
95
|
seeds?: number
|
|
94
96
|
/**
|
|
@@ -98,7 +100,8 @@ export interface ScorerClusteringEvalOptions {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
/**
|
|
101
|
-
*
|
|
103
|
+
* Cluster the eval records with the FS baseline, GBT and LR.
|
|
104
|
+
* Emit the markdown report to stdout.
|
|
102
105
|
*/
|
|
103
106
|
export async function scorerClusteringEval(
|
|
104
107
|
options: ScorerClusteringEvalOptions,
|
|
@@ -114,8 +117,6 @@ export async function scorerClusteringEval(
|
|
|
114
117
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
115
118
|
const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
|
|
116
119
|
|
|
117
|
-
// Build the NPI-keyed benchmark sample and pairwise probe.
|
|
118
|
-
// sample builder). ---
|
|
119
120
|
const {
|
|
120
121
|
rows,
|
|
121
122
|
keptNpis: kept,
|
|
@@ -128,8 +129,9 @@ export async function scorerClusteringEval(
|
|
|
128
129
|
report?.("[C] geocoding…")
|
|
129
130
|
const geocoder = await options.createGeocoder()
|
|
130
131
|
|
|
131
|
-
// `auth
|
|
132
|
-
//
|
|
132
|
+
// `auth` and `taxonomy` ride as attributes so the shared featurizer's roll-up
|
|
133
|
+
// features can read the authorized official.
|
|
134
|
+
// The FS arm ignores them, since no discriminators are configured.
|
|
133
135
|
const mapping: ColumnMapping = {
|
|
134
136
|
id: "npi",
|
|
135
137
|
name: "name",
|
|
@@ -145,10 +147,9 @@ export async function scorerClusteringEval(
|
|
|
145
147
|
|
|
146
148
|
geocoder[Symbol.dispose]()
|
|
147
149
|
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
// The
|
|
151
|
-
// definition. Feed the collapsed-spatial + address-frequency comparison set (the benchmark baseline).
|
|
150
|
+
// The collapsed-spatial and address-frequency comparison set is the benchmark feature basis.
|
|
151
|
+
// The shared production featurizer keeps train, eval and inference on one definition.
|
|
152
|
+
// The agreement pattern is independent of EM, so features stay consistent at train and inference time.
|
|
152
153
|
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
153
154
|
const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
|
|
154
155
|
|
|
@@ -164,10 +165,12 @@ export async function scorerClusteringEval(
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
/**
|
|
167
|
-
* One held-out-NPI split: train the GBT
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
168
|
+
* One held-out-NPI split: train the GBT and LR on train pairs, then cluster
|
|
169
|
+
* the eval records three ways through the same `resolveEntities` pipeline,
|
|
170
|
+
* sweeping the link threshold for each and taking best F1.
|
|
171
|
+
*
|
|
172
|
+
* The geocode is shared across seeds.
|
|
173
|
+
* Only the split, trained scorers and the eval subset move with the seed.
|
|
171
174
|
*/
|
|
172
175
|
function runSeed(seed: number): SeedResult {
|
|
173
176
|
const rnd = makeLcg(seed || 1)
|
|
@@ -189,7 +192,7 @@ export async function scorerClusteringEval(
|
|
|
189
192
|
const dim = trainX[0]?.length ?? 0
|
|
190
193
|
const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
|
|
191
194
|
|
|
192
|
-
// LR (batch GD, class-balanced)
|
|
195
|
+
// LR (batch GD, class-balanced) through the shared trainer.
|
|
193
196
|
const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
|
|
194
197
|
|
|
195
198
|
const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
|
|
@@ -201,14 +204,15 @@ export async function scorerClusteringEval(
|
|
|
201
204
|
): ArmScore =>
|
|
202
205
|
bestOver(thresholds, (t) => toArmScore(scoreEntities(resolveEntities(evalRecords, cfg(t)).entities, npiLabel, N)))
|
|
203
206
|
|
|
204
|
-
// FS baseline
|
|
205
|
-
// scorer
|
|
207
|
+
// The FS baseline uses EM-fit weights in bits over a fine grid.
|
|
208
|
+
// Each learned scorer sweeps its own eval-pair score distribution,
|
|
209
|
+
// so a coarse grid cannot understate it.
|
|
206
210
|
const { pairs: evalPairs } = block(evalRecords, defaultBlockingKeys())
|
|
207
211
|
|
|
208
212
|
const fs = armOver(
|
|
209
213
|
Array.from({ length: 26 }, (_, i) => i),
|
|
210
|
-
// learnedScorer
|
|
211
|
-
// is
|
|
214
|
+
// learnedScorer false keeps the FS baseline.
|
|
215
|
+
// The learned scorer is default-on, so without this the FS arm would silently be the GBT.
|
|
212
216
|
(t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
|
|
213
217
|
)
|
|
214
218
|
|
|
@@ -326,7 +330,7 @@ export async function scorerClusteringEval(
|
|
|
326
330
|
`fair. The GBT is a compact pure-Node implementation (120 rounds, depth 3), not a tuned XGBoost/LightGBM — a real ` +
|
|
327
331
|
`GBM with more NPIs/features could move the number further. Thresholds are swept per scorer (FS in bits, learned ` +
|
|
328
332
|
`scorers in logits), each at its own best operating point — note a 300-NPI smoke MISLED (FS ahead): too few ` +
|
|
329
|
-
`co-located collisions to exhibit the over-merge
|
|
333
|
+
`co-located collisions to exhibit the over-merge. It only bites at scale. Therefore, trust the larger eval. NPI-as-truth ` +
|
|
330
334
|
`is conservative (a cross-NPI merge is a candidate, not necessarily an error)._`
|
|
331
335
|
)
|
|
332
336
|
|
|
@@ -3,19 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Learned-scorer
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* The production question is whether that win GENERALIZES: train on one state, evaluate the dedup
|
|
10
|
-
* clustering F1 on a DIFFERENT state the model never saw. If it holds, the GBM is
|
|
11
|
-
* production-worthy; if it collapses, the scorer is fitting state-specific structure and needs
|
|
12
|
-
* per-state training (a finding either way).
|
|
6
|
+
* Learned-scorer cross-state generalization, the next axis after the held-out-NPI A/B. The
|
|
7
|
+
* within-state A/B showed the GBT beats the FS baseline on clustering, so this trains on one state and
|
|
8
|
+
* evaluates clustering F1 on a different state the model never saw.
|
|
13
9
|
*
|
|
14
|
-
* One registry pass builds the global address-frequency table
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* per-scorer threshold sweep. The metric is the dedup benchmark's clustering F1.
|
|
10
|
+
* One registry pass builds the global address-frequency table, a train-state sample and an
|
|
11
|
+
* eval-state sample. Both samples are geocoded. The GBT and LR train on the train state's pairs and
|
|
12
|
+
* cluster the eval state's records through the same `resolveEntities` pipeline, with best F1 over a
|
|
13
|
+
* fine per-scorer threshold sweep.
|
|
19
14
|
*
|
|
20
15
|
* Run: `mailwoman registry scorer-eval cross-state [--train-state TX] [--eval-state CA]
|
|
21
16
|
* [--npis 2000] [--out-md <md>]`
|
|
@@ -55,23 +50,33 @@ import {
|
|
|
55
50
|
*/
|
|
56
51
|
export interface ScorerCrossStateEvalOptions {
|
|
57
52
|
/**
|
|
58
|
-
* The injected geocoder factory
|
|
53
|
+
* The injected geocoder factory.
|
|
54
|
+
*
|
|
55
|
+
* The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
|
|
59
56
|
*/
|
|
60
57
|
createGeocoder: EvalGeocoderFactory
|
|
61
58
|
/**
|
|
62
|
-
* Record-matcher sources directory.
|
|
59
|
+
* Record-matcher sources directory.
|
|
60
|
+
*
|
|
61
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
|
|
63
62
|
*/
|
|
64
63
|
sources?: string
|
|
65
64
|
/**
|
|
66
|
-
* State the GBT/LR train on.
|
|
65
|
+
* State the GBT/LR train on.
|
|
66
|
+
*
|
|
67
|
+
* @defaultValue TX.
|
|
67
68
|
*/
|
|
68
69
|
trainState?: string
|
|
69
70
|
/**
|
|
70
|
-
* Held-out state clustered.
|
|
71
|
+
* Held-out state clustered.
|
|
72
|
+
*
|
|
73
|
+
* @defaultValue CA.
|
|
71
74
|
*/
|
|
72
75
|
evalState?: string
|
|
73
76
|
/**
|
|
74
|
-
* NPIs sampled per state.
|
|
77
|
+
* NPIs sampled per state.
|
|
78
|
+
*
|
|
79
|
+
* @defaultValue `2000`
|
|
75
80
|
*/
|
|
76
81
|
npis?: number
|
|
77
82
|
/**
|
|
@@ -81,7 +86,8 @@ export interface ScorerCrossStateEvalOptions {
|
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
/**
|
|
84
|
-
*
|
|
89
|
+
* Train on one state and cluster a different state's records.
|
|
90
|
+
* Emit the report to stdout.
|
|
85
91
|
*/
|
|
86
92
|
export async function scorerCrossStateEval(
|
|
87
93
|
options: ScorerCrossStateEvalOptions,
|
|
@@ -96,8 +102,6 @@ export async function scorerCrossStateEval(
|
|
|
96
102
|
const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`
|
|
97
103
|
const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`
|
|
98
104
|
|
|
99
|
-
// ONE registry pass fills BOTH state buckets (the SHARED multi-state sample builder): the global
|
|
100
|
-
// address-frequency table + a TRAIN-state sample + an EVAL-state sample.
|
|
101
105
|
const { byState, addressFrequency } = await buildNPPESStateSamples(
|
|
102
106
|
{
|
|
103
107
|
registryPath: REGISTRY,
|
|
@@ -114,8 +118,9 @@ export async function scorerCrossStateEval(
|
|
|
114
118
|
report?.("[C] geocoding both states…")
|
|
115
119
|
const geocoder = await options.createGeocoder()
|
|
116
120
|
|
|
117
|
-
// `auth
|
|
118
|
-
//
|
|
121
|
+
// `auth` and `taxonomy` ride as attributes so the shared featurizer's roll-up
|
|
122
|
+
// features can read the authorized official.
|
|
123
|
+
// The FS arm ignores them, since no discriminators are configured.
|
|
119
124
|
const mapping: ColumnMapping = {
|
|
120
125
|
id: "npi",
|
|
121
126
|
name: "name",
|
|
@@ -129,8 +134,8 @@ export async function scorerCrossStateEval(
|
|
|
129
134
|
const evalRecords = await ingestRows(evalSample.rows, mapping, { geocodeAddress: geocoder.geocodeAddress })
|
|
130
135
|
geocoder[Symbol.dispose]()
|
|
131
136
|
|
|
132
|
-
//
|
|
133
|
-
// collapsed-spatial
|
|
137
|
+
// The shared production featurizer keeps train, eval and inference on one definition,
|
|
138
|
+
// over the collapsed-spatial and address-frequency comparison set.
|
|
134
139
|
const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons
|
|
135
140
|
const featurize = createMatchFeaturizer({ comparisons, addressFrequency })
|
|
136
141
|
|
|
@@ -143,7 +148,7 @@ export async function scorerCrossStateEval(
|
|
|
143
148
|
const dim = trainX[0]?.length ?? 0
|
|
144
149
|
const gbt = trainGBT(trainX, trainY, trainW, { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 })
|
|
145
150
|
|
|
146
|
-
// LR (batch GD, class-balanced)
|
|
151
|
+
// LR (batch GD, class-balanced) through the shared trainer.
|
|
147
152
|
const lrSc = trainLogisticRegression(trainX, trainY, trainW, dim)
|
|
148
153
|
|
|
149
154
|
const gbtScorer = (a: SourceRecord, b: SourceRecord) => gbtScore(gbt, featurize(a, b))
|
|
@@ -165,8 +170,8 @@ export async function scorerCrossStateEval(
|
|
|
165
170
|
|
|
166
171
|
const fs = armOver(
|
|
167
172
|
Array.from({ length: 26 }, (_, i) => i),
|
|
168
|
-
// learnedScorer
|
|
169
|
-
// without this the
|
|
173
|
+
// learnedScorer false keeps the FS baseline.
|
|
174
|
+
// The learned scorer is default-on, so without this the FS arm would silently be the GBT.
|
|
170
175
|
(t) => ({ addressFrequency, collapseSpatial: true, trainEM: true, threshold: t, learnedScorer: false })
|
|
171
176
|
)
|
|
172
177
|
|
|
@@ -184,9 +189,8 @@ export async function scorerCrossStateEval(
|
|
|
184
189
|
threshold: t,
|
|
185
190
|
}))
|
|
186
191
|
|
|
187
|
-
// The
|
|
188
|
-
//
|
|
189
|
-
// caller would get, evaluated on a state it never trained on.
|
|
192
|
+
// The bundled DEDUP_GBT_MODEL is the shipped artifact every caller receives,
|
|
193
|
+
// evaluated here on a state it never trained on.
|
|
190
194
|
const bundledScorer = createGBTScorer({ model: DEDUP_GBT_MODEL, comparisons, addressFrequency })
|
|
191
195
|
|
|
192
196
|
const bundledArm = armOver(quantileThresholds(evalPairs.map(([a, b]) => bundledScorer(a, b))), (t) => ({
|