@mailwoman/mtf 10.7.0 → 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.
- package/README.md +35 -5
- package/crates/mtf-channels/tests/fixtures/README.md +13 -0
- package/crates/mtf-sampler/tests/fixtures/README.md +120 -0
- package/lib/code-units.ts +45 -0
- package/out/code-units.d.ts +24 -0
- package/out/code-units.d.ts.map +1 -0
- package/out/code-units.js +36 -0
- package/out/code-units.js.map +1 -0
- package/out/tools/build-wasm.run.js +2 -2
- package/out/tools/build-wasm.run.js.map +1 -1
- package/out/tools/sampler/native.d.ts +314 -0
- package/out/tools/sampler/native.d.ts.map +1 -0
- package/out/tools/sampler/native.js +114 -0
- package/out/tools/sampler/native.js.map +1 -0
- package/out/tools/tokenizer/binary.d.ts +38 -0
- package/out/tools/tokenizer/binary.d.ts.map +1 -0
- package/out/tools/tokenizer/binary.js +94 -0
- package/out/tools/tokenizer/binary.js.map +1 -0
- package/out/tools/tokenizer/byte-fallback.d.ts +39 -0
- package/out/tools/tokenizer/byte-fallback.d.ts.map +1 -0
- package/out/tools/tokenizer/byte-fallback.js +49 -0
- package/out/tools/tokenizer/byte-fallback.js.map +1 -0
- package/out/tools/tokenizer/model.d.ts +70 -0
- package/out/tools/tokenizer/model.d.ts.map +1 -0
- package/out/tools/tokenizer/model.js +56 -0
- package/out/tools/tokenizer/model.js.map +1 -0
- package/out/tools/tokenizer/prune.d.ts +69 -0
- package/out/tools/tokenizer/prune.d.ts.map +1 -0
- package/out/tools/tokenizer/prune.js +126 -0
- package/out/tools/tokenizer/prune.js.map +1 -0
- package/out/tools/tokenizer/prune.run.d.ts +16 -0
- package/out/tools/tokenizer/prune.run.d.ts.map +1 -0
- package/out/tools/tokenizer/prune.run.js +34 -0
- package/out/tools/tokenizer/prune.run.js.map +1 -0
- package/out/tools/tokenizer/sentencepiece.d.ts +63 -0
- package/out/tools/tokenizer/sentencepiece.d.ts.map +1 -0
- package/out/tools/tokenizer/sentencepiece.js +90 -0
- package/out/tools/tokenizer/sentencepiece.js.map +1 -0
- package/out/tools/tokenizer/splice.d.ts +117 -0
- package/out/tools/tokenizer/splice.d.ts.map +1 -0
- package/out/tools/tokenizer/splice.js +398 -0
- package/out/tools/tokenizer/splice.js.map +1 -0
- package/out/tools/tokenizer/splice.run.d.ts +29 -0
- package/out/tools/tokenizer/splice.run.d.ts.map +1 -0
- package/out/tools/tokenizer/splice.run.js +114 -0
- package/out/tools/tokenizer/splice.run.js.map +1 -0
- package/out/tools/tokenizer/symbols.d.ts +42 -0
- package/out/tools/tokenizer/symbols.d.ts.map +1 -0
- package/out/tools/tokenizer/symbols.js +113 -0
- package/out/tools/tokenizer/symbols.js.map +1 -0
- package/out/tools/tokenizer/train/text.run.d.ts +16 -0
- package/out/tools/tokenizer/train/text.run.d.ts.map +1 -0
- package/out/tools/tokenizer/train/text.run.js +67 -0
- package/out/tools/tokenizer/train/text.run.js.map +1 -0
- package/out/tools/tokenizer/train.d.ts +113 -0
- package/out/tools/tokenizer/train.d.ts.map +1 -0
- package/out/tools/tokenizer/train.js +162 -0
- package/out/tools/tokenizer/train.js.map +1 -0
- package/out/tools/tokenizer/train.run.d.ts +24 -0
- package/out/tools/tokenizer/train.run.d.ts.map +1 -0
- package/out/tools/tokenizer/train.run.js +131 -0
- package/out/tools/tokenizer/train.run.js.map +1 -0
- package/out/tools/tokenizer/utilization.run.d.ts +17 -0
- package/out/tools/tokenizer/utilization.run.d.ts.map +1 -0
- package/out/tools/tokenizer/utilization.run.js +80 -0
- package/out/tools/tokenizer/utilization.run.js.map +1 -0
- package/out/tools/tokenizer/verify.d.ts +94 -0
- package/out/tools/tokenizer/verify.d.ts.map +1 -0
- package/out/tools/tokenizer/verify.js +193 -0
- package/out/tools/tokenizer/verify.js.map +1 -0
- package/out/tools/tokenizer/verify.run.d.ts +22 -0
- package/out/tools/tokenizer/verify.run.d.ts.map +1 -0
- package/out/tools/tokenizer/verify.run.js +71 -0
- package/out/tools/tokenizer/verify.run.js.map +1 -0
- package/package.json +15 -3
- package/tools/build-wasm.run.ts +2 -2
- package/tools/sampler/native.ts +433 -0
- package/tools/tokenizer/binary.ts +118 -0
- package/tools/tokenizer/byte-fallback.ts +80 -0
- package/tools/tokenizer/model.ts +110 -0
- package/tools/tokenizer/prune.run.ts +37 -0
- package/tools/tokenizer/prune.ts +195 -0
- package/tools/tokenizer/sentencepiece.ts +142 -0
- package/tools/tokenizer/splice.run.ts +141 -0
- package/tools/tokenizer/splice.ts +592 -0
- package/tools/tokenizer/symbols.ts +119 -0
- package/tools/tokenizer/train/text.run.ts +80 -0
- package/tools/tokenizer/train.run.ts +151 -0
- package/tools/tokenizer/train.ts +266 -0
- package/tools/tokenizer/utilization.run.ts +96 -0
- package/tools/tokenizer/verify.run.ts +77 -0
- package/tools/tokenizer/verify.ts +313 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The strings a trained tokenizer keeps whole, and how they reach SentencePiece.
|
|
7
|
+
*
|
|
8
|
+
* A user-defined symbol bypasses unigram inference and is always emitted as one piece. The literal a caller writes
|
|
9
|
+
* is not the literal SentencePiece matches: it turns whitespace into `▁` before matching, so `PO Box` is passed as
|
|
10
|
+
* `PO▁Box`. The symbols also compete with the vocabulary budget, so a list longer than a quarter of the vocabulary
|
|
11
|
+
* is truncated.
|
|
12
|
+
*/
|
|
13
|
+
import { readLocalTextFile } from "@mailwoman/core/fs/readers";
|
|
14
|
+
import { splitLines } from "@mailwoman/core/strings/unicode";
|
|
15
|
+
/**
|
|
16
|
+
* The default symbols: US state and territory codes, country abbreviations
|
|
17
|
+
* and names, and postal-form anchors.
|
|
18
|
+
*
|
|
19
|
+
* A state code beside a postcode (`NY 10001`) stays one piece, so the region and postcode stay adjacent.
|
|
20
|
+
* Postal markers (`PO Box`, `Cedex`, `BP`) are fixed surface forms that are
|
|
21
|
+
* cheaper to add once than to learn.
|
|
22
|
+
*
|
|
23
|
+
* A hyphen is not listed because it already tokenizes as one piece.
|
|
24
|
+
* Whole Japanese postcodes come from mined postcode literals.
|
|
25
|
+
*
|
|
26
|
+
* The list keeps its duplicates (`CA`, `DE`), which the trainer removes.
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_USER_DEFINED_SYMBOLS = [
|
|
29
|
+
// US states and territories.
|
|
30
|
+
..."AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY DC PR VI GU AS MP".split(" "),
|
|
31
|
+
// Country abbreviations and names.
|
|
32
|
+
"USA",
|
|
33
|
+
"US",
|
|
34
|
+
"U.S.",
|
|
35
|
+
"U.S.A.",
|
|
36
|
+
"FR",
|
|
37
|
+
"FRA",
|
|
38
|
+
"France",
|
|
39
|
+
"JP",
|
|
40
|
+
"JPN",
|
|
41
|
+
"Japan",
|
|
42
|
+
"GB",
|
|
43
|
+
"UK",
|
|
44
|
+
"U.K.",
|
|
45
|
+
"DE",
|
|
46
|
+
"DEU",
|
|
47
|
+
"Germany",
|
|
48
|
+
"IT",
|
|
49
|
+
"ITA",
|
|
50
|
+
"Italy",
|
|
51
|
+
"ES",
|
|
52
|
+
"ESP",
|
|
53
|
+
"Spain",
|
|
54
|
+
"NL",
|
|
55
|
+
"NLD",
|
|
56
|
+
"Netherlands",
|
|
57
|
+
"CA",
|
|
58
|
+
"CAN",
|
|
59
|
+
"Canada",
|
|
60
|
+
"AU",
|
|
61
|
+
"AUS",
|
|
62
|
+
"Australia",
|
|
63
|
+
"CH",
|
|
64
|
+
"CHE",
|
|
65
|
+
"Switzerland",
|
|
66
|
+
"BE",
|
|
67
|
+
"BEL",
|
|
68
|
+
"Belgium",
|
|
69
|
+
"AT",
|
|
70
|
+
"AUT",
|
|
71
|
+
"Austria",
|
|
72
|
+
"SE",
|
|
73
|
+
"SWE",
|
|
74
|
+
"Sweden",
|
|
75
|
+
"RU",
|
|
76
|
+
"RUS",
|
|
77
|
+
// Postal-form anchors.
|
|
78
|
+
"PO Box",
|
|
79
|
+
"P.O. Box",
|
|
80
|
+
"P.O.Box",
|
|
81
|
+
"POB",
|
|
82
|
+
"Apt",
|
|
83
|
+
"Apt.",
|
|
84
|
+
"Suite",
|
|
85
|
+
"Ste",
|
|
86
|
+
"Cedex",
|
|
87
|
+
"CEDEX",
|
|
88
|
+
"BP",
|
|
89
|
+
];
|
|
90
|
+
/**
|
|
91
|
+
* One literal per line.
|
|
92
|
+
*
|
|
93
|
+
* A blank line or a `#` comment is skipped, and only line ends are trimmed,
|
|
94
|
+
* because a symbol may hold a space (`PO Box`).
|
|
95
|
+
*/
|
|
96
|
+
export async function readUserDefinedSymbolsFile(path) {
|
|
97
|
+
return splitLines(await readLocalTextFile(path))
|
|
98
|
+
.map((line) => line.trimEnd())
|
|
99
|
+
.filter((line) => line && !line.trim().startsWith("#"));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A symbol with each ASCII space replaced by SentencePiece's whitespace placeholder, `▁`.
|
|
103
|
+
*/
|
|
104
|
+
export function sentencePieceSymbol(symbol) {
|
|
105
|
+
return symbol.replaceAll(" ", "▁");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The non-empty entries, first occurrences only, in order.
|
|
109
|
+
*/
|
|
110
|
+
export function dedupeKeepOrder(items) {
|
|
111
|
+
return [...new Set([...items].filter((item) => item.length > 0))];
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../../tools/tokenizer/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;A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AAU,mBAAmB,CAAC,MAAc;IACjD,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAuB;IACtD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Train the first-generation tokenizer recipe on a text file of raw addresses, one per line.
|
|
7
|
+
*
|
|
8
|
+
* The recipe is fixed: a 16,000-piece unigram vocabulary, 0.9995 character coverage, byte fallback, the four special
|
|
9
|
+
* ids, and no user-defined symbols. It writes `tokenizer.model`, `tokenizer.vocab` and `META.json` under `--output`.
|
|
10
|
+
* `--version` must match the corpus version the tokenizer ships with.
|
|
11
|
+
*
|
|
12
|
+
* Usage: `node packages/mtf/tools/tokenizer/train/text.run.ts --input <txt> --output <dir> --version <v>
|
|
13
|
+
* [--spm-train <path>]`
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=text.run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.run.d.ts","sourceRoot":"","sources":["../../../../tools/tokenizer/train/text.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Train the first-generation tokenizer recipe on a text file of raw addresses, one per line.
|
|
7
|
+
*
|
|
8
|
+
* The recipe is fixed: a 16,000-piece unigram vocabulary, 0.9995 character coverage, byte fallback, the four special
|
|
9
|
+
* ids, and no user-defined symbols. It writes `tokenizer.model`, `tokenizer.vocab` and `META.json` under `--output`.
|
|
10
|
+
* `--version` must match the corpus version the tokenizer ships with.
|
|
11
|
+
*
|
|
12
|
+
* Usage: `node packages/mtf/tools/tokenizer/train/text.run.ts --input <txt> --output <dir> --version <v>
|
|
13
|
+
* [--spm-train <path>]`
|
|
14
|
+
*/
|
|
15
|
+
import { readLocalTextFile } from "@mailwoman/core/fs/readers";
|
|
16
|
+
import { temporaryDirectory } from "@mailwoman/core/fs/temporary";
|
|
17
|
+
import { makeDirectories, writeLocalJSONFile } from "@mailwoman/core/fs/writers";
|
|
18
|
+
import { gitHead } from "@mailwoman/core/git";
|
|
19
|
+
import { sha256File } from "@mailwoman/core/hash";
|
|
20
|
+
import { prettyJSON } from "@mailwoman/core/json";
|
|
21
|
+
import { parseArguments, requiredArgument } from "@mailwoman/core/scripting/arguments";
|
|
22
|
+
import { resolvePath } from "path-ts";
|
|
23
|
+
import { spmTrainBinary } from "../binary.js";
|
|
24
|
+
import { trainSentencePiece } from "../sentencepiece.js";
|
|
25
|
+
const RECIPE = {
|
|
26
|
+
vocab_size: 16_000,
|
|
27
|
+
character_coverage: 0.9995,
|
|
28
|
+
model_type: "unigram",
|
|
29
|
+
byte_fallback: true,
|
|
30
|
+
};
|
|
31
|
+
const { values } = parseArguments({
|
|
32
|
+
options: {
|
|
33
|
+
input: { type: "string" },
|
|
34
|
+
output: { type: "string" },
|
|
35
|
+
version: { type: "string" },
|
|
36
|
+
"spm-train": { type: "string" },
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const input = resolvePath(requiredArgument("train-text", "input", values.input));
|
|
40
|
+
const output = resolvePath(requiredArgument("train-text", "output", values.output));
|
|
41
|
+
const version = requiredArgument("train-text", "version", values.version);
|
|
42
|
+
await makeDirectories(output);
|
|
43
|
+
await using scratch = await temporaryDirectory("mtf-train-text-");
|
|
44
|
+
const trained = await trainSentencePiece({
|
|
45
|
+
input,
|
|
46
|
+
model_prefix: `${output}/tokenizer`,
|
|
47
|
+
...RECIPE,
|
|
48
|
+
pad_id: 0,
|
|
49
|
+
unk_id: 1,
|
|
50
|
+
bos_id: 2,
|
|
51
|
+
eos_id: 3,
|
|
52
|
+
user_defined_symbols: [],
|
|
53
|
+
}, { spmTrain: await spmTrainBinary(values["spm-train"]), workDirectory: scratch.path.toString() });
|
|
54
|
+
const text = await readLocalTextFile(input);
|
|
55
|
+
const meta = {
|
|
56
|
+
tokenizer_version: version,
|
|
57
|
+
...RECIPE,
|
|
58
|
+
// Every line break ends a line, and a final line without one still counts.
|
|
59
|
+
training_lines: (text.match(/\n/g)?.length ?? 0) + (text && !text.endsWith("\n") ? 1 : 0),
|
|
60
|
+
git_commit: await gitHead().catch(() => null),
|
|
61
|
+
model_sha256: await sha256File(trained.model),
|
|
62
|
+
model_path: trained.model,
|
|
63
|
+
vocab_path: trained.vocab,
|
|
64
|
+
};
|
|
65
|
+
await writeLocalJSONFile(meta, `${output}/META.json`);
|
|
66
|
+
console.log(prettyJSON(meta, false, 2));
|
|
67
|
+
//# sourceMappingURL=text.run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.run.js","sourceRoot":"","sources":["../../../../tools/tokenizer/train/text.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,M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AAC;IACT,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,oBAAoB,EAAE,EAAE;CACxB,EACD,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAC/F,CAAA;AAED,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAA;AAE3C,MAAM,IAAI,GAAG;IACZ,iBAAiB,EAAE,OAAO;IAC1B,GAAG,MAAM;IACT,2EAA2E;IAC3E,cAAc,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzF,UAAU,EAAE,MAAM,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;IAC7C,YAAY,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC,KAAK;IACzB,UAAU,EAAE,OAAO,CAAC,KAAK;CACzB,CAAA;AAED,MAAM,kBAAkB,CAAC,IAAI,EAAE,GAAG,MAAM,YAAY,CAAC,CAAA;AAErD,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Train a versioned SentencePiece tokenizer from a corpus's train split, and write its model card.
|
|
7
|
+
*
|
|
8
|
+
* The training lines are a balanced sample: a reservoir of `perCountrySample` raws per country, drawn with CPython's
|
|
9
|
+
* generator in the order `tokenizer/train.py` drew, then shuffled. The card records what reproduces the model: the
|
|
10
|
+
* corpus files read and their order, the SHA-256 of the training input and of the symbol list, the SentencePiece
|
|
11
|
+
* release, every flag, and the model's SHA-256.
|
|
12
|
+
*/
|
|
13
|
+
import { SENTENCEPIECE } from "./binary.ts";
|
|
14
|
+
import { type ByteFallbackReport } from "./byte-fallback.ts";
|
|
15
|
+
import { type TrainerFlags, type TrainerFlagValue } from "./sentencepiece.ts";
|
|
16
|
+
export interface TokenizerTrainingConfig {
|
|
17
|
+
corpusDirectory: string;
|
|
18
|
+
outputDirectory: string;
|
|
19
|
+
corpusVersion: string;
|
|
20
|
+
vocabSize: number;
|
|
21
|
+
characterCoverage: number;
|
|
22
|
+
modelType: string;
|
|
23
|
+
byteFallback: boolean;
|
|
24
|
+
splitDigits: boolean;
|
|
25
|
+
allowWhitespaceOnlyPieces: boolean;
|
|
26
|
+
perCountrySample: number;
|
|
27
|
+
countries: readonly string[];
|
|
28
|
+
minePostcodeLiterals: number;
|
|
29
|
+
userDefinedSymbols: readonly string[];
|
|
30
|
+
evalFixture: string | null;
|
|
31
|
+
seed: number;
|
|
32
|
+
/**
|
|
33
|
+
* Further trainer arguments, appended after the standard ones in this order.
|
|
34
|
+
*/
|
|
35
|
+
extraFlags: Readonly<Record<string, TrainerFlagValue>>;
|
|
36
|
+
/**
|
|
37
|
+
* The `spm_train` binary.
|
|
38
|
+
*/
|
|
39
|
+
spmTrain: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The defaults the Python tokenizer trainer used.
|
|
43
|
+
*/
|
|
44
|
+
export declare const TOKENIZER_TRAINING_DEFAULTS: {
|
|
45
|
+
readonly vocabSize: 48000;
|
|
46
|
+
readonly characterCoverage: 0.9999;
|
|
47
|
+
readonly modelType: "unigram";
|
|
48
|
+
readonly byteFallback: true;
|
|
49
|
+
readonly splitDigits: false;
|
|
50
|
+
readonly allowWhitespaceOnlyPieces: false;
|
|
51
|
+
readonly perCountrySample: 500000;
|
|
52
|
+
readonly countries: readonly ["US", "FR"];
|
|
53
|
+
readonly minePostcodeLiterals: 0;
|
|
54
|
+
readonly seed: 42;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The symbols to keep whole, as written and as passed to SentencePiece: the configured list,
|
|
58
|
+
* then any mined postcode literals, first occurrences only, truncated to a quarter of the vocabulary.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveUserDefinedSymbols(config: Pick<TokenizerTrainingConfig, "userDefinedSymbols" | "minePostcodeLiterals" | "corpusDirectory" | "countries" | "vocabSize">): Promise<{
|
|
61
|
+
symbols: string[];
|
|
62
|
+
passed: string[];
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* The trainer flags of a configuration, in the order the Python trainer passed them.
|
|
66
|
+
*/
|
|
67
|
+
export declare function trainerFlags(config: TokenizerTrainingConfig, input: string, modelPrefix: string, symbols: readonly string[]): TrainerFlags;
|
|
68
|
+
/**
|
|
69
|
+
* A train file read, in read order, and the SHA-256 its corpus manifest records, when it records one.
|
|
70
|
+
*/
|
|
71
|
+
interface CorpusFileRecord {
|
|
72
|
+
path: string;
|
|
73
|
+
sha256: string | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The card `trainTokenizer` writes as `model_card.json` and `META.json`.
|
|
77
|
+
*/
|
|
78
|
+
export interface TokenizerModelCard {
|
|
79
|
+
tokenizer_version: string;
|
|
80
|
+
corpus_version: string;
|
|
81
|
+
vocab_size: number;
|
|
82
|
+
training_lines: number;
|
|
83
|
+
training_duration_seconds: number;
|
|
84
|
+
generated_at: string;
|
|
85
|
+
git_commit: string | null;
|
|
86
|
+
model_sha256: string;
|
|
87
|
+
model_path: string;
|
|
88
|
+
vocab_path: string;
|
|
89
|
+
sentencepiece: typeof SENTENCEPIECE & {
|
|
90
|
+
trainer: "spm_train";
|
|
91
|
+
};
|
|
92
|
+
sentencepiece_flags: Record<string, unknown>;
|
|
93
|
+
training_input: {
|
|
94
|
+
sha256: string;
|
|
95
|
+
lines: number;
|
|
96
|
+
corpus_files: CorpusFileRecord[];
|
|
97
|
+
user_defined_symbols_sha256: string;
|
|
98
|
+
};
|
|
99
|
+
sampling: {
|
|
100
|
+
countries: string[];
|
|
101
|
+
per_country: number;
|
|
102
|
+
seed: number;
|
|
103
|
+
per_country_lines: Record<string, number>;
|
|
104
|
+
};
|
|
105
|
+
byte_fallback_eval: ByteFallbackReport | null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Sample, train and write `tokenizer.model`, `tokenizer.vocab`, `model_card.json`
|
|
109
|
+
* and `META.json` under the output directory.
|
|
110
|
+
*/
|
|
111
|
+
export declare function trainTokenizer(config: TokenizerTrainingConfig): Promise<TokenizerModelCard>;
|
|
112
|
+
export {};
|
|
113
|
+
//# sourceMappingURL=train.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"train.d.ts","sourceRoot":"","sources":["../../../tools/tokenizer/train.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,OAAO,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,KAAK,kBAAkB,EAAyC,MAAM,oBAAoB,CAAA;AAEnG,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAsB,MAAM,oBAAoB,CAAA;AAGjG,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,yBAAyB,EAAE,OAAO,CAAA;IAClC,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EA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,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,yBAAyB,EAAE,MAAM,CAAA;IACjC,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,OAAO,aAAa,GAAG;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,CAAA;IAC9D,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5C,cAAc,EAAE;QACf,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;QACb,YAAY,EAAE,gBAAgB,EAAE,CAAA;QAChC,2BAA2B,EAAE,MAAM,CAAA;KACnC,CAAA;IACD,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAA;IAC/G,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAC7C;AAMD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA2FjG"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Train a versioned SentencePiece tokenizer from a corpus's train split, and write its model card.
|
|
7
|
+
*
|
|
8
|
+
* The training lines are a balanced sample: a reservoir of `perCountrySample` raws per country, drawn with CPython's
|
|
9
|
+
* generator in the order `tokenizer/train.py` drew, then shuffled. The card records what reproduces the model: the
|
|
10
|
+
* corpus files read and their order, the SHA-256 of the training input and of the symbol list, the SentencePiece
|
|
11
|
+
* release, every flag, and the model's SHA-256.
|
|
12
|
+
*/
|
|
13
|
+
import { temporaryDirectory } from "@mailwoman/core/fs/temporary";
|
|
14
|
+
import { makeDirectories, writeLocalJSONFile } from "@mailwoman/core/fs/writers";
|
|
15
|
+
import { gitHead } from "@mailwoman/core/git";
|
|
16
|
+
import { sha256File, sha256Hex } from "@mailwoman/core/hash";
|
|
17
|
+
import { isoSeconds } from "@mailwoman/core/utils";
|
|
18
|
+
import { runMTFTokenizer, SENTENCEPIECE } from "./binary.js";
|
|
19
|
+
import { measureByteFallback, readFixtureLines } from "./byte-fallback.js";
|
|
20
|
+
import { readModelPieces } from "./model.js";
|
|
21
|
+
import { trainSentencePiece } from "./sentencepiece.js";
|
|
22
|
+
import { dedupeKeepOrder, sentencePieceSymbol } from "./symbols.js";
|
|
23
|
+
/**
|
|
24
|
+
* The defaults the Python tokenizer trainer used.
|
|
25
|
+
*/
|
|
26
|
+
export const TOKENIZER_TRAINING_DEFAULTS = {
|
|
27
|
+
vocabSize: 48_000,
|
|
28
|
+
characterCoverage: 0.9999,
|
|
29
|
+
modelType: "unigram",
|
|
30
|
+
byteFallback: true,
|
|
31
|
+
splitDigits: false,
|
|
32
|
+
allowWhitespaceOnlyPieces: false,
|
|
33
|
+
perCountrySample: 500_000,
|
|
34
|
+
countries: ["US", "FR"],
|
|
35
|
+
minePostcodeLiterals: 0,
|
|
36
|
+
seed: 42,
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The symbols to keep whole, as written and as passed to SentencePiece: the configured list,
|
|
40
|
+
* then any mined postcode literals, first occurrences only, truncated to a quarter of the vocabulary.
|
|
41
|
+
*/
|
|
42
|
+
export async function resolveUserDefinedSymbols(config) {
|
|
43
|
+
const listed = [...config.userDefinedSymbols];
|
|
44
|
+
if (config.minePostcodeLiterals > 0) {
|
|
45
|
+
listed.push(...(await runMTFTokenizer([
|
|
46
|
+
"mine-postcodes",
|
|
47
|
+
"--corpus",
|
|
48
|
+
config.corpusDirectory,
|
|
49
|
+
"--top-k",
|
|
50
|
+
String(config.minePostcodeLiterals),
|
|
51
|
+
"--countries",
|
|
52
|
+
config.countries.join(","),
|
|
53
|
+
])));
|
|
54
|
+
}
|
|
55
|
+
let symbols = dedupeKeepOrder(listed);
|
|
56
|
+
const cap = Math.max(0, Math.floor(config.vocabSize / 4));
|
|
57
|
+
if (symbols.length > cap) {
|
|
58
|
+
console.warn(`user_defined_symbols (${symbols.length}) exceeds the vocab_size/4 cap (${cap}); truncating`);
|
|
59
|
+
symbols = symbols.slice(0, cap);
|
|
60
|
+
}
|
|
61
|
+
return { symbols, passed: symbols.map(sentencePieceSymbol) };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The trainer flags of a configuration, in the order the Python trainer passed them.
|
|
65
|
+
*/
|
|
66
|
+
export function trainerFlags(config, input, modelPrefix, symbols) {
|
|
67
|
+
return {
|
|
68
|
+
input,
|
|
69
|
+
model_prefix: modelPrefix,
|
|
70
|
+
vocab_size: config.vocabSize,
|
|
71
|
+
character_coverage: config.characterCoverage,
|
|
72
|
+
model_type: config.modelType,
|
|
73
|
+
byte_fallback: config.byteFallback,
|
|
74
|
+
split_digits: config.splitDigits,
|
|
75
|
+
allow_whitespace_only_pieces: config.allowWhitespaceOnlyPieces,
|
|
76
|
+
pad_id: 0,
|
|
77
|
+
unk_id: 1,
|
|
78
|
+
bos_id: 2,
|
|
79
|
+
eos_id: 3,
|
|
80
|
+
user_defined_symbols: symbols,
|
|
81
|
+
...config.extraFlags,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function directoryName(path) {
|
|
85
|
+
return path.replace(/\/+$/, "").split("/").at(-1);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sample, train and write `tokenizer.model`, `tokenizer.vocab`, `model_card.json`
|
|
89
|
+
* and `META.json` under the output directory.
|
|
90
|
+
*/
|
|
91
|
+
export async function trainTokenizer(config) {
|
|
92
|
+
const started = performance.now();
|
|
93
|
+
await makeDirectories(config.outputDirectory);
|
|
94
|
+
const modelPrefix = `${config.outputDirectory}/tokenizer`;
|
|
95
|
+
await using scratch = await temporaryDirectory("mtf-train-");
|
|
96
|
+
const input = scratch.path("input.txt").toString();
|
|
97
|
+
const corpusFiles = await runMTFTokenizer(["train-files", "--corpus", config.corpusDirectory]);
|
|
98
|
+
const sampled = await runMTFTokenizer([
|
|
99
|
+
"sample-raws",
|
|
100
|
+
"--corpus",
|
|
101
|
+
config.corpusDirectory,
|
|
102
|
+
"--countries",
|
|
103
|
+
config.countries.join(","),
|
|
104
|
+
"--per-country",
|
|
105
|
+
String(config.perCountrySample),
|
|
106
|
+
"--seed",
|
|
107
|
+
String(config.seed),
|
|
108
|
+
"--out",
|
|
109
|
+
input,
|
|
110
|
+
]);
|
|
111
|
+
for (const [country, lines] of sampled.per_country) {
|
|
112
|
+
console.info(`sampled ${lines} lines for country=${country}`);
|
|
113
|
+
}
|
|
114
|
+
if (sampled.lines === 0) {
|
|
115
|
+
throw new Error(`sampled zero lines from ${config.corpusDirectory} for countries ${config.countries.join(",")}`);
|
|
116
|
+
}
|
|
117
|
+
const { symbols, passed } = await resolveUserDefinedSymbols(config);
|
|
118
|
+
const flags = trainerFlags(config, input, modelPrefix, passed);
|
|
119
|
+
const inputSHA256 = await sha256File(input);
|
|
120
|
+
console.info(`training sentencepiece: vocab=${config.vocabSize}, type=${config.modelType}, char_cov=${config.characterCoverage}, ` +
|
|
121
|
+
`byte_fb=${config.byteFallback}, lines=${sampled.lines}, uds=${symbols.length}`);
|
|
122
|
+
const trained = await trainSentencePiece(flags, { spmTrain: config.spmTrain, workDirectory: scratch.path.toString() });
|
|
123
|
+
const elapsed = (performance.now() - started) / 1000;
|
|
124
|
+
const byteFallback = config.evalFixture
|
|
125
|
+
? await measureByteFallback(trained.model, await readFixtureLines(config.evalFixture))
|
|
126
|
+
: null;
|
|
127
|
+
const portableFlags = Object.fromEntries(Object.entries(flags).filter(([name]) => name !== "input" && name !== "user_defined_symbols"));
|
|
128
|
+
portableFlags["user_defined_symbols_count"] = symbols.length;
|
|
129
|
+
portableFlags["user_defined_symbols_preview"] = symbols.slice(0, 64);
|
|
130
|
+
const card = {
|
|
131
|
+
tokenizer_version: directoryName(config.outputDirectory),
|
|
132
|
+
corpus_version: config.corpusVersion,
|
|
133
|
+
vocab_size: (await readModelPieces(trained.model)).length,
|
|
134
|
+
training_lines: sampled.lines,
|
|
135
|
+
training_duration_seconds: Math.round(elapsed * 1000) / 1000,
|
|
136
|
+
generated_at: isoSeconds(),
|
|
137
|
+
git_commit: await gitHead().catch(() => null),
|
|
138
|
+
model_sha256: await sha256File(trained.model),
|
|
139
|
+
model_path: trained.model,
|
|
140
|
+
vocab_path: trained.vocab,
|
|
141
|
+
sentencepiece: { ...SENTENCEPIECE, trainer: "spm_train" },
|
|
142
|
+
sentencepiece_flags: portableFlags,
|
|
143
|
+
training_input: {
|
|
144
|
+
sha256: inputSHA256,
|
|
145
|
+
lines: sampled.lines,
|
|
146
|
+
corpus_files: corpusFiles,
|
|
147
|
+
user_defined_symbols_sha256: sha256Hex(passed.map((symbol) => `${symbol}\n`).join("")),
|
|
148
|
+
},
|
|
149
|
+
sampling: {
|
|
150
|
+
countries: [...config.countries],
|
|
151
|
+
per_country: config.perCountrySample,
|
|
152
|
+
seed: config.seed,
|
|
153
|
+
per_country_lines: Object.fromEntries(sampled.per_country),
|
|
154
|
+
},
|
|
155
|
+
byte_fallback_eval: byteFallback,
|
|
156
|
+
};
|
|
157
|
+
await writeLocalJSONFile(card, `${config.outputDirectory}/model_card.json`);
|
|
158
|
+
await writeLocalJSONFile(card, `${config.outputDirectory}/META.json`);
|
|
159
|
+
console.info(`wrote ${trained.model} (vocab=${card.vocab_size}, byte_fb_overall=${byteFallback ? byteFallback.overall.rate.toFixed(4) : "n/a"})`);
|
|
160
|
+
return card;
|
|
161
|
+
}
|
|
162
|
+
//#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AS,CAAC;YAChC,WAAW,EAAE,MAAM,CAAC,gBAAgB;YACpC,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC;SAC1D;QACD,kBAAkB,EAAE,YAAY;KAChC,CAAA;IAED,MAAM,kBAAkB,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,eAAe,kBAAkB,CAAC,CAAA;IAC3E,MAAM,kBAAkB,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,eAAe,YAAY,CAAC,CAAA;IAErE,OAAO,CAAC,IAAI,CACX,SAAS,OAAO,CAAC,KAAK,WAAW,IAAI,CAAC,UAAU,qBAAqB,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CACnI,CAAA;IAED,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Train a versioned SentencePiece tokenizer from a corpus's train split.
|
|
7
|
+
*
|
|
8
|
+
* The tool writes `tokenizer.model`, `tokenizer.vocab`, `model_card.json` and `META.json` under `--output`. The card
|
|
9
|
+
* records the byte-fallback rate on `--eval-fixture`, so a tokenizer's coverage is a measured number. The training
|
|
10
|
+
* runs native `spm_train` from SentencePiece v0.2.2 and writes the model the Python wheel writes for the same call.
|
|
11
|
+
*
|
|
12
|
+
* `--corpus` takes a corpus tree (the parent of `train/`), a directory holding exactly one `corpus-v*` tree, or a
|
|
13
|
+
* version (`v0.3.0` or `0.3.0`), which resolves to `corpus/versioned/vX/corpus-vX` under the data root.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
*
|
|
17
|
+
* node packages/mtf/tools/tokenizer/train.run.ts --corpus v0.3.0 --output <dir> [--vocab 48000]
|
|
18
|
+
* [--character-coverage 0.9999] [--model-type unigram] [--no-byte-fallback] [--split-digits]
|
|
19
|
+
* [--countries US,FR] [--per-country-sample 500000] [--mine-postcode-literals 0]
|
|
20
|
+
* [--user-defined-symbols-file <txt>] [--no-default-user-defined-symbols] [--eval-fixture <jsonl>]
|
|
21
|
+
* [--seed 42] [--corpus-version <v>] [--flag name=value ...] [--spm-train <path>]
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=train.run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"train.run.d.ts","sourceRoot":"","sources":["../../../tools/tokenizer/train.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|