@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
package/README.md
CHANGED
|
@@ -52,12 +52,16 @@ The work proceeds in two phases.
|
|
|
52
52
|
### Layout
|
|
53
53
|
|
|
54
54
|
```text
|
|
55
|
-
packages/mtf/
|
|
56
|
-
Cargo.toml Cargo workspace for the crates below
|
|
55
|
+
packages/mtf/ (the crates are members of the repository root's cargo workspace)
|
|
57
56
|
crates/mtf-core/ Model representation, normalization, unigram encode, decode, errors
|
|
58
57
|
crates/mtf-wasm/ Thin wasm-bindgen adapter around mtf-core
|
|
59
|
-
crates/mtf-
|
|
58
|
+
crates/mtf-channels/ The training-row encoder: label projection, channel painters, packing
|
|
59
|
+
crates/mtf-sampler/ The training-row sampler: corpus listing, source mixture, augmentation, relabel, char path
|
|
60
|
+
crates/mtf-node/ The Node addon over mtf-sampler and mtf-channels, for the TypeScript audits and tools
|
|
61
|
+
crates/mtf-tools/ The `mtf-tokenizer` binary behind tools/tokenizer: model edits, corpus sampling, ONNX surgery
|
|
60
62
|
lib/ TypeScript loader and result conversion
|
|
63
|
+
tools/tokenizer/ Tokenizer training, splicing, pruning and checks
|
|
64
|
+
tools/sampler/ The loader for the mtf-node addon, built from source on first use
|
|
61
65
|
wasm/ Committed WASM binary and its build metadata
|
|
62
66
|
test/fixtures/ Reference outputs from the deployed runtime
|
|
63
67
|
```
|
|
@@ -87,7 +91,7 @@ toolchain. A repository check will rebuild it and compare hashes.
|
|
|
87
91
|
- **Model loading.** The loader validates lengths, counts and versions before allocating, and bounds input
|
|
88
92
|
length and token count.
|
|
89
93
|
- **Downstream consumers.** `packages/neural/lib/tokenizer.ts` converts byte offsets to UTF-16 ranges and
|
|
90
|
-
trims leading whitespace.
|
|
94
|
+
trims leading whitespace. The deleted Python tokenizer converted them to Python
|
|
91
95
|
character positions for label projection. A change to `▁` or to word boundaries changes both.
|
|
92
96
|
|
|
93
97
|
## Stage 1 baseline
|
|
@@ -178,6 +182,32 @@ Run the parity test from this directory with
|
|
|
178
182
|
`MTF_REFERENCE_MODEL=<path to the shipped tokenizer.model> cargo test --release`. Without the variable it
|
|
179
183
|
reads `../neural-weights-en-us/tokenizer.model` and fails if that file is absent.
|
|
180
184
|
|
|
185
|
+
## Tokenizer tools
|
|
186
|
+
|
|
187
|
+
`tools/tokenizer/` trains, splices, prunes and checks tokenizers. Each entry point is a `.run.ts` file, run from the
|
|
188
|
+
repository root with `node`:
|
|
189
|
+
|
|
190
|
+
| Tool | What it does |
|
|
191
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
192
|
+
| `train.run.ts` | Samples a corpus's train split per country, trains with `spm_train`, writes the model card |
|
|
193
|
+
| `train-text.run.ts` | Trains the 16,000-piece first-generation recipe on a text file |
|
|
194
|
+
| `splice.run.ts build-tokenizer` | Appends a locale model's diacritic pieces to a frozen tokenizer and checks code point overlap |
|
|
195
|
+
| `splice.run.ts onnx-mean-init` | Grows an exported model's embedding table, and its int8 twin's, onto a spliced tokenizer |
|
|
196
|
+
| `utilization.run.ts` | Counts each piece's use over a corpus's train split |
|
|
197
|
+
| `prune.run.ts` | Drops unused pieces from a tokenizer and the matching rows from the int8 model |
|
|
198
|
+
| `verify.run.ts prune` | Checks a pruned tokenizer and model for segmentation identity and bit-equal logits |
|
|
199
|
+
| `verify.run.ts byte-fallback` | Reports a tokenizer's byte-fallback rate on a fixture, overall and per script |
|
|
200
|
+
|
|
201
|
+
Training runs native `spm_train`, built from google/sentencepiece `v0.2.2` under the cache root on first use. It
|
|
202
|
+
reproduces the Python wheel's model byte for byte: the CLI records every trainer default it set, and the tool drops
|
|
203
|
+
the spec fields the training call did not name. That is the form the wheel writes. `tools/tokenizer/sentencepiece.integration.test.ts`
|
|
204
|
+
checks five recorded wheel trainings against `test/fixtures/spm-recipes/`.
|
|
205
|
+
|
|
206
|
+
The proto edits, parquet reads, CPython-compatible sampling, the byte-fallback count and the ONNX initializer
|
|
207
|
+
rewrite run in `mtf-tokenizer`, which Cargo builds under the `tools` profile on first use. It is a binary rather
|
|
208
|
+
than a Node addon: each tool calls it a few times over files, and a binary needs no addon toolchain or
|
|
209
|
+
per-platform artifact.
|
|
210
|
+
|
|
181
211
|
## License
|
|
182
212
|
|
|
183
213
|
`@mailwoman/mtf` is licensed AGPL-3.0-only, with a commercial license available, like the rest of
|
|
@@ -189,4 +219,4 @@ copyright notice in its header and states how it was modified. `third-party/` ho
|
|
|
189
219
|
unchanged, and `THIRD_PARTY_NOTICES.md` maps each ported file to its upstream source. A later port from
|
|
190
220
|
either project follows the same three steps: keep the upstream notice in the file header, state the
|
|
191
221
|
modification, and add the file to `THIRD_PARTY_NOTICES.md`. Code written here without an upstream
|
|
192
|
-
source
|
|
222
|
+
source has only the AGPL header.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# mtf-channels test fixtures
|
|
2
|
+
|
|
3
|
+
Both files are records of the training encoder this crate replaced (#2870). They were written from
|
|
4
|
+
that implementation before its deletion, so they are not regenerated. Each file states the source revision
|
|
5
|
+
it was recorded at.
|
|
6
|
+
|
|
7
|
+
- `encode-row-reference.json` holds one row encoded by the Python `encode_row` with every soft-feed
|
|
8
|
+
channel on, under both label sources, with the shaped anchor and with no channels. It also holds every
|
|
9
|
+
input the encoder read: pieces, lexicons, the anchor table and the label table.
|
|
10
|
+
- `text-reference.json` holds the postcode-shape matches, code units with acceptance counts, and
|
|
11
|
+
`str.lower`, `str.upper` and `str.strip` results for a list of adversarial texts. For each of 17
|
|
12
|
+
templates, it groups every Unicode scalar value by the answer that value gives when placed in the
|
|
13
|
+
template.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# mtf-sampler fixtures
|
|
2
|
+
|
|
3
|
+
`cpython-random.json` records CPython 3.12.3's `random.Random` outputs for the methods the training sampler and the
|
|
4
|
+
corpus builders call. `tests/pyrandom_cpython.rs` replays every case through `PyRandom` and requires equal values.
|
|
5
|
+
|
|
6
|
+
The file covers eight seeds: the integers `0`, `42`, `2**31 - 1`, `2**40 + 7` and `-5`, and the strings
|
|
7
|
+
`"20260601:corpus"`, `"42-postcode"` and `""`. For each seed, it records 50 consecutive calls of `random`,
|
|
8
|
+
`getrandbits` at 1, 32 and 33 bits, `randrange(7)`, `randrange(10, 2**33)`, `randint(1, 6)` and `choice` over 1,000
|
|
9
|
+
items, and 40 calls of `getrandbits(100)`. It also records `choices` uniform, with `weights` and with `cum_weights`,
|
|
10
|
+
`sample` on both of CPython's paths (a pool for a small population, a selected set for a large one), ten shuffles of
|
|
11
|
+
50 items, and a 140-step sequence that interleaves seven methods on one generator.
|
|
12
|
+
|
|
13
|
+
A population argument is stored as its size `n`, and its items are `list(range(n))`. An integer of 2**63 or more is
|
|
14
|
+
stored as a decimal string.
|
|
15
|
+
|
|
16
|
+
## Regeneration
|
|
17
|
+
|
|
18
|
+
The file was written on 2026-10-29 by a generator run under CPython 3.12.3. The generator is archived in this README
|
|
19
|
+
as text, so the repository tracks no Python file for it. To regenerate, save the block below as `cpython_random_fixture.py` outside the
|
|
20
|
+
repository and run `python3.12 -I cpython_random_fixture.py packages/mtf/crates/mtf-sampler/tests/fixtures/cpython-random.json`.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import json, platform, random, sys
|
|
24
|
+
|
|
25
|
+
SEEDS = [0, 42, 2**31 - 1, 2**40 + 7, -5, "20260601:corpus", "42-postcode", ""]
|
|
26
|
+
N = 50
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def case(seed, method, args, calls):
|
|
30
|
+
rng = random.Random(seed)
|
|
31
|
+
out = []
|
|
32
|
+
for _ in range(calls):
|
|
33
|
+
if method == "choices":
|
|
34
|
+
n, weights, cum_weights, k = args
|
|
35
|
+
out.append(rng.choices(list(range(n)), weights=weights, cum_weights=cum_weights, k=k))
|
|
36
|
+
elif method in ("choice", "sample"):
|
|
37
|
+
out.append(getattr(rng, method)(list(range(args[0])), *args[1:]))
|
|
38
|
+
else:
|
|
39
|
+
value = getattr(rng, method)(*args)
|
|
40
|
+
out.append(str(value) if isinstance(value, int) and value >= 2**63 else value)
|
|
41
|
+
return {"seed": seed, "method": method, "args": args, "outputs": out}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def shuffled(seed, n, rounds):
|
|
45
|
+
rng = random.Random(seed)
|
|
46
|
+
out = []
|
|
47
|
+
for _ in range(rounds):
|
|
48
|
+
items = list(range(n))
|
|
49
|
+
rng.shuffle(items)
|
|
50
|
+
out.append(items)
|
|
51
|
+
return {"seed": seed, "method": "shuffle", "args": [n], "outputs": out}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def mixed(seed):
|
|
55
|
+
rng = random.Random(seed)
|
|
56
|
+
weights = [0.5, 1, 2, 0, 3.25, 1, 1, 0.1, 7]
|
|
57
|
+
trace = []
|
|
58
|
+
for i in range(140):
|
|
59
|
+
kind = i % 7
|
|
60
|
+
if kind == 0:
|
|
61
|
+
trace.append(["random", [], rng.random()])
|
|
62
|
+
elif kind == 1:
|
|
63
|
+
trace.append(["randrange", [3, 1000], rng.randrange(3, 1000)])
|
|
64
|
+
elif kind == 2:
|
|
65
|
+
trace.append(["choices", [list(range(9)), weights, 4], rng.choices(list(range(9)), weights=weights, k=4)])
|
|
66
|
+
elif kind == 3:
|
|
67
|
+
items = list(range(17))
|
|
68
|
+
rng.shuffle(items)
|
|
69
|
+
trace.append(["shuffle", [17], items])
|
|
70
|
+
elif kind == 4:
|
|
71
|
+
trace.append(["sample", [40, 6], rng.sample(range(40), 6)])
|
|
72
|
+
elif kind == 5:
|
|
73
|
+
trace.append(["randint", [-3, 3], rng.randint(-3, 3)])
|
|
74
|
+
else:
|
|
75
|
+
trace.append(["choice", [11], rng.choice(range(11))])
|
|
76
|
+
return {"seed": seed, "method": "mixed", "args": [], "outputs": trace}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
cases = []
|
|
80
|
+
for seed in SEEDS:
|
|
81
|
+
cases.append(case(seed, "random", [], N))
|
|
82
|
+
cases.append(case(seed, "getrandbits", [1], N))
|
|
83
|
+
cases.append(case(seed, "getrandbits", [32], N))
|
|
84
|
+
cases.append(case(seed, "getrandbits", [33], N))
|
|
85
|
+
cases.append(case(seed, "getrandbits", [100], 40))
|
|
86
|
+
cases.append(case(seed, "randrange", [7], N))
|
|
87
|
+
cases.append(case(seed, "randrange", [10, 2**33], N))
|
|
88
|
+
cases.append(case(seed, "randint", [1, 6], N))
|
|
89
|
+
cases.append(case(seed, "choice", [1000], N))
|
|
90
|
+
cases.append(case(seed, "choices", [50, None, None, 25], 8))
|
|
91
|
+
cases.append(case(seed, "choices", [5, [1, 0, 2.5, 0.001, 9], None, 25], 8))
|
|
92
|
+
cases.append(case(seed, "choices", [4, None, [1, 3, 3, 10], 25], 8))
|
|
93
|
+
cases.append(case(seed, "sample", [30, 10], 20))
|
|
94
|
+
cases.append(case(seed, "sample", [10000, 50], 10))
|
|
95
|
+
cases.append(case(seed, "sample", [500, 5], 20))
|
|
96
|
+
cases.append(shuffled(seed, 50, 10))
|
|
97
|
+
cases.append(mixed(seed))
|
|
98
|
+
|
|
99
|
+
doc = {
|
|
100
|
+
"generator": "cpython_random_fixture.py (archived in the fixture README)",
|
|
101
|
+
"python": sys.version.split()[0],
|
|
102
|
+
"implementation": platform.python_implementation(),
|
|
103
|
+
"cases": cases,
|
|
104
|
+
}
|
|
105
|
+
with open(sys.argv[1], "w", encoding="utf-8") as out:
|
|
106
|
+
json.dump(doc, out, separators=(",", ":"))
|
|
107
|
+
out.write("\n")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## The loader-split reference
|
|
111
|
+
|
|
112
|
+
`loader-split-reference.json` records what the Python loader drew from the corpus `build_reference_corpus` in
|
|
113
|
+
`tests/common/mod.rs` writes: two sources, three countries with unequal country and source weights, several row groups
|
|
114
|
+
per file, a mixed-source validation file, and every augmentation before the postcode move on. `rows` is one pass of
|
|
115
|
+
the train stream with seed 11 and a shuffle buffer of 6, as `source|country|raw`; `val_rows` is the same over the
|
|
116
|
+
validation split; `encoded` is one pass of the char path in word mode with the default shuffle buffer, as each row's
|
|
117
|
+
labels, attention and first three units of char ids; `source_row_counts` is the rows per source. The Python loader
|
|
118
|
+
wrote it before the Rust sampler replaced it, and `tests/loader_split_reference.rs` requires the Rust sampler to
|
|
119
|
+
reproduce every value in order. It is a record of the Python sampler's output and is not regenerated from the Rust
|
|
120
|
+
sampler.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Code units: each digit run or alphanumeric code in an address, segmented as one unit (#2845).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TextSpan } from "@mailwoman/query-shape/types"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* One code unit and its half-open UTF-16 offsets into the text.
|
|
12
|
+
*/
|
|
13
|
+
export type CodeUnit = TextSpan
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A run of ASCII letters and digits holding at least one digit, with a hyphen
|
|
17
|
+
* allowed between two digits (`12345-6789`, `100-0005`).
|
|
18
|
+
*
|
|
19
|
+
* The run must not touch another ASCII letter or digit on either side, so `B2B` and `SW1A` are whole units.
|
|
20
|
+
* A Han or Kana character next to a run is a boundary, because Japanese and Chinese
|
|
21
|
+
* addresses write a block number straight after its place name (`丸の内1-9-1`).
|
|
22
|
+
*/
|
|
23
|
+
const CODE_UNIT = /(?<![A-Za-z0-9])(?=[A-Za-z0-9-]*\d)[A-Za-z0-9]+(?:-(?=\d)[A-Za-z0-9]+)*(?![A-Za-z0-9])/gu
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Every code unit in `text`, left to right.
|
|
27
|
+
*
|
|
28
|
+
* A word-piece vocabulary makes a postcode one piece only by memorizing that code.
|
|
29
|
+
* A code unit keeps the whole code together and describes it by its shape instead.
|
|
30
|
+
*/
|
|
31
|
+
export function segmentCodeUnits(text: string): CodeUnit[] {
|
|
32
|
+
return [...text.matchAll(CODE_UNIT)].map((match) => ({
|
|
33
|
+
text: match[0],
|
|
34
|
+
start: match.index,
|
|
35
|
+
end: match.index + match[0].length,
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The unit's character pattern: `9` per digit, `A` per letter, other characters
|
|
41
|
+
* kept (`SW1A` → `AA9A`, `12345-6789` → `99999-9999`).
|
|
42
|
+
*/
|
|
43
|
+
export function codeUnitPattern(unit: string): string {
|
|
44
|
+
return unit.replaceAll(/\d/g, "9").replaceAll(/[A-Za-z]/g, "A")
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Code units: each digit run or alphanumeric code in an address, segmented as one unit (#2845).
|
|
6
|
+
*/
|
|
7
|
+
import type { TextSpan } from "@mailwoman/query-shape/types";
|
|
8
|
+
/**
|
|
9
|
+
* One code unit and its half-open UTF-16 offsets into the text.
|
|
10
|
+
*/
|
|
11
|
+
export type CodeUnit = TextSpan;
|
|
12
|
+
/**
|
|
13
|
+
* Every code unit in `text`, left to right.
|
|
14
|
+
*
|
|
15
|
+
* A word-piece vocabulary makes a postcode one piece only by memorizing that code.
|
|
16
|
+
* A code unit keeps the whole code together and describes it by its shape instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare function segmentCodeUnits(text: string): CodeUnit[];
|
|
19
|
+
/**
|
|
20
|
+
* The unit's character pattern: `9` per digit, `A` per letter, other characters
|
|
21
|
+
* kept (`SW1A` → `AA9A`, `12345-6789` → `99999-9999`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function codeUnitPattern(unit: string): string;
|
|
24
|
+
//# sourceMappingURL=code-units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-units.d.ts","sourceRoot":"","sources":["../lib/code-units.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAA;AAY/B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAMzD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Code units: each digit run or alphanumeric code in an address, segmented as one unit (#2845).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A run of ASCII letters and digits holding at least one digit, with a hyphen
|
|
9
|
+
* allowed between two digits (`12345-6789`, `100-0005`).
|
|
10
|
+
*
|
|
11
|
+
* The run must not touch another ASCII letter or digit on either side, so `B2B` and `SW1A` are whole units.
|
|
12
|
+
* A Han or Kana character next to a run is a boundary, because Japanese and Chinese
|
|
13
|
+
* addresses write a block number straight after its place name (`丸の内1-9-1`).
|
|
14
|
+
*/
|
|
15
|
+
const CODE_UNIT = /(?<![A-Za-z0-9])(?=[A-Za-z0-9-]*\d)[A-Za-z0-9]+(?:-(?=\d)[A-Za-z0-9]+)*(?![A-Za-z0-9])/gu;
|
|
16
|
+
/**
|
|
17
|
+
* Every code unit in `text`, left to right.
|
|
18
|
+
*
|
|
19
|
+
* A word-piece vocabulary makes a postcode one piece only by memorizing that code.
|
|
20
|
+
* A code unit keeps the whole code together and describes it by its shape instead.
|
|
21
|
+
*/
|
|
22
|
+
export function segmentCodeUnits(text) {
|
|
23
|
+
return [...text.matchAll(CODE_UNIT)].map((match) => ({
|
|
24
|
+
text: match[0],
|
|
25
|
+
start: match.index,
|
|
26
|
+
end: match.index + match[0].length,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The unit's character pattern: `9` per digit, `A` per letter, other characters
|
|
31
|
+
* kept (`SW1A` → `AA9A`, `12345-6789` → `99999-9999`).
|
|
32
|
+
*/
|
|
33
|
+
export function codeUnitPattern(unit) {
|
|
34
|
+
return unit.replaceAll(/\d/g, "9").replaceAll(/[A-Za-z]/g, "A");
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=code-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-units.js","sourceRoot":"","sources":["../lib/code-units.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG,0FAA0F,CAAA;AAE5G;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpD,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QACd,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;KAClC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC3C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
import { statPath } from "@mailwoman/core/fs/readers/stat";
|
|
14
14
|
import { replaceFileAtomically } from "@mailwoman/core/fs/writers";
|
|
15
15
|
import { sha256File } from "@mailwoman/core/hash";
|
|
16
|
-
import { workspacePath } from "@mailwoman/core/paths";
|
|
16
|
+
import { repoRootPath, workspacePath } from "@mailwoman/core/paths";
|
|
17
17
|
import { runFile } from "@mailwoman/core/process";
|
|
18
18
|
import { parseArguments } from "@mailwoman/core/scripting/arguments";
|
|
19
19
|
const { values } = parseArguments({ options: { check: { type: "boolean", default: false } } });
|
|
20
20
|
const workspace = workspacePath("mtf");
|
|
21
|
-
const built =
|
|
21
|
+
const built = repoRootPath("target", "wasm32-unknown-unknown", "release", "mtf_wasm.wasm");
|
|
22
22
|
const committed = workspacePath("mtf", "wasm", "mtf.wasm");
|
|
23
23
|
await runFile("cargo", ["build", "--release", "--locked", "--target", "wasm32-unknown-unknown", "-p", "mtf-wasm"], {
|
|
24
24
|
cwd: workspace,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-wasm.run.js","sourceRoot":"","sources":["../../tools/build-wasm.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"build-wasm.run.js","sourceRoot":"","sources":["../../tools/build-wasm.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEpE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;AAE9F,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;AACtC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,wBAAwB,EAAE,SAAS,EAAE,eAAe,CAAC,CAAA;AAC1F,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAA;AAE1D,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,wBAAwB,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE;IAClH,GAAG,EAAE,SAAS;CACd,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;AAC3C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAA;AAEtC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAA;IAEnD,IAAI,eAAe,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,oCAAoC,WAAW,KAAK,IAAI,SAAS,CAAC,CAAA;IAC/E,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,qCAAqC,eAAe,WAAW,WAAW,KAAK,IAAI,SAAS,CAAC,CAAA;QAE3G,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACrB,CAAC;AACF,CAAC;KAAM,CAAC;IACP,MAAM,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAE7C,OAAO,CAAC,GAAG,CAAC,wBAAwB,WAAW,KAAK,IAAI,SAAS,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The `mtf-node` addon: the training-row sampler and the row encoders of `crates/mtf-node`, loaded into Node.
|
|
7
|
+
*
|
|
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`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* One sampled row.
|
|
16
|
+
* The span triple is present when the row's file stores one.
|
|
17
|
+
*/
|
|
18
|
+
export interface SampledRow {
|
|
19
|
+
raw: string;
|
|
20
|
+
tokens: string[];
|
|
21
|
+
labels: string[];
|
|
22
|
+
country: string | null;
|
|
23
|
+
source: string;
|
|
24
|
+
spanStarts?: number[] | null;
|
|
25
|
+
spanEnds?: number[] | null;
|
|
26
|
+
spanTags?: string[] | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A count per source.
|
|
30
|
+
*/
|
|
31
|
+
export interface SourceCount {
|
|
32
|
+
source: string;
|
|
33
|
+
count: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A count per postcode-move outcome.
|
|
37
|
+
*/
|
|
38
|
+
export interface OutcomeCount {
|
|
39
|
+
outcome: string;
|
|
40
|
+
count: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The kinds of event the sampler reports.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SamplerEventKind: {
|
|
46
|
+
readonly RowEmitted: "row_emitted";
|
|
47
|
+
readonly RowSkipped: "row_skipped";
|
|
48
|
+
readonly SourceRestarted: "source_restarted";
|
|
49
|
+
readonly EpochComplete: "epoch_complete";
|
|
50
|
+
};
|
|
51
|
+
export type SamplerEventKind = (typeof SamplerEventKind)[keyof typeof SamplerEventKind];
|
|
52
|
+
/**
|
|
53
|
+
* One sampler event, with the fields its kind sets.
|
|
54
|
+
*/
|
|
55
|
+
export interface SamplerEvent {
|
|
56
|
+
kind: SamplerEventKind;
|
|
57
|
+
index?: number | null;
|
|
58
|
+
source?: string | null;
|
|
59
|
+
country?: string | null;
|
|
60
|
+
reason?: string | null;
|
|
61
|
+
raw?: string | null;
|
|
62
|
+
passes?: number | null;
|
|
63
|
+
realized?: SourceCount[] | null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What opening a stream takes beyond the config, split and seed.
|
|
67
|
+
*/
|
|
68
|
+
export interface NativeStreamOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Caps the rows the stream emits, counted before the astral skip.
|
|
71
|
+
*/
|
|
72
|
+
rowLimit?: number | null;
|
|
73
|
+
/**
|
|
74
|
+
* The event kinds to collect for `takeEvents`.
|
|
75
|
+
*/
|
|
76
|
+
events?: SamplerEventKind[] | null;
|
|
77
|
+
}
|
|
78
|
+
export interface NativeSampler {
|
|
79
|
+
nextRows(count: number): SampledRow[];
|
|
80
|
+
takeEvents(): SamplerEvent[];
|
|
81
|
+
cancel(): void;
|
|
82
|
+
readonly yielded: number;
|
|
83
|
+
readonly astralSkipped: number;
|
|
84
|
+
readonly postcodeMoveOutcomes: OutcomeCount[];
|
|
85
|
+
}
|
|
86
|
+
export interface NativeTrainingBatches {
|
|
87
|
+
nextBatch(): SampledRow[];
|
|
88
|
+
cancel(): void;
|
|
89
|
+
readonly epoch: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* One upstream row and the rows the emit step made of it.
|
|
93
|
+
*/
|
|
94
|
+
export interface EmittedDraw {
|
|
95
|
+
drawn: SampledRow;
|
|
96
|
+
emitted: SampledRow[];
|
|
97
|
+
}
|
|
98
|
+
export interface NativeRawRows {
|
|
99
|
+
nextRaw(count: number): SampledRow[];
|
|
100
|
+
nextEmitted(count: number): EmittedDraw[];
|
|
101
|
+
takeEvents(): SamplerEvent[];
|
|
102
|
+
cancel(): void;
|
|
103
|
+
readonly drawn: number;
|
|
104
|
+
readonly postcodeMoveOutcomes: OutcomeCount[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* One row group's admitted rows over the requested columns.
|
|
108
|
+
*/
|
|
109
|
+
export interface SplitColumnChunk {
|
|
110
|
+
rows: number;
|
|
111
|
+
strings: Record<string, Array<string | null>>;
|
|
112
|
+
lists: Record<string, Array<string[] | null>>;
|
|
113
|
+
/**
|
|
114
|
+
* Each list-of-integers column, such as `span_starts`.
|
|
115
|
+
*/
|
|
116
|
+
intLists: Record<string, Array<number[] | null>>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The rows a split read keeps: those whose string column `column`, uppercased, is one of `values`.
|
|
120
|
+
* A row whose value is null is not kept.
|
|
121
|
+
*/
|
|
122
|
+
export interface SplitKeep {
|
|
123
|
+
column: string;
|
|
124
|
+
values: string[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Every row a split holds over a few columns, in file and row order.
|
|
128
|
+
*/
|
|
129
|
+
export interface NativeSplitColumns {
|
|
130
|
+
readonly files: number;
|
|
131
|
+
nextChunk(): SplitColumnChunk | null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* What a row encoder reads.
|
|
135
|
+
* Every lexicon path left unset leaves its channel off.
|
|
136
|
+
*/
|
|
137
|
+
export interface RowEncoderOptions {
|
|
138
|
+
tokenizerModelPath: string;
|
|
139
|
+
labelSchemaPath: string;
|
|
140
|
+
labelSet?: string | null;
|
|
141
|
+
maxLength: number;
|
|
142
|
+
padID?: number | null;
|
|
143
|
+
postcodeShapesPath: string;
|
|
144
|
+
postcodeSyntaxPath: string;
|
|
145
|
+
anchorLookupPath?: string | null;
|
|
146
|
+
anchorPaintMode?: "gold" | "shaped" | null;
|
|
147
|
+
gazetteerLexiconPath?: string | null;
|
|
148
|
+
gazetteerChoreography?: boolean | null;
|
|
149
|
+
countryLexiconPath?: string | null;
|
|
150
|
+
streetTypeLexiconPath?: string | null;
|
|
151
|
+
localitySurfaceLexiconPath?: string | null;
|
|
152
|
+
codeUnits?: boolean | null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* One configured channel of an encoded batch: `features` `[B, L, dim]` and `confidence` `[B, L]`.
|
|
156
|
+
*/
|
|
157
|
+
export interface EncodedChannel {
|
|
158
|
+
name: string;
|
|
159
|
+
dim: number;
|
|
160
|
+
features: Float32Array;
|
|
161
|
+
confidence: Float32Array;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* An encoded batch: `inputIDs`, `attentionMask` and `labels` int64 `[B, L]` in row-major order.
|
|
165
|
+
*/
|
|
166
|
+
export interface EncodedRows {
|
|
167
|
+
rows: number;
|
|
168
|
+
maxLength: number;
|
|
169
|
+
inputIDs: BigInt64Array;
|
|
170
|
+
attentionMask: BigInt64Array;
|
|
171
|
+
labels: BigInt64Array;
|
|
172
|
+
channels: EncodedChannel[];
|
|
173
|
+
}
|
|
174
|
+
export interface NativeRowEncoder {
|
|
175
|
+
encodeBatch(rows: SampledRow[]): EncodedRows;
|
|
176
|
+
readonly channelDims: Array<{
|
|
177
|
+
name: string;
|
|
178
|
+
dim: number;
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The character path's settings.
|
|
183
|
+
*/
|
|
184
|
+
export interface CharEncoderOptions {
|
|
185
|
+
mode: "word" | "char";
|
|
186
|
+
vocabPath: string;
|
|
187
|
+
maxUnits: number;
|
|
188
|
+
maxUnitWidth: number;
|
|
189
|
+
charCtx?: number | null;
|
|
190
|
+
labelSet: string;
|
|
191
|
+
labelSchemaPath: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* A char-path batch: `charIDs` int64 `[B, S, W]`, `attentionMask` and `labels` int64 `[B, S]`.
|
|
195
|
+
*/
|
|
196
|
+
export interface EncodedChars {
|
|
197
|
+
rows: number;
|
|
198
|
+
maxUnits: number;
|
|
199
|
+
maxUnitWidth: number;
|
|
200
|
+
charIDs: BigInt64Array;
|
|
201
|
+
attentionMask: BigInt64Array;
|
|
202
|
+
labels: BigInt64Array;
|
|
203
|
+
}
|
|
204
|
+
export interface NativeCharEncoder {
|
|
205
|
+
encodeBatch(rows: SampledRow[]): EncodedChars;
|
|
206
|
+
}
|
|
207
|
+
export interface SourceWeight {
|
|
208
|
+
source: string;
|
|
209
|
+
weight: number;
|
|
210
|
+
}
|
|
211
|
+
export interface DerivedSourceReps {
|
|
212
|
+
source: string;
|
|
213
|
+
targetRepsPerRow: number;
|
|
214
|
+
rows: number;
|
|
215
|
+
weight: number;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The addon's exports, as `crates/mtf-node/src/lib.rs` declares them.
|
|
219
|
+
*/
|
|
220
|
+
interface NativeModule {
|
|
221
|
+
Sampler: new (config: string, split: string, seed: number, options?: NativeStreamOptions | null) => NativeSampler;
|
|
222
|
+
TrainingBatches: new (config: string, batchSize: number, seed: number, rowLimit?: number | null, skipBatches?: number | null) => NativeTrainingBatches;
|
|
223
|
+
RawRows: new (config: string, split: string, seed: number, options?: NativeStreamOptions | null) => NativeRawRows;
|
|
224
|
+
SplitColumns: new (config: string, split: string, columns: string[], keep?: SplitKeep | null) => NativeSplitColumns;
|
|
225
|
+
RowEncoder: new (options: NativeRowEncoderOptions) => {
|
|
226
|
+
encodeBatch(rows: SampledRow[]): RawEncodedRows;
|
|
227
|
+
readonly channelDims: Array<{
|
|
228
|
+
name: string;
|
|
229
|
+
dim: number;
|
|
230
|
+
}>;
|
|
231
|
+
};
|
|
232
|
+
CharEncoder: new (options: CharEncoderOptions) => {
|
|
233
|
+
encodeBatch(rows: SampledRow[]): RawEncodedChars;
|
|
234
|
+
};
|
|
235
|
+
sourceRowCounts(config: string, split: string): SourceCount[];
|
|
236
|
+
deriveSourceWeights(fixed: SourceWeight[] | null, sourceReps: SourceWeight[], rowsBySource: SourceCount[], samples: number): {
|
|
237
|
+
merged: SourceWeight[];
|
|
238
|
+
derived: DerivedSourceReps[];
|
|
239
|
+
};
|
|
240
|
+
channelNames(): string[];
|
|
241
|
+
pythonCasefold(text: string): string;
|
|
242
|
+
pythonScriptRuns(text: string): string[];
|
|
243
|
+
pythonDetectScript(text: string): string;
|
|
244
|
+
pythonIsLatinText(text: string): boolean;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Python 3.12's string semantics for the training tools, read from the CPython
|
|
248
|
+
* Unicode tables in `mtf-channels/src/python_text/tables.rs`.
|
|
249
|
+
*
|
|
250
|
+
* Node's ICU follows another Unicode version and has no character-name table.
|
|
251
|
+
*/
|
|
252
|
+
export interface PythonText {
|
|
253
|
+
/**
|
|
254
|
+
* `str.casefold`.
|
|
255
|
+
*/
|
|
256
|
+
casefold(text: string): string;
|
|
257
|
+
/**
|
|
258
|
+
* The consecutive runs of letter scripts, every character that is not a letter skipped,
|
|
259
|
+
* as the mixed-script audit's `script_runs` names them.
|
|
260
|
+
*/
|
|
261
|
+
scriptRuns(text: string): string[];
|
|
262
|
+
/**
|
|
263
|
+
* The exposure phenomena's coarse script tag: a script block, `mixed` or `other`.
|
|
264
|
+
*/
|
|
265
|
+
detectScript(text: string): string;
|
|
266
|
+
/**
|
|
267
|
+
* Whether the text holds a letter and every letter is Latin script by Unicode name.
|
|
268
|
+
*/
|
|
269
|
+
isLatinText(text: string): boolean;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* napi-rs camel-cases each Rust field name, so `pad_id` arrives as `padId`.
|
|
273
|
+
*/
|
|
274
|
+
type NativeRowEncoderOptions = Omit<RowEncoderOptions, "padID"> & {
|
|
275
|
+
padId?: number | null;
|
|
276
|
+
};
|
|
277
|
+
interface RawEncodedRows extends Omit<EncodedRows, "inputIDs"> {
|
|
278
|
+
inputIds: BigInt64Array;
|
|
279
|
+
}
|
|
280
|
+
interface RawEncodedChars extends Omit<EncodedChars, "charIDs"> {
|
|
281
|
+
charIds: BigInt64Array;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The path of a current `mtf-node` build, building it first.
|
|
285
|
+
*
|
|
286
|
+
* Cargo rebuilds only when a crate source, a manifest or the lockfile changed,
|
|
287
|
+
* so a current build costs a second.
|
|
288
|
+
*/
|
|
289
|
+
export declare function buildMTFNode(): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* The loaded addon, built the first time a process asks.
|
|
292
|
+
*/
|
|
293
|
+
export declare function loadMTFNode(): Promise<NativeModule>;
|
|
294
|
+
/**
|
|
295
|
+
* The addon's classes and functions under the repository's identifier spelling.
|
|
296
|
+
*/
|
|
297
|
+
export interface MTFNode {
|
|
298
|
+
Sampler: NativeModule["Sampler"];
|
|
299
|
+
TrainingBatches: NativeModule["TrainingBatches"];
|
|
300
|
+
RawRows: NativeModule["RawRows"];
|
|
301
|
+
SplitColumns: NativeModule["SplitColumns"];
|
|
302
|
+
createRowEncoder(options: RowEncoderOptions): NativeRowEncoder;
|
|
303
|
+
createCharEncoder(options: CharEncoderOptions): NativeCharEncoder;
|
|
304
|
+
sourceRowCounts: NativeModule["sourceRowCounts"];
|
|
305
|
+
deriveSourceWeights: NativeModule["deriveSourceWeights"];
|
|
306
|
+
channelNames: NativeModule["channelNames"];
|
|
307
|
+
pythonText: PythonText;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The addon, with the encoders' outputs renamed to the repository's acronym spelling.
|
|
311
|
+
*/
|
|
312
|
+
export declare function mtfNode(): Promise<MTFNode>;
|
|
313
|
+
export {};
|
|
314
|
+
//# sourceMappingURL=native.d.ts.map
|