@mineproness/tensorloop 1.2.9 → 1.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/package.json +1 -1
- package/src/Linear/index.js +16 -16
- package/src.zip +0 -0
package/package.json
CHANGED
package/src/Linear/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoadBias,LoadVectors,SaveBias,SaveVectors } from '../GetConfigs.js'
|
|
1
|
+
import { LoadBias, LoadVectors, SaveBias, SaveVectors } from '../GetConfigs.js'
|
|
2
2
|
import { existsSync } from 'fs'
|
|
3
3
|
function GenerateWeightsBias(embeddingSize, vocabSize) {
|
|
4
4
|
const vectors = []
|
|
@@ -30,8 +30,8 @@ export class Linear {
|
|
|
30
30
|
const { vectors, Bias } = GenerateWeightsBias(embeddingSize, vocabSize)
|
|
31
31
|
this.Weights = vectors;
|
|
32
32
|
this.Bias = Bias;
|
|
33
|
-
SaveVectors(
|
|
34
|
-
SaveBias(this.Bias,configs.save.filename[1])
|
|
33
|
+
SaveVectors(this.Weights, configs.save.filename[0])
|
|
34
|
+
SaveBias(this.Bias, configs.save.filename[1])
|
|
35
35
|
}
|
|
36
36
|
} else {
|
|
37
37
|
const { vectors, Bias } = GenerateWeightsBias(embeddingSize, vocabSize)
|
|
@@ -40,7 +40,7 @@ export class Linear {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
Save() {
|
|
43
|
-
SaveVectors(this.Weights,this.configs.save.filename[0])
|
|
43
|
+
SaveVectors(this.Weights, this.configs.save.filename[0])
|
|
44
44
|
SaveBias(this.Bias, this.configs.save.filename[1])
|
|
45
45
|
}
|
|
46
46
|
forward(input) {
|
|
@@ -55,19 +55,19 @@ export class Linear {
|
|
|
55
55
|
}
|
|
56
56
|
return output
|
|
57
57
|
}
|
|
58
|
-
backward(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (let at = 0; at < input.length; at++) {
|
|
66
|
-
inputGradient[at] += gran * w[at]
|
|
67
|
-
w[at] -= learningRate * input[at] * gran
|
|
58
|
+
backward(dOut, lr, stepIndex) {
|
|
59
|
+
let dIn = new Float32Array(this.input[stepIndex]);
|
|
60
|
+
for (let i = 0; i < this.inputDim; i++) {
|
|
61
|
+
let gradSum = 0;
|
|
62
|
+
for (let j = 0; j < this.outputDim; j++) {
|
|
63
|
+
gradSum += dOut[j] * this.weights[i][j];
|
|
64
|
+
this.weights[i][j] -= lr * dOut[j] * this.input[stepIndex][i];
|
|
68
65
|
}
|
|
69
|
-
|
|
66
|
+
dIn[i] = gradSum;
|
|
70
67
|
}
|
|
71
|
-
|
|
68
|
+
for (let j = 0; j < this.outputDim; j++) {
|
|
69
|
+
this.bias[j] -= lr * dOut[j];
|
|
70
|
+
}
|
|
71
|
+
return dIn;
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src.zip
ADDED
|
Binary file
|