@mailwoman/core 5.6.0 → 5.7.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 (146) hide show
  1. package/data/chromium-i18n/ssl-address-download.ts +7 -11
  2. package/data/libpostal/resources-download.ts +9 -12
  3. package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
  4. package/out/coarse-placer/coarse-placer.js +12 -7
  5. package/out/coarse-placer/coarse-placer.js.map +1 -1
  6. package/out/coarse-placer/tools/build-dataset.d.ts +21 -0
  7. package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -0
  8. package/out/coarse-placer/tools/build-dataset.js +171 -0
  9. package/out/coarse-placer/tools/build-dataset.js.map +1 -0
  10. package/out/coarse-placer/tools/build-outlier-exposure.d.ts +19 -0
  11. package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -0
  12. package/out/coarse-placer/tools/build-outlier-exposure.js +144 -0
  13. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -0
  14. package/out/coarse-placer/tools/build-outlier-latin.d.ts +2 -0
  15. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -0
  16. package/out/coarse-placer/tools/build-outlier-latin.js +155 -0
  17. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -0
  18. package/out/coarse-placer/tools/build-outlier-oa.d.ts +2 -0
  19. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -0
  20. package/out/coarse-placer/tools/build-outlier-oa.js +182 -0
  21. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -0
  22. package/out/coarse-placer/tools/eval-latin-offmap.d.ts +2 -0
  23. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -0
  24. package/out/coarse-placer/tools/eval-latin-offmap.js +103 -0
  25. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -0
  26. package/out/coarse-placer/tools/eval-openset.d.ts +34 -0
  27. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -0
  28. package/out/coarse-placer/tools/eval-openset.js +394 -0
  29. package/out/coarse-placer/tools/eval-openset.js.map +1 -0
  30. package/out/coarse-placer/tools/eval-quant-compare.d.ts +2 -0
  31. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -0
  32. package/out/coarse-placer/tools/eval-quant-compare.js +107 -0
  33. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -0
  34. package/out/coarse-placer/tools/eval.d.ts +14 -0
  35. package/out/coarse-placer/tools/eval.d.ts.map +1 -0
  36. package/out/coarse-placer/tools/eval.js +131 -0
  37. package/out/coarse-placer/tools/eval.js.map +1 -0
  38. package/out/coarse-placer/tools/probe-frontier.d.ts +23 -0
  39. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -0
  40. package/out/coarse-placer/tools/probe-frontier.js +159 -0
  41. package/out/coarse-placer/tools/probe-frontier.js.map +1 -0
  42. package/out/coarse-placer/tools/quantize.d.ts +2 -0
  43. package/out/coarse-placer/tools/quantize.d.ts.map +1 -0
  44. package/out/coarse-placer/tools/quantize.js +80 -0
  45. package/out/coarse-placer/tools/quantize.js.map +1 -0
  46. package/out/coarse-placer/tools/train.d.ts +16 -0
  47. package/out/coarse-placer/tools/train.d.ts.map +1 -0
  48. package/out/coarse-placer/tools/train.js +173 -0
  49. package/out/coarse-placer/tools/train.js.map +1 -0
  50. package/out/data/chromium-i18n/ssl-address-download.js +5 -11
  51. package/out/data/chromium-i18n/ssl-address-download.js.map +1 -1
  52. package/out/data/libpostal/resources-download.js +7 -12
  53. package/out/data/libpostal/resources-download.js.map +1 -1
  54. package/out/decoder/arbitrate-tree.d.ts.map +1 -1
  55. package/out/decoder/arbitrate-tree.js +8 -4
  56. package/out/decoder/arbitrate-tree.js.map +1 -1
  57. package/out/decoder/build-tree.d.ts.map +1 -1
  58. package/out/decoder/build-tree.js +17 -9
  59. package/out/decoder/build-tree.js.map +1 -1
  60. package/out/decoder/calibration.d.ts.map +1 -1
  61. package/out/decoder/calibration.js +4 -2
  62. package/out/decoder/calibration.js.map +1 -1
  63. package/out/decoder/proposals-to-tree.d.ts.map +1 -1
  64. package/out/decoder/proposals-to-tree.js +4 -2
  65. package/out/decoder/proposals-to-tree.js.map +1 -1
  66. package/out/decoder/serialize-json.d.ts.map +1 -1
  67. package/out/decoder/serialize-json.js +10 -5
  68. package/out/decoder/serialize-json.js.map +1 -1
  69. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  70. package/out/decoder/serialize-tuples.js +6 -3
  71. package/out/decoder/serialize-tuples.js.map +1 -1
  72. package/out/decoder/serialize-xml.d.ts.map +1 -1
  73. package/out/decoder/serialize-xml.js +6 -3
  74. package/out/decoder/serialize-xml.js.map +1 -1
  75. package/out/decoder/unknown-spans.d.ts.map +1 -1
  76. package/out/decoder/unknown-spans.js +6 -3
  77. package/out/decoder/unknown-spans.js.map +1 -1
  78. package/out/env/index.d.ts +7 -0
  79. package/out/env/index.d.ts.map +1 -1
  80. package/out/env/index.js +1 -0
  81. package/out/env/index.js.map +1 -1
  82. package/out/env/paths.d.ts.map +1 -1
  83. package/out/env/paths.js +2 -1
  84. package/out/env/paths.js.map +1 -1
  85. package/out/env/schema.d.ts +7 -0
  86. package/out/env/schema.d.ts.map +1 -1
  87. package/out/env/schema.js +11 -0
  88. package/out/env/schema.js.map +1 -1
  89. package/out/parser/proposal-pipeline.d.ts.map +1 -1
  90. package/out/parser/proposal-pipeline.js +8 -4
  91. package/out/parser/proposal-pipeline.js.map +1 -1
  92. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  93. package/out/pipeline/runtime-pipeline.js +12 -6
  94. package/out/pipeline/runtime-pipeline.js.map +1 -1
  95. package/out/pipeline/span-logit-aggregation.js +2 -1
  96. package/out/pipeline/span-logit-aggregation.js.map +1 -1
  97. package/out/pipeline/span-proposer.d.ts.map +1 -1
  98. package/out/pipeline/span-proposer.js +14 -7
  99. package/out/pipeline/span-proposer.js.map +1 -1
  100. package/out/resolver/types.d.ts.map +1 -1
  101. package/out/resolver/types.js +2 -1
  102. package/out/resolver/types.js.map +1 -1
  103. package/out/resources/fs.js +1 -1
  104. package/out/resources/fs.js.map +1 -1
  105. package/out/resources/git.js +1 -1
  106. package/out/resources/git.js.map +1 -1
  107. package/out/resources/libpostal.js +1 -1
  108. package/out/resources/libpostal.js.map +1 -1
  109. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  110. package/out/resources/whosonfirst/placetypes/mermaid.js +2 -1
  111. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  112. package/out/types/mapping.d.ts.map +1 -1
  113. package/out/types/mapping.js +2 -1
  114. package/out/types/mapping.js.map +1 -1
  115. package/out/utils/data-root.d.ts +1 -1
  116. package/out/utils/data-root.d.ts.map +1 -1
  117. package/out/utils/data-root.js +11 -9
  118. package/out/utils/data-root.js.map +1 -1
  119. package/out/utils/index.d.ts +4 -0
  120. package/out/utils/index.d.ts.map +1 -1
  121. package/out/utils/index.js +4 -0
  122. package/out/utils/index.js.map +1 -1
  123. package/out/utils/python-json.d.ts +38 -0
  124. package/out/utils/python-json.d.ts.map +1 -0
  125. package/out/utils/python-json.js +90 -0
  126. package/out/utils/python-json.js.map +1 -0
  127. package/out/utils/python-random.d.ts +41 -0
  128. package/out/utils/python-random.d.ts.map +1 -0
  129. package/out/utils/python-random.js +78 -0
  130. package/out/utils/python-random.js.map +1 -0
  131. package/out/utils/repo.d.ts +16 -1
  132. package/out/utils/repo.d.ts.map +1 -1
  133. package/out/utils/repo.js +18 -1
  134. package/out/utils/repo.js.map +1 -1
  135. package/out/utils/scripting.d.ts +50 -0
  136. package/out/utils/scripting.d.ts.map +1 -0
  137. package/out/utils/scripting.js +99 -0
  138. package/out/utils/scripting.js.map +1 -0
  139. package/out/utils/sealed-db.d.ts +20 -0
  140. package/out/utils/sealed-db.d.ts.map +1 -0
  141. package/out/utils/sealed-db.js +74 -0
  142. package/out/utils/sealed-db.js.map +1 -0
  143. package/out/vitest.config.d.ts.map +1 -1
  144. package/out/vitest.config.js +1 -2
  145. package/out/vitest.config.js.map +1 -1
  146. package/package.json +6 -3
