@genai-fi/nanogpt 0.2.11 → 0.3.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.js +30 -25
- package/dist/NanoGPTModel.d.ts +13 -14
- package/dist/NanoGPTModel.js +167 -85
- package/dist/TeachableLLM.d.ts +3 -5
- package/dist/TeachableLLM.js +47 -35
- package/dist/Trainer.js +8 -8
- package/dist/concat-BIZS_td9.js +33 -0
- package/dist/data/parquet.js +1 -1
- package/dist/exports_layers-7idKoYqh.js +25 -0
- package/dist/{sum-D7fu15XL.js → gather-BPGW8RsB.js} +6 -8
- package/dist/index-C4L8Cm77.js +349 -0
- package/dist/{index-YPKosni4.js → index-pWA4_lUh.js} +1020 -782
- package/dist/layers/CausalSelfAttention.d.ts +11 -11
- package/dist/layers/CausalSelfAttention.js +71 -63
- package/dist/layers/MLP.d.ts +6 -7
- package/dist/layers/MLP.js +18 -16
- package/dist/layers/RMSNorm.d.ts +6 -7
- package/dist/layers/RMSNorm.js +15 -13
- package/dist/layers/RoPECache.d.ts +4 -6
- package/dist/layers/RoPECache.js +36 -23
- package/dist/layers/TiedEmbedding.d.ts +7 -8
- package/dist/layers/TiedEmbedding.js +16 -418
- package/dist/layers/TransformerBlock.d.ts +8 -9
- package/dist/layers/TransformerBlock.js +12 -12
- package/dist/main.d.ts +1 -0
- package/dist/main.js +35 -21
- package/dist/{mat_mul-Bu7bhLms.js → mat_mul-D7_a4KJn.js} +5 -5
- package/dist/moments-DfcpfwKi.js +132 -0
- package/dist/ones-Cog-G2ag.js +29 -0
- package/dist/ops/appendCache.d.ts +2 -0
- package/dist/ops/appendCache.js +9 -0
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +7 -85
- package/dist/ops/cpu/appendCache.d.ts +2 -0
- package/dist/ops/cpu/appendCache.js +28 -0
- package/dist/ops/cpu/attentionMask.js +18 -0
- package/dist/ops/cpu/gatherSub.d.ts +1 -0
- package/dist/ops/cpu/gatherSub.js +34 -0
- package/dist/ops/cpu/qkv.d.ts +5 -0
- package/dist/ops/cpu/qkv.js +38 -0
- package/dist/ops/cpu/rope.d.ts +6 -0
- package/dist/ops/cpu/rope.js +38 -0
- package/dist/ops/cpu/scatterSub.d.ts +1 -0
- package/dist/ops/cpu/scatterSub.js +70 -0
- package/dist/ops/gatherSub.d.ts +1 -1
- package/dist/ops/gatherSub.js +6 -63
- package/dist/ops/grads/attentionMask.d.ts +1 -0
- package/dist/ops/grads/attentionMask.js +21 -0
- package/dist/ops/grads/qkv.d.ts +1 -0
- package/dist/ops/grads/qkv.js +20 -0
- package/dist/ops/grads/rope.d.ts +1 -0
- package/dist/ops/grads/rope.js +14 -0
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.d.ts +1 -6
- package/dist/ops/qkv.js +7 -124
- package/dist/ops/rope.d.ts +0 -5
- package/dist/ops/rope.js +7 -150
- package/dist/ops/scatterSub.d.ts +1 -1
- package/dist/ops/scatterSub.js +6 -147
- package/dist/ops/webgl/appendCache.d.ts +1 -0
- package/dist/ops/webgl/appendCache.js +43 -0
- package/dist/ops/webgl/attentionMask.d.ts +1 -0
- package/dist/ops/webgl/attentionMask.js +43 -0
- package/dist/ops/webgl/gatherSub.d.ts +1 -0
- package/dist/ops/webgl/gatherSub.js +27 -0
- package/dist/ops/webgl/qkv.d.ts +1 -0
- package/dist/ops/webgl/qkv.js +46 -0
- package/dist/ops/webgl/rope.d.ts +1 -0
- package/dist/ops/webgl/rope.js +56 -0
- package/dist/ops/webgl/scatterSub.d.ts +1 -0
- package/dist/ops/webgl/scatterSub.js +27 -0
- package/dist/{parquet-BRl5lE_I.js → parquet-C0Tlmv9c.js} +3045 -3048
- package/dist/random_width-PbCt7RXv.js +15489 -0
- package/dist/range-CcDl05lo.js +26 -0
- package/dist/{reshape-DmnmKT6r.js → reshape-C8CR_Bad.js} +3 -3
- package/dist/sin-BJIrfnj7.js +47 -0
- package/dist/softmax-Be_lsqUc.js +105 -0
- package/dist/{complex-CJ-qCcLB.js → split-DZbvruEP.js} +6 -8
- package/dist/stack-BMm-efee.js +27 -0
- package/dist/sum-C7Mgy9Bw.js +104 -0
- package/dist/tensor-DJVbYhh1.js +24 -0
- package/dist/tensor2d-ZuQSh2D-.js +30 -0
- package/dist/tokeniser/bpe.d.ts +17 -6
- package/dist/tokeniser/bpe.js +88 -60
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.d.ts +6 -6
- package/dist/training/DatasetBuilder.js +1262 -17
- package/dist/training/Evaluator.d.ts +3 -2
- package/dist/training/FullTrainer.d.ts +9 -8
- package/dist/training/FullTrainer.js +26 -25
- package/dist/training/LayerTrainer.d.ts +9 -8
- package/dist/training/LayerTrainer.js +34 -33
- package/dist/training/Trainer.d.ts +22 -21
- package/dist/training/Trainer.js +21 -18
- package/dist/training/sparseCrossEntropy.js +22 -166
- package/dist/utilities/dummy.js +10 -8
- package/dist/utilities/generate.js +14 -11
- package/dist/utilities/load.d.ts +1 -2
- package/dist/utilities/load.js +37 -35
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/save.js +14 -9
- package/dist/utilities/tokenParse.d.ts +1 -1
- package/dist/utilities/tokenParse.js +7 -61
- package/dist/utilities/weights.d.ts +3 -3
- package/dist/utilities/weights.js +21 -19
- package/dist/variable-Dl_ub3pk.js +23 -0
- package/dist/{stack-BtKpB0Ry.js → zeros-CCy9C3uU.js} +18 -16
- package/package.json +2 -1
- package/dist/assets/worker-BYeSPNkq.js +0 -1
- package/dist/tokeniser/NodeTokeniser.d.ts +0 -20
- package/dist/tokeniser/NodeTokeniser.js +0 -46
- package/dist/tokeniser/WebTokeniser.d.ts +0 -18
- package/dist/tokeniser/WebTokeniser.js +0 -96
- package/dist/tokeniser/worker.js +0 -53
- /package/dist/{tokeniser/worker.d.ts → ops/cpu/attentionMask.d.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { E as e, R as f } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function E(n, o, r = 1, a = "float32") {
|
|
19
|
+
if (r === 0)
|
|
20
|
+
throw new Error("Cannot have a step of zero");
|
|
21
|
+
const t = { start: n, stop: o, step: r, dtype: a };
|
|
22
|
+
return e.runKernel(f, {}, t);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
E as r
|
|
26
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o,
|
|
1
|
+
import { o, h as t, E as a, q as p } from "./index-pWA4_lUh.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -19,7 +19,7 @@ function c(r, s) {
|
|
|
19
19
|
const e = { x: t(r, "x", "reshape", "string_or_numeric") }, n = { shape: s };
|
|
20
20
|
return a.runKernel(p, e, n);
|
|
21
21
|
}
|
|
22
|
-
const
|
|
22
|
+
const u = /* @__PURE__ */ o({ reshape_: c });
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
u as r
|
|
25
25
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { o, h as t, E as c, K as a, L as e } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function i(n) {
|
|
19
|
+
const s = { x: t(n, "x", "cos", "float32") };
|
|
20
|
+
return c.runKernel(a, s);
|
|
21
|
+
}
|
|
22
|
+
const f = /* @__PURE__ */ o({ cos_: i });
|
|
23
|
+
/**
|
|
24
|
+
* @license
|
|
25
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
26
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License.
|
|
28
|
+
* You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
* =============================================================================
|
|
38
|
+
*/
|
|
39
|
+
function x(n) {
|
|
40
|
+
const s = { x: t(n, "x", "sin", "float32") };
|
|
41
|
+
return c.runKernel(e, s);
|
|
42
|
+
}
|
|
43
|
+
const p = /* @__PURE__ */ o({ sin_: x });
|
|
44
|
+
export {
|
|
45
|
+
f as c,
|
|
46
|
+
p as s
|
|
47
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { o as r, h as e, E as c, _ as $, $ as h, a0 as E, s as S, Z as _, a1 as d } from "./index-pWA4_lUh.js";
|
|
2
|
+
import { m as k, s as w, e as K } from "./sum-C7Mgy9Bw.js";
|
|
3
|
+
import { r as l } from "./reshape-C8CR_Bad.js";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
* =============================================================================
|
|
19
|
+
*/
|
|
20
|
+
function T(n) {
|
|
21
|
+
const s = { x: e(n, "x", "exp") };
|
|
22
|
+
return c.runKernel($, s);
|
|
23
|
+
}
|
|
24
|
+
const b = /* @__PURE__ */ r({ exp_: T });
|
|
25
|
+
/**
|
|
26
|
+
* @license
|
|
27
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
28
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29
|
+
* you may not use this file except in compliance with the License.
|
|
30
|
+
* You may obtain a copy of the License at
|
|
31
|
+
*
|
|
32
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
35
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
37
|
+
* See the License for the specific language governing permissions and
|
|
38
|
+
* limitations under the License.
|
|
39
|
+
* =============================================================================
|
|
40
|
+
*/
|
|
41
|
+
function L(n) {
|
|
42
|
+
const s = { x: e(n, "x", "log", "float32") };
|
|
43
|
+
return c.runKernel(h, s);
|
|
44
|
+
}
|
|
45
|
+
const N = /* @__PURE__ */ r({ log_: L });
|
|
46
|
+
/**
|
|
47
|
+
* @license
|
|
48
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
49
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
50
|
+
* you may not use this file except in compliance with the License.
|
|
51
|
+
* You may obtain a copy of the License at
|
|
52
|
+
*
|
|
53
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
54
|
+
*
|
|
55
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
56
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
57
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
58
|
+
* See the License for the specific language governing permissions and
|
|
59
|
+
* limitations under the License.
|
|
60
|
+
* =============================================================================
|
|
61
|
+
*/
|
|
62
|
+
function v(n, o = null, s = !1) {
|
|
63
|
+
const t = e(n, "x", "logSumExp"), a = E(o, t.shape), p = k(
|
|
64
|
+
t,
|
|
65
|
+
a,
|
|
66
|
+
!0
|
|
67
|
+
/* keepDims */
|
|
68
|
+
), i = S(t, p), f = b(i), m = w(f, a), u = N(m), x = _(l(p, u.shape), u);
|
|
69
|
+
if (s) {
|
|
70
|
+
const g = K(x.shape, a);
|
|
71
|
+
return l(x, g);
|
|
72
|
+
}
|
|
73
|
+
return x;
|
|
74
|
+
}
|
|
75
|
+
const I = /* @__PURE__ */ r({ logSumExp_: v });
|
|
76
|
+
/**
|
|
77
|
+
* @license
|
|
78
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
79
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
80
|
+
* you may not use this file except in compliance with the License.
|
|
81
|
+
* You may obtain a copy of the License at
|
|
82
|
+
*
|
|
83
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
84
|
+
*
|
|
85
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
86
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
87
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
88
|
+
* See the License for the specific language governing permissions and
|
|
89
|
+
* limitations under the License.
|
|
90
|
+
* =============================================================================
|
|
91
|
+
*/
|
|
92
|
+
function y(n, o = -1) {
|
|
93
|
+
const s = e(n, "logits", "softmax", "float32");
|
|
94
|
+
if (o === -1 && (o = s.rank - 1), o !== s.rank - 1)
|
|
95
|
+
throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${s.rank} and dim was ${o}`);
|
|
96
|
+
const t = { logits: s }, a = { dim: o };
|
|
97
|
+
return c.runKernel(d, t, a);
|
|
98
|
+
}
|
|
99
|
+
const M = /* @__PURE__ */ r({ softmax_: y });
|
|
100
|
+
export {
|
|
101
|
+
N as a,
|
|
102
|
+
b as e,
|
|
103
|
+
I as l,
|
|
104
|
+
M as s
|
|
105
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as
|
|
1
|
+
import { o as p, h as i, E as a, S as c } from "./index-pWA4_lUh.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -15,13 +15,11 @@ import { o as c, d as s, g as n, E as m, C as r } from "./index-YPKosni4.js";
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
* =============================================================================
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const t = { real: a, imag: e };
|
|
22
|
-
return m.runKernel(r, t);
|
|
18
|
+
function e(t, s, o = 0) {
|
|
19
|
+
const n = { x: i(t, "x", "split") }, r = { numOrSizeSplits: s, axis: o };
|
|
20
|
+
return a.runKernel(c, n, r);
|
|
23
21
|
}
|
|
24
|
-
const
|
|
22
|
+
const u = /* @__PURE__ */ p({ split_: e });
|
|
25
23
|
export {
|
|
26
|
-
|
|
24
|
+
u as s
|
|
27
25
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { o as e, i as c, j as n, E as i, P as k } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function u(r, t = 0) {
|
|
19
|
+
const s = c(r, "tensors", "stack", "string_or_numeric");
|
|
20
|
+
n(s.length >= 1, () => "Pass at least one tensor to tf.stack"), s.length > 0 && n(t <= s[0].rank, () => "Axis must be <= rank of the tensor");
|
|
21
|
+
const o = s, a = { axis: t };
|
|
22
|
+
return i.runKernel(k, o, a);
|
|
23
|
+
}
|
|
24
|
+
const l = /* @__PURE__ */ e({ stack_: u });
|
|
25
|
+
export {
|
|
26
|
+
l as s
|
|
27
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { o as c, h as i, E as a, T as f, U as m, V as p } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function d(e, n) {
|
|
19
|
+
for (let t = 0; t < e.length; ++t)
|
|
20
|
+
if (e[e.length - t - 1] !== n - 1 - t)
|
|
21
|
+
return !1;
|
|
22
|
+
return !0;
|
|
23
|
+
}
|
|
24
|
+
function x(e, n, t) {
|
|
25
|
+
const s = e.length + n.length, r = [];
|
|
26
|
+
let o = 0, l = 0;
|
|
27
|
+
for (let u = 0; u < s; u++)
|
|
28
|
+
t.indexOf(u) === -1 ? r.push(e[o++]) : r.push(n[l++]);
|
|
29
|
+
return r;
|
|
30
|
+
}
|
|
31
|
+
function S(e, n) {
|
|
32
|
+
const t = [], s = e.length;
|
|
33
|
+
for (let o = 0; o < s; o++)
|
|
34
|
+
n.indexOf(o) === -1 && t.push(e[o]);
|
|
35
|
+
const r = n.map((o) => e[o]);
|
|
36
|
+
return [t, r];
|
|
37
|
+
}
|
|
38
|
+
function A(e, n) {
|
|
39
|
+
const t = n.map((s) => 1);
|
|
40
|
+
return x(e, t, n);
|
|
41
|
+
}
|
|
42
|
+
function E(e, n) {
|
|
43
|
+
if (d(e, n))
|
|
44
|
+
return null;
|
|
45
|
+
const t = [];
|
|
46
|
+
for (let s = 0; s < n; ++s)
|
|
47
|
+
e.indexOf(s) === -1 && t.push(s);
|
|
48
|
+
return e.forEach((s) => t.push(s)), t;
|
|
49
|
+
}
|
|
50
|
+
function O(e) {
|
|
51
|
+
return e.map((n, t) => [t, n]).sort((n, t) => n[1] - t[1]).map((n) => n[0]);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @license
|
|
55
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
56
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
57
|
+
* you may not use this file except in compliance with the License.
|
|
58
|
+
* You may obtain a copy of the License at
|
|
59
|
+
*
|
|
60
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
61
|
+
*
|
|
62
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
63
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
64
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
65
|
+
* See the License for the specific language governing permissions and
|
|
66
|
+
* limitations under the License.
|
|
67
|
+
* =============================================================================
|
|
68
|
+
*/
|
|
69
|
+
function h(e, n = null, t = !1) {
|
|
70
|
+
const r = { x: i(e, "x", "max") }, o = { reductionIndices: n, keepDims: t };
|
|
71
|
+
return a.runKernel(f, r, o);
|
|
72
|
+
}
|
|
73
|
+
const T = /* @__PURE__ */ c({ max_: h });
|
|
74
|
+
/**
|
|
75
|
+
* @license
|
|
76
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
77
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
78
|
+
* you may not use this file except in compliance with the License.
|
|
79
|
+
* You may obtain a copy of the License at
|
|
80
|
+
*
|
|
81
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
82
|
+
*
|
|
83
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
84
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
85
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
86
|
+
* See the License for the specific language governing permissions and
|
|
87
|
+
* limitations under the License.
|
|
88
|
+
* =============================================================================
|
|
89
|
+
*/
|
|
90
|
+
function g(e, n = null, t = !1) {
|
|
91
|
+
let s = i(e, "x", "sum");
|
|
92
|
+
s.dtype === "bool" && (s = m(s, "int32"));
|
|
93
|
+
const r = { x: s }, o = { axis: n, keepDims: t };
|
|
94
|
+
return a.runKernel(p, r, o);
|
|
95
|
+
}
|
|
96
|
+
const b = /* @__PURE__ */ c({ sum_: g });
|
|
97
|
+
export {
|
|
98
|
+
O as a,
|
|
99
|
+
S as c,
|
|
100
|
+
A as e,
|
|
101
|
+
E as g,
|
|
102
|
+
T as m,
|
|
103
|
+
b as s
|
|
104
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { D as t, F as a } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function f(r, n, e) {
|
|
19
|
+
const o = t(r, e);
|
|
20
|
+
return a(r, n, o, e);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
f as t
|
|
24
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { y as t, D as s, F as a } from "./index-pWA4_lUh.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function i(n, r, o) {
|
|
19
|
+
if (t(n), r != null && r.length !== 2)
|
|
20
|
+
throw new Error("tensor2d() requires shape to have two numbers");
|
|
21
|
+
const e = s(n, o);
|
|
22
|
+
if (e.length !== 2 && e.length !== 1)
|
|
23
|
+
throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");
|
|
24
|
+
if (e.length === 1 && r == null)
|
|
25
|
+
throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");
|
|
26
|
+
return a(n, r, e, o);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as t
|
|
30
|
+
};
|
package/dist/tokeniser/bpe.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { default as EE } from 'eventemitter3';
|
|
2
|
+
import { ITokeniser } from './type';
|
|
3
|
+
export default class BPETokeniser extends EE<'trainStatus'> implements ITokeniser {
|
|
4
|
+
private targetSize;
|
|
2
5
|
private vocab;
|
|
3
6
|
private vocabIndex;
|
|
4
7
|
private merges;
|
|
5
8
|
private pretokenMap;
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
9
|
+
constructor(vocabSize: number);
|
|
10
|
+
constructor(vocab: string[], merges?: [string, string][]);
|
|
11
|
+
destroy(): void;
|
|
12
|
+
get trained(): boolean;
|
|
13
|
+
get vocabSize(): number;
|
|
14
|
+
get eosToken(): number;
|
|
15
|
+
train(text: string[]): Promise<number>;
|
|
8
16
|
getVocab(): string[];
|
|
9
|
-
getMerges(): [string, string][]
|
|
17
|
+
getMerges(): Promise<[string, string][]>;
|
|
10
18
|
private tokeniseWord;
|
|
11
19
|
private tokeniseStrings;
|
|
12
|
-
tokenise(text: string[], numeric: true): number[][]
|
|
13
|
-
tokenise(text: string[]): string[][]
|
|
20
|
+
tokenise(text: string[], numeric: true): Promise<number[][]>;
|
|
21
|
+
tokenise(text: string[]): Promise<string[][]>;
|
|
22
|
+
detokenise(tokens: number[][]): Promise<string[]>;
|
|
23
|
+
encode(text: string): Promise<number[]>;
|
|
24
|
+
decode(tokens: number[]): Promise<string>;
|
|
14
25
|
}
|
package/dist/tokeniser/bpe.js
CHANGED
|
@@ -1,100 +1,128 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import p from "../utilities/tokenParse.js";
|
|
2
|
+
import { E as g } from "../index-Dwqa6Zy2.js";
|
|
3
|
+
function u(o, e) {
|
|
4
|
+
return `${o}-::-${e}`;
|
|
5
|
+
}
|
|
6
|
+
function k(o) {
|
|
7
|
+
const e = /* @__PURE__ */ new Map();
|
|
8
|
+
for (let s = 0; s < o.length; s++) {
|
|
9
|
+
const t = o[s];
|
|
6
10
|
for (let n = 0; n < t.length - 1; n++) {
|
|
7
|
-
const
|
|
11
|
+
const r = u(t[n], t[n + 1]), a = e.get(r) || {
|
|
8
12
|
a: t[n],
|
|
9
13
|
b: t[n + 1],
|
|
10
14
|
count: 0,
|
|
11
15
|
instances: /* @__PURE__ */ new Set()
|
|
12
16
|
};
|
|
13
|
-
|
|
17
|
+
a.count += 1, a.instances.add(s), e.set(r, a);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
|
-
return { pairs:
|
|
20
|
+
return { pairs: e, tokens: o };
|
|
17
21
|
}
|
|
18
|
-
function h(
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
|
|
22
|
+
function h(o, e, s, t, n) {
|
|
23
|
+
const r = u(e, s);
|
|
24
|
+
if (o.pairs.has(r)) {
|
|
25
|
+
const a = o.pairs.get(r);
|
|
26
|
+
a.count += n, n > 0 ? a.instances.add(t) : a.count <= 0 ? o.pairs.delete(r) : a.instances.delete(t);
|
|
23
27
|
} else
|
|
24
|
-
|
|
28
|
+
o.pairs.set(r, { a: e, b: s, count: n, instances: /* @__PURE__ */ new Set([t]) });
|
|
25
29
|
}
|
|
26
|
-
function
|
|
27
|
-
let
|
|
28
|
-
for (const t of
|
|
29
|
-
t.count >
|
|
30
|
-
return
|
|
30
|
+
function b(o) {
|
|
31
|
+
let e = null, s = 0;
|
|
32
|
+
for (const t of o.pairs.values())
|
|
33
|
+
t.count > s && (s = t.count, e = t);
|
|
34
|
+
return e;
|
|
31
35
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
36
|
+
function d(o, e) {
|
|
37
|
+
return o.map((s) => {
|
|
34
38
|
const t = [];
|
|
35
|
-
for (let n = 0; n <
|
|
36
|
-
n <
|
|
39
|
+
for (let n = 0; n < s.length; n++)
|
|
40
|
+
n < s.length - 1 && s[n] === e[0] && s[n + 1] === e[1] ? (t.push(e[0] + e[1]), n++) : t.push(s[n]);
|
|
37
41
|
return t;
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const t =
|
|
43
|
-
for (let
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
n.push(
|
|
44
|
+
function m(o, e) {
|
|
45
|
+
e.instances.forEach((s) => {
|
|
46
|
+
const t = o.tokens[s], n = [];
|
|
47
|
+
for (let r = 0; r < t.length; r++)
|
|
48
|
+
if (r < t.length - 1 && t[r] === e.a && t[r + 1] === e.b) {
|
|
49
|
+
const a = e.a + e.b;
|
|
50
|
+
n.push(a), r > 0 && (h(o, t[r - 1], e.a, s, -1), h(o, t[r - 1], a, s, 1)), r++, r < t.length - 1 && (h(o, e.b, t[r + 1], s, -1), h(o, a, t[r + 1], s, 1));
|
|
47
51
|
} else
|
|
48
|
-
n.push(t[
|
|
49
|
-
|
|
50
|
-
}),
|
|
52
|
+
n.push(t[r]);
|
|
53
|
+
o.tokens[s] = n;
|
|
54
|
+
}), o.pairs.delete(u(e.a, e.b));
|
|
51
55
|
}
|
|
52
|
-
class w {
|
|
56
|
+
class w extends g {
|
|
57
|
+
targetSize;
|
|
53
58
|
vocab = /* @__PURE__ */ new Set();
|
|
54
59
|
vocabIndex = /* @__PURE__ */ new Map();
|
|
55
60
|
merges = [];
|
|
56
61
|
pretokenMap = /* @__PURE__ */ new Map();
|
|
57
|
-
constructor(
|
|
58
|
-
|
|
62
|
+
constructor(e, s) {
|
|
63
|
+
super(), Array.isArray(e) ? (e.forEach((t, n) => {
|
|
59
64
|
this.vocab.add(t), this.vocabIndex.set(t, n);
|
|
60
|
-
}),
|
|
65
|
+
}), s && (this.merges = s), this.targetSize = e.length) : (this.vocab.add("<eos>"), this.vocab.add("<unk>"), this.targetSize = e);
|
|
66
|
+
}
|
|
67
|
+
destroy() {
|
|
68
|
+
this.vocab.clear(), this.vocabIndex.clear(), this.merges = [], this.pretokenMap.clear();
|
|
69
|
+
}
|
|
70
|
+
get trained() {
|
|
71
|
+
return this.vocab.size === this.targetSize && this.merges.length > 0;
|
|
72
|
+
}
|
|
73
|
+
get vocabSize() {
|
|
74
|
+
return this.vocab.size;
|
|
61
75
|
}
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
get eosToken() {
|
|
77
|
+
return this.vocabIndex.get("<eos>") ?? 0;
|
|
78
|
+
}
|
|
79
|
+
async train(e) {
|
|
80
|
+
const s = e.map((i) => p(i)).flat(1), t = new Set(s);
|
|
64
81
|
this.vocab = /* @__PURE__ */ new Set(), this.pretokenMap.clear(), this.merges = [], this.vocab.add("<eos>");
|
|
65
|
-
const
|
|
66
|
-
for (; this.vocab.size <
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
82
|
+
const n = Array.from(t), r = n.map((i) => Array.from(i).map((c) => (this.vocab.add(c), c))), a = k(r);
|
|
83
|
+
for (; this.vocab.size < this.targetSize && this.merges.length < this.targetSize; ) {
|
|
84
|
+
const i = b(a);
|
|
85
|
+
if (!i)
|
|
69
86
|
break;
|
|
70
|
-
this.merges.push([
|
|
87
|
+
this.merges.push([i.a, i.b]), this.vocab.add(i.a + i.b), m(a, i);
|
|
71
88
|
}
|
|
72
|
-
|
|
73
|
-
const c =
|
|
74
|
-
this.pretokenMap.set(
|
|
89
|
+
n.forEach((i, l) => {
|
|
90
|
+
const c = r[l];
|
|
91
|
+
this.pretokenMap.set(i, c);
|
|
75
92
|
}), this.vocabIndex.clear();
|
|
76
|
-
let
|
|
77
|
-
for (const
|
|
78
|
-
this.vocabIndex.set(
|
|
93
|
+
let f = 0;
|
|
94
|
+
for (const i of this.vocab.keys())
|
|
95
|
+
this.vocabIndex.set(i, f++);
|
|
96
|
+
return this.vocab.size;
|
|
79
97
|
}
|
|
80
98
|
getVocab() {
|
|
81
99
|
return Array.from(this.vocab);
|
|
82
100
|
}
|
|
83
|
-
getMerges() {
|
|
101
|
+
async getMerges() {
|
|
84
102
|
return this.merges;
|
|
85
103
|
}
|
|
86
|
-
tokeniseWord(
|
|
87
|
-
let
|
|
104
|
+
tokeniseWord(e) {
|
|
105
|
+
let s = Array.from(e);
|
|
88
106
|
return this.merges.forEach((t) => {
|
|
89
|
-
|
|
90
|
-
}), this.pretokenMap.set(
|
|
107
|
+
s = d([s], t)[0];
|
|
108
|
+
}), this.pretokenMap.set(e, s), s;
|
|
109
|
+
}
|
|
110
|
+
tokeniseStrings(e) {
|
|
111
|
+
return e.map((s) => p(s).map((r) => this.pretokenMap.has(r) ? this.pretokenMap.get(r) : this.tokeniseWord(r)).flat(1));
|
|
112
|
+
}
|
|
113
|
+
async tokenise(e, s) {
|
|
114
|
+
const t = this.tokeniseStrings(e);
|
|
115
|
+
return s ? t.map((n) => n.map((r) => this.vocabIndex.get(r) ?? -1)) : t;
|
|
116
|
+
}
|
|
117
|
+
async detokenise(e) {
|
|
118
|
+
const s = this.getVocab();
|
|
119
|
+
return e.map((n) => n.map((r) => s[r]).join(""));
|
|
91
120
|
}
|
|
92
|
-
|
|
93
|
-
return
|
|
121
|
+
async encode(e) {
|
|
122
|
+
return (await this.tokenise([e], !0))[0];
|
|
94
123
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return e ? t.map((n) => n.map((o) => this.vocabIndex.get(o) ?? -1)) : t;
|
|
124
|
+
async decode(e) {
|
|
125
|
+
return (await this.detokenise([e]))[0];
|
|
98
126
|
}
|
|
99
127
|
}
|
|
100
128
|
export {
|
package/dist/training/AdamExt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as r,
|
|
1
|
+
import { A as r, b as c, f as h, s as g, e as o } from "../index-pWA4_lUh.js";
|
|
2
2
|
class u extends r {
|
|
3
3
|
constructor(t, e, s, a, i) {
|
|
4
4
|
super(t, e, s, a), this.config = i, this.startLearningRate = t;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { Tensor } from '@tensorflow/tfjs-core';
|
|
1
2
|
import { ITokeniser } from '../tokeniser/type';
|
|
2
|
-
import {
|
|
3
|
+
import { Dataset } from '@tensorflow/tfjs-data';
|
|
3
4
|
export declare class DatasetBuilder {
|
|
4
5
|
tokenizer: ITokeniser;
|
|
5
6
|
blockSize: number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ys: TF.Tensor;
|
|
7
|
+
constructor(tokenizer: ITokeniser, blockSize?: number);
|
|
8
|
+
createTextDataset(textData: string[], batchSize?: number, start?: number, end?: number): Promise<Dataset<{
|
|
9
|
+
xs: Tensor;
|
|
10
|
+
ys: Tensor;
|
|
11
11
|
}>>;
|
|
12
12
|
}
|