@kotoshu/wasm 0.1.0 → 0.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.
- package/kotoshu_wasm.d.ts +28 -0
- package/kotoshu_wasm.js +1 -1
- package/kotoshu_wasm_bg.js +83 -0
- package/kotoshu_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/kotoshu_wasm.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* One loaded embedding tier: the wasm twin of the `onnx` feature's
|
|
6
|
+
* ort provider — same artifacts, scored in pure Rust. Handle-shaped:
|
|
7
|
+
* opaque on the JS side, freed by GC or `free()` (see the module docs
|
|
8
|
+
* for the memory footprint).
|
|
9
|
+
*/
|
|
10
|
+
export class KotoshuModel {
|
|
11
|
+
private constructor();
|
|
12
|
+
free(): void;
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
/**
|
|
5
17
|
* One loaded dictionary: the JS twin of the `ruby` feature's
|
|
6
18
|
* `Kotoshu::Native::Dictionary` — same engine, same suggestion-row shape.
|
|
@@ -37,3 +49,19 @@ export class KotoshuWasm {
|
|
|
37
49
|
*/
|
|
38
50
|
static readonly VERSION: string;
|
|
39
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Load an int8-per-row embedding tier from the byte CONTENTS of its
|
|
55
|
+
* `.onnx` artifact and `.vocab.json` sibling (wasm has no filesystem;
|
|
56
|
+
* the host fetches the pair — mini ≈ 3 MB, fluency ≈ 15 MB).
|
|
57
|
+
* Failures reject with the Rust error message.
|
|
58
|
+
*/
|
|
59
|
+
export function loadModel(model_bytes: Uint8Array, vocab_bytes: Uint8Array): KotoshuModel;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Score `word` against `context` (free text): the mean cosine over the
|
|
63
|
+
* in-vocabulary context tokens, in `[-1, 1]` — `0.0` when the word or
|
|
64
|
+
* every token is out of vocabulary. Ranking by this score orders
|
|
65
|
+
* candidates as the gem's context boost does; see the module docs.
|
|
66
|
+
*/
|
|
67
|
+
export function rerank(model: KotoshuModel, word: string, context: string): number;
|
package/kotoshu_wasm.js
CHANGED
package/kotoshu_wasm_bg.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One loaded embedding tier: the wasm twin of the `onnx` feature's
|
|
3
|
+
* ort provider — same artifacts, scored in pure Rust. Handle-shaped:
|
|
4
|
+
* opaque on the JS side, freed by GC or `free()` (see the module docs
|
|
5
|
+
* for the memory footprint).
|
|
6
|
+
*/
|
|
7
|
+
export class KotoshuModel {
|
|
8
|
+
static __wrap(ptr) {
|
|
9
|
+
const obj = Object.create(KotoshuModel.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
KotoshuModelFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
KotoshuModelFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_kotoshumodel_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (Symbol.dispose) KotoshuModel.prototype[Symbol.dispose] = KotoshuModel.prototype.free;
|
|
26
|
+
|
|
1
27
|
/**
|
|
2
28
|
* One loaded dictionary: the JS twin of the `ruby` feature's
|
|
3
29
|
* `Kotoshu::Native::Dictionary` — same engine, same suggestion-row shape.
|
|
@@ -84,6 +110,47 @@ export class KotoshuWasm {
|
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
112
|
if (Symbol.dispose) KotoshuWasm.prototype[Symbol.dispose] = KotoshuWasm.prototype.free;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Load an int8-per-row embedding tier from the byte CONTENTS of its
|
|
116
|
+
* `.onnx` artifact and `.vocab.json` sibling (wasm has no filesystem;
|
|
117
|
+
* the host fetches the pair — mini ≈ 3 MB, fluency ≈ 15 MB).
|
|
118
|
+
* Failures reject with the Rust error message.
|
|
119
|
+
* @param {Uint8Array} model_bytes
|
|
120
|
+
* @param {Uint8Array} vocab_bytes
|
|
121
|
+
* @returns {KotoshuModel}
|
|
122
|
+
*/
|
|
123
|
+
export function loadModel(model_bytes, vocab_bytes) {
|
|
124
|
+
const ptr0 = passArray8ToWasm0(model_bytes, wasm.__wbindgen_malloc);
|
|
125
|
+
const len0 = WASM_VECTOR_LEN;
|
|
126
|
+
const ptr1 = passArray8ToWasm0(vocab_bytes, wasm.__wbindgen_malloc);
|
|
127
|
+
const len1 = WASM_VECTOR_LEN;
|
|
128
|
+
const ret = wasm.loadModel(ptr0, len0, ptr1, len1);
|
|
129
|
+
if (ret[2]) {
|
|
130
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
131
|
+
}
|
|
132
|
+
return KotoshuModel.__wrap(ret[0]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Score `word` against `context` (free text): the mean cosine over the
|
|
137
|
+
* in-vocabulary context tokens, in `[-1, 1]` — `0.0` when the word or
|
|
138
|
+
* every token is out of vocabulary. Ranking by this score orders
|
|
139
|
+
* candidates as the gem's context boost does; see the module docs.
|
|
140
|
+
* @param {KotoshuModel} model
|
|
141
|
+
* @param {string} word
|
|
142
|
+
* @param {string} context
|
|
143
|
+
* @returns {number}
|
|
144
|
+
*/
|
|
145
|
+
export function rerank(model, word, context) {
|
|
146
|
+
_assertClass(model, KotoshuModel);
|
|
147
|
+
const ptr0 = passStringToWasm0(word, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
148
|
+
const len0 = WASM_VECTOR_LEN;
|
|
149
|
+
const ptr1 = passStringToWasm0(context, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
150
|
+
const len1 = WASM_VECTOR_LEN;
|
|
151
|
+
const ret = wasm.rerank(model.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
152
|
+
return ret;
|
|
153
|
+
}
|
|
87
154
|
export function __wbg_Error_408e67f47ca7b58b(arg0, arg1) {
|
|
88
155
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
89
156
|
return ret;
|
|
@@ -155,6 +222,9 @@ export function __wbindgen_init_externref_table() {
|
|
|
155
222
|
table.set(offset + 2, true);
|
|
156
223
|
table.set(offset + 3, false);
|
|
157
224
|
}
|
|
225
|
+
const KotoshuModelFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
226
|
+
? { register: () => {}, unregister: () => {} }
|
|
227
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_kotoshumodel_free(ptr, 1));
|
|
158
228
|
const KotoshuWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
159
229
|
? { register: () => {}, unregister: () => {} }
|
|
160
230
|
: new FinalizationRegistry(ptr => wasm.__wbg_kotoshuwasm_free(ptr, 1));
|
|
@@ -165,6 +235,12 @@ function addToExternrefTable0(obj) {
|
|
|
165
235
|
return idx;
|
|
166
236
|
}
|
|
167
237
|
|
|
238
|
+
function _assertClass(instance, klass) {
|
|
239
|
+
if (!(instance instanceof klass)) {
|
|
240
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
168
244
|
function debugString(val) {
|
|
169
245
|
// primitive types
|
|
170
246
|
const type = typeof val;
|
|
@@ -263,6 +339,13 @@ function isLikeNone(x) {
|
|
|
263
339
|
return x === undefined || x === null;
|
|
264
340
|
}
|
|
265
341
|
|
|
342
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
343
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
344
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
345
|
+
WASM_VECTOR_LEN = arg.length;
|
|
346
|
+
return ptr;
|
|
347
|
+
}
|
|
348
|
+
|
|
266
349
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
267
350
|
if (realloc === undefined) {
|
|
268
351
|
const buf = cachedTextEncoder.encode(arg);
|
package/kotoshu_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"Ribose Inc. <open.source@ribose.com>"
|
|
6
6
|
],
|
|
7
7
|
"description": "npm @kotoshu/wasm packaging shim: wasm-pack build of the kotoshu engine's wasm-bindgen surface",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.2.0",
|
|
9
9
|
"license": "BSD-2-Clause",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|