@mailwoman/mtf 0.0.0-stage → 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.
Files changed (103) hide show
  1. package/README.md +221 -2
  2. package/THIRD_PARTY_NOTICES.md +31 -0
  3. package/crates/mtf-channels/tests/fixtures/README.md +13 -0
  4. package/crates/mtf-sampler/tests/fixtures/README.md +120 -0
  5. package/lib/code-units.ts +45 -0
  6. package/lib/index.ts +266 -0
  7. package/out/code-units.d.ts +24 -0
  8. package/out/code-units.d.ts.map +1 -0
  9. package/out/code-units.js +36 -0
  10. package/out/code-units.js.map +1 -0
  11. package/out/index.d.ts +128 -0
  12. package/out/index.d.ts.map +1 -0
  13. package/out/index.js +171 -0
  14. package/out/index.js.map +1 -0
  15. package/out/tools/build-wasm.run.d.ts +14 -0
  16. package/out/tools/build-wasm.run.d.ts.map +1 -0
  17. package/out/tools/build-wasm.run.js +42 -0
  18. package/out/tools/build-wasm.run.js.map +1 -0
  19. package/out/tools/sampler/native.d.ts +314 -0
  20. package/out/tools/sampler/native.d.ts.map +1 -0
  21. package/out/tools/sampler/native.js +114 -0
  22. package/out/tools/sampler/native.js.map +1 -0
  23. package/out/tools/tokenizer/binary.d.ts +38 -0
  24. package/out/tools/tokenizer/binary.d.ts.map +1 -0
  25. package/out/tools/tokenizer/binary.js +94 -0
  26. package/out/tools/tokenizer/binary.js.map +1 -0
  27. package/out/tools/tokenizer/byte-fallback.d.ts +39 -0
  28. package/out/tools/tokenizer/byte-fallback.d.ts.map +1 -0
  29. package/out/tools/tokenizer/byte-fallback.js +49 -0
  30. package/out/tools/tokenizer/byte-fallback.js.map +1 -0
  31. package/out/tools/tokenizer/model.d.ts +70 -0
  32. package/out/tools/tokenizer/model.d.ts.map +1 -0
  33. package/out/tools/tokenizer/model.js +56 -0
  34. package/out/tools/tokenizer/model.js.map +1 -0
  35. package/out/tools/tokenizer/prune.d.ts +69 -0
  36. package/out/tools/tokenizer/prune.d.ts.map +1 -0
  37. package/out/tools/tokenizer/prune.js +126 -0
  38. package/out/tools/tokenizer/prune.js.map +1 -0
  39. package/out/tools/tokenizer/prune.run.d.ts +16 -0
  40. package/out/tools/tokenizer/prune.run.d.ts.map +1 -0
  41. package/out/tools/tokenizer/prune.run.js +34 -0
  42. package/out/tools/tokenizer/prune.run.js.map +1 -0
  43. package/out/tools/tokenizer/sentencepiece.d.ts +63 -0
  44. package/out/tools/tokenizer/sentencepiece.d.ts.map +1 -0
  45. package/out/tools/tokenizer/sentencepiece.js +90 -0
  46. package/out/tools/tokenizer/sentencepiece.js.map +1 -0
  47. package/out/tools/tokenizer/splice.d.ts +117 -0
  48. package/out/tools/tokenizer/splice.d.ts.map +1 -0
  49. package/out/tools/tokenizer/splice.js +398 -0
  50. package/out/tools/tokenizer/splice.js.map +1 -0
  51. package/out/tools/tokenizer/splice.run.d.ts +29 -0
  52. package/out/tools/tokenizer/splice.run.d.ts.map +1 -0
  53. package/out/tools/tokenizer/splice.run.js +114 -0
  54. package/out/tools/tokenizer/splice.run.js.map +1 -0
  55. package/out/tools/tokenizer/symbols.d.ts +42 -0
  56. package/out/tools/tokenizer/symbols.d.ts.map +1 -0
  57. package/out/tools/tokenizer/symbols.js +113 -0
  58. package/out/tools/tokenizer/symbols.js.map +1 -0
  59. package/out/tools/tokenizer/train/text.run.d.ts +16 -0
  60. package/out/tools/tokenizer/train/text.run.d.ts.map +1 -0
  61. package/out/tools/tokenizer/train/text.run.js +67 -0
  62. package/out/tools/tokenizer/train/text.run.js.map +1 -0
  63. package/out/tools/tokenizer/train.d.ts +113 -0
  64. package/out/tools/tokenizer/train.d.ts.map +1 -0
  65. package/out/tools/tokenizer/train.js +162 -0
  66. package/out/tools/tokenizer/train.js.map +1 -0
  67. package/out/tools/tokenizer/train.run.d.ts +24 -0
  68. package/out/tools/tokenizer/train.run.d.ts.map +1 -0
  69. package/out/tools/tokenizer/train.run.js +131 -0
  70. package/out/tools/tokenizer/train.run.js.map +1 -0
  71. package/out/tools/tokenizer/utilization.run.d.ts +17 -0
  72. package/out/tools/tokenizer/utilization.run.d.ts.map +1 -0
  73. package/out/tools/tokenizer/utilization.run.js +80 -0
  74. package/out/tools/tokenizer/utilization.run.js.map +1 -0
  75. package/out/tools/tokenizer/verify.d.ts +94 -0
  76. package/out/tools/tokenizer/verify.d.ts.map +1 -0
  77. package/out/tools/tokenizer/verify.js +193 -0
  78. package/out/tools/tokenizer/verify.js.map +1 -0
  79. package/out/tools/tokenizer/verify.run.d.ts +22 -0
  80. package/out/tools/tokenizer/verify.run.d.ts.map +1 -0
  81. package/out/tools/tokenizer/verify.run.js +71 -0
  82. package/out/tools/tokenizer/verify.run.js.map +1 -0
  83. package/package.json +107 -3
  84. package/third-party/darts-clone/LICENSE +10 -0
  85. package/third-party/sentencepiece/LICENSE +202 -0
  86. package/tools/build-wasm.run.ts +48 -0
  87. package/tools/sampler/native.ts +433 -0
  88. package/tools/tokenizer/binary.ts +118 -0
  89. package/tools/tokenizer/byte-fallback.ts +80 -0
  90. package/tools/tokenizer/model.ts +110 -0
  91. package/tools/tokenizer/prune.run.ts +37 -0
  92. package/tools/tokenizer/prune.ts +195 -0
  93. package/tools/tokenizer/sentencepiece.ts +142 -0
  94. package/tools/tokenizer/splice.run.ts +141 -0
  95. package/tools/tokenizer/splice.ts +592 -0
  96. package/tools/tokenizer/symbols.ts +119 -0
  97. package/tools/tokenizer/train/text.run.ts +80 -0
  98. package/tools/tokenizer/train.run.ts +151 -0
  99. package/tools/tokenizer/train.ts +266 -0
  100. package/tools/tokenizer/utilization.run.ts +96 -0
  101. package/tools/tokenizer/verify.run.ts +77 -0
  102. package/tools/tokenizer/verify.ts +313 -0
  103. package/wasm/mtf.wasm +0 -0
