@mailwoman/neural-weights-en-us 7.1.0 → 7.2.1
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/package.json +10 -2
- package/scripts/link-dev-weights.ts +139 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/neural-weights-en-us",
|
|
3
|
-
"version": "7.1
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "Mailwoman neural-classifier weights for locale 'en-us'. Data-only package — loaded by @mailwoman/neural at runtime.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,15 @@
|
|
|
17
17
|
"postcode-us.bin",
|
|
18
18
|
"anchor-lexicon-v1.json",
|
|
19
19
|
"country-surface-lexicon-v1.json",
|
|
20
|
-
"README.md"
|
|
20
|
+
"README.md",
|
|
21
|
+
"*.ts",
|
|
22
|
+
"*.tsx",
|
|
23
|
+
"**/*.ts",
|
|
24
|
+
"**/*.tsx",
|
|
25
|
+
"!*.test.ts",
|
|
26
|
+
"!*.test.tsx",
|
|
27
|
+
"!**/*.test.ts",
|
|
28
|
+
"!**/*.test.tsx"
|
|
21
29
|
],
|
|
22
30
|
"publishConfig": {
|
|
23
31
|
"access": "public"
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @copyright Sister Software
|
|
4
|
+
* @license AGPL-3.0
|
|
5
|
+
* @author Teffen Ellis, et al.
|
|
6
|
+
*
|
|
7
|
+
* Symlink dev model + tokenizer files into this package for local testing.
|
|
8
|
+
*
|
|
9
|
+
* The published @mailwoman/neural-weights-en-us bundle contains the real model.onnx
|
|
10
|
+
* + tokenizer.model files (declared in package.json `files`). In the monorepo only
|
|
11
|
+
* the metadata files (package.json, model-card.json, README.md) are committed; the
|
|
12
|
+
* binaries live in `$MAILWOMAN_DATA_ROOT/models/` from training and get copied
|
|
13
|
+
* in at publish time.
|
|
14
|
+
*
|
|
15
|
+
* This script symlinks the dev artifacts so `@mailwoman/neural`'s loadFromWeights
|
|
16
|
+
* can find them during local testing. Run from anywhere; resolves paths from the
|
|
17
|
+
* package dir.
|
|
18
|
+
*
|
|
19
|
+
* ---------------------------------------------------------------------------
|
|
20
|
+
* #397 GUARD — why this script verifies a hash (read before editing the paths)
|
|
21
|
+
* ---------------------------------------------------------------------------
|
|
22
|
+
* `neural/test/weights.test.ts` invokes this script, so EVERY `yarn test` run
|
|
23
|
+
* re-creates these symlinks. If the defaults below point at a stale model, the
|
|
24
|
+
* whole repo silently starts grading evals against the wrong weights — which is
|
|
25
|
+
* exactly the trap that wasted an eval shift (the symlink had drifted to
|
|
26
|
+
* v0.5.3 / tokenizer v0.5.0-a1 while the deployed default was v4.0.0).
|
|
27
|
+
*
|
|
28
|
+
* To make drift impossible to ignore, when the DEFAULT artifacts are used (no
|
|
29
|
+
* MAILWOMAN_DEV_MODEL / MAILWOMAN_DEV_TOKENIZER override) this script asserts the
|
|
30
|
+
* linked bytes match the package's own `model-card.json` `files_md5` — the md5s the
|
|
31
|
+
* release pipeline re-verifies the PUBLISHED tarball against. A mismatch FAILS LOUD
|
|
32
|
+
* instead of grading the wrong model.
|
|
33
|
+
*
|
|
34
|
+
* ON SHIP: bump the two DEFAULT_* paths below to the new artifacts. The md5s are NOT
|
|
35
|
+
* duplicated here — they come from model-card.json, which the release-prep PR updates
|
|
36
|
+
* anyway. A path bumped without the card (or vice versa) fails the guard immediately;
|
|
37
|
+
* the 2026-07-02 v5.1.0 ship missed the path bump here and the duplicated-md5 design
|
|
38
|
+
* couldn't catch it (the stale pin was self-consistent — #259's trap, post-release form).
|
|
39
|
+
* ---------------------------------------------------------------------------
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { createHash } from "node:crypto"
|
|
43
|
+
import { existsSync, readFileSync, symlinkSync, unlinkSync } from "node:fs"
|
|
44
|
+
import { resolve } from "node:path"
|
|
45
|
+
|
|
46
|
+
import { $public } from "@mailwoman/core/env"
|
|
47
|
+
import { dataRootPath, repoRootPath } from "@mailwoman/core/utils"
|
|
48
|
+
|
|
49
|
+
// --- current default (npm v5.9.0 = demo defaultVersion v5.9.0) --------------
|
|
50
|
+
// 6.5.0 ships the v381-punct-fix-full (step-8000) int8 model + the v0.9.0-multisplice tokenizer (tokenizer UNCHANGED since
|
|
51
|
+
// 6.1.0; only the model moved — the no-fragment digit-ownership shard + the #1101 punct-drop augmentation). Bump these two
|
|
52
|
+
// paths on each ship; the expected md5s live in model-card.json `files_md5` (single source — see the header).
|
|
53
|
+
const DEFAULT_MODEL = dataRootPath("models", "quantized", "model-v381-step-8000-int8.onnx")
|
|
54
|
+
const DEFAULT_TOKENIZER = dataRootPath("models", "tokenizer", "v0.9.0-multisplice", "tokenizer.model")
|
|
55
|
+
|
|
56
|
+
const PKG_DIR = repoRootPath("neural-weights-en-us")
|
|
57
|
+
|
|
58
|
+
// The shipped-bytes truth (#397 guard): the card's files_md5 block, which release Step 4
|
|
59
|
+
// re-verifies against the published tarball — so dev symlinks, the card, and npm agree.
|
|
60
|
+
const CARD = JSON.parse(readFileSync(resolve(PKG_DIR, "model-card.json"), "utf8")) as {
|
|
61
|
+
files_md5?: Record<string, string>
|
|
62
|
+
}
|
|
63
|
+
const DEFAULT_MODEL_MD5 = CARD.files_md5?.["model.onnx"]
|
|
64
|
+
const DEFAULT_TOKENIZER_MD5 = CARD.files_md5?.["tokenizer.model"]
|
|
65
|
+
|
|
66
|
+
if (!DEFAULT_MODEL_MD5 || !DEFAULT_TOKENIZER_MD5) {
|
|
67
|
+
console.error(
|
|
68
|
+
"ERROR (#397 guard): model-card.json has no files_md5.{model.onnx,tokenizer.model} — cannot verify the dev pin."
|
|
69
|
+
)
|
|
70
|
+
process.exit(1)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// An explicit override means the caller is deliberately experimenting with a
|
|
74
|
+
// non-default model — skip the hash assertion in that case (but warn loudly).
|
|
75
|
+
const MODEL_OVERRIDDEN = !!$public.MAILWOMAN_DEV_MODEL
|
|
76
|
+
const TOKENIZER_OVERRIDDEN = !!$public.MAILWOMAN_DEV_TOKENIZER
|
|
77
|
+
|
|
78
|
+
const SRC_MODEL = $public.MAILWOMAN_DEV_MODEL || DEFAULT_MODEL
|
|
79
|
+
const SRC_TOKENIZER = $public.MAILWOMAN_DEV_TOKENIZER || DEFAULT_TOKENIZER
|
|
80
|
+
|
|
81
|
+
if (!existsSync(SRC_MODEL)) {
|
|
82
|
+
console.error(`missing source model: ${SRC_MODEL}`)
|
|
83
|
+
console.error("set MAILWOMAN_DEV_MODEL to override")
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!existsSync(SRC_TOKENIZER)) {
|
|
88
|
+
console.error(`missing source tokenizer: ${SRC_TOKENIZER}`)
|
|
89
|
+
console.error("set MAILWOMAN_DEV_TOKENIZER to override")
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Replicate `ln -sf SRC DEST`: drop any pre-existing link/file at the destination, then symlink. */
|
|
94
|
+
function linkForce(src: string, dest: string): void {
|
|
95
|
+
if (existsSync(dest)) {
|
|
96
|
+
unlinkSync(dest)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
symlinkSync(src, dest)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const MODEL_DEST = resolve(PKG_DIR, "model.onnx")
|
|
103
|
+
const TOKENIZER_DEST = resolve(PKG_DIR, "tokenizer.model")
|
|
104
|
+
|
|
105
|
+
linkForce(SRC_MODEL, MODEL_DEST)
|
|
106
|
+
linkForce(SRC_TOKENIZER, TOKENIZER_DEST)
|
|
107
|
+
|
|
108
|
+
console.log("linked:")
|
|
109
|
+
console.log(` ${MODEL_DEST} → ${SRC_MODEL}`)
|
|
110
|
+
console.log(` ${TOKENIZER_DEST} → ${SRC_TOKENIZER}`)
|
|
111
|
+
|
|
112
|
+
// --- #397 drift guard: assert default bytes match what the demo serves ------
|
|
113
|
+
function assertMd5(label: string, path: string, expected: string): void {
|
|
114
|
+
const actual = createHash("md5").update(readFileSync(path)).digest("hex")
|
|
115
|
+
|
|
116
|
+
if (actual !== expected) {
|
|
117
|
+
console.error("")
|
|
118
|
+
console.error(`ERROR (#397 guard): linked default ${label} md5 mismatch.`)
|
|
119
|
+
console.error(` linked: ${path}`)
|
|
120
|
+
console.error(` got: ${actual}`)
|
|
121
|
+
console.error(` expected: ${expected} (deployed en-us defaultVersion)`)
|
|
122
|
+
console.error(" The dev symlink has drifted from the deployed default. Either the")
|
|
123
|
+
console.error(" artifact moved, or releases.json defaultVersion changed without a")
|
|
124
|
+
console.error(` matching bump to DEFAULT_${label.toUpperCase()}_MD5 in this script.`)
|
|
125
|
+
process.exit(1)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!MODEL_OVERRIDDEN) {
|
|
130
|
+
assertMd5("model", MODEL_DEST, DEFAULT_MODEL_MD5)
|
|
131
|
+
} else {
|
|
132
|
+
console.error(" (model override active — skipping #397 default-hash check)")
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!TOKENIZER_OVERRIDDEN) {
|
|
136
|
+
assertMd5("tokenizer", TOKENIZER_DEST, DEFAULT_TOKENIZER_MD5)
|
|
137
|
+
} else {
|
|
138
|
+
console.error(" (tokenizer override active — skipping #397 default-hash check)")
|
|
139
|
+
}
|