@scinorandex/embeddings 0.0.0-stage → 0.0.2

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 (45) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +140 -2
  3. package/bench/baseline.ts +41 -0
  4. package/bench/float_check.ts +123 -0
  5. package/bench/glove_cache_bench.ts +44 -0
  6. package/bench/limit_check.ts +32 -0
  7. package/bench/memdiag.ts +17 -0
  8. package/bench/optimized.ts +82 -0
  9. package/dist/common.d.ts +26 -0
  10. package/dist/common.js +183 -0
  11. package/dist/common.js.map +1 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.js +22 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/models/fasttext.d.ts +3 -0
  16. package/dist/models/fasttext.js +453 -0
  17. package/dist/models/fasttext.js.map +1 -0
  18. package/dist/models/glove.d.ts +3 -0
  19. package/dist/models/glove.js +429 -0
  20. package/dist/models/glove.js.map +1 -0
  21. package/dist/models/glove_worker.mjs +143 -0
  22. package/dist/models/matrix.d.ts +50 -0
  23. package/dist/models/matrix.js +362 -0
  24. package/dist/models/matrix.js.map +1 -0
  25. package/dist/models/parse_fast.mjs +245 -0
  26. package/dist/models/word2vec.d.ts +3 -0
  27. package/dist/models/word2vec.js +193 -0
  28. package/dist/models/word2vec.js.map +1 -0
  29. package/opencode.json +27 -0
  30. package/package.json +17 -4
  31. package/scripts/copy-assets.mjs +32 -0
  32. package/src/common.ts +260 -0
  33. package/src/index.ts +5 -0
  34. package/src/models/fasttext.ts +560 -0
  35. package/src/models/glove.ts +521 -0
  36. package/src/models/glove_worker.mjs +143 -0
  37. package/src/models/matrix.ts +461 -0
  38. package/src/models/parse_fast.d.mts +30 -0
  39. package/src/models/parse_fast.mjs +245 -0
  40. package/src/models/word2vec.ts +223 -0
  41. package/test/fasttext.ts +13 -0
  42. package/test/glove.ts +13 -0
  43. package/test/word2vec.ts +13 -0
  44. package/tsconfig.build.json +31 -0
  45. package/tsconfig.json +30 -0
