@mailwoman/mtf 11.0.0 → 11.2.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 (99) hide show
  1. package/README.md +2 -2
  2. package/crates/mtf-channels/tests/fixtures/README.md +12 -6
  3. package/crates/mtf-sampler/tests/fixtures/README.md +1 -1
  4. package/lib/code-units.ts +6 -6
  5. package/lib/index.ts +6 -7
  6. package/out/code-units.d.ts +2 -5
  7. package/out/code-units.d.ts.map +1 -1
  8. package/out/code-units.js +3 -7
  9. package/out/code-units.js.map +1 -1
  10. package/out/index.d.ts +3 -7
  11. package/out/index.d.ts.map +1 -1
  12. package/out/index.js +5 -7
  13. package/out/index.js.map +1 -1
  14. package/out/tools/build-wasm.run.d.ts +0 -12
  15. package/out/tools/build-wasm.run.d.ts.map +1 -1
  16. package/out/tools/build-wasm.run.js +2 -4
  17. package/out/tools/build-wasm.run.js.map +1 -1
  18. package/out/tools/sampler/native.d.ts +44 -18
  19. package/out/tools/sampler/native.d.ts.map +1 -1
  20. package/out/tools/sampler/native.js +14 -9
  21. package/out/tools/sampler/native.js.map +1 -1
  22. package/out/tools/tokenizer/binary.d.ts +0 -16
  23. package/out/tools/tokenizer/binary.d.ts.map +1 -1
  24. package/out/tools/tokenizer/binary.js +11 -11
  25. package/out/tools/tokenizer/binary.js.map +1 -1
  26. package/out/tools/tokenizer/byte-fallback.d.ts +0 -10
  27. package/out/tools/tokenizer/byte-fallback.d.ts.map +1 -1
  28. package/out/tools/tokenizer/byte-fallback.js +5 -6
  29. package/out/tools/tokenizer/byte-fallback.js.map +1 -1
  30. package/out/tools/tokenizer/model.d.ts +0 -8
  31. package/out/tools/tokenizer/model.d.ts.map +1 -1
  32. package/out/tools/tokenizer/model.js +4 -6
  33. package/out/tools/tokenizer/model.js.map +1 -1
  34. package/out/tools/tokenizer/prune.d.ts +2 -14
  35. package/out/tools/tokenizer/prune.d.ts.map +1 -1
  36. package/out/tools/tokenizer/prune.js +10 -10
  37. package/out/tools/tokenizer/prune.js.map +1 -1
  38. package/out/tools/tokenizer/prune.run.d.ts +0 -14
  39. package/out/tools/tokenizer/prune.run.d.ts.map +1 -1
  40. package/out/tools/tokenizer/prune.run.js +7 -7
  41. package/out/tools/tokenizer/prune.run.js.map +1 -1
  42. package/out/tools/tokenizer/sentencepiece.d.ts +0 -16
  43. package/out/tools/tokenizer/sentencepiece.d.ts.map +1 -1
  44. package/out/tools/tokenizer/sentencepiece.js +14 -11
  45. package/out/tools/tokenizer/sentencepiece.js.map +1 -1
  46. package/out/tools/tokenizer/splice.d.ts +1 -14
  47. package/out/tools/tokenizer/splice.d.ts.map +1 -1
  48. package/out/tools/tokenizer/splice.js +12 -11
  49. package/out/tools/tokenizer/splice.js.map +1 -1
  50. package/out/tools/tokenizer/splice.run.d.ts +0 -27
  51. package/out/tools/tokenizer/splice.run.d.ts.map +1 -1
  52. package/out/tools/tokenizer/splice.run.js +14 -13
  53. package/out/tools/tokenizer/splice.run.js.map +1 -1
  54. package/out/tools/tokenizer/symbols.d.ts +1 -13
  55. package/out/tools/tokenizer/symbols.d.ts.map +1 -1
  56. package/out/tools/tokenizer/symbols.js +9 -9
  57. package/out/tools/tokenizer/symbols.js.map +1 -1
  58. package/out/tools/tokenizer/train/text.run.d.ts +0 -14
  59. package/out/tools/tokenizer/train/text.run.d.ts.map +1 -1
  60. package/out/tools/tokenizer/train/text.run.js +6 -6
  61. package/out/tools/tokenizer/train/text.run.js.map +1 -1
  62. package/out/tools/tokenizer/train.d.ts +0 -12
  63. package/out/tools/tokenizer/train.d.ts.map +1 -1
  64. package/out/tools/tokenizer/train.js +7 -8
  65. package/out/tools/tokenizer/train.js.map +1 -1
  66. package/out/tools/tokenizer/train.run.d.ts +0 -22
  67. package/out/tools/tokenizer/train.run.d.ts.map +1 -1
  68. package/out/tools/tokenizer/train.run.js +12 -9
  69. package/out/tools/tokenizer/train.run.js.map +1 -1
  70. package/out/tools/tokenizer/utilization.run.d.ts +0 -15
  71. package/out/tools/tokenizer/utilization.run.d.ts.map +1 -1
  72. package/out/tools/tokenizer/utilization.run.js +8 -8
  73. package/out/tools/tokenizer/utilization.run.js.map +1 -1
  74. package/out/tools/tokenizer/verify.d.ts +0 -15
  75. package/out/tools/tokenizer/verify.d.ts.map +1 -1
  76. package/out/tools/tokenizer/verify.js +11 -10
  77. package/out/tools/tokenizer/verify.js.map +1 -1
  78. package/out/tools/tokenizer/verify.run.d.ts +0 -20
  79. package/out/tools/tokenizer/verify.run.d.ts.map +1 -1
  80. package/out/tools/tokenizer/verify.run.js +7 -8
  81. package/out/tools/tokenizer/verify.run.js.map +1 -1
  82. package/package.json +6 -4
  83. package/tools/build-wasm.run.ts +3 -4
  84. package/tools/sampler/native.ts +65 -14
  85. package/tools/tokenizer/binary.ts +12 -11
  86. package/tools/tokenizer/byte-fallback.ts +6 -6
  87. package/tools/tokenizer/model.ts +5 -6
  88. package/tools/tokenizer/prune.run.ts +8 -7
  89. package/tools/tokenizer/prune.ts +11 -10
  90. package/tools/tokenizer/sentencepiece.ts +15 -11
  91. package/tools/tokenizer/splice.run.ts +15 -13
  92. package/tools/tokenizer/splice.ts +13 -11
  93. package/tools/tokenizer/symbols.ts +10 -9
  94. package/tools/tokenizer/train/text.run.ts +7 -6
  95. package/tools/tokenizer/train.run.ts +13 -9
  96. package/tools/tokenizer/train.ts +8 -8
  97. package/tools/tokenizer/utilization.run.ts +9 -8
  98. package/tools/tokenizer/verify.run.ts +8 -8
  99. package/tools/tokenizer/verify.ts +12 -10
