appvoid commited on
Commit
c6ec9c9
·
verified ·
1 Parent(s): 9bfdf90

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +10 -27
index.html CHANGED
@@ -326,7 +326,6 @@
326
  this.activations = [];
327
  this.details = {};
328
  this.debug = debug;
329
- this.fewShotSamples = [];
330
  }
331
 
332
  // Add a new layer to the neural network
@@ -393,16 +392,6 @@
393
  }
394
  }
395
 
396
- // Generate few-shot samples
397
- generateFewShotSamples(trainSet, numSamples = 10) {
398
- const fewShotSamples = [];
399
- for (let i = 0; i < numSamples; i++) {
400
- const randomIndex = Math.floor(Math.random() * trainSet.length);
401
- fewShotSamples.push(trainSet[randomIndex]);
402
- }
403
- return fewShotSamples;
404
- }
405
-
406
  // Positional Encoding
407
  positionalEncoding(input, maxLen) {
408
  const pe = new Array(maxLen).fill(0).map((_, pos) => {
@@ -451,6 +440,13 @@
451
  return output;
452
  }
453
 
 
 
 
 
 
 
 
454
  // Train the neural network
455
  async train(trainSet, options = {}) {
456
  const {
@@ -471,10 +467,6 @@
471
  }
472
  let lastTrainLoss = 0;
473
  let lastTestLoss = null;
474
- let lastFewShotLoss = null;
475
-
476
- // Generate few-shot samples
477
- this.fewShotSamples = this.generateFewShotSamples(trainSet);
478
 
479
  for (let epoch = 0; epoch < epochs; epoch++) {
480
  let trainError = 0;
@@ -549,23 +541,15 @@
549
  lastTestLoss = testError / testSet.length;
550
  }
551
 
552
- // Evaluate on few-shot samples
553
- let fewShotError = 0;
554
- for (const data of this.fewShotSamples) {
555
- const prediction = this.predict(data.input);
556
- fewShotError += Math.abs(data.output[0] - prediction[0]);
557
- }
558
- lastFewShotLoss = fewShotError / this.fewShotSamples.length;
559
-
560
  if ((epoch + 1) % printEveryEpochs === 0 && this.debug === true) {
561
- console.log(`Epoch ${epoch + 1}, Train Loss: ${lastTrainLoss.toFixed(6)}${testSet ? `, Test Loss: ${lastTestLoss.toFixed(6)}` : ''}, Few-Shot Loss: ${lastFewShotLoss.toFixed(6)}`);
562
  }
563
  if (callback) {
564
- await callback(epoch + 1, lastTrainLoss, lastTestLoss, lastFewShotLoss);
565
  }
566
  await new Promise(resolve => setTimeout(resolve, 0));
567
  if (lastTrainLoss < earlyStopThreshold) {
568
- console.log(`We stopped at epoch ${epoch + 1} with train loss: ${lastTrainLoss.toFixed(6)}${testSet ? ` and test loss: ${lastTestLoss.toFixed(6)}` : ''} and few-shot loss: ${lastFewShotLoss.toFixed(6)}`);
569
  break;
570
  }
571
  }
@@ -579,7 +563,6 @@
579
  const trainingSummary = {
580
  trainLoss: lastTrainLoss,
581
  testLoss: lastTestLoss,
582
- fewShotLoss: lastFewShotLoss,
583
  parameters: totalParams,
584
  training: {
585
  time: end - start,
 
326
  this.activations = [];
327
  this.details = {};
328
  this.debug = debug;
 
329
  }
330
 
331
  // Add a new layer to the neural network
 
392
  }
393
  }
394
 
 
 
 
 
 
 
 
 
 
 
395
  // Positional Encoding
396
  positionalEncoding(input, maxLen) {
397
  const pe = new Array(maxLen).fill(0).map((_, pos) => {
 
440
  return output;
441
  }
442
 
443
+ // Layer Normalization
444
+ layerNormalization(input) {
445
+ const mean = input.reduce((sum, val) => sum + val, 0) / input.length;
446
+ const variance = input.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / input.length;
447
+ return input.map(val => (val - mean) / Math.sqrt(variance + 1e-5));
448
+ }
449
+
450
  // Train the neural network
451
  async train(trainSet, options = {}) {
452
  const {
 
467
  }
468
  let lastTrainLoss = 0;
469
  let lastTestLoss = null;
 
 
 
 
470
 
471
  for (let epoch = 0; epoch < epochs; epoch++) {
472
  let trainError = 0;
 
541
  lastTestLoss = testError / testSet.length;
542
  }
543
 
 
 
 
 
 
 
 
 
544
  if ((epoch + 1) % printEveryEpochs === 0 && this.debug === true) {
545
+ console.log(`Epoch ${epoch + 1}, Train Loss: ${lastTrainLoss.toFixed(6)}${testSet ? `, Test Loss: ${lastTestLoss.toFixed(6)}` : ''}`);
546
  }
547
  if (callback) {
548
+ await callback(epoch + 1, lastTrainLoss, lastTestLoss);
549
  }
550
  await new Promise(resolve => setTimeout(resolve, 0));
551
  if (lastTrainLoss < earlyStopThreshold) {
552
+ console.log(`We stopped at epoch ${epoch + 1} with train loss: ${lastTrainLoss.toFixed(6)}${testSet ? ` and test loss: ${lastTestLoss.toFixed(6)}` : ''}`);
553
  break;
554
  }
555
  }
 
563
  const trainingSummary = {
564
  trainLoss: lastTrainLoss,
565
  testLoss: lastTestLoss,
 
566
  parameters: totalParams,
567
  training: {
568
  time: end - start,