@@ -0,0 +1,50 @@
1
+ import { WordVector, type WordDist, type WordModel } from "../common";
2
+ export type Precision = "f32" | "f16" | "i8";
3
+ export interface LoadOptions {
4
+ normalize?: boolean;
5
+ precision?: Precision;
6
+ limit?: number;
7
+ cache?: boolean;
8
+ }
9
+ export interface ResolvedOptions {
10
+ normalize: boolean;
11
+ precision: Precision;
12
+ limit?: number;
13
+ cache: boolean;
14
+ }
15
+ export declare function resolve_options(options?: LoadOptions | number): ResolvedOptions;
16
+ export interface MatrixModelParams {
17
+ matrix: Float32Array | Float16Array | Int8Array;
18
+ precision: Precision;
19
+ size: number;
20
+ words: string[];
21
+ index: Map<string, number>;
22
+ normalized: boolean;
23
+ rawNorms: Float32Array | null;
24
+ i8Scales: Float32Array | null;
25
+ }
26
+ export declare class MatrixModel implements WordModel {
27
+ readonly words: number;
28
+ readonly size: number;
29
+ readonly precision: Precision;
30
+ private readonly m;
31
+ private readonly wordList;
32
+ private readonly index;
33
+ private readonly normalized;
34
+ private readonly invNorms;
35
+ private readonly i8Factors;
36
+ private readonly i8Scales;
37
+ constructor(params: MatrixModelParams);
38
+ get_vector(word: string): WordVector | null;
39
+ private row_vector;
40
+ get_vectors(filter?: string[]): WordVector[];
41
+ similarity(word1: string, word2: string): number | null;
42
+ get_nearest_word(vec: WordVector | Float32Array): WordDist;
43
+ get_nearest_words(vec: WordVector | Float32Array, n?: number): WordDist[];
44
+ most_similar(phrase: string, n?: number): WordDist[] | null;
45
+ analogy(word: string, pair: [string, string], n?: number): WordDist[];
46
+ get_zero_vector(): WordVector;
47
+ private unit_row;
48
+ private search;
49
+ }
50
+ export declare function finalize_model(matrix: Buffer, rows: number, size: number, words: string[], index: Map<string, number>, opts: ResolvedOptions): WordModel;
@@ -0,0 +1,362 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MatrixModel = void 0;
4
+ exports.resolve_options = resolve_options;
5
+ exports.finalize_model = finalize_model;
6
+ const common_1 = require("../common");
7
+ function resolve_options(options) {
8
+ var _a, _b, _c;
9
+ if (typeof options === "number")
10
+ options = { limit: options };
11
+ options = options !== null && options !== void 0 ? options : {};
12
+ return {
13
+ normalize: (_a = options.normalize) !== null && _a !== void 0 ? _a : true,
14
+ precision: (_b = options.precision) !== null && _b !== void 0 ? _b : "f32",
15
+ limit: options.limit,
16
+ cache: (_c = options.cache) !== null && _c !== void 0 ? _c : false,
17
+ };
18
+ }
19
+ class MatrixModel {
20
+ constructor(params) {
21
+ this.m = params.matrix;
22
+ this.precision = params.precision;
23
+ this.size = params.size;
24
+ this.words = params.words.length;
25
+ this.wordList = params.words;
26
+ this.index = params.index;
27
+ this.normalized = params.normalized;
28
+ this.i8Scales = params.i8Scales;
29
+ if (params.normalized) {
30
+ this.invNorms = null;
31
+ }
32
+ else {
33
+ const norms = params.rawNorms;
34
+ this.invNorms = new Float32Array(norms.length);
35
+ for (let i = 0; i < norms.length; i++)
36
+ this.invNorms[i] = 1 / norms[i];
37
+ }
38
+ if (params.precision === "i8") {
39
+ const scales = params.i8Scales;
40
+ const inv = this.invNorms;
41
+ this.i8Factors = new Float32Array(scales.length);
42
+ for (let i = 0; i < scales.length; i++)
43
+ this.i8Factors[i] = inv === null ? scales[i] : scales[i] * inv[i];
44
+ }
45
+ else {
46
+ this.i8Factors = null;
47
+ }
48
+ }
49
+ get_vector(word) {
50
+ const i = this.index.get(word);
51
+ if (i === undefined)
52
+ return null;
53
+ return this.row_vector(i, word);
54
+ }
55
+ row_vector(i, word) {
56
+ const size = this.size;
57
+ const off = i * size;
58
+ if (this.precision === "f32") {
59
+ const m = this.m;
60
+ return new common_1.WordVector(word, new Float32Array(m.buffer, m.byteOffset + off * 4, size));
61
+ }
62
+ const out = new Float32Array(size);
63
+ if (this.precision === "f16") {
64
+ const m = this.m;
65
+ for (let a = 0; a < size; a++)
66
+ out[a] = m[off + a];
67
+ }
68
+ else {
69
+ const m = this.m;
70
+ const s = this.i8Scales[i];
71
+ for (let a = 0; a < size; a++)
72
+ out[a] = m[off + a] * s;
73
+ }
74
+ return new common_1.WordVector(word, out);
75
+ }
76
+ get_vectors(filter) {
77
+ if (!filter) {
78
+ const out = new Array(this.words);
79
+ for (let i = 0; i < this.words; i++)
80
+ out[i] = this.row_vector(i, this.wordList[i]);
81
+ return out;
82
+ }
83
+ const fset = new Set(filter);
84
+ const out = [];
85
+ for (let i = 0; i < this.wordList.length; i++) {
86
+ const w = this.wordList[i];
87
+ if (fset.has(w))
88
+ out.push(this.row_vector(i, w));
89
+ }
90
+ return out;
91
+ }
92
+ similarity(word1, word2) {
93
+ const i1 = this.index.get(word1);
94
+ if (i1 === undefined)
95
+ return null;
96
+ const i2 = this.index.get(word2);
97
+ if (i2 === undefined)
98
+ return null;
99
+ if (word1 === word2)
100
+ return 1.0;
101
+ const size = this.size;
102
+ const m = this.m;
103
+ const off1 = i1 * size;
104
+ const off2 = i2 * size;
105
+ let s = 0;
106
+ for (let a = 0; a < size; a++)
107
+ s += m[off1 + a] * m[off2 + a];
108
+ if (this.precision === "i8") {
109
+ const f = this.i8Factors;
110
+ return s * f[i1] * f[i2];
111
+ }
112
+ const inv = this.invNorms;
113
+ return inv === null ? s : s * inv[i1] * inv[i2];
114
+ }
115
+ get_nearest_word(vec) {
116
+ return this.search(to_values(vec), 1, null)[0];
117
+ }
118
+ get_nearest_words(vec, n = 10) {
119
+ return this.search(to_values(vec), n, null);
120
+ }
121
+ most_similar(phrase, n = 40) {
122
+ const phrase_words = phrase.split(" ");
123
+ const phrase_set = new Set(phrase_words);
124
+ let found = false;
125
+ for (const w of phrase_words) {
126
+ if (this.index.has(w))
127
+ found = true;
128
+ else
129
+ console.log(`Out of dictionary word: ${w}`);
130
+ }
131
+ if (!found)
132
+ return null;
133
+ const vec = new Float32Array(this.size);
134
+ for (const w of phrase_words) {
135
+ const i = this.index.get(w);
136
+ if (i !== undefined)
137
+ this.unit_row(i, vec, true);
138
+ }
139
+ return this.search(vec, n, phrase_set);
140
+ }
141
+ analogy(word, pair, n = 40) {
142
+ if (typeof word !== "string")
143
+ throw new TypeError("Word of interest has to be supplied as string.");
144
+ if (!Array.isArray(pair))
145
+ throw new TypeError("Word pair has to be supplied in string Array.");
146
+ const phrase = [pair[0], pair[1], word];
147
+ for (const w of phrase) {
148
+ if (!this.index.has(w))
149
+ console.log(`Out of dictionary word: ${w}`);
150
+ }
151
+ if (phrase.some((w) => !this.index.has(w)))
152
+ throw new Error("Words of the analogy must all be in the model vocabulary.");
153
+ const size = this.size;
154
+ const vec = new Float32Array(size);
155
+ const i0 = this.index.get(pair[0]);
156
+ const i1 = this.index.get(pair[1]);
157
+ const iw = this.index.get(word);
158
+ this.unit_row(i1, vec, false);
159
+ const tmp = new Float32Array(size);
160
+ this.unit_row(i0, tmp, false);
161
+ for (let a = 0; a < size; a++)
162
+ vec[a] -= tmp[a];
163
+ this.unit_row(iw, vec, true);
164
+ const phrase_set = new Set(phrase);
165
+ return this.search(vec, n, phrase_set);
166
+ }
167
+ get_zero_vector() {
168
+ return new common_1.WordVector(null, new Float32Array(this.size));
169
+ }
170
+ unit_row(i, out, accumulate) {
171
+ const size = this.size;
172
+ const off = i * size;
173
+ const m = this.m;
174
+ if (this.precision === "i8") {
175
+ const f = this.i8Factors[i];
176
+ if (accumulate)
177
+ for (let a = 0; a < size; a++)
178
+ out[a] += m[off + a] * f;
179
+ else
180
+ for (let a = 0; a < size; a++)
181
+ out[a] = m[off + a] * f;
182
+ }
183
+ else {
184
+ const inv = this.invNorms === null ? 1 : this.invNorms[i];
185
+ if (accumulate)
186
+ for (let a = 0; a < size; a++)
187
+ out[a] += m[off + a] * inv;
188
+ else
189
+ for (let a = 0; a < size; a++)
190
+ out[a] = m[off + a] * inv;
191
+ }
192
+ }
193
+ search(q, n, skip) {
194
+ const size = this.size;
195
+ const wordList = this.wordList;
196
+ const count = wordList.length;
197
+ const wordsOut = new Array(n);
198
+ const distsOut = new Array(n + 1);
199
+ let pos = 0;
200
+ if (this.precision === "i8") {
201
+ const m = this.m;
202
+ const f8 = this.i8Factors;
203
+ let maxAbs = 0;
204
+ let normSq = 0;
205
+ for (let a = 0; a < size; a++) {
206
+ const v = q[a];
207
+ normSq += v * v;
208
+ const av = v < 0 ? -v : v;
209
+ if (av > maxAbs)
210
+ maxAbs = av;
211
+ }
212
+ const qScale = maxAbs > 0 ? 127 / maxAbs : 1;
213
+ const qNorm = Math.sqrt(normSq) || 1;
214
+ const q8 = new Int8Array(size);
215
+ for (let a = 0; a < size; a++) {
216
+ let v = Math.round(q[a] * qScale);
217
+ if (v > 127)
218
+ v = 127;
219
+ else if (v < -127)
220
+ v = -127;
221
+ q8[a] = v;
222
+ }
223
+ const qFactor = 1 / (qScale * qNorm);
224
+ for (let i = 0; i < count; i++) {
225
+ const off = i * size;
226
+ let s = 0;
227
+ for (let a = 0; a < size; a++)
228
+ s += q8[a] * m[off + a];
229
+ const d = s * qFactor * f8[i];
230
+ if (skip !== null && skip.has(wordList[i]))
231
+ continue;
232
+ pos = insert_topn(wordsOut, distsOut, pos, n, wordList[i], d);
233
+ }
234
+ }
235
+ else {
236
+ const m = this.m;
237
+ const qf = (0, common_1.normalize)(q);
238
+ const inv = this.invNorms;
239
+ for (let i = 0; i < count; i++) {
240
+ const off = i * size;
241
+ let s = 0;
242
+ for (let a = 0; a < size; a++)
243
+ s += qf[a] * m[off + a];
244
+ const d = inv === null ? s : s * inv[i];
245
+ if (skip !== null && skip.has(wordList[i]))
246
+ continue;
247
+ pos = insert_topn(wordsOut, distsOut, pos, n, wordList[i], d);
248
+ }
249
+ }
250
+ const out = new Array(n);
251
+ for (let i = 0; i < n; i++) {
252
+ out[i] = { word: i < pos ? wordsOut[i] : "", dist: i < pos ? distsOut[i] : -1 };
253
+ }
254
+ return out;
255
+ }
256
+ }
257
+ exports.MatrixModel = MatrixModel;
258
+ function finalize_model(matrix, rows, size, words, index, opts) {
259
+ const total = rows * size;
260
+ let data;
261
+ const usedBytes = total * 4;
262
+ if (matrix.length - usedBytes > 1 << 24) {
263
+ const trimmed = Buffer.from(matrix.subarray(0, usedBytes));
264
+ data = new Float32Array(trimmed.buffer, trimmed.byteOffset, total);
265
+ }
266
+ else {
267
+ data = new Float32Array(matrix.buffer, matrix.byteOffset, total);
268
+ }
269
+ let rawNorms = null;
270
+ if (opts.normalize) {
271
+ for (let r = 0; r < rows; r++) {
272
+ const off = r * size;
273
+ let n = 0;
274
+ for (let a = 0; a < size; a++) {
275
+ const v = data[off + a];
276
+ n += v * v;
277
+ }
278
+ n = Math.sqrt(n) || 1;
279
+ for (let a = 0; a < size; a++)
280
+ data[off + a] /= n;
281
+ }
282
+ }
283
+ else {
284
+ rawNorms = new Float32Array(rows);
285
+ for (let r = 0; r < rows; r++) {
286
+ const off = r * size;
287
+ let n = 0;
288
+ for (let a = 0; a < size; a++) {
289
+ const v = data[off + a];
290
+ n += v * v;
291
+ }
292
+ rawNorms[r] = Math.sqrt(n) || 1;
293
+ }
294
+ }
295
+ let m = data;
296
+ let i8Scales = null;
297
+ if (opts.precision === "f16") {
298
+ m = new Float16Array(data);
299
+ }
300
+ else if (opts.precision === "i8") {
301
+ const q = new Int8Array(total);
302
+ i8Scales = new Float32Array(rows);
303
+ for (let r = 0; r < rows; r++) {
304
+ const off = r * size;
305
+ let max = 0;
306
+ for (let a = 0; a < size; a++) {
307
+ const v = data[off + a];
308
+ const av = v < 0 ? -v : v;
309
+ if (av > max)
310
+ max = av;
311
+ }
312
+ const s = max > 0 ? 127 / max : 1;
313
+ i8Scales[r] = 1 / s;
314
+ for (let a = 0; a < size; a++) {
315
+ let v = Math.round(data[off + a] * s);
316
+ if (v > 127)
317
+ v = 127;
318
+ else if (v < -127)
319
+ v = -127;
320
+ q[off + a] = v;
321
+ }
322
+ }
323
+ m = q;
324
+ }
325
+ return new MatrixModel({
326
+ matrix: m,
327
+ precision: opts.precision,
328
+ size,
329
+ words,
330
+ index,
331
+ normalized: opts.normalize,
332
+ rawNorms,
333
+ i8Scales,
334
+ });
335
+ }
336
+ function insert_topn(wordsOut, distsOut, pos, n, word, d) {
337
+ if (!Number.isFinite(d))
338
+ return pos;
339
+ const cap = pos < n ? pos : n;
340
+ if (cap === n && d <= distsOut[n - 1])
341
+ return pos;
342
+ let lo = 0;
343
+ let hi = cap;
344
+ while (lo < hi) {
345
+ const mid = (lo + hi) >> 1;
346
+ if (distsOut[mid] >= d)
347
+ lo = mid + 1;
348
+ else
349
+ hi = mid;
350
+ }
351
+ for (let i = cap - 1; i >= lo; i--) {
352
+ distsOut[i + 1] = distsOut[i];
353
+ wordsOut[i + 1] = wordsOut[i];
354
+ }
355
+ distsOut[lo] = d;
356
+ wordsOut[lo] = word;
357
+ return pos < n ? pos + 1 : n;
358
+ }
359
+ function to_values(vec) {
360
+ return vec instanceof common_1.WordVector ? vec.values : vec;
361
+ }
362
+ //# sourceMappingURL=matrix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrix.js","sourceRoot":"","sources":["../../src/models/matrix.ts"],"names":[],"mappings":";;;;;AAAA,sCAAiF;AAgDjF,yBAAgC,OAA8B;;IAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC9D,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACxB,OAAO;QACL,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,IAAI;QACpC,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,KAAK;QACrC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,QAAE,OAAO,CAAC,KAAK,mCAAI,KAAK;KAC9B,CAAC;AACJ,CAAC;AA6BD;IAgBE,YAAY,MAAyB;QACnC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,C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AC,CAAC,CAAC;IAChC,CAAC;IACD,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,SAAS,CAAC,GAA8B;IAC/C,OAAO,GAAG,YAAY,mBAAU,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AACtD,CAAC"}
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Fast float parsing directly from byte buffers and strings (plain JS module
3
+ * so it can be shared with the GloVe worker threads without a loader).
4
+ *
5
+ * Plain decimal numbers (the common case in `.txt` embedding files) are
6
+ * decoded with a small hand-rolled scanner that never allocates strings.
7
+ * Values with at most 15 significant digits are reconstructed in a single
8
+ * correctly-rounded step, so the result is bit-identical to `parseFloat`.
9
+ * `parseFloat` is only used as a fallback for unusual inputs (`nan`, `inf`,
10
+ * very long digit runs, huge exponents).
11
+ *
12
+ * The hot path is `parse_floats_str`, which parses an entire line (e.g. all
13
+ * 300 values of one row) in a single call over a string; string scanning is
14
+ * significantly faster than `Buffer` byte scanning in V8, and keeping the
15
+ * per-value loop inside one function lets the JIT inline it.
16
+ */
17
+
18
+ const POW10 = new Float64Array(31);
19
+ POW10[0] = 1;
20
+ for (let i = 1; i <= 30; i++) POW10[i] = POW10[i - 1] * 10;
21
+
22
+ /**
23
+ * Parse `out.length` space-separated floats from `buf[start .. end)` into
24
+ * `out`. Returns the position just past the last parsed number.
25
+ */
26
+ export function parse_floats(buf, start, end, out) {
27
+ // Clamp so that `i < end` below implies a valid buffer index (lets the JIT
28
+ // elide per-access bounds checks in the hot loops).
29
+ if (end > buf.length) end = buf.length;
30
+
31
+ const n = out.length;
32
+ let i = start;
33
+ for (let v = 0; v < n; v++) {
34
+ while (i < end && buf[i] === 32) i++; // ' '
35
+
36
+ let sign = 1;
37
+ if (i < end && buf[i] === 45) sign = -1; // '-'
38
+ else if (i < end && buf[i] === 43) i++; // '+'
39
+
40
+ const numStart = i;
41
+ let intPart = 0;
42
+ let nInt = 0;
43
+ while (i < end) {
44
+ const c = buf[i];
45
+ if (c < 48 || c > 57) break;
46
+ intPart = intPart * 10 + (c - 48);
47
+ nInt++;
48
+ i++;
49
+ }
50
+
51
+ let frac = 0;
52
+ let nFrac = 0;
53
+ if (i < end && buf[i] === 46) {
54
+ i++; // '.'
55
+ while (i < end) {
56
+ const c = buf[i];
57
+ if (c < 48 || c > 57) break;
58
+ frac = frac * 10 + (c - 48);
59
+ nFrac++;
60
+ i++;
61
+ }
62
+ }
63
+
64
+ // Not a plain decimal (e.g. "nan", "inf"): let the standard parser handle it.
65
+ if (nInt === 0 && nFrac === 0) {
66
+ let e = i;
67
+ while (e < end && buf[e] !== 32) e++;
68
+ out[v] = parseFloat(buf.toString("latin1", numStart, e));
69
+ i = e;
70
+ continue;
71
+ }
72
+
73
+ // Consume the exponent part first, so the fallbacks below always see the
74
+ // complete token.
75
+ let exp = 0;
76
+ let eSign = 1;
77
+ if (i < end && (buf[i] === 101 || buf[i] === 69)) {
78
+ i++; // 'e' / 'E'
79
+ if (i < end && buf[i] === 45) {
80
+ eSign = -1;
81
+ i++;
82
+ } else if (i < end && buf[i] === 43) {
83
+ i++;
84
+ }
85
+ let expDigits = 0;
86
+ while (i < end) {
87
+ const c = buf[i];
88
+ if (c < 48 || c > 57) break;
89
+ if (exp < 999) exp = exp * 10 + (c - 48); // cap; exact value not needed
90
+ expDigits++;
91
+ i++;
92
+ }
93
+ if (expDigits === 0) {
94
+ // Malformed exponent (e.g. "1e"): let the standard parser decide.
95
+ out[v] = parseFloat(buf.toString("latin1", numStart, i));
96
+ continue;
97
+ }
98
+ }
99
+
100
+ // Too many significant digits to reconstruct exactly: standard parser.
101
+ if (nInt + nFrac > 15) {
102
+ out[v] = sign * parseFloat(buf.toString("latin1", numStart, i));
103
+ continue;
104
+ }
105
+
106
+ // Reconstruct the value in a single correctly-rounded step:
107
+ // value = mantissa * 10^power, where
108
+ // mantissa = intPart * 10^nFrac + frac (exact integer, <= 15 digits)
109
+ // power = eSign * exp - nFrac
110
+ // Since both mantissa and 10^power are exactly representable, one
111
+ // IEEE multiply/divide gives the same float64 as parseFloat.
112
+ const mantissa = intPart * POW10[nFrac] + frac;
113
+ const power = (eSign > 0 ? exp : -exp) - nFrac;
114
+ if (power >= 0 && power <= 30) {
115
+ out[v] = sign * mantissa * POW10[power];
116
+ } else if (power < 0 && -power <= 30) {
117
+ out[v] = sign * mantissa / POW10[-power];
118
+ } else {
119
+ out[v] = sign * parseFloat(buf.toString("latin1", numStart, i));
120
+ }
121
+ }
122
+ return i;
123
+ }
124
+
125
+ /**
126
+ * Incremental single-value parser, a thin wrapper around `parse_floats` for
127
+ * callers that parse one value at a time. The result keeps full float64
128
+ * precision (the scratch slot is a Float64Array).
129
+ */
130
+ export class FloatParser {
131
+ /** Position of the next character to parse (set before calling `next`). */
132
+ pos = 0;
133
+
134
+ #scratch = new Float64Array(1);
135
+
136
+ /**
137
+ * Parse the next space-separated float from `buf[pos .. end)`.
138
+ * Advances `pos` to just past the parsed number.
139
+ */
140
+ next(buf, end) {
141
+ this.pos = parse_floats(buf, this.pos, end, this.#scratch);
142
+ return this.#scratch[0];
143
+ }
144
+ }
145
+
146
+ /**
147
+ * String-based twin of `parse_floats` (same algorithm, bit-identical
148
+ * results): parses `out.length` space-separated floats from `line[start ..)`
149
+ * into `out`.
150
+ */
151
+ export function parse_floats_str(line, start, out) {
152
+ const end = line.length;
153
+ const n = out.length;
154
+ let i = start;
155
+ for (let v = 0; v < n; v++) {
156
+ while (i < end && line.charCodeAt(i) === 32) i++; // ' '
157
+
158
+ let sign = 1;
159
+ if (i < end && line.charCodeAt(i) === 45) sign = -1; // '-'
160
+ else if (i < end && line.charCodeAt(i) === 43) i++; // '+'
161
+
162
+ const numStart = i;
163
+ let intPart = 0;
164
+ let nInt = 0;
165
+ while (i < end) {
166
+ const c = line.charCodeAt(i);
167
+ if (c < 48 || c > 57) break;
168
+ intPart = intPart * 10 + (c - 48);
169
+ nInt++;
170
+ i++;
171
+ }
172
+
173
+ let frac = 0;
174
+ let nFrac = 0;
175
+ if (i < end && line.charCodeAt(i) === 46) {
176
+ i++; // '.'
177
+ while (i < end) {
178
+ const c = line.charCodeAt(i);
179
+ if (c < 48 || c > 57) break;
180
+ frac = frac * 10 + (c - 48);
181
+ nFrac++;
182
+ i++;
183
+ }
184
+ }
185
+
186
+ // Not a plain decimal (e.g. "nan", "inf"): let the standard parser handle it.
187
+ if (nInt === 0 && nFrac === 0) {
188
+ let e = i;
189
+ while (e < end && line.charCodeAt(e) !== 32) e++;
190
+ out[v] = parseFloat(line.substring(numStart, e));
191
+ i = e;
192
+ continue;
193
+ }
194
+
195
+ // Consume the exponent part first, so the fallbacks below always see the
196
+ // complete token.
197
+ let exp = 0;
198
+ let eSign = 1;
199
+ if (i < end && (line.charCodeAt(i) === 101 || line.charCodeAt(i) === 69)) {
200
+ i++; // 'e' / 'E'
201
+ if (i < end && line.charCodeAt(i) === 45) {
202
+ eSign = -1;
203
+ i++;
204
+ } else if (i < end && line.charCodeAt(i) === 43) {
205
+ i++;
206
+ }
207
+ let expDigits = 0;
208
+ while (i < end) {
209
+ const c = line.charCodeAt(i);
210
+ if (c < 48 || c > 57) break;
211
+ if (exp < 999) exp = exp * 10 + (c - 48); // cap; exact value not needed
212
+ expDigits++;
213
+ i++;
214
+ }
215
+ if (expDigits === 0) {
216
+ // Malformed exponent (e.g. "1e"): let the standard parser decide.
217
+ out[v] = parseFloat(line.substring(numStart, i));
218
+ continue;
219
+ }
220
+ }
221
+
222
+ // Too many significant digits to reconstruct exactly: standard parser.
223
+ if (nInt + nFrac > 15) {
224
+ out[v] = sign * parseFloat(line.substring(numStart, i));
225
+ continue;
226
+ }
227
+
228
+ // Reconstruct the value in a single correctly-rounded step:
229
+ // value = mantissa * 10^power, where
230
+ // mantissa = intPart * 10^nFrac + frac (exact integer, <= 15 digits)
231
+ // power = eSign * exp - nFrac
232
+ // Since both mantissa and 10^power are exactly representable, one
233
+ // IEEE multiply/divide gives the same float64 as parseFloat.
234
+ const mantissa = intPart * POW10[nFrac] + frac;
235
+ const power = (eSign > 0 ? exp : -exp) - nFrac;
236
+ if (power >= 0 && power <= 30) {
237
+ out[v] = sign * mantissa * POW10[power];
238
+ } else if (power < 0 && -power <= 30) {
239
+ out[v] = sign * mantissa / POW10[-power];
240
+ } else {
241
+ out[v] = sign * parseFloat(line.substring(numStart, i));
242
+ }
243
+ }
244
+ return i;
245
+ }
@@ -0,0 +1,3 @@
1
+ import { type LoadOptions } from "./matrix";
2
+ import type { WordModel } from "../common";
3
+ export declare function load_word2vec(model_path: string, options?: LoadOptions): Promise<WordModel>;