package/lib/index.ts ADDED
@@ -0,0 +1,266 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The TypeScript loader for the Multilingual Token Framework's WebAssembly runtime.
7
+ *
8
+ * The module's import has no side effects: the WASM fetch and instantiation happen in the caller.
9
+ * The caller obtains the WASM bytes or a compiled `WebAssembly.Module` (Workers supply the latter)
10
+ * and passes it to {@linkcode MTFRuntime.instantiate}.
11
+ * `MTF_WASM_URL` locates the committed binary beside this package.
12
+ * A loaded model's encode and decode methods are synchronous.
13
+ */
14
+
15
+ /**
16
+ * The location of the committed `wasm/mtf.wasm`, resolved from this module.
17
+ *
18
+ * The same relative path holds from `lib/` in the repository and from `out/` in a tarball.
19
+ */
20
+ export const MTF_WASM_URL = new URL("../wasm/mtf.wasm", import.meta.url)
21
+
22
+ /**
23
+ * A compiled `WebAssembly.Module`, as a Worker runtime supplies it.
24
+ *
25
+ * The type is opaque because the Node type preset omits the DOM library that declares
26
+ * `WebAssembly`, and this package's declarations must type-check without it.
27
+ */
28
+ export interface MTFCompiledModule {
29
+ readonly [Symbol.toStringTag]: string
30
+ }
31
+
32
+ /**
33
+ * The bytes or compiled module the runtime instantiates from.
34
+ */
35
+ export type MTFWasmSource = MTFCompiledModule | ArrayBuffer | Uint8Array<ArrayBuffer>
36
+
37
+ /**
38
+ * The members of the global `WebAssembly` object this loader calls.
39
+ */
40
+ interface WebAssemblyAPI {
41
+ // Bytes come first: an `ArrayBuffer` also satisfies the opaque module type.
42
+ instantiate(
43
+ bytes: ArrayBuffer | Uint8Array<ArrayBuffer>,
44
+ imports: object
45
+ ): Promise<{ instance: { exports: MTFExports } }>
46
+ instantiate(module: MTFCompiledModule, imports: object): Promise<{ exports: MTFExports }>
47
+ }
48
+
49
+ /**
50
+ * The runtime's global, typed to the members above.
51
+ *
52
+ * Every JavaScript runtime this package targets defines it.
53
+ */
54
+ declare const WebAssembly: WebAssemblyAPI
55
+
56
+ /**
57
+ * The pieces of one encoded input.
58
+ *
59
+ * `begins[i]` and `ends[i]` are UTF-8 byte offsets into the input as `TextEncoder` encodes it.
60
+ * A byte-fallback piece other than the last for its character has `begins[i] === ends[i]`.
61
+ */
62
+ export interface MTFEncodeResult {
63
+ ids: number[]
64
+ pieces: string[]
65
+ begins: number[]
66
+ ends: number[]
67
+ }
68
+
69
+ /**
70
+ * The C ABI that `crates/mtf-wasm` exports.
71
+ */
72
+ interface MTFExports {
73
+ memory: { readonly buffer: ArrayBuffer }
74
+ mtf_alloc(len: number): number
75
+ mtf_dealloc(ptr: number, len: number): void
76
+ mtf_error_ptr(): number
77
+ mtf_error_len(): number
78
+ mtf_model_load(ptr: number, len: number): number
79
+ mtf_model_free(handle: number): void
80
+ mtf_vocab_size(handle: number): number
81
+ mtf_encode(handle: number, ptr: number, len: number): number
82
+ mtf_decode(handle: number, ids: number, count: number): number
83
+ mtf_words_ptr(handle: number): number
84
+ mtf_bytes_ptr(handle: number): number
85
+ }
86
+
87
+ /**
88
+ * Words per piece in the encode output buffer: id, begin, end, piece offset, piece length.
89
+ */
90
+ const PIECE_WORDS = 5
91
+
92
+ const encoder = new TextEncoder()
93
+ const decoder = new TextDecoder("utf-8", { fatal: true })
94
+
95
+ /**
96
+ * One instantiated WebAssembly runtime.
97
+ *
98
+ * A runtime may hold several loaded models at once.
99
+ */
100
+ export class MTFRuntime {
101
+ readonly #exports: MTFExports
102
+
103
+ private constructor(exports: MTFExports) {
104
+ this.#exports = exports
105
+ }
106
+
107
+ /**
108
+ * Instantiates the runtime from WASM bytes or a compiled module.
109
+ */
110
+ static async instantiate(source: MTFWasmSource): Promise<MTFRuntime> {
111
+ const instance =
112
+ source instanceof ArrayBuffer || ArrayBuffer.isView(source)
113
+ ? (await WebAssembly.instantiate(source, {})).instance
114
+ : await WebAssembly.instantiate(source, {})
115
+
116
+ return new MTFRuntime(instance.exports)
117
+ }
118
+
119
+ /**
120
+ * Loads a serialized SentencePiece unigram model.
121
+ *
122
+ * @throws When the bytes are malformed or the model uses a feature the runtime does not implement.
123
+ */
124
+ loadModel(bytes: Uint8Array): MTFModel {
125
+ const handle = this.#withInput(bytes, (ptr, len) => this.#exports.mtf_model_load(ptr, len))
126
+
127
+ if (handle === 0) throw new Error(`mtf: model failed to load: ${this.lastError()}`)
128
+
129
+ return new MTFModel(this, this.#exports, handle)
130
+ }
131
+
132
+ /**
133
+ * Reads the message the last failed call recorded.
134
+ *
135
+ * @internal
136
+ */
137
+ lastError(): string {
138
+ const { mtf_error_ptr, mtf_error_len, memory } = this.#exports
139
+
140
+ return decoder.decode(new Uint8Array(memory.buffer, mtf_error_ptr(), mtf_error_len()))
141
+ }
142
+
143
+ /**
144
+ * Copies `bytes` into WASM memory for the duration of `call`.
145
+ *
146
+ * @internal
147
+ */
148
+ withInput<T>(bytes: Uint8Array, call: (ptr: number, len: number) => T): T {
149
+ return this.#withInput(bytes, call)
150
+ }
151
+
152
+ #withInput<T>(bytes: Uint8Array, call: (ptr: number, len: number) => T): T {
153
+ const { mtf_alloc, mtf_dealloc, memory } = this.#exports
154
+ const ptr = mtf_alloc(bytes.byteLength)
155
+
156
+ if (ptr === 0) throw new Error(`mtf: could not allocate ${bytes.byteLength} bytes`)
157
+
158
+ try {
159
+ new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes)
160
+
161
+ return call(ptr, bytes.byteLength)
162
+ } finally {
163
+ mtf_dealloc(ptr, bytes.byteLength)
164
+ }
165
+ }
166
+ }
167
+
168
+ /**
169
+ * A loaded model.
170
+ *
171
+ * Dispose it with `using` or {@linkcode MTFModel.dispose} to release its WASM memory.
172
+ */
173
+ export class MTFModel implements Disposable {
174
+ readonly #runtime: MTFRuntime
175
+ readonly #exports: MTFExports
176
+ #handle: number
177
+
178
+ /**
179
+ * @internal Construct through {@linkcode MTFRuntime.loadModel}.
180
+ */
181
+ constructor(runtime: MTFRuntime, exports: MTFExports, handle: number) {
182
+ this.#runtime = runtime
183
+ this.#exports = exports
184
+ this.#handle = handle
185
+ }
186
+
187
+ #live(): number {
188
+ if (this.#handle === 0) throw new Error("mtf: the model was disposed")
189
+
190
+ return this.#handle
191
+ }
192
+
193
+ /**
194
+ * The number of vocabulary rows.
195
+ */
196
+ get vocabSize(): number {
197
+ return this.#exports.mtf_vocab_size(this.#live())
198
+ }
199
+
200
+ /**
201
+ * Encodes `text` into pieces with UTF-8 byte offsets.
202
+ */
203
+ encode(text: string): MTFEncodeResult {
204
+ const handle = this.#live()
205
+ const { mtf_encode, mtf_words_ptr, mtf_bytes_ptr, memory } = this.#exports
206
+ const count = this.#runtime.withInput(encoder.encode(text), (ptr, len) => mtf_encode(handle, ptr, len))
207
+
208
+ if (count < 0) throw new Error(`mtf: encode failed: ${this.#runtime.lastError()}`)
209
+
210
+ const words = new Uint32Array(memory.buffer, mtf_words_ptr(handle), count * PIECE_WORDS)
211
+ const bytesPtr = mtf_bytes_ptr(handle)
212
+ const result: MTFEncodeResult = { ids: [], pieces: [], begins: [], ends: [] }
213
+
214
+ for (let i = 0; i < count; i++) {
215
+ const w = i * PIECE_WORDS
216
+
217
+ result.ids.push(words[w]!)
218
+ result.begins.push(words[w + 1]!)
219
+ result.ends.push(words[w + 2]!)
220
+ result.pieces.push(decoder.decode(new Uint8Array(memory.buffer, bytesPtr + words[w + 3]!, words[w + 4]!)))
221
+ }
222
+
223
+ return result
224
+ }
225
+
226
+ /**
227
+ * Decodes vocabulary IDs into text.
228
+ *
229
+ * @throws On an ID outside the vocabulary.
230
+ */
231
+ decode(ids: ArrayLike<number>): string {
232
+ const handle = this.#live()
233
+ const { mtf_decode, mtf_bytes_ptr, memory } = this.#exports
234
+ const packed = new Uint32Array(ids.length)
235
+
236
+ for (let i = 0; i < ids.length; i++) {
237
+ const id = ids[i]!
238
+
239
+ if (!Number.isInteger(id) || id < 0) throw new Error(`mtf: invalid id: ${id}`)
240
+
241
+ packed[i] = id
242
+ }
243
+
244
+ const bytes = new Uint8Array(packed.buffer)
245
+ const length = this.#runtime.withInput(bytes, (ptr) => mtf_decode(handle, ptr, packed.length))
246
+
247
+ if (length < 0) throw new Error(`mtf: decode failed: ${this.#runtime.lastError()}`)
248
+
249
+ return decoder.decode(new Uint8Array(memory.buffer, mtf_bytes_ptr(handle), length))
250
+ }
251
+
252
+ /**
253
+ * Releases the model's WASM memory.
254
+ * Later calls on this model throw.
255
+ */
256
+ dispose(): void {
257
+ if (this.#handle === 0) return
258
+
259
+ this.#exports.mtf_model_free(this.#handle)
260
+ this.#handle = 0
261
+ }
262
+
263
+ [Symbol.dispose](): void {
264
+ this.dispose()
265
+ }
266
+ }
@@ -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"}
package/out/index.d.ts ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The TypeScript loader for the Multilingual Token Framework's WebAssembly runtime.
7
+ *
8
+ * The module's import has no side effects: the WASM fetch and instantiation happen in the caller.
9
+ * The caller obtains the WASM bytes or a compiled `WebAssembly.Module` (Workers supply the latter)
10
+ * and passes it to {@linkcode MTFRuntime.instantiate}.
11
+ * `MTF_WASM_URL` locates the committed binary beside this package.
12
+ * A loaded model's encode and decode methods are synchronous.
13
+ */
14
+ /**
15
+ * The location of the committed `wasm/mtf.wasm`, resolved from this module.
16
+ *
17
+ * The same relative path holds from `lib/` in the repository and from `out/` in a tarball.
18
+ */
19
+ export declare const MTF_WASM_URL: import("node:url").URL;
20
+ /**
21
+ * A compiled `WebAssembly.Module`, as a Worker runtime supplies it.
22
+ *
23
+ * The type is opaque because the Node type preset omits the DOM library that declares
24
+ * `WebAssembly`, and this package's declarations must type-check without it.
25
+ */
26
+ export interface MTFCompiledModule {
27
+ readonly [Symbol.toStringTag]: string;
28
+ }
29
+ /**
30
+ * The bytes or compiled module the runtime instantiates from.
31
+ */
32
+ export type MTFWasmSource = MTFCompiledModule | ArrayBuffer | Uint8Array<ArrayBuffer>;
33
+ /**
34
+ * The pieces of one encoded input.
35
+ *
36
+ * `begins[i]` and `ends[i]` are UTF-8 byte offsets into the input as `TextEncoder` encodes it.
37
+ * A byte-fallback piece other than the last for its character has `begins[i] === ends[i]`.
38
+ */
39
+ export interface MTFEncodeResult {
40
+ ids: number[];
41
+ pieces: string[];
42
+ begins: number[];
43
+ ends: number[];
44
+ }
45
+ /**
46
+ * The C ABI that `crates/mtf-wasm` exports.
47
+ */
48
+ interface MTFExports {
49
+ memory: {
50
+ readonly buffer: ArrayBuffer;
51
+ };
52
+ mtf_alloc(len: number): number;
53
+ mtf_dealloc(ptr: number, len: number): void;
54
+ mtf_error_ptr(): number;
55
+ mtf_error_len(): number;
56
+ mtf_model_load(ptr: number, len: number): number;
57
+ mtf_model_free(handle: number): void;
58
+ mtf_vocab_size(handle: number): number;
59
+ mtf_encode(handle: number, ptr: number, len: number): number;
60
+ mtf_decode(handle: number, ids: number, count: number): number;
61
+ mtf_words_ptr(handle: number): number;
62
+ mtf_bytes_ptr(handle: number): number;
63
+ }
64
+ /**
65
+ * One instantiated WebAssembly runtime.
66
+ *
67
+ * A runtime may hold several loaded models at once.
68
+ */
69
+ export declare class MTFRuntime {
70
+ #private;
71
+ private constructor();
72
+ /**
73
+ * Instantiates the runtime from WASM bytes or a compiled module.
74
+ */
75
+ static instantiate(source: MTFWasmSource): Promise<MTFRuntime>;
76
+ /**
77
+ * Loads a serialized SentencePiece unigram model.
78
+ *
79
+ * @throws When the bytes are malformed or the model uses a feature the runtime does not implement.
80
+ */
81
+ loadModel(bytes: Uint8Array): MTFModel;
82
+ /**
83
+ * Reads the message the last failed call recorded.
84
+ *
85
+ * @internal
86
+ */
87
+ lastError(): string;
88
+ /**
89
+ * Copies `bytes` into WASM memory for the duration of `call`.
90
+ *
91
+ * @internal
92
+ */
93
+ withInput<T>(bytes: Uint8Array, call: (ptr: number, len: number) => T): T;
94
+ }
95
+ /**
96
+ * A loaded model.
97
+ *
98
+ * Dispose it with `using` or {@linkcode MTFModel.dispose} to release its WASM memory.
99
+ */
100
+ export declare class MTFModel implements Disposable {
101
+ #private;
102
+ /**
103
+ * @internal Construct through {@linkcode MTFRuntime.loadModel}.
104
+ */
105
+ constructor(runtime: MTFRuntime, exports: MTFExports, handle: number);
106
+ /**
107
+ * The number of vocabulary rows.
108
+ */
109
+ get vocabSize(): number;
110
+ /**
111
+ * Encodes `text` into pieces with UTF-8 byte offsets.
112
+ */
113
+ encode(text: string): MTFEncodeResult;
114
+ /**
115
+ * Decodes vocabulary IDs into text.
116
+ *
117
+ * @throws On an ID outside the vocabulary.
118
+ */
119
+ decode(ids: ArrayLike<number>): string;
120
+ /**
121
+ * Releases the model's WASM memory.
122
+ * Later calls on this model throw.
123
+ */
124
+ dispose(): void;
125
+ [Symbol.dispose](): void;
126
+ }
127
+ export {};
128
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,wBAA+C,CAAA;AAExE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;AAqBrF;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,EAAE,MAAM,EAAE,CAAA;CACd;AAED;;GAEG;AACH,UAAU,UAAU;IACnB,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;KAAE,CAAA;IACxC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,WAAW,CAAC,GAA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M,CAEtB;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAqBpC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAmBrC;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAKd;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;CACD"}
package/out/index.js ADDED
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The TypeScript loader for the Multilingual Token Framework's WebAssembly runtime.
7
+ *
8
+ * The module's import has no side effects: the WASM fetch and instantiation happen in the caller.
9
+ * The caller obtains the WASM bytes or a compiled `WebAssembly.Module` (Workers supply the latter)
10
+ * and passes it to {@linkcode MTFRuntime.instantiate}.
11
+ * `MTF_WASM_URL` locates the committed binary beside this package.
12
+ * A loaded model's encode and decode methods are synchronous.
13
+ */
14
+ /**
15
+ * The location of the committed `wasm/mtf.wasm`, resolved from this module.
16
+ *
17
+ * The same relative path holds from `lib/` in the repository and from `out/` in a tarball.
18
+ */
19
+ export const MTF_WASM_URL = new URL("../wasm/mtf.wasm", import.meta.url);
20
+ /**
21
+ * Words per piece in the encode output buffer: id, begin, end, piece offset, piece length.
22
+ */
23
+ const PIECE_WORDS = 5;
24
+ const encoder = new TextEncoder();
25
+ const decoder = new TextDecoder("utf-8", { fatal: true });
26
+ /**
27
+ * One instantiated WebAssembly runtime.
28
+ *
29
+ * A runtime may hold several loaded models at once.
30
+ */
31
+ export class MTFRuntime {
32
+ #exports;
33
+ constructor(exports) {
34
+ this.#exports = exports;
35
+ }
36
+ /**
37
+ * Instantiates the runtime from WASM bytes or a compiled module.
38
+ */
39
+ static async instantiate(source) {
40
+ const instance = source instanceof ArrayBuffer || ArrayBuffer.isView(source)
41
+ ? (await WebAssembly.instantiate(source, {})).instance
42
+ : await WebAssembly.instantiate(source, {});
43
+ return new MTFRuntime(instance.exports);
44
+ }
45
+ /**
46
+ * Loads a serialized SentencePiece unigram model.
47
+ *
48
+ * @throws When the bytes are malformed or the model uses a feature the runtime does not implement.
49
+ */
50
+ loadModel(bytes) {
51
+ const handle = this.#withInput(bytes, (ptr, len) => this.#exports.mtf_model_load(ptr, len));
52
+ if (handle === 0)
53
+ throw new Error(`mtf: model failed to load: ${this.lastError()}`);
54
+ return new MTFModel(this, this.#exports, handle);
55
+ }
56
+ /**
57
+ * Reads the message the last failed call recorded.
58
+ *
59
+ * @internal
60
+ */
61
+ lastError() {
62
+ const { mtf_error_ptr, mtf_error_len, memory } = this.#exports;
63
+ return decoder.decode(new Uint8Array(memory.buffer, mtf_error_ptr(), mtf_error_len()));
64
+ }
65
+ /**
66
+ * Copies `bytes` into WASM memory for the duration of `call`.
67
+ *
68
+ * @internal
69
+ */
70
+ withInput(bytes, call) {
71
+ return this.#withInput(bytes, call);
72
+ }
73
+ #withInput(bytes, call) {
74
+ const { mtf_alloc, mtf_dealloc, memory } = this.#exports;
75
+ const ptr = mtf_alloc(bytes.byteLength);
76
+ if (ptr === 0)
77
+ throw new Error(`mtf: could not allocate ${bytes.byteLength} bytes`);
78
+ try {
79
+ new Uint8Array(memory.buffer, ptr, bytes.byteLength).set(bytes);
80
+ return call(ptr, bytes.byteLength);
81
+ }
82
+ finally {
83
+ mtf_dealloc(ptr, bytes.byteLength);
84
+ }
85
+ }
86
+ }
87
+ /**
88
+ * A loaded model.
89
+ *
90
+ * Dispose it with `using` or {@linkcode MTFModel.dispose} to release its WASM memory.
91
+ */
92
+ export class MTFModel {
93
+ #runtime;
94
+ #exports;
95
+ #handle;
96
+ /**
97
+ * @internal Construct through {@linkcode MTFRuntime.loadModel}.
98
+ */
99
+ constructor(runtime, exports, handle) {
100
+ this.#runtime = runtime;
101
+ this.#exports = exports;
102
+ this.#handle = handle;
103
+ }
104
+ #live() {
105
+ if (this.#handle === 0)
106
+ throw new Error("mtf: the model was disposed");
107
+ return this.#handle;
108
+ }
109
+ /**
110
+ * The number of vocabulary rows.
111
+ */
112
+ get vocabSize() {
113
+ return this.#exports.mtf_vocab_size(this.#live());
114
+ }
115
+ /**
116
+ * Encodes `text` into pieces with UTF-8 byte offsets.
117
+ */
118
+ encode(text) {
119
+ const handle = this.#live();
120
+ const { mtf_encode, mtf_words_ptr, mtf_bytes_ptr, memory } = this.#exports;
121
+ const count = this.#runtime.withInput(encoder.encode(text), (ptr, len) => mtf_encode(handle, ptr, len));
122
+ if (count < 0)
123
+ throw new Error(`mtf: encode failed: ${this.#runtime.lastError()}`);
124
+ const words = new Uint32Array(memory.buffer, mtf_words_ptr(handle), count * PIECE_WORDS);
125
+ const bytesPtr = mtf_bytes_ptr(handle);
126
+ const result = { ids: [], pieces: [], begins: [], ends: [] };
127
+ for (let i = 0; i < count; i++) {
128
+ const w = i * PIECE_WORDS;
129
+ result.ids.push(words[w]);
130
+ result.begins.push(words[w + 1]);
131
+ result.ends.push(words[w + 2]);
132
+ result.pieces.push(decoder.decode(new Uint8Array(memory.buffer, bytesPtr + words[w + 3], words[w + 4])));
133
+ }
134
+ return result;
135
+ }
136
+ /**
137
+ * Decodes vocabulary IDs into text.
138
+ *
139
+ * @throws On an ID outside the vocabulary.
140
+ */
141
+ decode(ids) {
142
+ const handle = this.#live();
143
+ const { mtf_decode, mtf_bytes_ptr, memory } = this.#exports;
144
+ const packed = new Uint32Array(ids.length);
145
+ for (let i = 0; i < ids.length; i++) {
146
+ const id = ids[i];
147
+ if (!Number.isInteger(id) || id < 0)
148
+ throw new Error(`mtf: invalid id: ${id}`);
149
+ packed[i] = id;
150
+ }
151
+ const bytes = new Uint8Array(packed.buffer);
152
+ const length = this.#runtime.withInput(bytes, (ptr) => mtf_decode(handle, ptr, packed.length));
153
+ if (length < 0)
154
+ throw new Error(`mtf: decode failed: ${this.#runtime.lastError()}`);
155
+ return decoder.decode(new Uint8Array(memory.buffer, mtf_bytes_ptr(handle), length));
156
+ }
157
+ /**
158
+ * Releases the model's WASM memory.
159
+ * Later calls on this model throw.
160
+ */
161
+ dispose() {
162
+ if (this.#handle === 0)
163
+ return;
164
+ this.#exports.mtf_model_free(this.#handle);
165
+ this.#handle = 0;
166
+ }
167
+ [Symbol.dispose]() {
168
+ this.dispose();
169
+ }
170
+ }
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;AAmExE;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,CAAA;AAErB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AACjC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAEzD;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,CAAY;IAE7B,YAAoB,OAAmB;QACtC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAqB;QAC7C,MAAM,QAAQ,GACb,MAAM,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;YAC1D,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ;YACtD,CAAC,CAAC,MAAM,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAE7C,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,KAAiB;QAC1B,MAAM,MAA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GPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Builds `crates/mtf-wasm` for `wasm32-unknown-unknown` and writes the result to `wasm/mtf.wasm`.
7
+ *
8
+ * With `--check`, the tool builds without writing.
9
+ * It exits non-zero when the build's SHA-256 differs from the committed binary's.
10
+ *
11
+ * Usage: `node packages/mtf/tools/build-wasm.run.ts [--check]`
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=build-wasm.run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-wasm.run.d.ts","sourceRoot":"","sources":["../../tools/build-wasm.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}