@@ -1,15 +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
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The `mtf-node` addon: the training-row sampler and the row encoders of
6
+ * `crates/mtf-node`, loaded into Node.
5
7
  *
6
- * The `mtf-node` addon: the training-row sampler and the row encoders of `crates/mtf-node`, loaded into Node.
8
+ * Cargo builds the addon from source the first time a process asks for it,
9
+ * under the root workspace's `node` profile and the toolchain the root
10
+ * `rust-toolchain.toml` pins, into the root `target/node/`.
11
+ * The build reads `mtf-sampler` with its parquet reader, so it stays out of the
12
+ * browser `wasm/mtf.wasm`, whose one dependency is `mtf-core`.
7
13
  *
8
- * Cargo builds the addon from source the first time a process asks for it, under the root workspace's `node`
9
- * profile and the toolchain the root `rust-toolchain.toml` pins, into the root `target/node/`. The build
10
- * reads `mtf-sampler` with its parquet reader, so it stays out of the browser `wasm/mtf.wasm`, whose one dependency is
11
- * `mtf-core`. The addon is built for the host it runs on: Linux and macOS, where Cargo writes the library to
12
- * `libmtf_node.so` and `libmtf_node.dylib`.
14
+ * The addon is built for the host it runs on: Linux and macOS, where Cargo writes
15
+ * the library to `libmtf_node.so` and `libmtf_node.dylib`.
13
16
  */
14
17
 
15
18
  import { repoRootPath, workspacePath } from "@mailwoman/core/paths"
