@mineproness/tensorloop 2.1.45 → 2.1.47

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": "2.1.45",
3
+ "version": "2.1.47",
4
4
  "description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called Tensorloop.",
5
5
  "keywords": [
6
6
  "ai",
@@ -6,6 +6,6 @@ export class Embedding{
6
6
  }
7
7
  })
8
8
  forward(token: number | number[]) : Float32Array[] | Float32Array[][]
9
- backward(token: number , inputGradient: number[] | Float32Array[], learingRate: number) : void
9
+ backward(inputGradient: number[] | Float32Array[], learingRate: number) : void
10
10
  Save() : void
11
11
  }
@@ -37,22 +37,17 @@ export default class Model {
37
37
  activation: configs.activation
38
38
  })
39
39
  }
40
- train(text = "", batchSize = 5000, batchExecution = 0, epochs = 500, learningRate = 0.01) {
40
+ train(text = "", epochs = 500, learningRate = 0.01) {
41
41
  process.stdout.write("\x1Bc")
42
42
  console.log("Preparing Training Pairs....")
43
- const tokens = text.split(/\r?n/).map((e) => e.trim()).filter((e) => e.length > 0).map((e)=> e + " <EOS>").map((e) => this.tokenizer.encoder(e).tokenIDs).flat()
44
- const trainingPairs2 = []
43
+ const tokens = text.split(/\r?\n/).map((e) => e.trim()).filter((e) => e.length > 0).map((e)=> e + " <EOS>").map((e) => this.tokenizer.encoder(e).tokenIDs).flat()
44
+ const trainingPair = []
45
45
  for (let a = 0; a + this.contextSize < tokens.length; a++) {
46
- trainingPairs2.push({
46
+ trainingPair.push({
47
47
  inputIDX: tokens.slice(a, a + this.contextSize),
48
48
  targetIDX: tokens.slice(a + 1, a + this.contextSize + 1)
49
49
  })
50
50
  }
51
- const trainingPairs = []
52
- for (let a = 0; a < trainingPairs2.length; batchSize++) {
53
- trainingPairs.push(trainingPairs2.slice(a, a + batchSize))
54
- }
55
- const trainingPair = trainingPairs[batchExecution]
56
51
  let firstRun = true;
57
52
  console.log(`TotalPairs: ${trainingPair.length}`)
58
53
  if (trainingPair.length == 0 || !trainingPair) throw new Error(`The Batch Execution ${batchExecution} is doesn't exist.`);
@@ -67,17 +62,18 @@ export default class Model {
67
62
  vector = this.block2.forward(vector)
68
63
  const logits = this.linear.forward(vector)
69
64
  const probs = this.softmax.forward(logits)
70
- const loss = this.softmax.crossEntropy(probs, target)
65
+ const loss = this.softmax.crossEntropy(probs, target)[0]
71
66
  const dLogits = this.softmax.backward(probs, target)
72
67
  totalLoss += loss;
73
68
  let dOutput = this.linear.backward(dLogits, learningRate);
74
69
  dOutput = this.block2.backward(dOutput, learningRate)
75
70
  dOutput = this.block1.backward(dOutput, learningRate)
76
71
  this.posEmbedding.backward(dOutput, learningRate)
77
- this.embedding.backward(input, dOutput, learningRate)
72
+ this.embedding.backward(dOutput, learningRate)
78
73
  if (firstRun) {
79
74
  firstRun = null;
80
75
  console.log("")
76
+ console.log("")
81
77
  }
82
78
  const percentense = (((a + 1) / trainingPair.length) * 100).toFixed(2)
83
79
  const filted = Math.round((percentense / 100) * 20);
@@ -27,22 +27,23 @@ export class PositionEmbedding {
27
27
  this.vectors = LoadVectors(configs.save.filename, embeddingSize)
28
28
  } else {
29
29
  this.vectors = GenerateVectors(embeddingSize, vocabSize)
30
- this.Save()
30
+ SaveVectors(this.vectors, this.configs.save.filename)
31
+
31
32
  }
32
33
  } else {
33
34
  this.vectors = GenerateVectors(embeddingSize, vocabSize)
34
- this.gpu = new GPUPosition(this.vectors, embeddingSize, vocabSize)
35
35
  }
36
+ this.gpu = new GPUPosition(this.vectors, embeddingSize, vocabSize)
36
37
  }
37
38
  forward(vec) {
38
39
  return this.gpu.forward(vec)
39
40
  }
40
41
  backward(inputGradient, learingRate) {
41
- this.gpu.backward(inputGradient, learingRate)
42
+ this.gpu.backward(inputGradient, learingRate)
42
43
  }
43
44
  Save() {
44
45
  const save = this.gpu.Save()
45
46
  SaveVectors(save, this.configs.save.filename)
46
-
47
+
47
48
  }
48
49
  }