@@ -0,0 +1,155 @@
1
+ import { appendFileSync, writeFileSync } from "node:fs";
2
+ import * as path from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { DuckDBInstance } from "@duckdb/node-api";
5
+ /**
6
+ * @copyright Sister Software
7
+ * @license AGPL-3.0
8
+ * @author Teffen Ellis, et al.
9
+ *
10
+ * Latin-script off-map outlier exposure for the #244 coarse-placer (milestone 3). M2's OTHER class
11
+ * was trained on NON-Latin/non-CJK scripts (Cyrillic, Arabic, …) from WOF names, so off-map
12
+ * COUNTRIES written in Latin script (Poland, Brazil, Mexico, …) still mis-place to a trained
13
+ * Latin country (the "Latin-off-map residual"). The fix is REAL off-map addresses (not synthetic
14
+ * name variants — see #564: synthetic mass fits its own quirks): assemble address strings from
15
+ * the Overture per-country address parquet and append them as `country: "OTHER"`.
16
+ *
17
+ * Discipline: countries split into TRAIN (their rows feed train/val OTHER) and HELDOUT (rows go
18
+ * ONLY to the dedicated test file), so we can measure generalization to off-map countries the
19
+ * model never saw — not just memorization. The in-map test.jsonl is left UNTOUCHED so the
20
+ * before/after in-map regression check stays clean; the Latin metric lives in its own file.
21
+ *
22
+ * Run AFTER build-dataset.ts + build-outlier-exposure.ts (it appends). Re-runnable: it rewrites the
23
+ * dedicated test file and appends fresh OTHER rows (so don't run it twice onto the same splits
24
+ * without rebuilding train/val).
25
+ *
26
+ * Usage: node core/coarse-placer/tools/build-outlier-latin.ts [--per-country 6000] [--overture
27
+ * $MAILWOMAN_DATA_ROOT/overture/2026-05-20.0]
28
+ */
29
+ import { dataRootPath } from "@mailwoman/core/utils";
30
+ const { values: args } = parseArgs({
31
+ options: {
32
+ "per-country": { type: "string", default: "6000" },
33
+ overture: { type: "string", default: dataRootPath("overture", "2026-05-20.0") },
34
+ data: { type: "string", default: path.resolve(import.meta.dirname, "../../data/coarse-placer") },
35
+ },
36
+ });
37
+ const PER = Number(args["per-country"]);
38
+ // Off-map (NOT among the trained countries) and Latin-script. TRAIN feeds the OTHER class; HELDOUT
39
+ // is test-only — the generalization probe (unseen off-map countries should still route OTHER).
40
+ // #743: PL/PT/CZ moved from OTHER to FIRST-CLASS in-map countries (they're now in COARSE_CLASSES),
41
+ // so they're removed here — keeping them would feed contradictory gold (the same address labelled
42
+ // both PL and OTHER). That leaves BR/MX as the Latin off-map TRAIN exposure and CA/LI as the
43
+ // heldout probe (the hard near-twins of in-map US/DE — an honest worst case). The in-map expansion
44
+ // itself shrinks the off-map Latin surface, and the bulk OTHER exposure is non-Latin (build-
45
+ // outlier-exposure.ts), so the thinner Latin train set is acceptable; watch OTHER-Latin recall in
46
+ // the openset eval.
47
+ const TRAIN_COUNTRIES = ["BR", "MX"];
48
+ const HELDOUT_COUNTRIES = ["CA", "LI"];
49
+ /** Address_levels arrives as a list (node-api) or its string repr; pull the value strings out. */
50
+ function levelValues(al) {
51
+ if (Array.isArray(al))
52
+ return al.map((x) => (x && x.value ? String(x.value) : "")).filter(Boolean);
53
+ const s = String(al ?? "");
54
+ const out = [];
55
+ for (const m of s.matchAll(/'value':\s*'([^']*)'/g)) {
56
+ out.push(m[1]);
57
+ }
58
+ if (!out.length) {
59
+ for (const m of s.matchAll(/"value":\s*"([^"]*)"/g)) {
60
+ out.push(m[1]);
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+ /** FNV-1a → uint32, for deterministic ordering/variant choice. */
66
+ function hash(s) {
67
+ let h = 2166136261;
68
+ for (let i = 0; i < s.length; i++) {
69
+ h ^= s.charCodeAt(i);
70
+ h = Math.imul(h, 16777619);
71
+ }
72
+ return h >>> 0;
73
+ }
74
+ /** Assemble a plausible address string from an Overture address row. Deterministic variant by hash. */
75
+ function assemble(r) {
76
+ const num = (r.number ?? "").toString().trim();
77
+ const street = (r.street ?? "").toString().trim();
78
+ const pc = (r.postcode ?? "").toString().trim();
79
+ const levels = levelValues(r.address_levels);
80
+ const locality = (r.postal_city ? String(r.postal_city) : "") || levels[levels.length - 1] || levels[0] || "";
81
+ if (!street && !locality)
82
+ return null; // nothing distinctive
83
+ const head = [num, street].filter(Boolean).join(" ");
84
+ const tail = [pc, locality].filter(Boolean).join(" ");
85
+ const h = hash(`${num}|${street}|${pc}|${locality}`);
86
+ switch (h % 3) {
87
+ case 0:
88
+ return [head, tail].filter(Boolean).join(", ");
89
+ case 1:
90
+ return [head, locality, pc].filter(Boolean).join(", ").trim();
91
+ default:
92
+ return [head, [locality, pc].filter(Boolean).join(" ")].filter(Boolean).join(", ");
93
+ }
94
+ }
95
+ const duck = await (await DuckDBInstance.create()).connect();
96
+ async function rowsFor(cc) {
97
+ const f = path.join(args.overture, `addresses-${cc.toLowerCase()}.parquet`);
98
+ let res;
99
+ try {
100
+ res = await duck.runAndReadAll(`SELECT number, street, postcode, postal_city, address_levels FROM read_parquet('${f}') LIMIT ${PER}`);
101
+ }
102
+ catch (e) {
103
+ console.error(` ${cc}: SKIP (${e.message.split("\n")[0]})`);
104
+ return [];
105
+ }
106
+ const seen = new Set();
107
+ const out = [];
108
+ for (const r of res.getRowObjects()) {
109
+ const raw = assemble(r);
110
+ if (!raw || seen.has(raw) || raw.length < 6)
111
+ continue;
112
+ seen.add(raw);
113
+ out.push(raw);
114
+ }
115
+ return out;
116
+ }
117
+ const trainAppend = [];
118
+ const valAppend = [];
119
+ const testRows = [];
120
+ // dedicated Latin off-map test: {raw, country:"OTHER", group, srcCountry}
121
+ for (const cc of TRAIN_COUNTRIES) {
122
+ const rows = (await rowsFor(cc)).sort((a, b) => hash(a) - hash(b));
123
+ const nVal = Math.floor(rows.length * 0.1);
124
+ const nTest = Math.floor(rows.length * 0.1);
125
+ const val = rows.slice(0, nVal);
126
+ const test = rows.slice(nVal, nVal + nTest);
127
+ const train = rows.slice(nVal + nTest);
128
+ for (const raw of train) {
129
+ trainAppend.push(raw);
130
+ }
131
+ for (const raw of val) {
132
+ valAppend.push(raw);
133
+ }
134
+ for (const raw of test) {
135
+ testRows.push({ raw, country: "OTHER", group: "indist", srcCountry: cc });
136
+ }
137
+ console.log(` TRAIN ${cc}: ${rows.length} (train ${train.length} / val ${val.length} / test ${test.length})`);
138
+ }
139
+ for (const cc of HELDOUT_COUNTRIES) {
140
+ const rows = await rowsFor(cc);
141
+ for (const raw of rows) {
142
+ testRows.push({ raw, country: "OTHER", group: "heldout", srcCountry: cc });
143
+ }
144
+ console.log(` HELDOUT ${cc}: ${rows.length} (test-only)`);
145
+ }
146
+ ;
147
+ duck.disconnect?.();
148
+ // Append OTHER rows to train/val; write the dedicated Latin off-map test file.
149
+ const wr = (rows) => rows.map((raw) => JSON.stringify({ raw, country: "OTHER" })).join("\n") + "\n";
150
+ appendFileSync(path.join(args.data, "train.jsonl"), wr(trainAppend));
151
+ appendFileSync(path.join(args.data, "val.jsonl"), wr(valAppend));
152
+ writeFileSync(path.join(args.data, "test-latin-offmap.jsonl"), testRows.map((r) => JSON.stringify(r)).join("\n") + "\n");
153
+ console.log(`\nappended OTHER → train +${trainAppend.length}, val +${valAppend.length}`);
154
+ console.log(`wrote test-latin-offmap.jsonl: ${testRows.length} rows (indist ${testRows.filter((r) => r.group === "indist").length} / heldout ${testRows.filter((r) => r.group === "heldout").length})`);
155
+ //# sourceMappingURL=build-outlier-latin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-outlier-latin.js","sourceRoot":"","sources":["../../../coarse-placer/tools/build-outlier-latin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AASpD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,C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AC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,MAAM,cAAc,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,MAAM,GAAG,CAC1L,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=build-outlier-oa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-outlier-oa.d.ts","sourceRoot":"","sources":["../../../coarse-placer/tools/build-outlier-oa.ts"],"names":[],"mappings":""}
@@ -0,0 +1,182 @@
1
+ import { appendFileSync, writeFileSync } from "node:fs";
2
+ import * as path from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { DuckDBInstance } from "@duckdb/node-api";
5
+ /**
6
+ * @copyright Sister Software
7
+ * @license AGPL-3.0
8
+ * @author Teffen Ellis, et al.
9
+ *
10
+ * OpenAddresses Latin-off-map outlier exposure for the #244 coarse-placer (milestone 3, breadth).
11
+ * The successor to build-outlier-latin.ts (Overture): Overture's ALPHA addresses theme only
12
+ * carries real rows for ~7 off-map countries, so a model trained on them MEMORIZED rather than
13
+ * learned an "off-map" boundary (night-15 finding). OpenAddresses covers far more countries —
14
+ * this assembles address strings from OA's per-country CSVs and appends them as `country:
15
+ * "OTHER"`.
16
+ *
17
+ * Discipline (per the #244 scoping note + DeepSeek consult):
18
+ *
19
+ * - LEAVE-ONE-LANGUAGE-FAMILY-OUT, not random: whole families are held out (Nordic, Baltic, …) so a
20
+ * trained sibling's shared n-grams can't rescue the generalization metric. TRAIN families
21
+ * feed train/val/test(indist); HELDOUT families go ONLY to the dedicated test file.
22
+ * - Schema variance: read via DuckDB read_csv_auto(..., union_by_name) so differing per-source OA
23
+ * schemas align; assemble to the SAME format the in-map rows use (build-outlier-latin's
24
+ * assemble).
25
+ * - Dedup (per country) + per-country CAP (downsample): PL/CZ dwarf others, so cap so OTHER isn't
26
+ * "mostly Polish".
27
+ * - Country filter: only OFF-MAP countries (never the 11 in-map); the in-map test.jsonl is untouched.
28
+ *
29
+ * Run AFTER build-dataset.ts + build-outlier-exposure.ts (it APPENDS). Re-runnable: rewrites the
30
+ * dedicated test file and appends fresh OTHER rows — rebuild train/val before re-running.
31
+ *
32
+ * Usage: node core/coarse-placer/tools/build-outlier-oa.ts --oa-dir <extracted-OA-root> [--per-country
33
+ * 6000] [--data data/coarse-placer]
34
+ */
35
+ import { dataRootPath } from "@mailwoman/core/utils";
36
+ const { values: args } = parseArgs({
37
+ options: {
38
+ "oa-dir": { type: "string", default: dataRootPath("openaddresses", "extracted") },
39
+ "per-country": { type: "string", default: "6000" },
40
+ data: { type: "string", default: path.resolve(import.meta.dirname, "../../data/coarse-placer") },
41
+ },
42
+ });
43
+ const PER = Number(args["per-country"]);
44
+ // The 11 IN-MAP countries the coarse-placer routes to — never appear in OTHER. (build-dataset.ts)
45
+ const IN_MAP = new Set(["US", "FR", "GB", "CN", "NL", "IT", "DE", "JP", "ES", "KR", "TW"]);
46
+ // Language/region families for the leave-one-family-out split. Off-map countries OA's europe+asia zips
47
+ // plausibly carry; the actual TRAIN/HELDOUT set is intersected with what's on disk at runtime. HELDOUT
48
+ // families are the generalization probe (the model never sees a single row from them).
49
+ // Off-map families, intersected at runtime with what OA's europe+asia zips actually carry (verified
50
+ // on disk: ae at au be cz dk ee fi gr il is kw kz lt lu lv nc nz pl pt qa ro sa se sg si sk).
51
+ const FAMILIES = {
52
+ slavic_latin: ["PL", "CZ", "SK", "SI"],
53
+ romance_offmap: ["PT", "RO"],
54
+ germanic_offmap: ["AT", "BE", "LU"],
55
+ nordic: ["SE", "DK", "FI", "IS"],
56
+ hellenic: ["GR"],
57
+ central_asian: ["KZ"],
58
+ maritime_asia: ["SG"],
59
+ baltic: ["EE", "LV", "LT"],
60
+ oceania: ["AU", "NZ", "NC"],
61
+ middle_east: ["AE", "IL", "KW", "QA", "SA"],
62
+ };
63
+ // Leave-one-language-FAMILY-out probe (DeepSeek): hold out WHOLE families the model never sees a row
64
+ // from — Baltic (Latin, distinct), Oceania (English-Latin, distinct), Middle-East (romanized non-Latin).
65
+ const HELDOUT_FAMILIES = new Set(["baltic", "oceania", "middle_east"]);
66
+ /** FNV-1a → uint32, deterministic ordering/variant choice. */
67
+ function hash(s) {
68
+ let h = 2166136261;
69
+ for (let i = 0; i < s.length; i++) {
70
+ h ^= s.charCodeAt(i);
71
+ h = Math.imul(h, 16777619);
72
+ }
73
+ return h >>> 0;
74
+ }
75
+ /** Assemble a plausible address string from an OA row — SAME shape variants as build-outlier-latin. */
76
+ function assemble(r) {
77
+ const num = (r.number ?? "").toString().trim();
78
+ const street = (r.street ?? "").toString().trim();
79
+ const pc = (r.postcode ?? "").toString().trim();
80
+ const locality = (r.city ?? "").toString().trim();
81
+ if (!street && !locality)
82
+ return null;
83
+ // nothing distinctive
84
+ // Drop raw-coord-only / PO-box-ish noise (DeepSeek gotcha): need a real street or locality token.
85
+ if (!street && !/[a-z]/i.test(locality))
86
+ return null;
87
+ const head = [num, street].filter(Boolean).join(" ");
88
+ const h = hash(`${num}|${street}|${pc}|${locality}`);
89
+ switch (h % 3) {
90
+ case 0:
91
+ return [head, [pc, locality].filter(Boolean).join(" ")].filter(Boolean).join(", ");
92
+ case 1:
93
+ return [head, locality, pc].filter(Boolean).join(", ").trim();
94
+ default:
95
+ return [head, [locality, pc].filter(Boolean).join(" ")].filter(Boolean).join(", ");
96
+ }
97
+ }
98
+ const duck = await (await DuckDBInstance.create()).connect();
99
+ /**
100
+ * Read+assemble up to PER deduped rows for a country from its OA CSVs (glob under the per-country dir).
101
+ */
102
+ async function rowsFor(cc) {
103
+ const lc = cc.toLowerCase();
104
+ // OA collected layout: `<cc>/[<region>/]<source>.csv` (country at root; `summary/` excluded by
105
+ // rooting the glob at <cc>). `**` matches zero-or-more dirs → handles both flat + region-nested.
106
+ const glob = path.join(args["oa-dir"], lc, "**", "*.csv");
107
+ let res;
108
+ try {
109
+ res = await duck.runAndReadAll(
110
+ // union_by_name aligns the differing per-source schemas; LOWER the header access so NUMBER /
111
+ // number both resolve. Pull a generous superset, dedup+cap in JS.
112
+ `SELECT COLUMNS('(?i)^(number|street|city|postcode)$') FROM read_csv_auto('${glob}', union_by_name=true, ignore_errors=true, sample_size=-1) LIMIT ${PER * 8}`);
113
+ }
114
+ catch (e) {
115
+ console.error(` ${cc}: SKIP (${e.message.split("\n")[0]})`);
116
+ return [];
117
+ }
118
+ const seen = new Set();
119
+ const out = [];
120
+ for (const r of res.getRowObjects()) {
121
+ // COLUMNS() preserves source-case keys; normalize to lowercase access.
122
+ const row = {};
123
+ for (const [k, v] of Object.entries(r)) {
124
+ row[k.toLowerCase()] = v;
125
+ }
126
+ const raw = assemble(row);
127
+ if (!raw || raw.length < 6 || seen.has(raw))
128
+ continue;
129
+ seen.add(raw);
130
+ out.push(raw);
131
+ if (out.length >= PER)
132
+ break;
133
+ }
134
+ return out.sort((a, b) => hash(a) - hash(b));
135
+ }
136
+ const trainAppend = [];
137
+ const valAppend = [];
138
+ const testRows = []; // {raw, country:"OTHER", group, srcCountry, family}
139
+ let trainCC = 0;
140
+ let heldCC = 0;
141
+ for (const [family, countries] of Object.entries(FAMILIES)) {
142
+ const heldout = HELDOUT_FAMILIES.has(family);
143
+ for (const cc of countries) {
144
+ if (IN_MAP.has(cc))
145
+ continue;
146
+ const rows = await rowsFor(cc);
147
+ if (rows.length === 0)
148
+ continue;
149
+ if (heldout) {
150
+ for (const raw of rows) {
151
+ testRows.push({ raw, country: "OTHER", group: "heldout", srcCountry: cc, family });
152
+ }
153
+ heldCC++;
154
+ console.log(` HELDOUT ${cc} (${family}): ${rows.length} (test-only)`);
155
+ }
156
+ else {
157
+ const nVal = Math.floor(rows.length * 0.1);
158
+ const nTest = Math.floor(rows.length * 0.1);
159
+ for (const raw of rows.slice(0, nVal)) {
160
+ valAppend.push(raw);
161
+ }
162
+ for (const raw of rows.slice(nVal, nVal + nTest)) {
163
+ testRows.push({ raw, country: "OTHER", group: "indist", srcCountry: cc, family });
164
+ }
165
+ for (const raw of rows.slice(nVal + nTest)) {
166
+ trainAppend.push(raw);
167
+ }
168
+ trainCC++;
169
+ console.log(` TRAIN ${cc} (${family}): ${rows.length}`);
170
+ }
171
+ }
172
+ }
173
+ ;
174
+ duck.disconnect?.();
175
+ const wr = (rows) => rows.map((raw) => JSON.stringify({ raw, country: "OTHER" })).join("\n") + "\n";
176
+ appendFileSync(path.join(args.data, "train.jsonl"), wr(trainAppend));
177
+ appendFileSync(path.join(args.data, "val.jsonl"), wr(valAppend));
178
+ writeFileSync(path.join(args.data, "test-latin-offmap.jsonl"), testRows.map((r) => JSON.stringify(r)).join("\n") + "\n");
179
+ console.log(`\nTRAIN countries: ${trainCC} · HELDOUT countries: ${heldCC}`);
180
+ console.log(`appended OTHER → train +${trainAppend.length}, val +${valAppend.length}`);
181
+ console.log(`wrote test-latin-offmap.jsonl: ${testRows.length} (indist ${testRows.filter((r) => r.group === "indist").length} / heldout ${testRows.filter((r) => r.group === "heldout").length})`);
182
+ //# sourceMappingURL=build-outlier-oa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-outlier-oa.js","sourceRoot":"","sources":["../../../coarse-placer/tools/build-outlier-oa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAUpD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE;QACR,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAA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AAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AACxH,OAAO,CAAC,GAAG,CAAC,sBAAsB,OAAO,yBAAyB,MAAM,EAAE,CAAC,CAAA;AAC3E,OAAO,CAAC,GAAG,CAAC,2BAA2B,WAAW,CAAC,MAAM,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAA;AACtF,OAAO,CAAC,GAAG,CACV,kCAAkC,QAAQ,CAAC,MAAM,YAAY,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,MAAM,cAAc,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,MAAM,GAAG,CACrL,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=eval-latin-offmap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-latin-offmap.d.ts","sourceRoot":"","sources":["../../../coarse-placer/tools/eval-latin-offmap.ts"],"names":[],"mappings":""}
@@ -0,0 +1,103 @@
1
+ import { readFileSync } from "node:fs";
2
+ import * as path from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ /**
5
+ * @copyright Sister Software
6
+ * @license AGPL-3.0
7
+ * @author Teffen Ellis, et al.
8
+ *
9
+ * Measure the #244 coarse-placer's handling of the Latin-script off-map residual (milestone 3). A
10
+ * Latin off-map address is HANDLED when the model routes it to OTHER or abstains — anything else
11
+ * is a confident mis-placement onto a wrong (trained) country. Reports handled-rate overall, by
12
+ * group (indist = held-out rows of trained-OTHER countries; heldout = countries never trained),
13
+ * and by source country, plus where the misses land. Run baseline (current model) and the M3
14
+ * retrain through this to read the before/after.
15
+ *
16
+ * Usage: node core/coarse-placer/tools/eval-latin-offmap.ts --model <dir> [--abstain 0.5]
17
+ */
18
+ import { dataRootPath } from "@mailwoman/core/utils";
19
+ const root = new URL("../../", import.meta.url);
20
+ const { CoarsePlacer } = (await import(new URL("core/out/coarse-placer/coarse-placer.js", root).href));
21
+ const { values: args } = parseArgs({
22
+ options: {
23
+ model: { type: "string", default: dataRootPath("coarse-placer", "model") },
24
+ abstain: { type: "string", default: "0.5" },
25
+ data: { type: "string", default: path.resolve(import.meta.dirname, "../../data/coarse-placer") },
26
+ },
27
+ });
28
+ const meta = JSON.parse(readFileSync(path.join(args.model, "meta.json"), "utf8"));
29
+ const buf = readFileSync(path.join(args.model, "weights.bin"));
30
+ const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
31
+ let weights;
32
+ if (meta.quantization === "int8-per-row") {
33
+ const int8 = new Int8Array(ab);
34
+ const C = meta.classes.length;
35
+ const dim = meta.featureDim;
36
+ const scales = meta.scales;
37
+ weights = new Float32Array(C * dim);
38
+ for (let c = 0; c < C; c++) {
39
+ const s = scales[c];
40
+ const base = c * dim;
41
+ for (let i = 0; i < dim; i++) {
42
+ weights[base + i] = int8[base + i] * s;
43
+ }
44
+ }
45
+ }
46
+ else {
47
+ weights = new Float32Array(ab);
48
+ }
49
+ const placer = new CoarsePlacer({ ...meta, weights }, { abstainBelow: Number(args.abstain) });
50
+ const rows = readFileSync(path.join(args.data, "test-latin-offmap.jsonl"), "utf8")
51
+ .trim()
52
+ .split("\n")
53
+ .map((l) => JSON.parse(l));
54
+ const handled = (p) => p.abstained || p.country === "OTHER";
55
+ const by = {}; // key → {n, ok}
56
+ const missTo = {}; // wrong country → count
57
+ const bump = (k) => (by[k] ??= { n: 0, ok: 0 });
58
+ let n = 0;
59
+ let ok = 0;
60
+ const samples = [];
61
+ for (const r of rows) {
62
+ const p = placer.predict(r.raw);
63
+ const h = handled(p);
64
+ n++;
65
+ if (h) {
66
+ ok++;
67
+ }
68
+ bump(`group:${r.group}`).n++;
69
+ bump(`cc:${r.srcCountry}`).n++;
70
+ if (h) {
71
+ bump(`group:${r.group}`).ok++;
72
+ bump(`cc:${r.srcCountry}`).ok++;
73
+ }
74
+ else {
75
+ missTo[p.country] = (missTo[p.country] ?? 0) + 1;
76
+ if (samples.length < 8) {
77
+ samples.push(` ${r.srcCountry} → ${p.country} @${p.confidence.toFixed(2)} «${r.raw.slice(0, 38)}»`);
78
+ }
79
+ }
80
+ }
81
+ const pct = (o, m) => `${((100 * o) / m).toFixed(1)}%`;
82
+ console.log(`Latin off-map handling — model ${path.basename(args.model)} (abstain ${args.abstain}, n=${n})`);
83
+ console.log(` OVERALL handled (OTHER-or-abstain): ${ok}/${n} (${pct(ok, n)}) ← want ≥90%`);
84
+ console.log(` by group:`);
85
+ for (const k of Object.keys(by)
86
+ .filter((k) => k.startsWith("group:"))
87
+ .sort()) {
88
+ console.log(` ${k.slice(6).padEnd(8)} ${pct(by[k].ok, by[k].n)} (n=${by[k].n})`);
89
+ }
90
+ console.log(` by source country:`);
91
+ for (const k of Object.keys(by)
92
+ .filter((k) => k.startsWith("cc:"))
93
+ .sort()) {
94
+ console.log(` ${k.slice(3).padEnd(4)} ${pct(by[k].ok, by[k].n)} (n=${by[k].n})`);
95
+ }
96
+ const misses = Object.entries(missTo).sort((a, b) => b[1] - a[1]);
97
+ if (misses.length) {
98
+ console.log(` misses land on: ${misses.map(([c, m]) => `${c}:${m}`).join(", ")}`);
99
+ }
100
+ if (samples.length) {
101
+ console.log(` sample misplacements:\n${samples.join("\n")}`);
102
+ }
103
+ //# sourceMappingURL=eval-latin-offmap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-latin-offmap.js","sourceRoot":"","sources":["../../../coarse-placer/tools/eval-latin-offmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,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 Phase 1 — POST-HOC open-set scoring on the EXISTING (shipped) coarse-placer, NO retrain.
7
+ * The OA-breadth verdict found the 12-way softmax's own max-prob detector tops out at ~88/88 on
8
+ * the leave-one-family-out probe (in-map accuracy vs off-map HELDOUT-family caught). This asks:
9
+ * does a DIFFERENT open-set score, read off the same frozen weights, clear the 90/90 the softmax
10
+ * can't?
11
+ *
12
+ * The 11-way routing (argmax over the in-map classes) is FIXED — the model is unchanged. The only
13
+ * thing each score changes is the REJECT decision (keep the in-map route vs. abstain → OTHER). We
14
+ * sweep each score's threshold and trace its (in-map accuracy, heldout-caught) Pareto.
15
+ *
16
+ * Scores compared (all functions of the frozen 12 logits / 11 in-map logits `z`):
17
+ *
18
+ * - Maxprob : softmax max over the 11 in-map classes (the verdict's baseline detector)
19
+ * - P_inmap : 1 - P(OTHER) (trust the model's own OTHER head)
20
+ * - Energy : logsumexp(z) (free-energy; higher = more in-map)
21
+ * - Maxlogit : max(z)
22
+ * - Maha : -min_c (z-μ_c)ᵀ Σ⁻¹ (z-μ_c), class-conditional Gaussians (tied Σ) fit on in-map TRAIN
23
+ * logits (Lee et al. 2018, in the 11-dim in-map-logit space — the linear model's only dense
24
+ * representation). Higher = closer to the in-map manifold.
25
+ *
26
+ * In-map accuracy = of the 11-country test rows, fraction NOT rejected AND argmax-in-map == truth.
27
+ * heldout caught = of the never-trained off-map families (baltic/oceania/middle-east), fraction
28
+ * rejected. Both move with the threshold; the Pareto is the whole story.
29
+ *
30
+ * Usage: node core/coarse-placer/tools/eval-openset.ts [--model <dir>] [--out-md <path>] Requires
31
+ * `yarn compile` (imports the compiled featurizer).
32
+ */
33
+ export {};
34
+ //# sourceMappingURL=eval-openset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-openset.d.ts","sourceRoot":"","sources":["../../../coarse-placer/tools/eval-openset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG"}