@@ -134,7 +137,7 @@ export interface SplitColumnChunk {
134
137
 
135
138
  /**
136
139
  * The rows a split read keeps: those whose string column `column`, uppercased, is one of `values`.
137
- * A row whose value is null is not kept.
140
+ * A row whose value is null isn't kept.
138
141
  */
139
142
  export interface SplitKeep {
140
143
  column: string
@@ -159,10 +162,10 @@ export interface RowEncoderOptions {
159
162
  labelSet?: string | null
160
163
  maxLength: number
161
164
  padID?: number | null
162
- postcodeShapesPath: string
163
- postcodeSyntaxPath: string
165
+ postalArtifactPath: string
166
+ postalDefinitionPath: string
164
167
  anchorLookupPath?: string | null
165
- anchorPaintMode?: "gold" | "shaped" | null
168
+ anchorPaintMode?: "gold" | "postal" | null
166
169
  gazetteerLexiconPath?: string | null
167
170
  gazetteerChoreography?: boolean | null
168
171
  countryLexiconPath?: string | null
@@ -193,6 +196,41 @@ export interface EncodedRows {
193
196
  channels: EncodedChannel[]
194
197
  }
195
198
 
199
+ /**
200
+ * One postcode span of a line, as character offsets.
201
+ *
202
+ * The key is the one the anchor table resolved it under, when the finder holds a table with that key.
203
+ */
204
+ export interface NativePostcodeSpan {
205
+ start: number
206
+ end: number
207
+ key?: string | null
208
+ /**
209
+ * The countries the candidate's shapes belong to.
210
+ */
211
+ countries: string[]
212
+ }
213
+
214
+ /**
215
+ * The encoder's postcode finder without the rest of the encoder.
216
+ *
217
+ * The audits compare it with `findPostcodeSpans` of `@mailwoman/postcode`.
218
+ */
219
+ export interface NativePostcodeFinder {
220
+ /**
221
+ * The postcode spans of `raw`, in start order.
222
+ */
223
+ spans(raw: string): NativePostcodeSpan[]
224
+ /**
225
+ * The code units of `raw`, as character offsets, with the number of countries whose syntax accepts each.
226
+ */
227
+ codeUnits(raw: string): Array<{ start: number; end: number; accepting: number }>
228
+ /**
229
+ * The number of countries whose postcode syntax accepts the whole of `unit`.
230
+ */
231
+ accepting(unit: string): number
232
+ }
233
+
196
234
  export interface NativeRowEncoder {
197
235
  encodeBatch(rows: SampledRow[]): EncodedRows
198
236
  readonly channelDims: Array<{ name: string; dim: number }>
@@ -258,6 +296,11 @@ interface NativeModule {
258
296
  readonly channelDims: Array<{ name: string; dim: number }>
259
297
  }
260
298
  CharEncoder: new (options: CharEncoderOptions) => { encodeBatch(rows: SampledRow[]): RawEncodedChars }
299
+ PostcodeFinder: new (
300
+ artifactPath: string,
301
+ definitionPath: string,
302
+ anchorLookupPath?: string | null
303
+ ) => NativePostcodeFinder
261
304
  sourceRowCounts(config: string, split: string): SourceCount[]
262
305
  deriveSourceWeights(
263
306
  fixed: SourceWeight[] | null,
@@ -284,7 +327,7 @@ export interface PythonText {
284
327
  */
285
328
  casefold(text: string): string
286
329
  /**
287
- * The consecutive runs of letter scripts, every character that is not a letter skipped,
330
+ * The consecutive runs of letter scripts, every character that's not a letter skipped,
288
331
  * as the mixed-script audit's `script_runs` names them.
289
332
  */
290
333
  scriptRuns(text: string): string[]
@@ -375,6 +418,11 @@ export interface MTFNode {
375
418
  SplitColumns: NativeModule["SplitColumns"]
376
419
  createRowEncoder(options: RowEncoderOptions): NativeRowEncoder
377
420
  createCharEncoder(options: CharEncoderOptions): NativeCharEncoder
421
+ createPostcodeFinder(
422
+ artifactPath: string,
423
+ definitionPath: string,
424
+ anchorLookupPath?: string | null
425
+ ): NativePostcodeFinder
378
426
  sourceRowCounts: NativeModule["sourceRowCounts"]
379
427
  deriveSourceWeights: NativeModule["deriveSourceWeights"]
380
428
  channelNames: NativeModule["channelNames"]
@@ -409,6 +457,9 @@ export async function mtfNode(): Promise<MTFNode> {
409
457
  },
410
458
  }
411
459
  },
460
+ createPostcodeFinder(artifactPath, definitionPath, anchorLookupPath) {
461
+ return new native.PostcodeFinder(artifactPath, definitionPath, anchorLookupPath ?? undefined)
462
+ },
412
463
  createCharEncoder(options) {
413
464
  const encoder = new native.CharEncoder(options)
414
465
 
@@ -1,18 +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
+ * The two native programs the tokenizer tools run: `mtf-tokenizer`, built from
6
+ * `crates/mtf-tools`, and SentencePiece v0.2.2's `spm_train`.
5
7
  *
6
- * The two native programs the tokenizer tools run: `mtf-tokenizer`, built from `crates/mtf-tools`, and
7
- * SentencePiece v0.2.2's `spm_train`.
8
+ * `mtf-tokenizer` is a binary rather than a Node addon.
9
+ * Each tool calls it a handful of times over files, so a process per call costs milliseconds.
8
10
  *
9
- * `mtf-tokenizer` is a binary rather than a Node addon. Each tool calls it a handful of times over files, so a
10
- * process per call costs milliseconds. A binary also builds without an addon toolchain, a per-platform artifact or ABI
11
- * matching against Node. Cargo builds it on first use under the `tools` profile.
11
+ * A binary also builds without an addon toolchain, a per-platform artifact or ABI matching against Node.
12
+ * Cargo builds it on first use under the `tools` profile.
12
13
  *
13
- * `spm_train` is built from the google/sentencepiece tag the runtime and the Python wheel were built from, with the
14
- * CMake recipe of `packages/sentencepiece-wasm/build.sh` minus emscripten. The checkout and build live under the
15
- * cache root, outside the repository.
14
+ * `spm_train` is built from the google/sentencepiece tag the runtime and the Python wheel were
15
+ * built from, with the CMake recipe of `packages/sentencepiece-wasm/build.sh` minus emscripten.
16
+ * The checkout and build live under the cache root, outside the repository.
16
17
  */
17
18
 
18
19
  import { cacheRootPath } from "@mailwoman/core/data-root"
@@ -1,12 +1,12 @@
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 rate at which a tokenizer falls back to raw bytes, overall and per script.
7
6
  *
8
- * `mtf-tokenizer byte-fallback` encodes each line with the model and assigns it a script from the Unicode name of
9
- * its letters, through the tables `mtf-channels` generates from CPython's Unicode database.
7
+ * `mtf-tokenizer byte-fallback` encodes each line with the model and assigns it a
8
+ * script from the Unicode name of its letters, through the tables `mtf-channels`
9
+ * generates from CPython's Unicode database.
10
10
  */
11
11
 
12
12
  import { readLocalTextFile } from "@mailwoman/core/fs/readers"
@@ -1,10 +1,9 @@
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
- * 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"
@@ -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` is a JSON file whose
9
- * `fired_ids` lists the pieces the evaluation surface uses. The tool writes `tokenizer.model`, `model.onnx`,
10
- * `id-map.json` and `prune-report.json` under `--out-dir`. `verify.run.ts prune` then checks the result.
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>`
@@ -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, so segmentation is unchanged for
9
- * every input whose best path avoided the pruned pieces. The kept pieces stay in their order. The embedding rows
10
- * are gathered by the old-to-new id map with the scale and zero point untouched, so each kept row stays the same
11
- * bytes.
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, every
64
- * piece that is not a normal piece (control, unknown, user-defined, unused and byte pieces),
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
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
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
- * One SentencePiece training call, made with native `spm_train` and written in the Python wheel's model form.
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
- * The flags are the keyword arguments a `SentencePieceTrainer.train(**flags)` call took, in the same order and with
9
- * the same values. Two lists go through files rather than the command line, because the CLI splits an inline list
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
- * `spm_train` sets every trainer flag on its spec, so the model records defaults the caller did not supply.
14
- * The wheel's spec holds only fields supplied in the call. After training, the rewrite drops trainer and normalizer
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
- * @copyright Sister Software
3
- * @license AGPL-3.0
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, trains a locale unigram model on them,
9
- * appends that model's pieces that hold a code point outside ASCII to the base tokenizer, and checks that English
10
- * tokenizes as before. With `--trained-samples`, it also writes the code point overlap report beside the spliced
11
- * tokenizer and fails on an overlap no `--accept-overlap` entry accepts.
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, and its int8 twin's, to the spliced vocabulary.
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 departments of a country published
25
- * as one national file, such as France's. Raise it, or pass a sampled national extract, to keep the corpus spread
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
- * @copyright Sister Software
3
- * @license AGPL-3.0
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
- * Splice the diacritic pieces of a locale tokenizer into a frozen unigram vocabulary, and grow an exported model's
7
- * embedding table to match.
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
- * An appended piece contains a code point outside ASCII, so it cannot match any span of an ASCII string, and ASCII
10
- * text tokenizes exactly as before. `verifySourceIdentical` checks that on a probe rather than assuming it. A
11
- * trained locale that shares a code point with the new pieces can re-tokenize. `checkCodepointOverlap`
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 are run-on records rather than names.
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 is not in `acceptedOverlap`.
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. 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.
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 is not listed because it already tokenizes as one piece.
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, byte fallback, the four special
9
- * ids, and no user-defined symbols. It writes `tokenizer.model`, `tokenizer.vocab` and `META.json` under `--output`.
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` 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.
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 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.
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
  *
@@ -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, 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.
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 (`/data/...`) is rewritten
9
- * onto this host by `--data-root-remap <from>:<to>`, which defaults to `/data` onto the data root. Every file must
10
- * exist after the rewrite. The tool writes `{counts, ...}` to `--out`, with the run's sidecar fields beside the
11
- * counts.
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) and prints the
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, segmentation identity (B1) and bit-equal
12
- * logits (B2), writes `verify-report.json` into the pruned directory, and exits non-zero unless both pass.
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, modulo the id
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
- * B2, logit identity: the original and pruned int8 models answer the evaluation inputs with the same output bits.
12
- * The graphs differ only in the embedding table and the kept rows are the same bytes, so any difference is a defect
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"