@mailwoman/mtf 10.8.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/crates/mtf-channels/tests/fixtures/README.md +1 -1
- package/crates/mtf-sampler/tests/fixtures/README.md +1 -1
- package/lib/code-units.ts +4 -4
- package/lib/index.ts +12 -9
- package/out/code-units.d.ts +0 -3
- package/out/code-units.d.ts.map +1 -1
- package/out/code-units.js +3 -7
- package/out/code-units.js.map +1 -1
- package/out/index.d.ts +7 -9
- package/out/index.d.ts.map +1 -1
- package/out/index.js +11 -9
- package/out/index.js.map +1 -1
- package/out/tools/build-wasm.run.d.ts +0 -12
- package/out/tools/build-wasm.run.d.ts.map +1 -1
- package/out/tools/build-wasm.run.js +2 -4
- package/out/tools/build-wasm.run.js.map +1 -1
- package/out/tools/sampler/native.d.ts +2 -15
- package/out/tools/sampler/native.d.ts.map +1 -1
- package/out/tools/sampler/native.js +11 -9
- package/out/tools/sampler/native.js.map +1 -1
- package/out/tools/tokenizer/binary.d.ts +0 -16
- package/out/tools/tokenizer/binary.d.ts.map +1 -1
- package/out/tools/tokenizer/binary.js +11 -11
- package/out/tools/tokenizer/binary.js.map +1 -1
- package/out/tools/tokenizer/byte-fallback.d.ts +0 -10
- package/out/tools/tokenizer/byte-fallback.d.ts.map +1 -1
- package/out/tools/tokenizer/byte-fallback.js +5 -6
- package/out/tools/tokenizer/byte-fallback.js.map +1 -1
- package/out/tools/tokenizer/model.d.ts +0 -8
- package/out/tools/tokenizer/model.d.ts.map +1 -1
- package/out/tools/tokenizer/model.js +6 -8
- package/out/tools/tokenizer/model.js.map +1 -1
- package/out/tools/tokenizer/prune.d.ts +2 -14
- package/out/tools/tokenizer/prune.d.ts.map +1 -1
- package/out/tools/tokenizer/prune.js +10 -10
- package/out/tools/tokenizer/prune.js.map +1 -1
- package/out/tools/tokenizer/prune.run.d.ts +0 -14
- package/out/tools/tokenizer/prune.run.d.ts.map +1 -1
- package/out/tools/tokenizer/prune.run.js +7 -7
- package/out/tools/tokenizer/prune.run.js.map +1 -1
- package/out/tools/tokenizer/sentencepiece.d.ts +0 -16
- package/out/tools/tokenizer/sentencepiece.d.ts.map +1 -1
- package/out/tools/tokenizer/sentencepiece.js +14 -11
- package/out/tools/tokenizer/sentencepiece.js.map +1 -1
- package/out/tools/tokenizer/splice.d.ts +1 -14
- package/out/tools/tokenizer/splice.d.ts.map +1 -1
- package/out/tools/tokenizer/splice.js +12 -11
- package/out/tools/tokenizer/splice.js.map +1 -1
- package/out/tools/tokenizer/splice.run.d.ts +0 -27
- package/out/tools/tokenizer/splice.run.d.ts.map +1 -1
- package/out/tools/tokenizer/splice.run.js +14 -13
- package/out/tools/tokenizer/splice.run.js.map +1 -1
- package/out/tools/tokenizer/symbols.d.ts +1 -13
- package/out/tools/tokenizer/symbols.d.ts.map +1 -1
- package/out/tools/tokenizer/symbols.js +9 -9
- package/out/tools/tokenizer/symbols.js.map +1 -1
- package/out/tools/tokenizer/train/text.run.d.ts +0 -14
- package/out/tools/tokenizer/train/text.run.d.ts.map +1 -1
- package/out/tools/tokenizer/train/text.run.js +6 -6
- package/out/tools/tokenizer/train/text.run.js.map +1 -1
- package/out/tools/tokenizer/train.d.ts +0 -12
- package/out/tools/tokenizer/train.d.ts.map +1 -1
- package/out/tools/tokenizer/train.js +7 -8
- package/out/tools/tokenizer/train.js.map +1 -1
- package/out/tools/tokenizer/train.run.d.ts +0 -22
- package/out/tools/tokenizer/train.run.d.ts.map +1 -1
- package/out/tools/tokenizer/train.run.js +12 -9
- package/out/tools/tokenizer/train.run.js.map +1 -1
- package/out/tools/tokenizer/utilization.run.d.ts +0 -15
- package/out/tools/tokenizer/utilization.run.d.ts.map +1 -1
- package/out/tools/tokenizer/utilization.run.js +8 -8
- package/out/tools/tokenizer/utilization.run.js.map +1 -1
- package/out/tools/tokenizer/verify.d.ts +0 -15
- package/out/tools/tokenizer/verify.d.ts.map +1 -1
- package/out/tools/tokenizer/verify.js +11 -10
- package/out/tools/tokenizer/verify.js.map +1 -1
- package/out/tools/tokenizer/verify.run.d.ts +0 -20
- package/out/tools/tokenizer/verify.run.d.ts.map +1 -1
- package/out/tools/tokenizer/verify.run.js +7 -8
- package/out/tools/tokenizer/verify.run.js.map +1 -1
- package/package.json +7 -4
- package/tools/build-wasm.run.ts +3 -4
- package/tools/sampler/native.ts +14 -11
- package/tools/tokenizer/binary.ts +12 -11
- package/tools/tokenizer/byte-fallback.ts +6 -6
- package/tools/tokenizer/model.ts +7 -8
- package/tools/tokenizer/prune.run.ts +8 -7
- package/tools/tokenizer/prune.ts +11 -10
- package/tools/tokenizer/sentencepiece.ts +15 -11
- package/tools/tokenizer/splice.run.ts +15 -13
- package/tools/tokenizer/splice.ts +13 -11
- package/tools/tokenizer/symbols.ts +10 -9
- package/tools/tokenizer/train/text.run.ts +7 -6
- package/tools/tokenizer/train.run.ts +13 -9
- package/tools/tokenizer/train.ts +8 -8
- package/tools/tokenizer/utilization.run.ts +9 -8
- package/tools/tokenizer/verify.run.ts +8 -8
- package/tools/tokenizer/verify.ts +12 -10
package/tools/tokenizer/model.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* A SentencePiece model's vocabulary, read and edited through `mtf-tokenizer`, and an encoder over it through the
|
|
7
|
-
* `@mailwoman/mtf` runtime.
|
|
5
|
+
* A SentencePiece model's vocabulary, read and edited through `mtf-tokenizer`,
|
|
6
|
+
* and an encoder over it through the `@mailwoman/mtf` runtime.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import { readLocalBuffer, readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
11
10
|
import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
|
|
12
11
|
import { replaceFileAtomically, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { type MTFModel, MTFRuntime, mtfWASMURL } from "#index"
|
|
15
14
|
|
|
16
15
|
import { runMTFTokenizer } from "./binary.ts"
|
|
17
16
|
|
|
@@ -104,7 +103,7 @@ let runtime: Promise<MTFRuntime> | null = null
|
|
|
104
103
|
* Dispose it after use.
|
|
105
104
|
*/
|
|
106
105
|
export async function loadEncoder(path: string): Promise<MTFModel> {
|
|
107
|
-
runtime ??= readLocalBuffer(
|
|
106
|
+
runtime ??= readLocalBuffer(mtfWASMURL()).then((bytes) => MTFRuntime.instantiate(new Uint8Array(bytes)))
|
|
108
107
|
|
|
109
108
|
return (await runtime).loadModel(await readLocalBuffer(path))
|
|
110
109
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Prune a tokenizer's unused pieces and the int8 model's matching embedding rows.
|
|
7
6
|
*
|
|
8
|
-
* `--train-counts` is the per-piece count `utilization.run.ts` writes; `--eval-fired`
|
|
9
|
-
* `fired_ids` lists the pieces the evaluation surface uses.
|
|
10
|
-
*
|
|
7
|
+
* `--train-counts` is the per-piece count `utilization.run.ts` writes; `--eval-fired`
|
|
8
|
+
* is a JSON file whose `fired_ids` lists the pieces the evaluation surface uses.
|
|
9
|
+
* The tool writes `tokenizer.model`, `model.onnx`, `id-map.json`
|
|
10
|
+
* and `prune-report.json` under `--out-dir`.
|
|
11
|
+
* `verify.run.ts prune` then checks the result.
|
|
11
12
|
*
|
|
12
13
|
* Usage: `node packages/mtf/tools/tokenizer/prune.run.ts --tokenizer <model> --onnx <int8 onnx>
|
|
13
14
|
* --train-counts <json> --eval-fired <json> --out-dir <dir>`
|
package/tools/tokenizer/prune.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Prune a tokenizer's unused pieces and the matching rows of an int8 model's embedding table.
|
|
7
6
|
*
|
|
8
|
-
* A piece that never won a Viterbi path contributes no score to any other path,
|
|
9
|
-
* every input whose best path avoided the pruned pieces.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* A piece that never won a Viterbi path contributes no score to any other path,
|
|
8
|
+
* so segmentation is unchanged for every input whose best path avoided the pruned pieces.
|
|
9
|
+
* The kept pieces stay in their order.
|
|
10
|
+
*
|
|
11
|
+
* The embedding rows are gathered by the old-to-new id map with the scale
|
|
12
|
+
* and zero point untouched, so each kept row stays the same bytes.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import { readLocalBuffer, readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
@@ -60,8 +61,8 @@ export interface PruneOptions {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
|
-
* The pieces to keep: every piece the training corpus or the evaluation surface used,
|
|
64
|
-
* piece that
|
|
64
|
+
* The pieces to keep: every piece the training corpus or the evaluation surface used,
|
|
65
|
+
* every piece that's not a normal piece (control, unknown, user-defined, unused and byte pieces),
|
|
65
66
|
* and every piece of at most one code point once a leading `▁` is removed.
|
|
66
67
|
* This keeps every character reachable.
|
|
67
68
|
*/
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
+
* One SentencePiece training call, made with native `spm_train` and written
|
|
6
|
+
* in the Python wheel's model form.
|
|
7
|
+
*
|
|
8
|
+
* The flags are the keyword arguments a `SentencePieceTrainer.train(**flags)` call took,
|
|
9
|
+
* in the same order and with the same values.
|
|
10
|
+
* Two lists go through files rather than the command line, because the CLI splits an
|
|
11
|
+
* inline list on commas and a user-defined symbol may itself be a comma.
|
|
5
12
|
*
|
|
6
|
-
*
|
|
13
|
+
* `minloglevel` sets only the wheel's log level and has no CLI flag, so it is left off the command line.
|
|
7
14
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* on commas and a user-defined symbol may itself be a comma. `minloglevel` sets only the wheel's log level and has
|
|
11
|
-
* no CLI flag, so it is left off the command line.
|
|
15
|
+
* `spm_train` sets every trainer flag on its spec, so the model records defaults the caller didn't supply.
|
|
16
|
+
* The wheel's spec holds only fields supplied in the call.
|
|
12
17
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* fields absent from the flags. This produces the same bytes the wheel produces for that call.
|
|
18
|
+
* After training, the rewrite drops trainer and normalizer fields absent from the flags.
|
|
19
|
+
* This produces the same bytes the wheel produces for that call.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Splice locale diacritic pieces into a frozen tokenizer, or grow an exported model onto a spliced tokenizer.
|
|
5
|
+
* Splice locale diacritic pieces into a frozen tokenizer, or grow an exported
|
|
6
|
+
* model onto a spliced tokenizer.
|
|
7
7
|
*
|
|
8
|
-
* `build-tokenizer` reads the locales' OpenAddresses street and city names,
|
|
9
|
-
* appends that model's pieces that hold a code
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* `build-tokenizer` reads the locales' OpenAddresses street and city names,
|
|
9
|
+
* trains a locale unigram model on them, appends that model's pieces that hold a code
|
|
10
|
+
* point outside ASCII to the base tokenizer, and checks that English tokenizes as before.
|
|
11
|
+
* With `--trained-samples`, it also writes the code point overlap report beside the
|
|
12
|
+
* spliced tokenizer and fails on an overlap no `--accept-overlap` entry accepts.
|
|
12
13
|
*
|
|
13
|
-
* `onnx-mean-init` grows an exported model's token embedding table,
|
|
14
|
+
* `onnx-mean-init` grows an exported model's token embedding table,
|
|
15
|
+
* and its int8 twin's, to the spliced vocabulary.
|
|
14
16
|
*
|
|
15
17
|
* Usage:
|
|
16
18
|
*
|
|
@@ -21,9 +23,9 @@
|
|
|
21
23
|
* node packages/mtf/tools/tokenizer/splice.run.ts onnx-mean-init --fp32-onnx <onnx> --base-tokenizer <model>
|
|
22
24
|
* --spliced-tokenizer <model> --out-fp32 <onnx> [--int8-onnx <onnx> --out-int8 <onnx>]
|
|
23
25
|
*
|
|
24
|
-
* A per-file cap that reads a whole small regional file can read only the first
|
|
25
|
-
* as one national file, such as France's.
|
|
26
|
-
* across the country.
|
|
26
|
+
* A per-file cap that reads a whole small regional file can read only the first
|
|
27
|
+
* departments of a country published as one national file, such as France's.
|
|
28
|
+
* Raise it, or pass a sampled national extract, to keep the corpus spread across the country.
|
|
27
29
|
*/
|
|
28
30
|
|
|
29
31
|
import { makeDirectories } from "@mailwoman/core/fs/writers"
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
+
* Splice the diacritic pieces of a locale tokenizer into a frozen unigram vocabulary,
|
|
6
|
+
* and grow an exported model's embedding table to match.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* An appended piece contains a code point outside ASCII, so it cannot match any span
|
|
9
|
+
* of an ASCII string, and ASCII text tokenizes exactly as before.
|
|
10
|
+
* `verifySourceIdentical` checks that on a probe rather than assuming it.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* reports and refuses unless the locale is accepted. The method does not scale to CJK.
|
|
12
|
+
* A trained locale that shares a code point with the new pieces can re-tokenize.
|
|
13
|
+
* `checkCodepointOverlap` reports and refuses unless the locale is accepted.
|
|
14
|
+
* The method doesn't scale to CJK.
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
import { readFileRange, readLocalBuffer, readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
@@ -56,7 +58,7 @@ function core(piece: string): string {
|
|
|
56
58
|
const NON_ASCII = 0x80
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
|
-
* Corpus lines this long or longer, in code points, are left out: they
|
|
61
|
+
* Corpus lines this long or longer, in code points, are left out: they're run-on records rather than names.
|
|
60
62
|
*/
|
|
61
63
|
const MAX_LINE_CODE_POINTS = 80
|
|
62
64
|
|
|
@@ -284,7 +286,7 @@ export interface OverlapReport {
|
|
|
284
286
|
|
|
285
287
|
/**
|
|
286
288
|
* Report the code points outside ASCII that the new pieces share with each trained locale's
|
|
287
|
-
* sample, write the report, and raise when an overlapping locale
|
|
289
|
+
* sample, write the report, and raise when an overlapping locale isn't in `acceptedOverlap`.
|
|
288
290
|
*
|
|
289
291
|
* The evaluation for an accepted locale must meet a registered per-locale non-inferiority
|
|
290
292
|
* comparison for it before the first measurement.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* The strings a trained tokenizer keeps whole, and how they reach SentencePiece.
|
|
7
6
|
*
|
|
8
|
-
* A user-defined symbol bypasses unigram inference and is always emitted as one piece.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* A user-defined symbol bypasses unigram inference and is always emitted as one piece.
|
|
8
|
+
* The literal a caller writes isn't the literal SentencePiece matches: it turns
|
|
9
|
+
* whitespace into `▁` before matching, so `PO Box` is passed as `PO▁Box`.
|
|
10
|
+
*
|
|
11
|
+
* The symbols also compete with the vocabulary budget, so a list longer than
|
|
12
|
+
* a quarter of the vocabulary is truncated.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import { readLocalTextFile } from "@mailwoman/core/fs/readers"
|
|
@@ -22,7 +23,7 @@ import { splitLines } from "@mailwoman/core/strings/unicode"
|
|
|
22
23
|
* Postal markers (`PO Box`, `Cedex`, `BP`) are fixed surface forms that are
|
|
23
24
|
* cheaper to add once than to learn.
|
|
24
25
|
*
|
|
25
|
-
* A hyphen
|
|
26
|
+
* A hyphen isn't listed because it already tokenizes as one piece.
|
|
26
27
|
* Whole Japanese postcodes come from mined postcode literals.
|
|
27
28
|
*
|
|
28
29
|
* The list keeps its duplicates (`CA`, `DE`), which the trainer removes.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Train the first-generation tokenizer recipe on a text file of raw addresses, one per line.
|
|
7
6
|
*
|
|
8
|
-
* The recipe is fixed: a 16,000-piece unigram vocabulary, 0.9995 character coverage,
|
|
9
|
-
* ids, and no user-defined symbols.
|
|
7
|
+
* The recipe is fixed: a 16,000-piece unigram vocabulary, 0.9995 character coverage,
|
|
8
|
+
* byte fallback, the four special ids, and no user-defined symbols.
|
|
9
|
+
* It writes `tokenizer.model`, `tokenizer.vocab` and `META.json` under `--output`.
|
|
10
|
+
*
|
|
10
11
|
* `--version` must match the corpus version the tokenizer ships with.
|
|
11
12
|
*
|
|
12
13
|
* Usage: `node packages/mtf/tools/tokenizer/train/text.run.ts --input <txt> --output <dir> --version <v>
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Train a versioned SentencePiece tokenizer from a corpus's train split.
|
|
7
6
|
*
|
|
8
|
-
* The tool writes `tokenizer.model`, `tokenizer.vocab`, `model_card.json`
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* The tool writes `tokenizer.model`, `tokenizer.vocab`, `model_card.json`
|
|
8
|
+
* and `META.json` under `--output`.
|
|
9
|
+
* The card records the byte-fallback rate on `--eval-fixture`, so a tokenizer's
|
|
10
|
+
* coverage is a measured number.
|
|
11
|
+
*
|
|
12
|
+
* The training runs native `spm_train` from SentencePiece v0.2.2 and writes the
|
|
13
|
+
* model the Python wheel writes for the same call.
|
|
11
14
|
*
|
|
12
|
-
* `--corpus` takes a corpus tree (the parent of `train/`), a directory holding
|
|
13
|
-
* version (`v0.3.0` or `0.3.0`), which resolves
|
|
15
|
+
* `--corpus` takes a corpus tree (the parent of `train/`), a directory holding
|
|
16
|
+
* exactly one `corpus-v*` tree, or a version (`v0.3.0` or `0.3.0`), which resolves
|
|
17
|
+
* to `corpus/versioned/vX/corpus-vX` under the data root.
|
|
14
18
|
*
|
|
15
19
|
* Usage:
|
|
16
20
|
*
|
package/tools/tokenizer/train.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Train a versioned SentencePiece tokenizer from a corpus's train split, and write its model card.
|
|
7
6
|
*
|
|
8
|
-
* The training lines are a balanced sample: a reservoir of `perCountrySample` raws per country,
|
|
9
|
-
* generator in the order `tokenizer/train.py` drew, then shuffled.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* The training lines are a balanced sample: a reservoir of `perCountrySample` raws per country,
|
|
8
|
+
* drawn with CPython's generator in the order `tokenizer/train.py` drew, then shuffled.
|
|
9
|
+
* The card records what reproduces the model: the corpus files read and their order,
|
|
10
|
+
* the SHA-256 of the training input and of the symbol list, the SentencePiece release,
|
|
11
|
+
* every flag, and the model's SHA-256.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { temporaryDirectory } from "@mailwoman/core/fs/temporary"
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Count each tokenizer piece's occurrences in the corpus train split that `prune.run.ts` reads.
|
|
7
6
|
*
|
|
8
|
-
* The manifest's train paths are listed as built, so a path under the training volume
|
|
9
|
-
* onto this host by `--data-root-remap <from>:<to>`,
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* The manifest's train paths are listed as built, so a path under the training volume
|
|
8
|
+
* (`/data/...`) is rewritten onto this host by `--data-root-remap <from>:<to>`,
|
|
9
|
+
* which defaults to `/data` onto the data root.
|
|
10
|
+
* Every file must exist after the rewrite.
|
|
11
|
+
*
|
|
12
|
+
* The tool writes `{counts, ...}` to `--out`, with the run's sidecar fields beside the counts.
|
|
12
13
|
*
|
|
13
14
|
* Usage: `node packages/mtf/tools/tokenizer/utilization.run.ts --manifest <MANIFEST.json> --tokenizer <model>
|
|
14
15
|
* --out <json> [--workers <n>] [--data-root-remap <from>:<to>]`
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* Check a tokenizer.
|
|
7
6
|
*
|
|
8
|
-
* `byte-fallback` encodes a held-out fixture (JSONL with `raw`, `text` or `input`, or plain text)
|
|
9
|
-
* byte-fallback rate overall and per script.
|
|
7
|
+
* `byte-fallback` encodes a held-out fixture (JSONL with `raw`, `text` or `input`, or plain text)
|
|
8
|
+
* and prints the byte-fallback rate overall and per script.
|
|
10
9
|
*
|
|
11
|
-
* `prune` runs the two release checks of a pruned tokenizer and model,
|
|
12
|
-
* logits (B2), writes `verify-report.json`
|
|
10
|
+
* `prune` runs the two release checks of a pruned tokenizer and model,
|
|
11
|
+
* segmentation identity (B1) and bit-equal logits (B2), writes `verify-report.json`
|
|
12
|
+
* into the pruned directory, and exits non-zero unless both pass.
|
|
13
13
|
*
|
|
14
14
|
* Usage:
|
|
15
15
|
*
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
5
|
* The two checks a pruned tokenizer and model pass before release.
|
|
7
6
|
*
|
|
8
|
-
* B1, segmentation identity: the original and pruned tokenizers produce the same piece sequence,
|
|
9
|
-
* renumbering, on every evaluation text and on a random sample of the training rows.
|
|
7
|
+
* B1, segmentation identity: the original and pruned tokenizers produce the same piece sequence,
|
|
8
|
+
* modulo the id renumbering, on every evaluation text and on a random sample of the training rows.
|
|
9
|
+
*
|
|
10
|
+
* B2, logit identity: the original and pruned int8 models answer the evaluation
|
|
11
|
+
* inputs with the same output bits.
|
|
12
|
+
* The graphs differ only in the embedding table and the kept rows are the same bytes,
|
|
13
|
+
* so any difference is a defect of the surgery.
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
* The
|
|
13
|
-
* of the surgery. Every channel input is fed zeros, because the identity must hold for any channel values. The
|
|
14
|
-
* release battery covers realistic inputs.
|
|
15
|
+
* Every channel input is fed zeros, because the identity must hold for any channel values.
|
|
16
|
+
* The release battery covers realistic inputs.
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
|