@mailwoman/entity-resolution 0.0.0-stage → 10.8.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.
Files changed (227) hide show
  1. package/README.md +114 -2
  2. package/lib/address-key.ts +46 -0
  3. package/lib/geocode-handler.ts +37 -0
  4. package/lib/geojson.ts +72 -0
  5. package/lib/index.ts +23 -0
  6. package/lib/ingest.ts +349 -0
  7. package/lib/learned-scorer.ts +134 -0
  8. package/lib/map-html.ts +287 -0
  9. package/lib/models/crosssource-gbt-en-us.ts +43 -0
  10. package/lib/models/dedup-gbt-en-us.ts +47 -0
  11. package/lib/models/org-crosssource-gbt-en-us.ts +43 -0
  12. package/lib/reconcile.ts +239 -0
  13. package/lib/resolve.ts +569 -0
  14. package/lib/types.ts +110 -0
  15. package/out/address-key.d.ts +34 -0
  16. package/out/address-key.d.ts.map +1 -0
  17. package/out/address-key.js +41 -0
  18. package/out/address-key.js.map +1 -0
  19. package/out/geocode-handler.d.ts +20 -0
  20. package/out/geocode-handler.d.ts.map +1 -0
  21. package/out/geocode-handler.js +29 -0
  22. package/out/geocode-handler.js.map +1 -0
  23. package/out/geojson.d.ts +28 -0
  24. package/out/geojson.d.ts.map +1 -0
  25. package/out/geojson.js +62 -0
  26. package/out/geojson.js.map +1 -0
  27. package/out/index.d.ts +23 -0
  28. package/out/index.d.ts.map +1 -0
  29. package/out/index.js +23 -0
  30. package/out/index.js.map +1 -0
  31. package/out/ingest.d.ts +173 -0
  32. package/out/ingest.d.ts.map +1 -0
  33. package/out/ingest.js +185 -0
  34. package/out/ingest.js.map +1 -0
  35. package/out/learned-scorer.d.ts +61 -0
  36. package/out/learned-scorer.d.ts.map +1 -0
  37. package/out/learned-scorer.js +91 -0
  38. package/out/learned-scorer.js.map +1 -0
  39. package/out/map-html.d.ts +39 -0
  40. package/out/map-html.d.ts.map +1 -0
  41. package/out/map-html.js +220 -0
  42. package/out/map-html.js.map +1 -0
  43. package/out/models/crosssource-gbt-en-us.d.ts +45 -0
  44. package/out/models/crosssource-gbt-en-us.d.ts.map +1 -0
  45. package/out/models/crosssource-gbt-en-us.js +40 -0
  46. package/out/models/crosssource-gbt-en-us.js.map +1 -0
  47. package/out/models/dedup-gbt-en-us.d.ts +44 -0
  48. package/out/models/dedup-gbt-en-us.d.ts.map +1 -0
  49. package/out/models/dedup-gbt-en-us.js +44 -0
  50. package/out/models/dedup-gbt-en-us.js.map +1 -0
  51. package/out/models/org-crosssource-gbt-en-us.d.ts +45 -0
  52. package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -0
  53. package/out/models/org-crosssource-gbt-en-us.js +40 -0
  54. package/out/models/org-crosssource-gbt-en-us.js.map +1 -0
  55. package/out/reconcile.d.ts +96 -0
  56. package/out/reconcile.d.ts.map +1 -0
  57. package/out/reconcile.js +127 -0
  58. package/out/reconcile.js.map +1 -0
  59. package/out/resolve.d.ts +264 -0
  60. package/out/resolve.d.ts.map +1 -0
  61. package/out/resolve.js +282 -0
  62. package/out/resolve.js.map +1 -0
  63. package/out/tools/coverage-reconciliation.d.ts +67 -0
  64. package/out/tools/coverage-reconciliation.d.ts.map +1 -0
  65. package/out/tools/coverage-reconciliation.js +113 -0
  66. package/out/tools/coverage-reconciliation.js.map +1 -0
  67. package/out/tools/cross/dataset-correlation.d.ts +61 -0
  68. package/out/tools/cross/dataset-correlation.d.ts.map +1 -0
  69. package/out/tools/cross/dataset-correlation.js +244 -0
  70. package/out/tools/cross/dataset-correlation.js.map +1 -0
  71. package/out/tools/cross/source-threshold-sweep.d.ts +60 -0
  72. package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -0
  73. package/out/tools/cross/source-threshold-sweep.js +264 -0
  74. package/out/tools/cross/source-threshold-sweep.js.map +1 -0
  75. package/out/tools/dedup-ceiling.d.ts +62 -0
  76. package/out/tools/dedup-ceiling.d.ts.map +1 -0
  77. package/out/tools/dedup-ceiling.js +171 -0
  78. package/out/tools/dedup-ceiling.js.map +1 -0
  79. package/out/tools/eval-geocoder.d.ts +68 -0
  80. package/out/tools/eval-geocoder.d.ts.map +1 -0
  81. package/out/tools/eval-geocoder.js +13 -0
  82. package/out/tools/eval-geocoder.js.map +1 -0
  83. package/out/tools/geocoder/namesake-probe.d.ts +33 -0
  84. package/out/tools/geocoder/namesake-probe.d.ts.map +1 -0
  85. package/out/tools/geocoder/namesake-probe.js +60 -0
  86. package/out/tools/geocoder/namesake-probe.js.map +1 -0
  87. package/out/tools/geocoder/vs-provided-coords.d.ts +53 -0
  88. package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -0
  89. package/out/tools/geocoder/vs-provided-coords.js +161 -0
  90. package/out/tools/geocoder/vs-provided-coords.js.map +1 -0
  91. package/out/tools/gold-set-sample.d.ts +67 -0
  92. package/out/tools/gold-set-sample.d.ts.map +1 -0
  93. package/out/tools/gold-set-sample.js +81 -0
  94. package/out/tools/gold-set-sample.js.map +1 -0
  95. package/out/tools/learned/scorer/clustering-eval.d.ts +77 -0
  96. package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -0
  97. package/out/tools/learned/scorer/clustering-eval.js +207 -0
  98. package/out/tools/learned/scorer/clustering-eval.js.map +1 -0
  99. package/out/tools/learned/scorer/crossstate-eval.d.ts +65 -0
  100. package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -0
  101. package/out/tools/learned/scorer/crossstate-eval.js +168 -0
  102. package/out/tools/learned/scorer/crossstate-eval.js.map +1 -0
  103. package/out/tools/learned/scorer/eval.d.ts +64 -0
  104. package/out/tools/learned/scorer/eval.d.ts.map +1 -0
  105. package/out/tools/learned/scorer/eval.js +275 -0
  106. package/out/tools/learned/scorer/eval.js.map +1 -0
  107. package/out/tools/matcher-scale.d.ts +40 -0
  108. package/out/tools/matcher-scale.d.ts.map +1 -0
  109. package/out/tools/matcher-scale.js +111 -0
  110. package/out/tools/matcher-scale.js.map +1 -0
  111. package/out/tools/nppes/dedup-benchmark.d.ts +82 -0
  112. package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -0
  113. package/out/tools/nppes/dedup-benchmark.js +226 -0
  114. package/out/tools/nppes/dedup-benchmark.js.map +1 -0
  115. package/out/tools/nppes/org-name.d.ts +15 -0
  116. package/out/tools/nppes/org-name.d.ts.map +1 -0
  117. package/out/tools/nppes/org-name.js +6 -0
  118. package/out/tools/nppes/org-name.js.map +1 -0
  119. package/out/tools/nppes/overmerge-packet.d.ts +43 -0
  120. package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
  121. package/out/tools/nppes/overmerge-packet.js +54 -0
  122. package/out/tools/nppes/overmerge-packet.js.map +1 -0
  123. package/out/tools/nppes/report.d.ts +97 -0
  124. package/out/tools/nppes/report.d.ts.map +1 -0
  125. package/out/tools/nppes/report.js +178 -0
  126. package/out/tools/nppes/report.js.map +1 -0
  127. package/out/tools/nppes/sample.d.ts +101 -0
  128. package/out/tools/nppes/sample.d.ts.map +1 -0
  129. package/out/tools/nppes/sample.js +127 -0
  130. package/out/tools/nppes/sample.js.map +1 -0
  131. package/out/tools/nppes/scoring.d.ts +37 -0
  132. package/out/tools/nppes/scoring.d.ts.map +1 -0
  133. package/out/tools/nppes/scoring.js +81 -0
  134. package/out/tools/nppes/scoring.js.map +1 -0
  135. package/out/tools/nppes/settings.d.ts +41 -0
  136. package/out/tools/nppes/settings.d.ts.map +1 -0
  137. package/out/tools/nppes/settings.js +79 -0
  138. package/out/tools/nppes/settings.js.map +1 -0
  139. package/out/tools/nppes/truth-grains.d.ts +63 -0
  140. package/out/tools/nppes/truth-grains.d.ts.map +1 -0
  141. package/out/tools/nppes/truth-grains.js +142 -0
  142. package/out/tools/nppes/truth-grains.js.map +1 -0
  143. package/out/tools/shared.d.ts +325 -0
  144. package/out/tools/shared.d.ts.map +1 -0
  145. package/out/tools/shared.js +453 -0
  146. package/out/tools/shared.js.map +1 -0
  147. package/out/tools/train/cross-gbt.d.ts +89 -0
  148. package/out/tools/train/cross-gbt.d.ts.map +1 -0
  149. package/out/tools/train/cross-gbt.js +132 -0
  150. package/out/tools/train/cross-gbt.js.map +1 -0
  151. package/out/tools/train/gbt.d.ts +85 -0
  152. package/out/tools/train/gbt.d.ts.map +1 -0
  153. package/out/tools/train/gbt.js +155 -0
  154. package/out/tools/train/gbt.js.map +1 -0
  155. package/out/tools/train/org-cross-gbt.d.ts +85 -0
  156. package/out/tools/train/org-cross-gbt.d.ts.map +1 -0
  157. package/out/tools/train/org-cross-gbt.js +122 -0
  158. package/out/tools/train/org-cross-gbt.js.map +1 -0
  159. package/out/tools/txhhsc-to-oarow.d.ts +42 -0
  160. package/out/tools/txhhsc-to-oarow.d.ts.map +1 -0
  161. package/out/tools/txhhsc-to-oarow.js +78 -0
  162. package/out/tools/txhhsc-to-oarow.js.map +1 -0
  163. package/out/tools/viz/browser.d.ts +31 -0
  164. package/out/tools/viz/browser.d.ts.map +1 -0
  165. package/out/tools/viz/browser.js +26 -0
  166. package/out/tools/viz/browser.js.map +1 -0
  167. package/out/tools/viz/cross-dataset-map.d.ts +39 -0
  168. package/out/tools/viz/cross-dataset-map.d.ts.map +1 -0
  169. package/out/tools/viz/cross-dataset-map.js +84 -0
  170. package/out/tools/viz/cross-dataset-map.js.map +1 -0
  171. package/out/tools/viz/geocode-first-surface.d.ts +36 -0
  172. package/out/tools/viz/geocode-first-surface.d.ts.map +1 -0
  173. package/out/tools/viz/geocode-first-surface.js +234 -0
  174. package/out/tools/viz/geocode-first-surface.js.map +1 -0
  175. package/out/tools/viz/render/map.d.ts +42 -0
  176. package/out/tools/viz/render/map.d.ts.map +1 -0
  177. package/out/tools/viz/render/map.js +40 -0
  178. package/out/tools/viz/render/map.js.map +1 -0
  179. package/out/tools/viz/render.d.ts +46 -0
  180. package/out/tools/viz/render.d.ts.map +1 -0
  181. package/out/tools/viz/render.js +49 -0
  182. package/out/tools/viz/render.js.map +1 -0
  183. package/out/tools/viz/source-provenance-map.d.ts +57 -0
  184. package/out/tools/viz/source-provenance-map.d.ts.map +1 -0
  185. package/out/tools/viz/source-provenance-map.js +82 -0
  186. package/out/tools/viz/source-provenance-map.js.map +1 -0
  187. package/out/tools/viz/yardstick-figure.d.ts +22 -0
  188. package/out/tools/viz/yardstick-figure.d.ts.map +1 -0
  189. package/out/tools/viz/yardstick-figure.js +106 -0
  190. package/out/tools/viz/yardstick-figure.js.map +1 -0
  191. package/out/types.d.ts +108 -0
  192. package/out/types.d.ts.map +1 -0
  193. package/out/types.js +11 -0
  194. package/out/types.js.map +1 -0
  195. package/package.json +113 -3
  196. package/tools/coverage-reconciliation.ts +192 -0
  197. package/tools/cross/dataset-correlation.ts +380 -0
  198. package/tools/cross/source-threshold-sweep.ts +416 -0
  199. package/tools/dedup-ceiling.ts +225 -0
  200. package/tools/eval-geocoder.ts +77 -0
  201. package/tools/geocoder/namesake-probe.ts +91 -0
  202. package/tools/geocoder/vs-provided-coords.ts +232 -0
  203. package/tools/gold-set-sample.ts +147 -0
  204. package/tools/learned/scorer/clustering-eval.ts +349 -0
  205. package/tools/learned/scorer/crossstate-eval.ts +280 -0
  206. package/tools/learned/scorer/eval.ts +429 -0
  207. package/tools/matcher-scale.ts +185 -0
  208. package/tools/nppes/dedup-benchmark.ts +364 -0
  209. package/tools/nppes/org-name.ts +15 -0
  210. package/tools/nppes/overmerge-packet.ts +98 -0
  211. package/tools/nppes/report.ts +380 -0
  212. package/tools/nppes/sample.ts +250 -0
  213. package/tools/nppes/scoring.ts +115 -0
  214. package/tools/nppes/settings.ts +102 -0
  215. package/tools/nppes/truth-grains.ts +185 -0
  216. package/tools/shared.ts +743 -0
  217. package/tools/train/cross-gbt.ts +214 -0
  218. package/tools/train/gbt.ts +261 -0
  219. package/tools/train/org-cross-gbt.ts +189 -0
  220. package/tools/txhhsc-to-oarow.ts +118 -0
  221. package/tools/viz/browser.ts +41 -0
  222. package/tools/viz/cross-dataset-map.ts +133 -0
  223. package/tools/viz/geocode-first-surface.ts +305 -0
  224. package/tools/viz/render/map.ts +61 -0
  225. package/tools/viz/render.ts +103 -0
  226. package/tools/viz/source-provenance-map.ts +154 -0
  227. package/tools/viz/yardstick-figure.ts +197 -0
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Train the cross-source link scorer. The dedup GBT is trained on within-NPPES labels, so its
7
+ * strongest feature (`spatial-exact × name-disagree`) rejects the prototypical cross-source pair,
8
+ * the same provider under different operational text across registries.
9
+ * CMS Open Payments joins NPPES by NPI. That join provides ground-truth positive pairs labeled by a key the matcher never sees.
10
+ *
11
+ * The pipeline assembles NPPES and Open Payments TX records for the same NPI population, then the
12
+ * shared `trainCrossSourceModel` geocodes through the standard ingest and blocks the union. It keeps only
13
+ * cross-source candidate pairs. It trains the shipped model into
14
+ * `registry/models/crosssource-gbt-en-us.ts`.
15
+ *
16
+ * Sources (both public domain, `.notes/data-sources.md`):
17
+ *
18
+ * - `nppes_npi-registry_*.tsv`: the practice-location and primary-name records.
19
+ * - `openpayments_covered-recipient-profile_*.csv`: the OP profile supplement (NPI, profile
20
+ * first/last, profile practice address).
21
+ *
22
+ * Run: `mailwoman registry train-scorer cross-gbt [--state TX] [--npis 2000]
23
+ * [--precision-bar 0.95] [--wof <admin.db>] [--data-root <dir>]
24
+ * [--out registry/models/crosssource-gbt-en-us.ts]`
25
+ */
26
+ import { dataRootPath } from "@mailwoman/core/data-root";
27
+ import { isoDate } from "@mailwoman/core/utils";
28
+ import { resolvePath } from "path-ts";
29
+ import { addressFrequencyKey, streamRows } from "#index";
30
+ import { addr, norm, NPPES_COLUMNS as N, stateOption, trainCrossSourceModel } from "#tools/shared";
31
+ /**
32
+ * Train and emit the cross-source link GBT.
33
+ */
34
+ export async function trainCrossSourceGBT(options, report) {
35
+ const SOURCES = resolvePath(options.sources ?? dataRootPath("record-matcher", "sources"));
36
+ const STATE = stateOption(options);
37
+ const NPIS = options.npis ?? 2000;
38
+ const OUT = options.out || "packages/entity-resolution/lib/models/crosssource-gbt-en-us.ts";
39
+ const LOCALE = options.locale || "en-US";
40
+ // Max cross-source recall subject to this held-out pairwise precision.
41
+ const PRECISION_BAR = options.precisionBar ?? 0.95;
42
+ const TRAIN_DATE = options.date || isoDate();
43
+ const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`;
44
+ const OP_PROFILE = `${SOURCES}/openpayments_covered-recipient-profile_20260603.csv`;
45
+ report?.(`[A] streaming the OP profile supplement (${STATE})…`);
46
+ const opByNPI = new Map();
47
+ for await (const r of streamRows(OP_PROFILE)) {
48
+ if (opByNPI.size >= NPIS)
49
+ break;
50
+ const npi = norm(r["Covered_Recipient_NPI"]);
51
+ const st = norm(r["Covered_Recipient_Profile_State"]).toUpperCase();
52
+ if (!npi || st !== STATE || opByNPI.has(npi))
53
+ continue;
54
+ const name = `${norm(r["Covered_Recipient_Profile_First_Name"])} ${norm(r["Covered_Recipient_Profile_Last_Name"])}`.trim();
55
+ const address = addr(r["Covered_Recipient_Profile_Address_Line_1"], r["Covered_Recipient_Profile_City"], st, r["Covered_Recipient_Profile_Zipcode"]);
56
+ if (!name || !address)
57
+ continue;
58
+ opByNPI.set(npi, { npi, name, org: "", address, source: "openpayments" });
59
+ }
60
+ report?.(` ${opByNPI.size} OP ${STATE} practitioners`);
61
+ report?.("[B] full registry pass: address-frequency table + the NPI-joined NPPES rows…");
62
+ const rows = [];
63
+ const joined = new Set();
64
+ const addrCounts = new Map();
65
+ let addrTotal = 0;
66
+ let scanned = 0;
67
+ for await (const r of streamRows(REGISTRY)) {
68
+ if (++scanned % 1_000_000 === 0) {
69
+ report?.(` scanned ${scanned / 1e6}M, joined ${joined.size}`);
70
+ }
71
+ const practice = addr(r[N.pAddr], r[N.pCity], r[N.pState], r[N.pZip]);
72
+ if (practice) {
73
+ const k = addressFrequencyKey(practice);
74
+ addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1);
75
+ addrTotal++;
76
+ }
77
+ const npi = norm(r[N.npi]);
78
+ if (!npi || !opByNPI.has(npi) || joined.has(npi) || !practice)
79
+ continue;
80
+ // Practitioner-level matching: OP covered recipients are individuals (entity type 1).
81
+ if (norm(r[N.entityType]) !== "1")
82
+ continue;
83
+ const name = `${norm(r[N.first])} ${norm(r[N.last])}`.trim();
84
+ if (!name)
85
+ continue;
86
+ joined.add(npi);
87
+ rows.push({ npi, name, org: "", address: practice, source: "nppes" });
88
+ }
89
+ for (const npi of joined) {
90
+ rows.push(opByNPI.get(npi));
91
+ }
92
+ const addressFrequency = {
93
+ total: addrTotal,
94
+ distinct: addrCounts.size,
95
+ frequency: (v) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
96
+ };
97
+ report?.(` ${joined.size} NPI-joined pairs → ${rows.length} records`);
98
+ return trainCrossSourceModel({
99
+ createGeocoder: options.createGeocoder,
100
+ rows,
101
+ joined,
102
+ addressFrequency,
103
+ sources: ["nppes", "openpayments"],
104
+ precisionBar: PRECISION_BAR,
105
+ out: OUT,
106
+ exportPrefix: "CROSS_SOURCE_GBT",
107
+ moduleDoc: ` * The CROSS-SOURCE link scorer (#655 option 2) — trained on NPI-joined NPPES ↔ Open Payments\n` +
108
+ ` * pairs (the non-circular cross-registry anchor; both public domain). Scores "same provider,\n` +
109
+ ` * different registry text" links the dedup GBT rejects by construction. Generated by\n` +
110
+ ` * \`mailwoman registry train-scorer cross-gbt\` (registry/tools/train-cross-gbt.ts) — retrain + re-run rather than editing.\n`,
111
+ meta: (figures) => ({
112
+ version: "1.0.0",
113
+ objective: "cross-source-link",
114
+ locale: LOCALE,
115
+ trainedOn: TRAIN_DATE,
116
+ state: STATE,
117
+ npis: joined.size,
118
+ records: figures.records,
119
+ pairs: figures.pairs,
120
+ posRate: figures.posRate,
121
+ precisionBar: PRECISION_BAR,
122
+ holdoutBarRecall: figures.barRecall,
123
+ holdoutF1Max: figures.f1Max,
124
+ hyperparams: figures.hyperparams,
125
+ recommendedThreshold: figures.recommendedThreshold,
126
+ features: figures.features,
127
+ sources: ["nppes", "openpayments"],
128
+ }),
129
+ report,
130
+ });
131
+ }
132
+ //# sourceMappingURL=cross-gbt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-gbt.js","sourceRoot":"","sources":["../../../tools/train/cross-gbt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAwB,MAAM,SAAS,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,IAAI,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAuB,MAAM,eAAe,CAAA;AAwDvH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,OAAmC,EACnC,MAA+B;IAE/B,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAA;IACzF,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAA;IACjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,gEAAgE,CAAA;IAC3F,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAA;IACxC,uEAAuE;IACvE,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAA;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,EAAE,CAAA;IAE5C,MAAM,QAAQ,GAAG,GAAG,OAAO,kCAAkC,CAAA;IAC7D,MAAM,UAAU,GAAG,GAAG,OAAO,sDAAsD,CAAA;IAEnF,MAAM,EAAE,CAAC,4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AO,EAAE,OAAO;YAChB,SAAS,EAAE,mBAAmB;YAC9B,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,YAAY,EAAE,aAAa;YAC3B,gBAAgB,EAAE,OAAO,CAAC,SAAS;YACnC,YAAY,EAAE,OAAO,CAAC,KAAK;YAC3B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;YAClD,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC;SAClC,CAAC;QACF,MAAM;KACN,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Trains the production learned-scorer model. `buildNPPESSample` creates the same NPI-keyed records used by
7
+ * the dedup benchmark and clustering A/B. The sample uses the real registry and includes name drift plus address variation.
8
+ * The trainer geocodes records and groups them into candidate pairs. It featurizes each pair with
9
+ * `createMatchFeaturizer`. It labels pairs by NPI and fits a gradient-boosted tree model.
10
+ * It writes the model to the committed package module `registry/models/dedup-gbt-en-us.ts`.
11
+ *
12
+ * Unlike the eval, this trains on all sampled NPIs with no held-out split, since the held-out F1
13
+ * is the eval's job.
14
+ *
15
+ * Run: `mailwoman registry train-scorer gbt [--state TX] [--npis 3000] [--wof <admin.db>]
16
+ * [--data-root <dir>] [--out registry/models/dedup-gbt-en-us.ts]`
17
+ */
18
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder";
19
+ /**
20
+ * Options for {@linkcode trainDedupGBT}.
21
+ */
22
+ export interface TrainDedupGBTOptions {
23
+ /**
24
+ * The injected geocoder factory.
25
+ *
26
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
27
+ */
28
+ createGeocoder: EvalGeocoderFactory;
29
+ /**
30
+ * Record-matcher sources directory.
31
+ *
32
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
33
+ */
34
+ sources?: string;
35
+ /**
36
+ * State filter.
37
+ *
38
+ * @defaultValue TX.
39
+ */
40
+ state?: string;
41
+ /**
42
+ * NPIs sampled.
43
+ *
44
+ * @defaultValue `3000`
45
+ */
46
+ npis?: number;
47
+ /**
48
+ * Output TS module path.
49
+ *
50
+ * @defaultValue `registry/models/dedup-gbt-en-us.ts`
51
+ */
52
+ out?: string;
53
+ /**
54
+ * Locale recorded in the model meta (the command's factory loads the matching weights).
55
+ *
56
+ * @defaultValue `"en-US"`
57
+ */
58
+ locale?: string;
59
+ /**
60
+ * Cost-sensitive training: up-weight the negative (distinct-pair) class by this factor
61
+ * so the model is more conservative about merging.
62
+ *
63
+ * It trades recall for precision to reduce over-merge.
64
+ * `1` is the symmetric class-balanced default.
65
+ *
66
+ * A value above 1 penalizes a false merge more than a missed merge.
67
+ */
68
+ cost?: number;
69
+ /**
70
+ * The training date stored in the metadata (overridable for reproducible commits).
71
+ *
72
+ * @defaultValue today.
73
+ */
74
+ date?: string;
75
+ }
76
+ /**
77
+ * Train and emit the production dedup GBT.
78
+ */
79
+ export declare function trainDedupGBT(options: TrainDedupGBTOptions, report?: (line: string) => void): Promise<{
80
+ out: string;
81
+ pairs: number;
82
+ recommendedThreshold: number;
83
+ heldOutF1: number;
84
+ }>;
85
+ //# sourceMappingURL=gbt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gbt.d.ts","sourceRoot":"","sources":["../../../tools/train/gbt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAmBH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAW/D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;OAIG;IACH,cAAc,EAAE,mBAAmB,CAAA;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,wBAAsB,aAAa,CAClC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAsJ1F"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Trains the production learned-scorer model. `buildNPPESSample` creates the same NPI-keyed records used by
7
+ * the dedup benchmark and clustering A/B. The sample uses the real registry and includes name drift plus address variation.
8
+ * The trainer geocodes records and groups them into candidate pairs. It featurizes each pair with
9
+ * `createMatchFeaturizer`. It labels pairs by NPI and fits a gradient-boosted tree model.
10
+ * It writes the model to the committed package module `registry/models/dedup-gbt-en-us.ts`.
11
+ *
12
+ * Unlike the eval, this trains on all sampled NPIs with no held-out split, since the held-out F1
13
+ * is the eval's job.
14
+ *
15
+ * Run: `mailwoman registry train-scorer gbt [--state TX] [--npis 3000] [--wof <admin.db>]
16
+ * [--data-root <dir>] [--out registry/models/dedup-gbt-en-us.ts]`
17
+ */
18
+ import { dataRootPath } from "@mailwoman/core/data-root";
19
+ import { makeDirectories, writeLocalFile } from "@mailwoman/core/fs/writers";
20
+ import { prettyJSON, stringifyJSON } from "@mailwoman/core/json";
21
+ import { makeLcg } from "@mailwoman/core/random";
22
+ import { isoDate } from "@mailwoman/core/utils";
23
+ import { block, gbtScore, trainGBT } from "@mailwoman/match";
24
+ import { dirname } from "path-ts";
25
+ import { buildDefaultModel, createMatchFeaturizer, defaultBlockingKeys, ingestRows, resolveEntities, } from "#index";
26
+ import { buildNPPESSample } from "#tools/nppes/sample";
27
+ import { scoreEntities } from "#tools/nppes/scoring";
28
+ import { stateOption, uniqueQuantiles } from "#tools/shared";
29
+ /**
30
+ * Share of entities assigned to fit.
31
+ * The rest are held out.
32
+ */
33
+ const FIT_SPLIT_FRACTION = 0.8;
34
+ /**
35
+ * Train and emit the production dedup GBT.
36
+ */
37
+ export async function trainDedupGBT(options, report) {
38
+ const SOURCES = options.sources || dataRootPath("record-matcher", "sources");
39
+ const STATE = stateOption(options);
40
+ const NPIS = options.npis ?? 3000;
41
+ const OUT = options.out || "packages/entity-resolution/lib/models/dedup-gbt-en-us.ts";
42
+ const LOCALE = options.locale || "en-US";
43
+ const COST = options.cost ?? 1;
44
+ const TRAIN_DATE = options.date || isoDate();
45
+ const REGISTRY = `${SOURCES}/nppes_npi-registry_20260607.tsv`;
46
+ const OTHER_NAMES = `${SOURCES}/nppes_other-names_20260607.tsv`;
47
+ const { rows, keptNpis, addressFrequency } = await buildNPPESSample({ registryPath: REGISTRY, otherNamesPath: OTHER_NAMES, state: STATE, maxNpis: NPIS }, report);
48
+ // The geocoder is injected, since the registry package never imports the runtime.
49
+ report?.("[C] geocoding…");
50
+ const geocoder = await options.createGeocoder();
51
+ // `record.id` supplies the NPI label.
52
+ // Multiple records can share an NPI as ground truth.
53
+ const mapping = {
54
+ id: "npi",
55
+ name: "name",
56
+ organization: "org",
57
+ address: "address",
58
+ attributes: { authorizedOfficial: "auth" },
59
+ };
60
+ const records = await ingestRows(rows, mapping, {
61
+ geocodeAddress: geocoder.geocodeAddress,
62
+ });
63
+ geocoder[Symbol.dispose]();
64
+ const geocoded = records.filter((r) => r.address?.geocode).length;
65
+ report?.(` ${records.length} records, ${geocoded} geocoded`);
66
+ report?.("[D] blocking + featurizing…");
67
+ const comparisons = buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons;
68
+ const featurize = createMatchFeaturizer({ comparisons, addressFrequency });
69
+ const { pairs } = block(records, defaultBlockingKeys());
70
+ const X = pairs.map(([a, b]) => featurize(a, b));
71
+ const Y = pairs.map(([a, b]) => (a.id === b.id ? 1 : 0));
72
+ const posRate = Y.reduce((s, v) => s + v, 0) / Math.max(1, Y.length);
73
+ const W = Y.map((y) => (y === 1 ? 1 - posRate : posRate * COST));
74
+ const hyperparams = { rounds: 120, depth: 3, lr: 0.3, minLeaf: 20 };
75
+ if (COST !== 1) {
76
+ report?.(` cost-sensitive: negative class weighted ×${COST} (penalize over-merge)`);
77
+ }
78
+ // Calibrate the default link threshold.
79
+ // The GBT logit uses no Fellegi-Sunter weight units.
80
+ // With class-balanced weights, logit 0 ignores the roughly 1% match base rate and over-merges.
81
+ // The threshold is swept on a held-out 20% of NPIs.
82
+ // The shipped full-data model has near-identical logit calibration, so the threshold transfers.
83
+ report?.("[E] calibrating the default link threshold on a held-out NPI split…");
84
+ const rnd = makeLcg(20_260_615);
85
+ const split = new Map();
86
+ for (const npi of keptNpis) {
87
+ split.set(npi, rnd() < FIT_SPLIT_FRACTION ? "fit" : "holdout");
88
+ }
89
+ const fitPairs = pairs.filter(([a, b]) => split.get(a.id) === "fit" && split.get(b.id) === "fit");
90
+ const calibGbt = trainGBT(fitPairs.map(([a, b]) => featurize(a, b)), fitPairs.map(([a, b]) => (a.id === b.id ? 1 : 0)), fitPairs.map(([a, b]) => (a.id === b.id ? 1 - posRate : posRate * COST)), hyperparams);
91
+ const calibScorer = (a, b) => gbtScore(calibGbt, featurize(a, b));
92
+ const holdoutRecords = records.filter((r) => split.get(r.id) === "holdout");
93
+ const { pairs: holdoutPairs } = block(holdoutRecords, defaultBlockingKeys());
94
+ const holdoutScores = holdoutPairs.map(([a, b]) => calibScorer(a, b)).toSorted((p, q) => p - q);
95
+ const npiLabel = (rec) => rec.id;
96
+ let recommendedThreshold = 0;
97
+ let bestF1 = -1;
98
+ for (const t of uniqueQuantiles(holdoutScores, 40)) {
99
+ const { entities } = resolveEntities(holdoutRecords, {
100
+ addressFrequency,
101
+ collapseSpatial: true,
102
+ scorer: calibScorer,
103
+ threshold: t,
104
+ });
105
+ const f1 = scoreEntities(entities, npiLabel, holdoutRecords.length).f1;
106
+ if (f1 > bestF1) {
107
+ bestF1 = f1;
108
+ recommendedThreshold = t;
109
+ }
110
+ }
111
+ report?.(` recommended link threshold ${recommendedThreshold.toFixed(3)} (held-out clustering F1 ${(100 * bestF1).toFixed(1)}%)`);
112
+ report?.("[F] training the shipped model on all pairs…");
113
+ const model = trainGBT(X, Y, W, hyperparams);
114
+ report?.(` ${pairs.length} pairs (${(100 * posRate).toFixed(1)}% positive), ${model.trees.length} trees`);
115
+ // Emit the model as a committed TypeScript module with a prettier-stable literal,
116
+ // so a retrain produces a clean one-line diff.
117
+ const meta = {
118
+ version: "1.0.0",
119
+ locale: LOCALE,
120
+ trainedOn: TRAIN_DATE,
121
+ state: STATE,
122
+ npis: keptNpis.size,
123
+ records: records.length,
124
+ pairs: pairs.length,
125
+ posRate: Number(posRate.toFixed(4)),
126
+ costNegative: COST,
127
+ hyperparams,
128
+ recommendedThreshold: Number(recommendedThreshold.toFixed(4)),
129
+ features: X[0]?.length ?? 0,
130
+ addressFrequencyDistinct: addressFrequency.distinct,
131
+ addressFrequencyTotal: addressFrequency.total,
132
+ };
133
+ const moduleSource = `/**\n` +
134
+ ` * @copyright Sister Software\n` +
135
+ ` * @license AGPL-3.0\n` +
136
+ ` * @author Teffen Ellis, et al.\n` +
137
+ ` *\n` +
138
+ ` * GENERATED by \`mailwoman registry train-scorer gbt\` (registry/tools/train-gbt.ts) — DO NOT edit by hand; retrain to update.\n` +
139
+ ` *\n` +
140
+ ` * The default learned-scorer model (#603): a gradient-boosted-tree dedup scorer trained on the\n` +
141
+ ` * NPPES NPI-truth set (${STATE}, ${keptNpis.size} NPIs → ${pairs.length} candidate pairs). Validated to\n` +
142
+ ` * generalize across states by learned-scorer-crossstate-eval.ts. Used by resolveEntities'\n` +
143
+ ` * opt-in learnedScorer hook via createGBTScorer. The trained {@link GBT} is plain data.\n` +
144
+ ` */\n\n` +
145
+ `import type { GBT } from "@mailwoman/match"\n\n` +
146
+ `/** Provenance for the bundled model — what it was trained on. */\n` +
147
+ `export const DEDUP_GBT_META = ${prettyJSON(meta)} as const\n\n` +
148
+ `// prettier-ignore\n` +
149
+ `export const DEDUP_GBT_MODEL: GBT = ${stringifyJSON(model)}\n`;
150
+ await makeDirectories(dirname(OUT));
151
+ await writeLocalFile(moduleSource, OUT);
152
+ report?.(`[written] ${OUT} (${(moduleSource.length / 1024).toFixed(0)} KB)`);
153
+ return { out: OUT, pairs: pairs.length, recommendedThreshold, heldOutF1: bestF1 };
154
+ }
155
+ //# sourceMappingURL=gbt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gbt.js","sourceRoot":"","sources":["../../../tools/train/gbt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,E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G,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAE5E,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,EAAE,CAAA;AAClF,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Train the organization-level cross-source link scorer. The practitioner cross-source GBT does
7
+ * not transfer to organization records because its person-name features go dark. The organization
8
+ * cross-dataset flows therefore pin the FS baseline. CMS Provider of Services joins Care Compare
9
+ * by CCN. Each system represents the same facility and maintains its name and address separately.
10
+ *
11
+ * The pipeline runs a national CCN join into one record per source per facility, then the shared
12
+ * `trainCrossSourceModel` geocodes the rows and blocks the union. It keeps cross-source pairs.
13
+ * It featurizes them with the shared featurizer and labels them by CCN.
14
+ * Calibration uses held-out CCNs.
15
+ * The function emits `registry/models/org-crosssource-gbt-en-us.ts`.
16
+ *
17
+ * Sources (both public domain, direct CSVs):
18
+ *
19
+ * - `cms-pos_hospital-other_*.csv`: Provider of Services (PRVDR_NUM, FAC_NAME, ST_ADR…).
20
+ * - `cms-carecompare_hospital-general_*.csv`: Care Compare (Facility ID, Facility Name, Address…).
21
+ *
22
+ * Run: `mailwoman registry train-scorer org-cross-gbt [--cap 6000] [--precision-bar 0.95]
23
+ * [--wof <admin.db>] [--data-root <dir>] [--out registry/models/org-crosssource-gbt-en-us.ts]`
24
+ */
25
+ import { type PathBuilderLike } from "path-ts";
26
+ import type { EvalGeocoderFactory } from "#tools/eval-geocoder";
27
+ /**
28
+ * Options for {@linkcode trainOrgCrossSourceGBT}.
29
+ */
30
+ export interface TrainOrgCrossSourceGBTOptions {
31
+ /**
32
+ * The injected geocoder factory.
33
+ *
34
+ * The command wires `mailwoman/geocode-core`, as `./eval-geocoder.ts` does.
35
+ */
36
+ createGeocoder: EvalGeocoderFactory;
37
+ /**
38
+ * Record-matcher sources directory.
39
+ *
40
+ * @defaultValue `$MAILWOMAN_DATA_ROOT/record-matcher/sources`
41
+ */
42
+ sources?: PathBuilderLike;
43
+ /**
44
+ * Care Compare facilities sampled.
45
+ *
46
+ * @defaultValue `6000`
47
+ */
48
+ cap?: number;
49
+ /**
50
+ * Output TS module path.
51
+ *
52
+ * @defaultValue `registry/models/org-crosssource-gbt-en-us.ts`
53
+ */
54
+ out?: string;
55
+ /**
56
+ * Locale recorded in the model meta.
57
+ *
58
+ * @defaultValue `"en-US"`
59
+ */
60
+ locale?: string;
61
+ /**
62
+ * Max cross-source recall subject to this held-out pairwise precision.
63
+ *
64
+ * @defaultValue `0.95`
65
+ */
66
+ precisionBar?: number;
67
+ /**
68
+ * The metadata stores this training date.
69
+ *
70
+ * @defaultValue today.
71
+ */
72
+ date?: string;
73
+ }
74
+ /**
75
+ * Train and emit the org-level cross-source link GBT.
76
+ *
77
+ * The CCN is the cross-system facility key.
78
+ * It is stored in {@link CrossSourceRow.npi} and copied to `record.id` as the held-out label.
79
+ */
80
+ export declare function trainOrgCrossSourceGBT(options: TrainOrgCrossSourceGBTOptions, report?: (line: string) => void): Promise<{
81
+ out: string;
82
+ pairs: number;
83
+ recommendedThreshold: number;
84
+ }>;
85
+ //# sourceMappingURL=org-cross-gbt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-cross-gbt.d.ts","sourceRoot":"","sources":["../../../tools/train/org-cross-gbt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAG3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG/D;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;;;OAIG;IACH,cAAc,EAAE,mBAAmB,CAAA;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,6BAA6B,EACtC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,CAAC,CAkGvE"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Train the organization-level cross-source link scorer. The practitioner cross-source GBT does
7
+ * not transfer to organization records because its person-name features go dark. The organization
8
+ * cross-dataset flows therefore pin the FS baseline. CMS Provider of Services joins Care Compare
9
+ * by CCN. Each system represents the same facility and maintains its name and address separately.
10
+ *
11
+ * The pipeline runs a national CCN join into one record per source per facility, then the shared
12
+ * `trainCrossSourceModel` geocodes the rows and blocks the union. It keeps cross-source pairs.
13
+ * It featurizes them with the shared featurizer and labels them by CCN.
14
+ * Calibration uses held-out CCNs.
15
+ * The function emits `registry/models/org-crosssource-gbt-en-us.ts`.
16
+ *
17
+ * Sources (both public domain, direct CSVs):
18
+ *
19
+ * - `cms-pos_hospital-other_*.csv`: Provider of Services (PRVDR_NUM, FAC_NAME, ST_ADR…).
20
+ * - `cms-carecompare_hospital-general_*.csv`: Care Compare (Facility ID, Facility Name, Address…).
21
+ *
22
+ * Run: `mailwoman registry train-scorer org-cross-gbt [--cap 6000] [--precision-bar 0.95]
23
+ * [--wof <admin.db>] [--data-root <dir>] [--out registry/models/org-crosssource-gbt-en-us.ts]`
24
+ */
25
+ import { dataRootPath } from "@mailwoman/core/data-root";
26
+ import { isoDate } from "@mailwoman/core/utils";
27
+ import { resolvePath } from "path-ts";
28
+ import { addressFrequencyKey, streamRows } from "#index";
29
+ import { addr, norm, trainCrossSourceModel } from "#tools/shared";
30
+ /**
31
+ * Train and emit the org-level cross-source link GBT.
32
+ *
33
+ * The CCN is the cross-system facility key.
34
+ * It is stored in {@link CrossSourceRow.npi} and copied to `record.id` as the held-out label.
35
+ */
36
+ export async function trainOrgCrossSourceGBT(options, report) {
37
+ const SOURCES = resolvePath(options.sources ?? dataRootPath("record-matcher", "sources"));
38
+ const CAP = options.cap ?? 6000;
39
+ const OUT = options.out || "packages/entity-resolution/lib/models/org-crosssource-gbt-en-us.ts";
40
+ const LOCALE = options.locale || "en-US";
41
+ // Max cross-source recall subject to this held-out pairwise precision.
42
+ const PRECISION_BAR = options.precisionBar ?? 0.95;
43
+ const TRAIN_DATE = options.date || isoDate();
44
+ const POS = `${SOURCES}/cms-pos_hospital-other_2026q1.csv`;
45
+ const CARE_COMPARE = `${SOURCES}/cms-carecompare_hospital-general_20260706.csv`;
46
+ report?.("[A] streaming Care Compare…");
47
+ const ccByID = new Map();
48
+ for await (const r of streamRows(CARE_COMPARE)) {
49
+ if (ccByID.size >= CAP)
50
+ break;
51
+ const ccn = norm(r["Facility ID"]);
52
+ const name = norm(r["Facility Name"]);
53
+ const address = addr(r["Address"], r["City/Town"], r["State"], r["ZIP Code"]);
54
+ if (!ccn || !name || !address)
55
+ continue;
56
+ ccByID.set(ccn, { npi: ccn, name, org: name, address, source: "care-compare" });
57
+ }
58
+ report?.(` ${ccByID.size} Care Compare facilities`);
59
+ report?.("[B] streaming POS + building the frequency table…");
60
+ const rows = [];
61
+ const joined = new Set();
62
+ const addrCounts = new Map();
63
+ let addrTotal = 0;
64
+ for await (const r of streamRows(POS)) {
65
+ const address = addr(r["ST_ADR"], r["CITY_NAME"], r["STATE_CD"], r["ZIP_CD"]);
66
+ if (address) {
67
+ const k = addressFrequencyKey(address);
68
+ addrCounts.set(k, (addrCounts.get(k) ?? 0) + 1);
69
+ addrTotal++;
70
+ }
71
+ const ccn = norm(r["PRVDR_NUM"]);
72
+ if (!ccn || !ccByID.has(ccn) || joined.has(ccn) || !address)
73
+ continue;
74
+ const name = norm(r["FAC_NAME"]);
75
+ if (!name)
76
+ continue;
77
+ joined.add(ccn);
78
+ rows.push({ npi: ccn, name, org: name, address, source: "cms-pos" });
79
+ }
80
+ for (const ccn of joined) {
81
+ rows.push(ccByID.get(ccn));
82
+ }
83
+ const addressFrequency = {
84
+ total: addrTotal,
85
+ distinct: addrCounts.size,
86
+ frequency: (v) => (v ? (addrCounts.get(addressFrequencyKey(v)) ?? 0) / addrTotal : 0),
87
+ };
88
+ report?.(` ${joined.size} CCN-joined facilities → ${rows.length} records`);
89
+ return trainCrossSourceModel({
90
+ createGeocoder: options.createGeocoder,
91
+ rows,
92
+ joined,
93
+ addressFrequency,
94
+ sources: ["cms-pos", "care-compare"],
95
+ precisionBar: PRECISION_BAR,
96
+ out: OUT,
97
+ exportPrefix: "ORG_CROSS_SOURCE_GBT",
98
+ moduleDoc: ` * The ORG-LEVEL cross-source link scorer (#655 follow-on) — trained on CCN-joined CMS POS ↔\n` +
99
+ ` * Care Compare facility pairs (both public domain). Scores "same facility, different registry\n` +
100
+ ` * text" links for org-level cross-dataset flows. Generated by\n` +
101
+ ` * \`mailwoman registry train-scorer org-cross-gbt\` (registry/tools/train-org-cross-gbt.ts) — retrain rather than editing.\n`,
102
+ meta: (figures) => ({
103
+ version: "1.0.0",
104
+ objective: "org-cross-source-link",
105
+ locale: LOCALE,
106
+ trainedOn: TRAIN_DATE,
107
+ facilities: joined.size,
108
+ records: figures.records,
109
+ pairs: figures.pairs,
110
+ posRate: figures.posRate,
111
+ precisionBar: PRECISION_BAR,
112
+ holdoutBarRecall: figures.barRecall,
113
+ holdoutF1Max: figures.f1Max,
114
+ hyperparams: figures.hyperparams,
115
+ recommendedThreshold: figures.recommendedThreshold,
116
+ features: figures.features,
117
+ sources: ["cms-pos", "care-compare"],
118
+ }),
119
+ report,
120
+ });
121
+ }
122
+ //# sourceMappingURL=org-cross-gbt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-cross-gbt.js","sourceRoot":"","sources":["../../../tools/train/org-cross-gbt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAwB,MAAM,SAAS,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,qBAAqB,EAAuB,MAAM,eAAe,CAAA;AAkDtF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC3C,OAAsC,EACtC,MAA+B;IAE/B,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAA;IACzF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAA;IAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,oEAAoE,CAAA;IAC/F,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAA;IACxC,uEAAuE;IACvE,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAA;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,EAAE,CAAA;IAE5C,MAAM,GAAG,GAAG,GAAG,OAAO,oCAAoC,CAAA;IAC1D,MAAM,YAA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