@mineproness/tensorloop 1.4.7 → 1.4.8

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.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "The most powerfull Machine Learning Library for AI.",
5
5
  "keywords": [
6
6
  "ai",
@@ -18,62 +18,42 @@ export class TransformerBlock {
18
18
  normal1[a] = this.norm1.forward(input[a], a)
19
19
  }
20
20
  const attention = this.selfAttention.forward(normal1)
21
- const residual1 = []
22
- for (let a = 0; a < input.length; a++) {
23
- residual1[a] = new Float32Array(input[0].length)
24
- for (let i = 0; i < input[0].length; i++) {
25
- residual1[a][i] = input[a][i] + attention[a][i]
26
- }
27
- }
28
21
  const normal2 = []
29
- for (let a = 0; a < input.length; a++) {
30
- normal2[a] = this.norm2.forward(residual1[a], a)
31
- }
32
- const ffnOutput = this.ffn.forward(normal2)
33
- const output = []
34
- for (let g = 0; g < residual1.length; g++) {
35
- output[g] = new Float32Array(residual1[0].length)
36
- for (let a = 0; a < output[0].length; a++) {
37
- output[g][a] = residual1[g][a] + ffnOutput[g][a]
38
- }
22
+ for (let a = 0; a < attention.length; a++) {
23
+ normal2[a] = this.norm2.forward(attention[a], a)
39
24
  }
40
- return output
25
+ return this.ffn.forward(normal2)
41
26
  }
42
27
  backward(dOutput, learningRate) {
43
- const dFFN = this.ffn.backward(dOutput, learningRate)
44
- const dResidual1 = []
28
+ const dFFN =
29
+ this.ffn.backward(dOutput, learningRate)
30
+
31
+ const dAttentionInput = []
32
+
45
33
  for (let a = 0; a < dFFN.length; a++) {
46
- const dNorm2 = this.norm2.backward(
47
- dFFN[a],
48
- learningRate,
49
- a
50
- )
51
- dResidual1[a] = new Float32Array(dOutput[a].length)
52
- for (let i = 0; i < dOutput[a].length; i++) {
53
- dResidual1[a][i] =
54
- dOutput[a][i] + dNorm2[i]
55
- }
34
+ dAttentionInput[a] =
35
+ this.norm2.backward(
36
+ dFFN[a],
37
+ learningRate,
38
+ a
39
+ )
56
40
  }
57
- const dAttention = this.selfAttention.backward(
58
- dResidual1,
59
- learningRate
60
- )
61
- const dInputFromAttention = []
62
- for (let a = 0; a < dAttention.length; a++) {
63
- dInputFromAttention[a] = this.norm1.backward(
64
- dAttention[a],
65
- learningRate,
66
- a
41
+
42
+ const dAttention =
43
+ this.selfAttention.backward(
44
+ dAttentionInput,
45
+ learningRate
67
46
  )
68
- }
47
+
69
48
  const dInput = []
70
- for (let a = 0; a < dOutput.length; a++) {
71
- dInput[a] = new Float32Array(dOutput[a].length)
72
- for (let i = 0; i < dOutput[a].length; i++) {
73
- dInput[a][i] =
74
- dOutput[a][i] +
75
- dInputFromAttention[a][i]
76
- }
49
+
50
+ for (let a = 0; a < dAttention.length; a++) {
51
+ dInput[a] =
52
+ this.norm1.backward(
53
+ dAttention[a],
54
+ learningRate,
55
+ a
56
+ )
77
57
  }
78
58
 
79
59
  return dInput