@mailwoman/registry 9.4.0 → 10.1.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 +10 -10
- package/lib/address-key.ts +14 -10
- package/lib/geocode-handler.ts +6 -4
- package/lib/geojson.ts +13 -17
- package/lib/ingest.ts +57 -83
- package/lib/learned-scorer.ts +38 -44
- package/lib/map-html.ts +24 -70
- 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 -55
- package/lib/resolve.ts +180 -124
- package/lib/types.ts +18 -12
- 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 +6 -4
- 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 -15
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts +46 -75
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +27 -54
- 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 +9 -62
- 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 +35 -50
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +19 -43
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +150 -90
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +62 -63
- 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 +58 -0
- package/out/tools/cross/dataset-correlation.d.ts.map +1 -0
- package/out/tools/{cross-dataset-correlation.js → cross/dataset-correlation.js} +10 -62
- package/out/tools/cross/dataset-correlation.js.map +1 -0
- package/out/tools/cross/source-threshold-sweep.d.ts +60 -0
- package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -0
- package/out/tools/{cross-source-threshold-sweep.js → cross/source-threshold-sweep.js} +15 -41
- package/out/tools/cross/source-threshold-sweep.js.map +1 -0
- 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 +22 -15
- 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 +33 -0
- package/out/tools/geocoder/namesake-probe.d.ts.map +1 -0
- package/out/tools/{geocoder-namesake-probe.js → geocoder/namesake-probe.js} +7 -8
- package/out/tools/geocoder/namesake-probe.js.map +1 -0
- package/out/tools/geocoder/vs-provided-coords.d.ts +53 -0
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -0
- package/out/tools/{geocoder-vs-provided-coords.js → geocoder/vs-provided-coords.js} +31 -28
- package/out/tools/geocoder/vs-provided-coords.js.map +1 -0
- 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 +77 -0
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -0
- package/out/tools/{learned-scorer-clustering-eval.js → learned/scorer/clustering-eval.js} +29 -39
- package/out/tools/learned/scorer/clustering-eval.js.map +1 -0
- package/out/tools/learned/scorer/crossstate-eval.d.ts +65 -0
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -0
- package/out/tools/{learned-scorer-crossstate-eval.js → learned/scorer/crossstate-eval.js} +20 -26
- package/out/tools/learned/scorer/crossstate-eval.js.map +1 -0
- package/out/tools/learned/scorer/eval.d.ts +60 -0
- package/out/tools/learned/scorer/eval.d.ts.map +1 -0
- package/out/tools/{learned-scorer-eval.js → learned/scorer/eval.js} +12 -72
- package/out/tools/learned/scorer/eval.js.map +1 -0
- 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 +81 -0
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -0
- package/out/tools/{nppes-dedup-benchmark.js → nppes/dedup-benchmark.js} +21 -67
- package/out/tools/nppes/dedup-benchmark.js.map +1 -0
- package/out/tools/nppes/org-name.d.ts +5 -4
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +2 -2
- 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 +7 -8
- 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 +28 -17
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +23 -26
- 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 +63 -59
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +49 -66
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train/cross-gbt.d.ts +88 -0
- package/out/tools/train/cross-gbt.d.ts.map +1 -0
- package/out/tools/{train-cross-gbt.js → train/cross-gbt.js} +15 -26
- package/out/tools/train/cross-gbt.js.map +1 -0
- package/out/tools/train/gbt.d.ts +85 -0
- package/out/tools/train/gbt.d.ts.map +1 -0
- package/out/tools/{train-gbt.js → train/gbt.js} +28 -32
- package/out/tools/train/gbt.js.map +1 -0
- package/out/tools/train/org-cross-gbt.d.ts +84 -0
- package/out/tools/train/org-cross-gbt.d.ts.map +1 -0
- package/out/tools/{train-org-cross-gbt.js → train/org-cross-gbt.js} +19 -23
- package/out/tools/train/org-cross-gbt.js.map +1 -0
- 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 +10 -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 → render/map.d.ts} +6 -6
- package/out/tools/viz/render/map.d.ts.map +1 -0
- package/out/tools/viz/{render-map.js → render/map.js} +7 -6
- package/out/tools/viz/render/map.js.map +1 -0
- package/out/tools/viz/render.d.ts +12 -8
- package/out/tools/viz/render.d.ts.map +1 -1
- package/out/tools/viz/render.js +8 -7
- package/out/tools/viz/render.js.map +1 -1
- 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 +17 -11
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -2
- package/out/types.js.map +1 -1
- package/package.json +41 -184
- package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
- package/{lib/tools/cross-dataset-correlation.ts → tools/cross/dataset-correlation.ts} +31 -72
- package/{lib/tools/cross-source-threshold-sweep.ts → tools/cross/source-threshold-sweep.ts} +29 -46
- package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
- package/tools/eval-geocoder.ts +74 -0
- package/{lib/tools/geocoder-namesake-probe.ts → tools/geocoder/namesake-probe.ts} +9 -8
- package/{lib/tools/geocoder-vs-provided-coords.ts → tools/geocoder/vs-provided-coords.ts} +39 -30
- package/{lib/tools → tools}/gold-set-sample.ts +35 -29
- package/{lib/tools/learned-scorer-clustering-eval.ts → tools/learned/scorer/clustering-eval.ts} +49 -45
- package/{lib/tools/learned-scorer-crossstate-eval.ts → tools/learned/scorer/crossstate-eval.ts} +34 -30
- package/{lib/tools/learned-scorer-eval.ts → tools/learned/scorer/eval.ts} +35 -78
- package/{lib/tools → tools}/matcher-scale.ts +21 -33
- package/{lib/tools/nppes-dedup-benchmark.ts → tools/nppes/dedup-benchmark.ts} +37 -82
- package/{lib/tools → tools}/nppes/org-name.ts +5 -4
- package/{lib/tools → tools}/nppes/overmerge-packet.ts +17 -13
- package/{lib/tools → tools}/nppes/report.ts +32 -25
- package/{lib/tools → tools}/nppes/sample.ts +41 -36
- 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 +73 -83
- package/{lib/tools/train-cross-gbt.ts → tools/train/cross-gbt.ts} +38 -34
- package/{lib/tools/train-gbt.ts → tools/train/gbt.ts} +55 -41
- package/{lib/tools/train-org-cross-gbt.ts → tools/train/org-cross-gbt.ts} +39 -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 +28 -17
- package/{lib/tools/viz/render-map.ts → tools/viz/render/map.ts} +7 -6
- package/{lib/tools → 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/out/tools/cross-dataset-correlation.d.ts +0 -65
- package/out/tools/cross-dataset-correlation.d.ts.map +0 -1
- package/out/tools/cross-dataset-correlation.js.map +0 -1
- package/out/tools/cross-source-threshold-sweep.d.ts +0 -66
- package/out/tools/cross-source-threshold-sweep.d.ts.map +0 -1
- package/out/tools/cross-source-threshold-sweep.js.map +0 -1
- package/out/tools/geocoder-namesake-probe.d.ts +0 -32
- package/out/tools/geocoder-namesake-probe.d.ts.map +0 -1
- package/out/tools/geocoder-namesake-probe.js.map +0 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts +0 -50
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +0 -1
- package/out/tools/geocoder-vs-provided-coords.js.map +0 -1
- 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/learned-scorer-clustering-eval.d.ts +0 -74
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +0 -1
- package/out/tools/learned-scorer-clustering-eval.js.map +0 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts +0 -59
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +0 -1
- package/out/tools/learned-scorer-crossstate-eval.js.map +0 -1
- package/out/tools/learned-scorer-eval.d.ts +0 -77
- package/out/tools/learned-scorer-eval.d.ts.map +0 -1
- package/out/tools/learned-scorer-eval.js.map +0 -1
- package/out/tools/nppes-dedup-benchmark.d.ts +0 -101
- package/out/tools/nppes-dedup-benchmark.d.ts.map +0 -1
- package/out/tools/nppes-dedup-benchmark.js.map +0 -1
- package/out/tools/train-cross-gbt.d.ts +0 -78
- package/out/tools/train-cross-gbt.d.ts.map +0 -1
- package/out/tools/train-cross-gbt.js.map +0 -1
- package/out/tools/train-gbt.d.ts +0 -69
- package/out/tools/train-gbt.d.ts.map +0 -1
- package/out/tools/train-gbt.js.map +0 -1
- package/out/tools/train-org-cross-gbt.d.ts +0 -71
- package/out/tools/train-org-cross-gbt.d.ts.map +0 -1
- package/out/tools/train-org-cross-gbt.js.map +0 -1
- package/out/tools/viz/render-map.d.ts.map +0 -1
- package/out/tools/viz/render-map.js.map +0 -1
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Admin-tier wrong-region probe
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and flags any result outside the Texas bounding box.
|
|
6
|
+
* Admin-tier wrong-region probe. When no street extract covers an address, the admin cascade can
|
|
7
|
+
* resolve the locality by name and, when the region or postcode constraint is weak, pick the
|
|
8
|
+
* population-dominant foreign namesake instead of the in-state Texas city. This probes a curated
|
|
9
|
+
* set of TX namesake cities, with and without ZIP. It flags any result outside the Texas bounding
|
|
10
|
+
* box.
|
|
12
11
|
*
|
|
13
12
|
* Run: `mailwoman registry scorer-eval namesake-probe`
|
|
14
13
|
*/
|
|
@@ -23,7 +22,9 @@ import { inTXBBOX } from "#tools/shared"
|
|
|
23
22
|
*/
|
|
24
23
|
export interface GeocoderNamesakeProbeOptions {
|
|
25
24
|
/**
|
|
26
|
-
* The injected geocoder factory
|
|
25
|
+
* The injected geocoder factory.
|
|
26
|
+
*
|
|
27
|
+
* The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
|
|
27
28
|
*/
|
|
28
29
|
createGeocoder: EvalGeocoderFactory
|
|
29
30
|
}
|
|
@@ -43,7 +44,7 @@ const CASES: Array<{ city: string; zip: string; tx: [number, number]; namesake:
|
|
|
43
44
|
]
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
|
-
*
|
|
47
|
+
* Probe a curated set of TX namesake cities and print one line per variant to stdout.
|
|
47
48
|
*/
|
|
48
49
|
export async function geocoderNamesakeProbe(
|
|
49
50
|
options: GeocoderNamesakeProbeOptions,
|
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Geocoder validation against provided coordinates
|
|
7
|
-
*
|
|
6
|
+
* Geocoder validation against provided coordinates. TX HHSC's nursing-facilities registry ships
|
|
7
|
+
* a `Geo Location` (`lat,lon`) per facility alongside its physical address. Geocode the address
|
|
8
|
+
* with mailwoman's parser and resolver, then measure the great-circle delta to the provided point,
|
|
9
|
+
* broken down by resolution tier.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* tier we assign (address_point / interpolated / admin). This is an independent check of the
|
|
13
|
-
* geocoder on real facility addresses; it does not touch the matcher.
|
|
14
|
-
*
|
|
15
|
-
* The provided coordinate is treated as ground truth for _this_ eval, with the honest caveat that
|
|
16
|
-
* it is itself a third-party geocode of unknown provenance — a large delta is a discrepancy to
|
|
17
|
-
* inspect, not automatically our error.
|
|
11
|
+
* The provided coordinate is treated as ground truth for this eval, with the caveat that it is
|
|
12
|
+
* itself a third-party geocode of unknown provenance. A large delta is a discrepancy to inspect
|
|
13
|
+
* rather than automatically our error.
|
|
18
14
|
*
|
|
19
15
|
* Run: `mailwoman registry scorer-eval vs-provided-coords [--max 1176] [--wof <admin.db>]
|
|
20
16
|
* [--data-root <dir>] [--out-md docs/articles/evals/resolver-geo/<date>-...md]`
|
|
@@ -25,6 +21,7 @@ import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
|
25
21
|
import { isPresent } from "@mailwoman/core/objects"
|
|
26
22
|
import { percentile } from "@mailwoman/core/stats"
|
|
27
23
|
import { haversineKm } from "@mailwoman/match"
|
|
24
|
+
import { TextSpliterator } from "spliterator"
|
|
28
25
|
|
|
29
26
|
import { streamRows } from "#index"
|
|
30
27
|
import type { EvalGeocoderFactory } from "#tools/eval-geocoder"
|
|
@@ -45,15 +42,21 @@ const MAX_ABS_LONGITUDE = 180
|
|
|
45
42
|
*/
|
|
46
43
|
export interface GeocoderVsProvidedCoordsOptions {
|
|
47
44
|
/**
|
|
48
|
-
* The injected geocoder factory
|
|
45
|
+
* The injected geocoder factory.
|
|
46
|
+
*
|
|
47
|
+
* The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
|
|
49
48
|
*/
|
|
50
49
|
createGeocoder: EvalGeocoderFactory
|
|
51
50
|
/**
|
|
52
|
-
* Record-matcher sources directory.
|
|
51
|
+
* Record-matcher sources directory.
|
|
52
|
+
*
|
|
53
|
+
* Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
|
|
53
54
|
*/
|
|
54
55
|
sources?: string
|
|
55
56
|
/**
|
|
56
|
-
* Facilities geocoded.
|
|
57
|
+
* Facilities geocoded.
|
|
58
|
+
*
|
|
59
|
+
* Default 2000.
|
|
57
60
|
*/
|
|
58
61
|
max?: number
|
|
59
62
|
/**
|
|
@@ -63,22 +66,28 @@ export interface GeocoderVsProvidedCoordsOptions {
|
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
/**
|
|
66
|
-
* Parse a `lat,lon` string into a coordinate, or null if malformed
|
|
69
|
+
* Parse a `lat,lon` string into a coordinate, or null if malformed or out of range.
|
|
70
|
+
*
|
|
71
|
+
* Deliberately strict and deliberately not `GeoPoint.from()`.
|
|
72
|
+
* The provided coordinate is this eval's ground truth, so a row that cannot be read exactly
|
|
73
|
+
* is dropped (counted in `noCoord`) rather than repaired into something plausible.
|
|
74
|
+
*
|
|
75
|
+
* A silently repaired coordinate lands in the delta distribution as geocoder error.
|
|
76
|
+
*
|
|
77
|
+
* This source writes `latitude,longitude`, while `GeoPoint` reads GeoJSON `[longitude, latitude]`,
|
|
78
|
+
* so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there.
|
|
79
|
+
* `GeoPoint.from` also maps 0,0 to null.
|
|
80
|
+
*
|
|
81
|
+
* This moves Null Island out of the measured outliers and into the skipped bucket.
|
|
82
|
+
*
|
|
83
|
+
* The report attributes part of its p99/max tail to malformed provided coordinates,
|
|
84
|
+
* so those rows have to stay rejected or measured as-is, never rewritten.
|
|
67
85
|
*
|
|
68
|
-
*
|
|
69
|
-
* a row we cannot read exactly has to be _dropped_ (counted in `noCoord`) rather than repaired into something plausible
|
|
70
|
-
* — a silently repaired coordinate lands in the delta distribution as geocoder error. Two of the three divergences that
|
|
71
|
-
* originally justified this parser were defects in `GeoPoint` and were fixed on 2026-08-05: it no longer guesses axis
|
|
72
|
-
* order from the magnitudes, and an out-of-range value is now rejected instead of accepted (`200,-97.74` used to become
|
|
73
|
-
* a point). What remains is not a defect and not negotiable. This source writes `latitude,longitude`; `GeoPoint` reads
|
|
74
|
-
* GeoJSON `[longitude, latitude]`, so `31.5,-89.5` is a Mississippi row here and a South-Atlantic point there — and
|
|
75
|
-
* `GeoPoint.from` maps 0,0 to null, which moves Null Island out of the measured outliers and into the skipped bucket.
|
|
76
|
-
* The report below attributes part of its p99/max tail to malformed provided coordinates, so those rows have to stay
|
|
77
|
-
* rejected or measured as-is, never rewritten. Strictness is the measurement, not an unfinished migration.
|
|
86
|
+
* Strictness is the measurement rather than an unfinished migration.
|
|
78
87
|
*/
|
|
79
88
|
function parseLatLon(raw: string | undefined): { latitude: number; longitude: number } | null {
|
|
80
89
|
if (!raw) return null
|
|
81
|
-
const [a, b] =
|
|
90
|
+
const [a, b] = TextSpliterator.from(raw, { delimiter: "," }).map(Number).toArray()
|
|
82
91
|
|
|
83
92
|
if (!Number.isFinite(a) || !Number.isFinite(b)) return null
|
|
84
93
|
|
|
@@ -87,12 +96,13 @@ function parseLatLon(raw: string | undefined): { latitude: number; longitude: nu
|
|
|
87
96
|
return { latitude: a!, longitude: b! }
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
// The core nearest-rank `percentile` (q in [0,100])
|
|
91
|
-
//
|
|
99
|
+
// The core nearest-rank `percentile` (q in [0,100]) uses a floor index and clamping.
|
|
100
|
+
// `?? NaN` returns NaN when the percentile helper returns null for an empty sample.
|
|
92
101
|
const quantile = (xs: number[], q: number): number => percentile(xs, q * 100) ?? Number.NaN
|
|
93
102
|
|
|
94
103
|
/**
|
|
95
|
-
*
|
|
104
|
+
* Geocode each facility's physical address and measure the delta to its provided
|
|
105
|
+
* coordinate, then emit the report to stdout.
|
|
96
106
|
*/
|
|
97
107
|
export async function geocoderVsProvidedCoords(
|
|
98
108
|
options: GeocoderVsProvidedCoordsOptions,
|
|
@@ -149,7 +159,6 @@ export async function geocoderVsProvidedCoords(
|
|
|
149
159
|
|
|
150
160
|
geocoder[Symbol.dispose]()
|
|
151
161
|
|
|
152
|
-
// Overall + per-tier percentiles.
|
|
153
162
|
const all = results.map((r) => r.deltaM).toSorted((a, b) => a - b)
|
|
154
163
|
const byTier = new Map<string, number[]>()
|
|
155
164
|
|
|
@@ -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
|
+
* Default `$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
|
+
* Default 200000.
|
|
39
43
|
*/
|
|
40
44
|
cap?: number
|
|
41
45
|
/**
|
|
42
|
-
* State filter.
|
|
46
|
+
* State filter.
|
|
47
|
+
*
|
|
48
|
+
* Default TX.
|
|
43
49
|
*/
|
|
44
50
|
state?: string
|
|
45
51
|
/**
|
|
46
|
-
* Org-name Jaccard collision threshold.
|
|
52
|
+
* Org-name Jaccard collision threshold.
|
|
53
|
+
*
|
|
54
|
+
* Default 0.7.
|
|
47
55
|
*/
|
|
48
56
|
tau?: number
|
|
49
57
|
/**
|
|
50
|
-
* Adjudication sample size.
|
|
58
|
+
* Adjudication sample size.
|
|
59
|
+
*
|
|
60
|
+
* Default 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
|
|
package/{lib/tools/learned-scorer-clustering-eval.ts → tools/learned/scorer/clustering-eval.ts}
RENAMED
|
@@ -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
|
+
* Default `$MAILWOMAN_DATA_ROOT/record-matcher/sources`.
|
|
72
64
|
*/
|
|
73
65
|
sources?: string
|
|
74
66
|
/**
|
|
75
|
-
* State filter.
|
|
67
|
+
* State filter.
|
|
68
|
+
*
|
|
69
|
+
* Default TX.
|
|
76
70
|
*/
|
|
77
71
|
state?: string
|
|
78
72
|
/**
|
|
79
|
-
* NPIs sampled.
|
|
73
|
+
* NPIs sampled.
|
|
74
|
+
*
|
|
75
|
+
* Default 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
|
+
* Default 0.67.
|
|
84
82
|
*/
|
|
85
83
|
split?: number
|
|
86
84
|
/**
|
|
87
|
-
* Base
|
|
85
|
+
* Base prng seed.
|
|
86
|
+
*
|
|
87
|
+
* Default 1.
|
|
88
88
|
*/
|
|
89
89
|
seed?: number
|
|
90
90
|
/**
|
|
91
|
-
* Held-out-NPI splits averaged.
|
|
91
|
+
* Held-out-NPI splits averaged.
|
|
92
|
+
*
|
|
93
|
+
* Default 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
|
-
// --- Data-gen: the same NPI-keyed records as the dedup benchmark + the pairwise probe (the SHARED
|
|
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
|
|
package/{lib/tools/learned-scorer-crossstate-eval.ts → tools/learned/scorer/crossstate-eval.ts}
RENAMED
|
@@ -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
|
+
* Default `$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
|
+
* Default TX.
|
|
67
68
|
*/
|
|
68
69
|
trainState?: string
|
|
69
70
|
/**
|
|
70
|
-
* Held-out state clustered.
|
|
71
|
+
* Held-out state clustered.
|
|
72
|
+
*
|
|
73
|
+
* Default CA.
|
|
71
74
|
*/
|
|
72
75
|
evalState?: string
|
|
73
76
|
/**
|
|
74
|
-
* NPIs sampled per state.
|
|
77
|
+
* NPIs sampled per state.
|
|
78
|
+
*
|
|
79
|
+
* Default 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) => ({
|