garu-ko 0.4.0 → 0.5.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/dist/index.js CHANGED
@@ -65,7 +65,32 @@ export class Garu {
65
65
  }
66
66
  // Construct the WASM analyzer
67
67
  const wasmInstance = new wasmModule.GaruWasm(modelBytes);
68
- return new Garu(wasmInstance, modelBytes.byteLength);
68
+ // Load CNN reranker
69
+ let cnnBytes = null;
70
+ try {
71
+ if (isNode) {
72
+ const { readFile } = await import('fs/promises');
73
+ const { fileURLToPath } = await import('url');
74
+ const { join, dirname } = await import('path');
75
+ const dir = dirname(fileURLToPath(import.meta.url));
76
+ const buf = await readFile(join(dir, '..', 'models', 'cnn2.bin'));
77
+ cnnBytes = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
78
+ }
79
+ else {
80
+ const cnnUrl = new URL('../models/cnn2.bin', import.meta.url).href;
81
+ const cnnResp = await fetch(cnnUrl);
82
+ if (cnnResp.ok) {
83
+ cnnBytes = new Uint8Array(await cnnResp.arrayBuffer());
84
+ }
85
+ }
86
+ }
87
+ catch {
88
+ // CNN loading is best-effort
89
+ }
90
+ if (cnnBytes) {
91
+ wasmInstance.load_cnn(cnnBytes);
92
+ }
93
+ return new Garu(wasmInstance, modelBytes.byteLength + (cnnBytes?.byteLength ?? 0));
69
94
  }
70
95
  /**
71
96
  * Analyze Korean text, returning morphological tokens with scores.
@@ -133,7 +158,7 @@ export class Garu {
133
158
  return {
134
159
  version: this._wasm.constructor.version(),
135
160
  size: this._modelSize,
136
- accuracy: 0.908,
161
+ accuracy: 0.910,
137
162
  };
138
163
  }
139
164
  /**
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-ko",
3
- "version": "0.4.0",
4
- "description": "Ultra-lightweight Korean morphological analyzer for the web (1.2MB model, WASM 119KB, F1 93.5%)",
3
+ "version": "0.5.0",
4
+ "description": "Ultra-lightweight Korean morphological analyzer for the web (1.7MB model, WASM, F1 93.7%)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -6,7 +6,7 @@ export class GaruWasm {
6
6
  [Symbol.dispose](): void;
7
7
  analyze(text: string): any;
8
8
  analyze_topn(text: string, n: number): any;
9
- constructor(model_data: Uint8Array);
9
+ constructor(model_data: Uint8Array, cnn_data: Uint8Array);
10
10
  tokenize(text: string): any;
11
11
  static version(): string;
12
12
  }
@@ -18,7 +18,7 @@ export interface InitOutput {
18
18
  readonly __wbg_garuwasm_free: (a: number, b: number) => void;
19
19
  readonly garuwasm_analyze: (a: number, b: number, c: number) => [number, number, number];
20
20
  readonly garuwasm_analyze_topn: (a: number, b: number, c: number, d: number) => [number, number, number];
21
- readonly garuwasm_new: (a: number, b: number) => [number, number, number];
21
+ readonly garuwasm_new: (a: number, b: number, c: number, d: number) => [number, number, number];
22
22
  readonly garuwasm_tokenize: (a: number, b: number, c: number) => [number, number, number];
23
23
  readonly garuwasm_version: () => [number, number];
24
24
  readonly __wbindgen_malloc: (a: number, b: number) => number;
package/pkg/garu_wasm.js CHANGED
@@ -40,11 +40,14 @@ export class GaruWasm {
40
40
  }
41
41
  /**
42
42
  * @param {Uint8Array} model_data
43
+ * @param {Uint8Array} cnn_data
43
44
  */
44
- constructor(model_data) {
45
+ constructor(model_data, cnn_data) {
45
46
  const ptr0 = passArray8ToWasm0(model_data, wasm.__wbindgen_malloc);
46
47
  const len0 = WASM_VECTOR_LEN;
47
- const ret = wasm.garuwasm_new(ptr0, len0);
48
+ const ptr1 = passArray8ToWasm0(cnn_data, wasm.__wbindgen_malloc);
49
+ const len1 = WASM_VECTOR_LEN;
50
+ const ret = wasm.garuwasm_new(ptr0, len0, ptr1, len1);
48
51
  if (ret[2]) {
49
52
  throw takeFromExternrefTable0(ret[1]);
50
53
  }
@@ -82,7 +85,7 @@ export class GaruWasm {
82
85
  }
83
86
  }
84
87
  if (Symbol.dispose) GaruWasm.prototype[Symbol.dispose] = GaruWasm.prototype.free;
85
- import * as import1 from "./snippets/garu-core-2da6ed4f058f2483/inline0.js"
88
+ import * as import1 from "./snippets/garu-core-56e20afd30dd714b/inline0.js"
86
89
 
87
90
  function __wbg_get_imports() {
88
91
  const import0 = {
@@ -143,7 +146,7 @@ function __wbg_get_imports() {
143
146
  return {
144
147
  __proto__: null,
145
148
  "./garu_wasm_bg.js": import0,
146
- "./snippets/garu-core-2da6ed4f058f2483/inline0.js": import1,
149
+ "./snippets/garu-core-56e20afd30dd714b/inline0.js": import1,
147
150
  };
148
151
  }
149
152
 
Binary file
@@ -4,7 +4,7 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_garuwasm_free: (a: number, b: number) => void;
5
5
  export const garuwasm_analyze: (a: number, b: number, c: number) => [number, number, number];
6
6
  export const garuwasm_analyze_topn: (a: number, b: number, c: number, d: number) => [number, number, number];
7
- export const garuwasm_new: (a: number, b: number) => [number, number, number];
7
+ export const garuwasm_new: (a: number, b: number, c: number, d: number) => [number, number, number];
8
8
  export const garuwasm_tokenize: (a: number, b: number, c: number) => [number, number, number];
9
9
  export const garuwasm_version: () => [number, number];
10
10
  export const __wbindgen_malloc: (a: number, b: number) => number;
package/pkg/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "garu-wasm",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "files": [
6
6
  "garu_wasm_bg.wasm",
7
7
  "garu_wasm.js",
@@ -0,0 +1 @@
1
+ export function performance_now() { return performance.now(); }
@@ -0,0 +1 @@
1
+ export function performance_now() { return performance.now(); }