@genai-fi/nanogpt 0.17.4 → 0.18.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/Generator.d.ts +2 -15
- package/dist/Generator.js +45 -34
- package/dist/{RealDiv-CGwv0liw.js → RealDiv-ioj6Z-ox.js} +9 -9
- package/dist/{Reshape-BW__R4mZ.js → Reshape-BZC-ebeR.js} +7 -7
- package/dist/{Reshape-CPBkTIH2.js → Reshape-pwprEaej.js} +1 -1
- package/dist/TeachableLLM.d.ts +3 -8
- package/dist/TeachableLLM.js +61 -44
- package/dist/Trainer.d.ts +6 -4
- package/dist/Trainer.js +107 -92
- package/dist/{axis_util-GTVlo58H.js → axis_util-QWWgLjut.js} +1 -1
- package/dist/backend.js +2 -2
- package/dist/{backend_util-GaFarB78.js → backend_util-qwSFfxYx.js} +21 -21
- package/dist/{backend_webgpu-BqASlsbV.js → backend_webgpu-DI2wXEC2.js} +8 -8
- package/dist/{broadcast_to-eS93CCN_.js → broadcast_to-C_EJTVTZ.js} +2 -2
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +5 -5
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/matMulGelu.js +2 -2
- package/dist/checks/normRMS.js +6 -6
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.js +6 -6
- package/dist/checks/qkv.js +2 -2
- package/dist/checks/rope.js +2 -2
- package/dist/{clip_by_value-DDA7rrcT.js → clip_by_value-CLAD4h_I.js} +1 -1
- package/dist/complex-3DpPEG9B.js +11 -0
- package/dist/{concat-CAQpCret.js → concat-Dqk7Xk7h.js} +5 -5
- package/dist/{concat_util-D18dJ4fD.js → concat_util-C1Mxe27t.js} +1 -1
- package/dist/{dataset-CGGp1z9P.js → dataset-DlqAN81i.js} +3 -3
- package/dist/{dropout_util--NxWuYg2.js → dropout_util-N0z8Os-K.js} +1 -1
- package/dist/{expand_dims-Bkd1YD5x.js → expand_dims-D0rBtgT1.js} +4 -4
- package/dist/{exports_initializers-CYzKLjN7.js → exports_initializers-DIOZQt_L.js} +1 -1
- package/dist/{floor-BQtb-Azg.js → floor-CymuCmTO.js} +1 -1
- package/dist/{gather-qIqEqaGn.js → gather-DEyjXNb1.js} +1 -1
- package/dist/{gelu-B220X1Go.js → gelu-DpTCC3eB.js} +1 -1
- package/dist/{gpgpu_math-BwvV12df.js → gpgpu_math-3bCb5ooU.js} +25 -25
- package/dist/{index-CjOWnMXP.js → index-BQvB7LCC.js} +15 -15
- package/dist/{index-CUXkjxiT.js → index-DSGwv2Yx.js} +33 -33
- package/dist/inference/types.d.ts +16 -0
- package/dist/inference/types.js +1 -0
- package/dist/{kernel_funcs_utils-pq0CK9co.js → kernel_funcs_utils-DGqzNlHT.js} +6 -6
- package/dist/layers/BaseLayer.js +4 -4
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/LoRA.js +4 -4
- package/dist/layers/MLP.js +4 -4
- package/dist/layers/PositionEmbedding.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +6 -6
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/layers/WeightStore.js +2 -2
- package/dist/loader/load.d.ts +2 -8
- package/dist/loader/loadTransformers.d.ts +2 -8
- package/dist/loader/loadTransformers.js +13 -11
- package/dist/loader/newZipLoad.d.ts +2 -8
- package/dist/loader/newZipLoad.js +25 -10
- package/dist/loader/oldZipLoad.js +13 -13
- package/dist/loader/save.d.ts +9 -2
- package/dist/loader/save.js +64 -55
- package/dist/loader/types.d.ts +29 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.js +45 -43
- package/dist/{matMul16-BcVC_E62.js → matMul16-BIT70Vya.js} +3 -3
- package/dist/{matMulGelu-JNLZqKQp.js → matMulGelu-CsZnh18H.js} +18 -18
- package/dist/mat_mul-DP86qZtZ.js +11 -0
- package/dist/mod-BXjLYwvM.js +11 -0
- package/dist/models/NanoGPTV1.js +2 -2
- package/dist/models/NanoGPTV2.js +2 -2
- package/dist/models/model.d.ts +3 -2
- package/dist/models/model.js +13 -13
- package/dist/{not_equal-hurPF26l.js → not_equal-CkQKkKZy.js} +15 -15
- package/dist/{ones-BytntneX.js → ones-DbVB5N58.js} +3 -3
- package/dist/ops/adamAdjust.js +3 -3
- package/dist/ops/adamMoments.js +3 -3
- package/dist/ops/add16.js +1 -1
- package/dist/ops/appendCache.js +6 -6
- package/dist/ops/attentionMask.js +3 -3
- package/dist/ops/concat16.js +3 -3
- package/dist/ops/cpu/adamAdjust.js +9 -9
- package/dist/ops/cpu/adamMoments.js +5 -5
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +6 -6
- package/dist/ops/cpu/fusedSoftmax.js +4 -4
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +4 -4
- package/dist/ops/cpu/matMul16.js +2 -2
- package/dist/ops/cpu/matMulGelu.js +7 -7
- package/dist/ops/cpu/matMulMul.js +2 -2
- package/dist/ops/cpu/mulDropout.js +5 -5
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +5 -5
- package/dist/ops/dot16.js +2 -2
- package/dist/ops/dropout.js +6 -6
- package/dist/ops/dropout16.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/globalNorm.js +7 -7
- package/dist/ops/grads/add16.js +1 -1
- package/dist/ops/grads/attentionMask.js +2 -2
- package/dist/ops/grads/dropout16.js +1 -1
- package/dist/ops/grads/gelu.js +2 -2
- package/dist/ops/grads/matMul16.js +3 -3
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/mul16.js +1 -1
- package/dist/ops/grads/normRMS.js +7 -7
- package/dist/ops/grads/pack16.js +3 -3
- package/dist/ops/grads/qkv.js +11 -11
- package/dist/ops/grads/rope.js +2 -2
- package/dist/ops/grads/softmax16.js +1 -1
- package/dist/ops/grads/unpack16.js +2 -2
- package/dist/ops/matMul16.js +3 -3
- package/dist/ops/matMulGelu.js +6 -6
- package/dist/ops/matMulMul.js +3 -3
- package/dist/ops/mul16.js +1 -1
- package/dist/ops/mulDrop.js +3 -3
- package/dist/ops/normRMS.js +4 -4
- package/dist/ops/pack16.js +2 -2
- package/dist/ops/qkv.js +3 -3
- package/dist/ops/reshape16.js +6 -6
- package/dist/ops/rope.js +2 -2
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.js +2 -2
- package/dist/ops/softmax16.js +1 -1
- package/dist/ops/sub16.js +1 -1
- package/dist/ops/sum16.js +6 -6
- package/dist/ops/transpose16.js +3 -3
- package/dist/ops/unpack16.js +2 -2
- package/dist/ops/webgl/adamAdjust.js +2 -2
- package/dist/ops/webgl/adamMoments.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/dropout16.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +7 -7
- package/dist/ops/webgl/gatherSub.js +3 -3
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMul16.js +13 -13
- package/dist/ops/webgl/matMulGelu.js +4 -4
- package/dist/ops/webgl/matMulMul.js +2 -2
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +2 -2
- package/dist/ops/webgpu/adamAdjust.js +3 -3
- package/dist/ops/webgpu/adamMoments.js +3 -3
- package/dist/ops/webgpu/add16.js +6 -6
- package/dist/ops/webgpu/appendCache.js +3 -3
- package/dist/ops/webgpu/attentionMask.js +2 -2
- package/dist/ops/webgpu/attentionMask32_program.js +2 -2
- package/dist/ops/webgpu/clipScale.js +7 -7
- package/dist/ops/webgpu/concat16.js +5 -5
- package/dist/ops/webgpu/dropout16.js +6 -6
- package/dist/ops/webgpu/gatherSub.js +3 -3
- package/dist/ops/webgpu/gelu.js +8 -8
- package/dist/ops/webgpu/matMul16.js +16 -16
- package/dist/ops/webgpu/matMul16_program.js +2 -2
- package/dist/ops/webgpu/mul16.js +5 -5
- package/dist/ops/webgpu/norm2.js +1 -1
- package/dist/ops/webgpu/normRMS.js +2 -2
- package/dist/ops/webgpu/normRMSGrad.js +4 -4
- package/dist/ops/webgpu/pack16.js +4 -4
- package/dist/ops/webgpu/pack16_program.js +2 -2
- package/dist/ops/webgpu/qkv.js +2 -2
- package/dist/ops/webgpu/rope.js +3 -3
- package/dist/ops/webgpu/scatterSub.js +3 -3
- package/dist/ops/webgpu/slice16.js +4 -4
- package/dist/ops/webgpu/softmax16.js +4 -4
- package/dist/ops/webgpu/softmax16_program.js +2 -2
- package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
- package/dist/ops/webgpu/softmax16grad.js +4 -4
- package/dist/ops/webgpu/sub16.js +6 -6
- package/dist/ops/webgpu/sum16.js +3 -3
- package/dist/ops/webgpu/transpose16.js +8 -8
- package/dist/ops/webgpu/transpose16_program.js +2 -2
- package/dist/ops/webgpu/transpose16_shared_program.js +3 -3
- package/dist/ops/webgpu/unpack16.js +3 -3
- package/dist/ops/webgpu/utils/binary_op.js +3 -3
- package/dist/ops/webgpu/utils/reductions.js +5 -5
- package/dist/{ops-CsXeTq1P.js → ops-CURIZSVt.js} +100 -100
- package/dist/{pack16-bqltoUlR.js → pack16-WlOSOuZA.js} +2 -2
- package/dist/patches/webgpu_backend.js +6 -6
- package/dist/patches/webgpu_base.js +1 -1
- package/dist/patches/webgpu_program.js +2 -2
- package/dist/{random_normal-IBRrha8a.js → random_normal-CIm8lk2-.js} +1 -1
- package/dist/{random_width-DN5ZtQkM.js → random_width-B_fVXhGx.js} +131 -131
- package/dist/{range-C-CjF-LI.js → range-BDxO73mk.js} +1 -1
- package/dist/{readers-iz5u3HBo.js → readers-17HLdxVM.js} +2 -2
- package/dist/relu-DTvZKBsZ.js +9 -0
- package/dist/{reshape-BDOuCSNW.js → reshape-BIN71H3p.js} +1 -1
- package/dist/{resize_nearest_neighbor-BojqlfRe.js → resize_nearest_neighbor-C6_0dAnK.js} +41 -41
- package/dist/{rope-0j_f1TPm.js → rope-CC5RjmKU.js} +4 -4
- package/dist/{scatter_nd_util-ByNJaL6I.js → scatter_nd_util-C-x73Cj6.js} +1 -1
- package/dist/{segment_util-Dasb2Zaf.js → segment_util-4zuHV5IG.js} +2 -2
- package/dist/{selu_util-BLhIqRkw.js → selu_util-BXdhy_W6.js} +5 -5
- package/dist/{shared-CagdqkLh.js → shared-DRWDyk9w.js} +6 -6
- package/dist/{shared-3agzAqQ_.js → shared-zTaJ5siv.js} +1 -1
- package/dist/slice-BvItlgXu.js +12 -0
- package/dist/{slice_util-CC35pLmT.js → slice_util-DPY56GzQ.js} +5 -5
- package/dist/{softmax-D4q1LJN7.js → softmax-BLGJqdwx.js} +1 -1
- package/dist/split-BN9LkEgS.js +9 -0
- package/dist/{squeeze-ho4wLUek.js → squeeze-O_YWJpw_.js} +2 -2
- package/dist/{stack-DudVrtmG.js → stack-z6QE7kmP.js} +1 -1
- package/dist/{step-BTxPtq1r.js → step-DQY6_ABw.js} +4 -4
- package/dist/{sum-BpiwSWvg.js → sum-D39FeU5h.js} +3 -3
- package/dist/{tensor-BWFldCso.js → tensor-D8e0Gd7c.js} +1 -1
- package/dist/{tensor1d-LMGMIUlr.js → tensor1d-BMl0eZYV.js} +1 -1
- package/dist/{tensor2d-BnXMKScO.js → tensor2d-DTtQ1QcT.js} +1 -1
- package/dist/{tensor4d-C6UCG_u8.js → tensor4d-Dj4rDssL.js} +1 -1
- package/dist/{tfjs_backend-BGnG-ppu.js → tfjs_backend-Bk3PmK91.js} +65 -65
- package/dist/{tile-CFy-xTO6.js → tile-CsWlVKKz.js} +1 -1
- package/dist/tokeniser/BaseTokeniser.d.ts +4 -1
- package/dist/tokeniser/BaseTokeniser.js +21 -5
- package/dist/tokeniser/CharTokeniser.d.ts +1 -1
- package/dist/tokeniser/CharTokeniser.js +62 -50
- package/dist/tokeniser/bpe.d.ts +1 -1
- package/dist/tokeniser/bpe.js +41 -35
- package/dist/tokeniser/type.d.ts +3 -1
- package/dist/training/AdamW.d.ts +3 -0
- package/dist/training/AdamW.js +59 -30
- package/dist/training/BasicTrainer.d.ts +1 -0
- package/dist/training/BasicTrainer.js +112 -92
- package/dist/training/DatasetBuilder.js +3 -3
- package/dist/training/Evaluator.js +2 -2
- package/dist/training/LRScheduler.d.ts +1 -0
- package/dist/training/LRScheduler.js +18 -12
- package/dist/training/PreTrainer.js +3 -3
- package/dist/training/SFTDatasetBuilder.js +3 -3
- package/dist/training/SFTTrainer.js +1 -1
- package/dist/training/orthoGrad.js +1 -1
- package/dist/training/sparseCrossEntropy.js +30 -30
- package/dist/training/types.d.ts +5 -3
- package/dist/training/validation.js +13 -13
- package/dist/{transpose-9kRxIXWR.js → transpose-Qxz-4os3.js} +7 -7
- package/dist/{unsorted_segment_sum-DJvk5xnh.js → unsorted_segment_sum-BfFVV9Zm.js} +20 -20
- package/dist/utilities/datasetID.d.ts +2 -0
- package/dist/utilities/datasetID.js +21 -0
- package/dist/utilities/dummy.js +6 -6
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.js +1 -1
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.js +5 -5
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-Ck482e3n.js → variable-SSATClyt.js} +1 -1
- package/dist/{webgpu_program-B4HmApL1.js → webgpu_program-CbjdYLYk.js} +1 -1
- package/dist/{webgpu_util-DYlGSwOJ.js → webgpu_util-DuofJBMo.js} +7 -7
- package/dist/{zeros-DvZpK8s6.js → zeros-Bw0puq_w.js} +2 -2
- package/dist/{zeros_like-CWjDdwr-.js → zeros_like-rOHr54NY.js} +69 -69
- package/package.json +3 -3
- package/dist/complex-DI35Q-gW.js +0 -11
- package/dist/mat_mul-DhG0Newp.js +0 -11
- package/dist/mod-CSdCpRjf.js +0 -11
- package/dist/relu-J_X6MUzx.js +0 -9
- package/dist/slice-BzS11Qh0.js +0 -12
- package/dist/split-C2Sj255c.js +0 -9
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { o as g,
|
|
2
|
-
import { t as be } from "./tensor1d-
|
|
3
|
-
import { r as Le } from "./random_normal-
|
|
4
|
-
import { s as P } from "./slice-
|
|
5
|
-
import { r as c } from "./reshape-
|
|
6
|
-
import { g as Ne } from "./gather-
|
|
7
|
-
import { e as Pe } from "./step-
|
|
8
|
-
import { c as
|
|
9
|
-
import { t as
|
|
10
|
-
import { s as
|
|
11
|
-
import { m as $ } from "./mat_mul-
|
|
12
|
-
import { t as
|
|
13
|
-
import { c as j } from "./concat-
|
|
14
|
-
import { g as xe, r as Be } from "./dropout_util
|
|
15
|
-
import { f as Ge } from "./floor-
|
|
16
|
-
function
|
|
1
|
+
import { o as g, n as w, v as A, ag as Te, d as ke, h as M, m as Q, E as q, z as ae, N as ue, _ as le, a2 as fe, bb as he, aD as pe, bc as Ie, t as S, J as $e, a_ as Ee } from "./index-DSGwv2Yx.js";
|
|
2
|
+
import { t as be } from "./tensor1d-BMl0eZYV.js";
|
|
3
|
+
import { r as Le } from "./random_normal-CIm8lk2-.js";
|
|
4
|
+
import { s as P } from "./slice-BvItlgXu.js";
|
|
5
|
+
import { r as c } from "./reshape-BIN71H3p.js";
|
|
6
|
+
import { g as Ne } from "./gather-DEyjXNb1.js";
|
|
7
|
+
import { e as Pe } from "./step-DQY6_ABw.js";
|
|
8
|
+
import { c as ve } from "./clip_by_value-CLAD4h_I.js";
|
|
9
|
+
import { t as Ce } from "./tile-CsWlVKKz.js";
|
|
10
|
+
import { s as Fe, b as Me, c as je, g as Ve } from "./selu_util-BXdhy_W6.js";
|
|
11
|
+
import { m as $ } from "./mat_mul-DP86qZtZ.js";
|
|
12
|
+
import { t as Ue } from "./transpose-Qxz-4os3.js";
|
|
13
|
+
import { c as j } from "./concat-Dqk7Xk7h.js";
|
|
14
|
+
import { g as xe, r as Be } from "./dropout_util-N0z8Os-K.js";
|
|
15
|
+
import { f as Ge } from "./floor-CymuCmTO.js";
|
|
16
|
+
function Je(e) {
|
|
17
17
|
return j(
|
|
18
18
|
e,
|
|
19
19
|
0
|
|
20
20
|
/* axis */
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const qe = /* @__PURE__ */ g({ concat1d_: Je });
|
|
24
24
|
function Ke(e, n) {
|
|
25
25
|
return j(e, n);
|
|
26
26
|
}
|
|
@@ -52,7 +52,7 @@ function en(e, n, t) {
|
|
|
52
52
|
const s = w(e, "x", "slice4d");
|
|
53
53
|
return A(s.rank === 4, () => `slice4d expects a rank-4 tensor, but got a rank-${s.rank} tensor`), P(s, n, t);
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const U = /* @__PURE__ */ g({ slice4d_: en });
|
|
56
56
|
function nn(e, n, t, s) {
|
|
57
57
|
const r = w(e, "x", "dropout");
|
|
58
58
|
if (A(r.dtype === "float32", () => `x has to be a floating point tensor since it's going to be scaled, but got a ${r.dtype} tensor instead.`), A(n >= 0 && n < 1, () => `rate must be a float in the range [0, 1), but got ${n}.`), n === 0)
|
|
@@ -62,7 +62,7 @@ function nn(e, n, t, s) {
|
|
|
62
62
|
}
|
|
63
63
|
const tn = /* @__PURE__ */ g({ dropout_: nn });
|
|
64
64
|
function sn({ a: e, b: n, transposeA: t = !1, transposeB: s = !1, bias: r, activation: o = "linear", preluActivationWeights: i, leakyreluAlpha: f = 0.2 }) {
|
|
65
|
-
if (
|
|
65
|
+
if (Fe(q.state.gradientDepth, o) === !1) {
|
|
66
66
|
let _ = $(e, n, t, s);
|
|
67
67
|
return r != null && (_ = M(_, r)), Me(_, o, i, f);
|
|
68
68
|
}
|
|
@@ -70,38 +70,38 @@ function sn({ a: e, b: n, transposeA: t = !1, transposeB: s = !1, bias: r, activ
|
|
|
70
70
|
[a, u] = ae(a, u);
|
|
71
71
|
const m = t ? a.shape[a.rank - 2] : a.shape[a.rank - 1], d = s ? u.shape[u.rank - 1] : u.shape[u.rank - 2], T = t ? a.shape[a.rank - 1] : a.shape[a.rank - 2], h = s ? u.shape[u.rank - 2] : u.shape[u.rank - 1], ne = a.shape.slice(0, -2), I = u.shape.slice(0, -2), te = ue(ne), se = ue(I);
|
|
72
72
|
A(m === d, () => `Error in fused matMul: inner shapes (${m}) and (${d}) of Tensors with shapes ${a.shape} and ${u.shape} and transposeA=${t} and transposeB=${s} must match.`);
|
|
73
|
-
const B = le(a.shape.slice(0, -2), u.shape.slice(0, -2)).concat([T, h]), G = t ? c(a, [te, m, T]) : c(a, [te, T, m]),
|
|
73
|
+
const B = le(a.shape.slice(0, -2), u.shape.slice(0, -2)).concat([T, h]), G = t ? c(a, [te, m, T]) : c(a, [te, T, m]), J = s ? c(u, [se, h, d]) : c(u, [se, d, h]);
|
|
74
74
|
let E;
|
|
75
75
|
r != null && (E = w(r, "bias", "fused matMul"), [E] = ae(E, a), le(B, E.shape));
|
|
76
76
|
let re;
|
|
77
77
|
i != null && (re = w(i, "prelu weights", "fused matMul"));
|
|
78
|
-
const oe = (_,
|
|
79
|
-
const [O, D, y,
|
|
78
|
+
const oe = (_, v) => {
|
|
79
|
+
const [O, D, y, V] = v, k = je(c(_, y.shape), y, o);
|
|
80
80
|
let b, L;
|
|
81
81
|
if (!t && !s ? (b = $(k, D, !1, !0), L = $(O, k, !0, !1)) : !t && s ? (b = $(k, D, !1, !1), L = $(k, O, !0, !1)) : t && !s ? (b = $(D, k, !1, !0), L = $(O, k, !1, !1)) : (b = $(D, k, !0, !0), L = $(k, O, !0, !0)), r != null) {
|
|
82
|
-
const ye =
|
|
82
|
+
const ye = Ve(V, k);
|
|
83
83
|
return [b, L, ye];
|
|
84
84
|
} else
|
|
85
85
|
return [b, L];
|
|
86
86
|
}, ie = {
|
|
87
87
|
a: G,
|
|
88
|
-
b:
|
|
88
|
+
b: J,
|
|
89
89
|
bias: E,
|
|
90
90
|
preluActivationWeights: re
|
|
91
91
|
}, ce = { transposeA: t, transposeB: s, activation: o, leakyreluAlpha: f };
|
|
92
|
-
return r == null ? fe((
|
|
92
|
+
return r == null ? fe((v, O, D) => {
|
|
93
93
|
const y = (
|
|
94
94
|
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
95
|
-
|
|
95
|
+
q.runKernel(he, ie, ce)
|
|
96
96
|
);
|
|
97
|
-
return D([
|
|
98
|
-
})(G,
|
|
99
|
-
const
|
|
97
|
+
return D([v, O, y]), { value: c(y, B), gradFunc: oe };
|
|
98
|
+
})(G, J) : fe((v, O, D, y) => {
|
|
99
|
+
const V = (
|
|
100
100
|
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
101
|
-
|
|
101
|
+
q.runKernel(he, ie, ce)
|
|
102
102
|
);
|
|
103
|
-
return y([
|
|
104
|
-
})(G,
|
|
103
|
+
return y([v, O, V, D]), { value: c(V, B), gradFunc: oe };
|
|
104
|
+
})(G, J, E);
|
|
105
105
|
}
|
|
106
106
|
const de = /* @__PURE__ */ g({ fusedMatMul_: sn });
|
|
107
107
|
class Ae extends Error {
|
|
@@ -119,9 +119,9 @@ class l extends Error {
|
|
|
119
119
|
super(n), Object.setPrototypeOf(this, l.prototype);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class
|
|
122
|
+
class F extends Error {
|
|
123
123
|
constructor(n) {
|
|
124
|
-
super(n), Object.setPrototypeOf(this,
|
|
124
|
+
super(n), Object.setPrototypeOf(this, F.prototype);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
class ee extends Error {
|
|
@@ -144,16 +144,16 @@ function me(e, n) {
|
|
|
144
144
|
if (!e)
|
|
145
145
|
throw new ee(n);
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function vn(e, n) {
|
|
148
148
|
let t = 0;
|
|
149
149
|
for (const s of e)
|
|
150
150
|
s === n && t++;
|
|
151
151
|
return t;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function Cn(e) {
|
|
154
154
|
return e.length === 1 ? e[0] : e;
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function Fn(e) {
|
|
157
157
|
return Array.isArray(e) ? e : [e];
|
|
158
158
|
}
|
|
159
159
|
function Mn(e) {
|
|
@@ -164,7 +164,7 @@ function jn(e) {
|
|
|
164
164
|
return e.length <= 1 || e.indexOf("_") === -1 ? e : e.replace(/[_]+(\w|$)/g, (n, t) => t.toUpperCase());
|
|
165
165
|
}
|
|
166
166
|
let p = {};
|
|
167
|
-
function
|
|
167
|
+
function Vn(e) {
|
|
168
168
|
if (e == null)
|
|
169
169
|
return null;
|
|
170
170
|
const n = {};
|
|
@@ -182,7 +182,7 @@ function W(e) {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function Un(e, n = {}, t = {}, s = "object", r = !1) {
|
|
186
186
|
if (typeof e == "string") {
|
|
187
187
|
const o = e;
|
|
188
188
|
let i;
|
|
@@ -255,7 +255,7 @@ function x(e, n, t) {
|
|
|
255
255
|
if (t != null && e.indexOf(t) < 0)
|
|
256
256
|
throw new l(`${t} is not a valid ${n}. Valid values are ${e} or null/undefined.`);
|
|
257
257
|
}
|
|
258
|
-
function
|
|
258
|
+
function Jn(e, n, t = 0, s = 1 / 0) {
|
|
259
259
|
return me(t >= 0), me(s >= t), Array.isArray(e) && e.length >= t && e.length <= s && e.every((r) => typeof r === n);
|
|
260
260
|
}
|
|
261
261
|
function on(e, n) {
|
|
@@ -264,7 +264,7 @@ function on(e, n) {
|
|
|
264
264
|
function Oe(e) {
|
|
265
265
|
return e === null ? "null" : Array.isArray(e) ? "[" + e.map((n) => Oe(n)).join(",") + "]" : typeof e == "string" ? `"${e}"` : `${e}`;
|
|
266
266
|
}
|
|
267
|
-
function
|
|
267
|
+
function qn(e, n, t) {
|
|
268
268
|
let s = t != null ? t() : pe(), r;
|
|
269
269
|
return (...i) => {
|
|
270
270
|
const f = t != null ? t() : pe();
|
|
@@ -288,18 +288,18 @@ function Wn(e) {
|
|
|
288
288
|
function Yn(e) {
|
|
289
289
|
x(ln, "PoolMode", e);
|
|
290
290
|
}
|
|
291
|
-
const
|
|
291
|
+
const C = [], ge = "/";
|
|
292
292
|
function Hn(e, n) {
|
|
293
|
-
|
|
293
|
+
C.push(e);
|
|
294
294
|
try {
|
|
295
295
|
const t = n();
|
|
296
|
-
return
|
|
296
|
+
return C.pop(), t;
|
|
297
297
|
} catch (t) {
|
|
298
|
-
throw
|
|
298
|
+
throw C.pop(), t;
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
function hn() {
|
|
302
|
-
return
|
|
302
|
+
return C.length === 0 ? "" : C.join(ge) + ge;
|
|
303
303
|
}
|
|
304
304
|
function Qn(e) {
|
|
305
305
|
if (!De(e))
|
|
@@ -401,7 +401,7 @@ function R(e, n, t) {
|
|
|
401
401
|
case 3:
|
|
402
402
|
return z(e, [n, 0, 0], [t, e.shape[1], e.shape[2]]);
|
|
403
403
|
case 4:
|
|
404
|
-
return
|
|
404
|
+
return U(e, [n, 0, 0, 0], [t, e.shape[1], e.shape[2], e.shape[3]]);
|
|
405
405
|
case 5:
|
|
406
406
|
return P(e, [n, 0, 0, 0, 0], [
|
|
407
407
|
t,
|
|
@@ -434,7 +434,7 @@ function Z(e, n, t) {
|
|
|
434
434
|
case 3:
|
|
435
435
|
return z(e, [0, 0, n], [e.shape[0], e.shape[1], t]);
|
|
436
436
|
case 4:
|
|
437
|
-
return
|
|
437
|
+
return U(e, [0, 0, 0, n], [e.shape[0], e.shape[1], e.shape[2], t]);
|
|
438
438
|
default:
|
|
439
439
|
throw new l(`sliceAlongLastAxis() received an unsupported tensor rank: ${e.rank}`);
|
|
440
440
|
}
|
|
@@ -470,9 +470,9 @@ function at(e, n, t, s) {
|
|
|
470
470
|
case 1:
|
|
471
471
|
return R(e, n, t);
|
|
472
472
|
case 2:
|
|
473
|
-
return
|
|
473
|
+
return U(e, [0, n, 0, 0], [e.shape[0], t, e.shape[2], e.shape[3]]);
|
|
474
474
|
case 3:
|
|
475
|
-
return
|
|
475
|
+
return U(e, [0, 0, n, 0], [e.shape[0], e.shape[1], t, e.shape[3]]);
|
|
476
476
|
case 4:
|
|
477
477
|
return Z(e, n, t);
|
|
478
478
|
default:
|
|
@@ -490,7 +490,7 @@ function ut(e, n = -1) {
|
|
|
490
490
|
function lt(e, n) {
|
|
491
491
|
switch (e.rank) {
|
|
492
492
|
case 1:
|
|
493
|
-
return
|
|
493
|
+
return qe([e, n]);
|
|
494
494
|
case 2:
|
|
495
495
|
return Re([e, n], 0);
|
|
496
496
|
case 3:
|
|
@@ -504,18 +504,18 @@ function lt(e, n) {
|
|
|
504
504
|
function mn(e, n) {
|
|
505
505
|
if (Array.isArray(n) || (n = [n]), e.rank !== n.length)
|
|
506
506
|
throw new l(`The length of input n (${n.length}) does not match the number of dimensions in input x (${e.rank})`);
|
|
507
|
-
return
|
|
507
|
+
return Ce(e, n);
|
|
508
508
|
}
|
|
509
509
|
function ft(e, n = 0, t = 1, s, r) {
|
|
510
510
|
return Le(e, n, t, s, r);
|
|
511
511
|
}
|
|
512
512
|
function ht(e, n, t, s) {
|
|
513
513
|
if (e.rank < 2 || n.rank < 2)
|
|
514
|
-
throw new
|
|
514
|
+
throw new F(`dot requires both inputs to be rank >= 2 but got x shape = ${e.shape} and y shape = ${n.shape}`);
|
|
515
515
|
if (n.rank >= 3) {
|
|
516
516
|
const r = e.shape.slice(-1)[0], o = n.shape.slice(-2)[0];
|
|
517
517
|
if (r !== o)
|
|
518
|
-
throw new
|
|
518
|
+
throw new F(`If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = ${e.shape} and y shape = ${n.shape}`);
|
|
519
519
|
}
|
|
520
520
|
if (e.rank === 2 && n.rank === 2)
|
|
521
521
|
return de({
|
|
@@ -530,7 +530,7 @@ function ht(e, n, t, s) {
|
|
|
530
530
|
const r = e.shape.slice(), o = r.pop();
|
|
531
531
|
e = c(e, [-1, o]);
|
|
532
532
|
const i = n.shape.slice(), f = i.pop(), a = i.pop(), u = [...i, f], m = Array.from({ length: n.rank }, (ne, I) => I === 0 ? n.rank - 2 : I <= n.rank - 2 ? I - 1 : I);
|
|
533
|
-
n = c(
|
|
533
|
+
n = c(Ue(n, m), [a, -1]);
|
|
534
534
|
const d = [...r, ...u];
|
|
535
535
|
return c(de({
|
|
536
536
|
a: e,
|
|
@@ -576,7 +576,7 @@ function mt(e, n, t) {
|
|
|
576
576
|
}
|
|
577
577
|
function gt(e, n = 1) {
|
|
578
578
|
if (n !== 1)
|
|
579
|
-
throw new
|
|
579
|
+
throw new F(`Support for alpha values other than 1 (${n}) is not implemented yet.`);
|
|
580
580
|
return Pe(e);
|
|
581
581
|
}
|
|
582
582
|
function kt(e) {
|
|
@@ -588,7 +588,7 @@ function $t(e, n, t, s) {
|
|
|
588
588
|
function wt(e) {
|
|
589
589
|
return S(() => {
|
|
590
590
|
const n = M(0.5, Q(0.2, e));
|
|
591
|
-
return
|
|
591
|
+
return ve(n, 0, 1);
|
|
592
592
|
});
|
|
593
593
|
}
|
|
594
594
|
function At(e, n, t = !1) {
|
|
@@ -599,17 +599,17 @@ export {
|
|
|
599
599
|
Ae as A,
|
|
600
600
|
pt as B,
|
|
601
601
|
tt as C,
|
|
602
|
-
|
|
602
|
+
vn as D,
|
|
603
603
|
gt as E,
|
|
604
604
|
wt as F,
|
|
605
605
|
kt as G,
|
|
606
606
|
nt as H,
|
|
607
607
|
zn as I,
|
|
608
|
-
|
|
608
|
+
Jn as J,
|
|
609
609
|
mt as K,
|
|
610
610
|
at as L,
|
|
611
611
|
Zn as M,
|
|
612
|
-
|
|
612
|
+
F as N,
|
|
613
613
|
on as O,
|
|
614
614
|
Kn as P,
|
|
615
615
|
Wn as Q,
|
|
@@ -629,13 +629,13 @@ export {
|
|
|
629
629
|
_e as b,
|
|
630
630
|
x as c,
|
|
631
631
|
ht as d,
|
|
632
|
-
|
|
632
|
+
Un as e,
|
|
633
633
|
Xn as f,
|
|
634
634
|
Qn as g,
|
|
635
|
-
|
|
636
|
-
|
|
635
|
+
Cn as h,
|
|
636
|
+
Fn as i,
|
|
637
637
|
st as j,
|
|
638
|
-
|
|
638
|
+
qn as k,
|
|
639
639
|
it as l,
|
|
640
640
|
dt as m,
|
|
641
641
|
Hn as n,
|
|
@@ -643,7 +643,7 @@ export {
|
|
|
643
643
|
rt as p,
|
|
644
644
|
jn as q,
|
|
645
645
|
ft as r,
|
|
646
|
-
|
|
646
|
+
Vn as s,
|
|
647
647
|
Mn as t,
|
|
648
648
|
Bn as u,
|
|
649
649
|
xn as v,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as e,
|
|
1
|
+
import { o as e, n as a, v as i, E as c, T as l } from "./index-DSGwv2Yx.js";
|
|
2
2
|
function u(r, t) {
|
|
3
3
|
const n = a(r, "x", "tile", "string_or_numeric");
|
|
4
4
|
i(n.rank === t.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${t}.`);
|
|
@@ -2,6 +2,8 @@ import { Conversation, ITokeniser } from './type';
|
|
|
2
2
|
import { default as EE } from 'eventemitter3';
|
|
3
3
|
export declare const SPECIALS: string[];
|
|
4
4
|
export default abstract class BaseTokeniser extends EE<'trainStatus'> implements ITokeniser {
|
|
5
|
+
id: string;
|
|
6
|
+
datasetID?: string;
|
|
5
7
|
protected specialTokens: Map<string, number>;
|
|
6
8
|
protected specialTokenSet: Set<number>;
|
|
7
9
|
abstract vocabSize: number;
|
|
@@ -12,7 +14,8 @@ export default abstract class BaseTokeniser extends EE<'trainStatus'> implements
|
|
|
12
14
|
isSpecialToken(index: number): boolean;
|
|
13
15
|
protected addSpecialTokens(): void;
|
|
14
16
|
protected addSpecialToken(token: string, index: number): void;
|
|
15
|
-
|
|
17
|
+
protected generateID(): void;
|
|
18
|
+
abstract train(text: Conversation[][], cb?: (vocab: number) => void, datasetID?: string): Promise<number>;
|
|
16
19
|
abstract getVocab(): string[];
|
|
17
20
|
abstract getMerges(): [string, string][];
|
|
18
21
|
abstract destroy(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { E as r } from "../index-DvYrXKkX.js";
|
|
2
|
-
const
|
|
2
|
+
const l = [
|
|
3
3
|
"<eos>",
|
|
4
4
|
"<bos>",
|
|
5
5
|
"",
|
|
@@ -11,20 +11,36 @@ const h = [
|
|
|
11
11
|
"<|system_start|>",
|
|
12
12
|
"<|system_end|>"
|
|
13
13
|
];
|
|
14
|
-
class
|
|
14
|
+
class T extends r {
|
|
15
|
+
id = "untrained";
|
|
16
|
+
datasetID;
|
|
15
17
|
specialTokens = /* @__PURE__ */ new Map();
|
|
16
18
|
specialTokenSet = /* @__PURE__ */ new Set();
|
|
17
19
|
isSpecialToken(s) {
|
|
18
20
|
return this.specialTokenSet.has(s);
|
|
19
21
|
}
|
|
20
22
|
addSpecialTokens() {
|
|
21
|
-
|
|
23
|
+
l.forEach((s, t) => {
|
|
22
24
|
this.addToken(s, t), this.specialTokens.set(s, t), this.specialTokenSet.add(t);
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
addSpecialToken(s, t) {
|
|
26
28
|
this.specialTokens.set(s, t), this.specialTokenSet.add(t);
|
|
27
29
|
}
|
|
30
|
+
generateID() {
|
|
31
|
+
const s = this.getVocab();
|
|
32
|
+
let t = 2166136261, e = 2654435769;
|
|
33
|
+
for (let a = 0; a < s.length; a++) {
|
|
34
|
+
const i = s[a];
|
|
35
|
+
t ^= i.length, t = Math.imul(t, 16777619), e ^= a, e = Math.imul(e, 2246822507);
|
|
36
|
+
for (let c = 0; c < i.length; c++) {
|
|
37
|
+
const h = i.charCodeAt(c);
|
|
38
|
+
t ^= h, t = Math.imul(t, 16777619), e ^= h, e = Math.imul(e, 3266489909);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const o = (t >>> 0).toString(36), n = (e >>> 0).toString(36);
|
|
42
|
+
this.id = "tokeniser_" + o + "_" + n;
|
|
43
|
+
}
|
|
28
44
|
encodeSequence(s) {
|
|
29
45
|
const t = this.encode(s);
|
|
30
46
|
return [this.bosToken, ...t, this.eosToken];
|
|
@@ -94,6 +110,6 @@ class k extends r {
|
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
113
|
+
l as SPECIALS,
|
|
114
|
+
T as default
|
|
99
115
|
};
|
|
@@ -12,7 +12,7 @@ export default class CharTokeniser extends BaseTokeniser {
|
|
|
12
12
|
addToken(token: string, index?: number): number;
|
|
13
13
|
get trained(): boolean;
|
|
14
14
|
destroy(): void;
|
|
15
|
-
train(text: Conversation[][]): Promise<number>;
|
|
15
|
+
train(text: Conversation[][], cb?: (vocab: number) => void, datasetID?: string): Promise<number>;
|
|
16
16
|
tokenise(text: string[], numeric: true): number[][];
|
|
17
17
|
tokenise(text: string[]): string[][];
|
|
18
18
|
detokenise(tokens: (number[] | Uint16Array)[]): string[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { yieldIfNeeded as u } from "../utilities/yielder.js";
|
|
2
|
+
import b, { SPECIALS as T } from "./BaseTokeniser.js";
|
|
3
|
+
const l = ["<eos>", "<unk>"];
|
|
4
|
+
class x extends b {
|
|
4
5
|
vocabSize = 0;
|
|
5
6
|
eosToken = 0;
|
|
6
7
|
bosToken = 0;
|
|
@@ -8,30 +9,30 @@ class T extends k {
|
|
|
8
9
|
vocab = [];
|
|
9
10
|
cache = /* @__PURE__ */ new Map();
|
|
10
11
|
_trained = !1;
|
|
11
|
-
constructor(
|
|
12
|
-
if (super(), Array.isArray(
|
|
13
|
-
if (this.vocab =
|
|
14
|
-
this.vocabSize = this.vocab.length,
|
|
15
|
-
const e = this.vocab.indexOf(
|
|
16
|
-
e !== -1 && this.addSpecialToken(
|
|
17
|
-
}), this.eosToken = this.getSpecialTokenIndex("<eos>"), this.bosToken = this.getSpecialTokenIndex("<bos>") ?? this.eosToken, this.unkToken = this.getSpecialTokenIndex("") ?? -1, this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("<unk>")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("<pad>")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("_")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf(" ")), this.unkToken === -1 && (this.unkToken = this.eosToken), this.vocab = this.vocab.map((
|
|
18
|
-
this.cache.set(
|
|
12
|
+
constructor(t) {
|
|
13
|
+
if (super(), Array.isArray(t)) {
|
|
14
|
+
if (this.vocab = t, this.vocab.length > 0)
|
|
15
|
+
this.vocabSize = this.vocab.length, T.forEach((i) => {
|
|
16
|
+
const e = this.vocab.indexOf(i);
|
|
17
|
+
e !== -1 && this.addSpecialToken(i, e);
|
|
18
|
+
}), this.eosToken = this.getSpecialTokenIndex("<eos>"), this.bosToken = this.getSpecialTokenIndex("<bos>") ?? this.eosToken, this.unkToken = this.getSpecialTokenIndex("") ?? -1, this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("<unk>")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("<pad>")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf("_")), this.unkToken === -1 && (this.unkToken = this.vocab.indexOf(" ")), this.unkToken === -1 && (this.unkToken = this.eosToken), this.vocab = this.vocab.map((i) => i === "<pad>" ? "" : i), this.vocab.forEach((i, e) => {
|
|
19
|
+
this.cache.set(i, e);
|
|
19
20
|
});
|
|
20
21
|
else
|
|
21
22
|
throw new Error("Vocab cannot be empty");
|
|
22
23
|
this._trained = !0;
|
|
23
24
|
} else
|
|
24
|
-
this.vocabSize =
|
|
25
|
-
this.cache.set(
|
|
25
|
+
this.vocabSize = t, this.vocab = new Array(this.vocabSize).fill(""), this.addSpecialTokens(), this.eosToken = this.getSpecialTokenIndex("<eos>"), this.bosToken = this.getSpecialTokenIndex("<bos>") ?? this.eosToken, this.unkToken = this.getSpecialTokenIndex(""), this.vocab.forEach((i, e) => {
|
|
26
|
+
this.cache.set(i, e);
|
|
26
27
|
}), this.cache.set("", this.unkToken);
|
|
27
28
|
}
|
|
28
|
-
addToken(
|
|
29
|
-
if (this.cache.has(
|
|
30
|
-
return this.cache.get(
|
|
29
|
+
addToken(t, i) {
|
|
30
|
+
if (this.cache.has(t))
|
|
31
|
+
return this.cache.get(t);
|
|
31
32
|
let e;
|
|
32
|
-
if (
|
|
33
|
+
if (i !== void 0 ? e = i : (e = this.vocab.indexOf("", this.unkToken + 1), e === -1 && (e = this.vocabSize)), e >= this.vocabSize)
|
|
33
34
|
throw new Error("Vocab size exceeded");
|
|
34
|
-
return this.vocab[e] =
|
|
35
|
+
return this.vocab[e] = t, this.cache.set(t, e), e;
|
|
35
36
|
}
|
|
36
37
|
get trained() {
|
|
37
38
|
return this.vocab.length === this.vocabSize && this._trained;
|
|
@@ -39,43 +40,54 @@ class T extends k {
|
|
|
39
40
|
destroy() {
|
|
40
41
|
this.cache.clear(), this.vocab = [];
|
|
41
42
|
}
|
|
42
|
-
async train(i) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}),
|
|
43
|
+
async train(t, i, e) {
|
|
44
|
+
this.datasetID = e;
|
|
45
|
+
const a = /* @__PURE__ */ new Set();
|
|
46
|
+
let h = performance.now();
|
|
47
|
+
for (const n of t)
|
|
48
|
+
n.forEach((o) => {
|
|
49
|
+
for (const r of o.content)
|
|
50
|
+
a.add(r);
|
|
51
|
+
}), h = await u(h, i, 0);
|
|
52
|
+
const s = Array.from(a), k = this.vocab.indexOf("", this.unkToken + 1), d = this.vocabSize - l.length;
|
|
53
|
+
if (k === -1)
|
|
54
|
+
return this.generateID(), this.vocabSize;
|
|
55
|
+
if (this._trained = !0, s.length > d) {
|
|
56
|
+
const n = /* @__PURE__ */ new Map();
|
|
57
|
+
t.forEach((o) => {
|
|
58
|
+
o.forEach((r) => {
|
|
59
|
+
for (const f of r.content)
|
|
60
|
+
n.set(f, (n.get(f) || 0) + 1);
|
|
61
|
+
});
|
|
62
|
+
}), s.sort((o, r) => (n.get(o) || 0) - (n.get(r) || 0)), s.splice(0, s.length - d);
|
|
51
63
|
}
|
|
52
|
-
let c =
|
|
64
|
+
let c = k;
|
|
53
65
|
if (c !== -1) {
|
|
54
|
-
const
|
|
55
|
-
for (const
|
|
56
|
-
if (!
|
|
66
|
+
const n = new Set(this.vocab);
|
|
67
|
+
for (const o of s)
|
|
68
|
+
if (!n.has(o) && (this.vocab[c] = o, n.add(o), c = this.vocab.indexOf("", c + 1), c === -1))
|
|
57
69
|
break;
|
|
58
70
|
}
|
|
59
|
-
return this.cache.clear(), this.vocab.forEach((
|
|
60
|
-
this.cache.set(
|
|
61
|
-
}), this.emit("trainStatus", "trained"), this.vocabSize;
|
|
71
|
+
return this.cache.clear(), this.vocab.forEach((n, o) => {
|
|
72
|
+
this.cache.set(n, o);
|
|
73
|
+
}), this.generateID(), this.emit("trainStatus", "trained"), this.vocabSize;
|
|
62
74
|
}
|
|
63
|
-
tokenise(
|
|
75
|
+
tokenise(t, i) {
|
|
64
76
|
if (!this.trained)
|
|
65
77
|
throw new Error("Tokeniser not trained");
|
|
66
|
-
return
|
|
67
|
-
const
|
|
68
|
-
return
|
|
78
|
+
return t.map((a) => i ? a.split("").map((h) => this.cache.get(h) ?? this.unkToken) : a.split("").map((h) => {
|
|
79
|
+
const s = this.cache.get(h);
|
|
80
|
+
return s !== void 0 ? this.vocab[s] : "";
|
|
69
81
|
}));
|
|
70
82
|
}
|
|
71
|
-
detokenise(
|
|
72
|
-
return
|
|
83
|
+
detokenise(t) {
|
|
84
|
+
return t.map((e) => Array.from(e).map((a) => this.vocab[a] || "").join(""));
|
|
73
85
|
}
|
|
74
|
-
encode(
|
|
75
|
-
return this.tokenise([
|
|
86
|
+
encode(t) {
|
|
87
|
+
return this.tokenise([t], !0)[0];
|
|
76
88
|
}
|
|
77
|
-
decode(
|
|
78
|
-
return this.detokenise([
|
|
89
|
+
decode(t) {
|
|
90
|
+
return this.detokenise([t])[0];
|
|
79
91
|
}
|
|
80
92
|
getVocab() {
|
|
81
93
|
return this.vocab;
|
|
@@ -83,13 +95,13 @@ class T extends k {
|
|
|
83
95
|
getMerges() {
|
|
84
96
|
return [];
|
|
85
97
|
}
|
|
86
|
-
async createTrainingData(
|
|
87
|
-
const e = await this.tokenise(
|
|
88
|
-
for (let
|
|
89
|
-
|
|
90
|
-
return [
|
|
98
|
+
async createTrainingData(t, i = 5) {
|
|
99
|
+
const e = await this.tokenise(t, !0), a = [], h = [];
|
|
100
|
+
for (let s = 0; s < e.length - i; s++)
|
|
101
|
+
a.push(...e[s].slice(0, i)), h.push(e[s + 1][0]);
|
|
102
|
+
return [a, h];
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
105
|
export {
|
|
94
|
-
|
|
106
|
+
x as default
|
|
95
107
|
};
|
package/dist/tokeniser/bpe.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export default class BPETokeniser extends BaseTokeniser {
|
|
|
15
15
|
get eosToken(): number;
|
|
16
16
|
get bosToken(): number;
|
|
17
17
|
get unkToken(): number;
|
|
18
|
-
train(text?: Conversation[][], cb?: (vocab: number) => void): Promise<number>;
|
|
18
|
+
train(text?: Conversation[][], cb?: (vocab: number) => void, datasetID?: string): Promise<number>;
|
|
19
19
|
getVocab(): string[];
|
|
20
20
|
getMerges(): [string, string][];
|
|
21
21
|
private tokeniseWord;
|