@mineproness/tensorloop 2.1.58 → 2.1.59
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/package.json +1 -1
- package/src/Linear/index.js +1 -1
- package/src/getVec.js +16 -14
package/package.json
CHANGED
package/src/Linear/index.js
CHANGED
|
@@ -42,7 +42,7 @@ export class Linear {
|
|
|
42
42
|
let total = embeddingSize * vocabSize;
|
|
43
43
|
if (configs && configs.save) {
|
|
44
44
|
const w = getVector(configs.save.filename[0], total);
|
|
45
|
-
const b = getVector(configs.save.filename[1],
|
|
45
|
+
const b = getVector(configs.save.filename[1], vocabSize, true)
|
|
46
46
|
if (!w && !b) {
|
|
47
47
|
this.bias = GenerateBias(vocabSize)
|
|
48
48
|
this.weights = GenerateVectors(embeddingSize, vocabSize)
|
package/src/getVec.js
CHANGED
|
@@ -5,21 +5,23 @@ export function getVector(filename, size, bias) {
|
|
|
5
5
|
if (!fs.existsSync(filename)) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
const r = new Float32Array(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}else{
|
|
17
|
-
output[a] = bias ? 0 : (Math.random() * 2 - 1) * 0.02
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
return r
|
|
8
|
+
const buffer = fs.readFileSync(filename);
|
|
9
|
+
const r = new Float32Array(
|
|
10
|
+
buffer.buffer,
|
|
11
|
+
buffer.byteOffset,
|
|
12
|
+
buffer.byteLength / 4
|
|
13
|
+
);
|
|
14
|
+
if (r.length >= size) {
|
|
15
|
+
return r;
|
|
22
16
|
}
|
|
17
|
+
const output = new Float32Array(size);
|
|
18
|
+
output.set(r);
|
|
19
|
+
if (!bias) {
|
|
20
|
+
for (let i = r.length; i < size; i++) {
|
|
21
|
+
output[i] = (Math.random() * 2 - 1) * 0.02;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return output;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export function SaveVector(filename, vectors) {
|