@mineproness/tensorloop 1.5.9 → 2.0.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/SelfAttention/index.js +10 -4
- package/src/Softmax/index.d.ts +1 -1
package/package.json
CHANGED
|
@@ -22,9 +22,9 @@ export class SelfAttention {
|
|
|
22
22
|
this.value = new Linear(embeddingSize, embeddingSize, { save: { filename: [`${configs.dirname}/value.bin`, `${configs.dirname}/valueBias.bin`] } })
|
|
23
23
|
}
|
|
24
24
|
forward(vectors) {
|
|
25
|
-
this.q =
|
|
26
|
-
this.v =
|
|
27
|
-
this.k =
|
|
25
|
+
this.q = this.query.forward(vectors)
|
|
26
|
+
this.v = this.value.forward(vectors)
|
|
27
|
+
this.k = this.key.forward(vectors)
|
|
28
28
|
const attentionSocres = []
|
|
29
29
|
for (let i = 0; i < this.q.length; i++) {
|
|
30
30
|
attentionSocres[i] = new Float32Array(this.k.length);
|
|
@@ -44,7 +44,8 @@ export class SelfAttention {
|
|
|
44
44
|
attentionSocres[i][j] = dot / this.score;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
this.softmax.forward(attentionSocres)
|
|
48
|
+
const weights = this.softmax.getSoftmaxes()
|
|
48
49
|
this.weights = weights
|
|
49
50
|
const output = [];
|
|
50
51
|
|
|
@@ -123,4 +124,9 @@ export class SelfAttention {
|
|
|
123
124
|
this.key.Save()
|
|
124
125
|
this.value.Save()
|
|
125
126
|
}
|
|
127
|
+
ClearInputCache(){
|
|
128
|
+
this.query.ClearInputCache()
|
|
129
|
+
this.key.ClearInputCache()
|
|
130
|
+
this.value.ClearInputCache()
|
|
131
|
+
}
|
|
126
132
|
}
|
package/src/Softmax/index.d.ts
CHANGED