@genai-fi/nanogpt 0.12.1 → 0.12.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.
- package/dist/tokeniser/bpe.js +11 -11
- package/package.json +1 -1
package/dist/tokeniser/bpe.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import p from "../utilities/tokenParse.js";
|
|
2
|
+
import f, { SPECIALS as g } from "./BaseTokeniser.js";
|
|
3
3
|
function u(o, e) {
|
|
4
4
|
return `${o}-::-${e}`;
|
|
5
5
|
}
|
|
@@ -53,7 +53,7 @@ function v(o, e) {
|
|
|
53
53
|
o.tokens[s] = n;
|
|
54
54
|
}), o.pairs.delete(u(e.a, e.b));
|
|
55
55
|
}
|
|
56
|
-
class x extends
|
|
56
|
+
class x extends f {
|
|
57
57
|
targetSize;
|
|
58
58
|
vocab = /* @__PURE__ */ new Set();
|
|
59
59
|
vocabIndex = /* @__PURE__ */ new Map();
|
|
@@ -62,7 +62,7 @@ class x extends d {
|
|
|
62
62
|
constructor(e, s) {
|
|
63
63
|
super(), Array.isArray(e) ? (e.forEach((t, n) => {
|
|
64
64
|
this.vocab.add(t), this.vocabIndex.set(t, n);
|
|
65
|
-
}), s && (this.merges = s), this.targetSize = e.length,
|
|
65
|
+
}), s && (this.merges = s), this.targetSize = e.length, g.forEach((t) => {
|
|
66
66
|
const n = e.indexOf(t);
|
|
67
67
|
n !== -1 && this.addSpecialToken(t, n);
|
|
68
68
|
})) : (this.addSpecialTokens(), this.targetSize = e);
|
|
@@ -80,7 +80,7 @@ class x extends d {
|
|
|
80
80
|
this.vocab.clear(), this.vocabIndex.clear(), this.merges = [], this.pretokenMap.clear();
|
|
81
81
|
}
|
|
82
82
|
get trained() {
|
|
83
|
-
return this.vocab.size
|
|
83
|
+
return this.vocab.size > g.length && this.vocab.size <= this.targetSize && this.merges.length > 0;
|
|
84
84
|
}
|
|
85
85
|
get vocabSize() {
|
|
86
86
|
return this.vocab.size;
|
|
@@ -95,7 +95,7 @@ class x extends d {
|
|
|
95
95
|
return this.vocabIndex.get("") ?? 1;
|
|
96
96
|
}
|
|
97
97
|
async train(e) {
|
|
98
|
-
const s = e.map((a) =>
|
|
98
|
+
const s = e.map((a) => p(a)).flat(1), t = new Set(s);
|
|
99
99
|
this.vocab = /* @__PURE__ */ new Set(), this.pretokenMap.clear(), this.merges = [], this.addSpecialTokens();
|
|
100
100
|
const n = Array.from(t), r = n.map((a) => Array.from(a).map((c) => (this.vocab.add(c), c))), i = b(r);
|
|
101
101
|
for (; this.vocab.size < this.targetSize && this.merges.length < this.targetSize; ) {
|
|
@@ -104,13 +104,13 @@ class x extends d {
|
|
|
104
104
|
break;
|
|
105
105
|
this.merges.push([a.a, a.b]), this.vocab.add(a.a + a.b), v(i, a);
|
|
106
106
|
}
|
|
107
|
-
n.forEach((a,
|
|
108
|
-
const c = r[
|
|
107
|
+
n.forEach((a, l) => {
|
|
108
|
+
const c = r[l];
|
|
109
109
|
this.pretokenMap.set(a, c);
|
|
110
110
|
}), this.vocabIndex.clear();
|
|
111
|
-
let
|
|
111
|
+
let d = 0;
|
|
112
112
|
for (const a of this.vocab.keys())
|
|
113
|
-
this.vocabIndex.set(a,
|
|
113
|
+
this.vocabIndex.set(a, d++);
|
|
114
114
|
return this.emit("trainStatus", "trained"), this.vocab.size;
|
|
115
115
|
}
|
|
116
116
|
getVocab() {
|
|
@@ -126,7 +126,7 @@ class x extends d {
|
|
|
126
126
|
}), this.pretokenMap.set(e, s), s;
|
|
127
127
|
}
|
|
128
128
|
tokeniseStrings(e) {
|
|
129
|
-
return e.map((s) =>
|
|
129
|
+
return e.map((s) => p(s).map((r) => this.pretokenMap.has(r) ? this.pretokenMap.get(r) : this.tokeniseWord(r)).flat(1));
|
|
130
130
|
}
|
|
131
131
|
tokenise(e, s) {
|
|
132
132
|
const t = this.tokeniseStrings(e);
|