@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mineproness/tensorloop",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "description": "The most powerfull Machine Learning Library for AI.",
5
5
  "keywords": [
6
6
  "ai",
@@ -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( this.Weights,configs.save.filename[0])
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(outputGradient, learningRate, idx) {
59
- const input = this.input[idx];
60
- const weights = this.Weights
61
- const inputGradient = new Float32Array(input.length)
62
- for (let a = 0; a < weights.length; a++) {
63
- const gran = outputGradient[a]
64
- const w = weights[a]
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
- this.Bias[a] -= learningRate * gran
66
+ dIn[i] = gradSum;
70
67
  }
71
- return inputGradient
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