kuromi: add sanity checks/demo multiple thoughts
btw in last commit sam meant "demo" not "demi"
This commit is contained in:
parent
4312ee1116
commit
5e9e138be0
1 changed files with 48 additions and 17 deletions
|
@ -118,20 +118,44 @@ let targets = [
|
|||
[6]
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Example dataset (XOR problem)
|
||||
let strings2 = ["i'm", "fine", "myself."]
|
||||
|
||||
let inputs2 = [
|
||||
[0, 0, 0],
|
||||
[1, 0, 0],
|
||||
[1, 0, 1],
|
||||
[1, 1, 1]
|
||||
];
|
||||
|
||||
let nn2 = new NeuralNetwork(strings2.length, inputs2.length, 1); // Increased hidden nodes to 4
|
||||
|
||||
let targets2 = [
|
||||
[0],
|
||||
[1],
|
||||
[2],
|
||||
[3]
|
||||
];
|
||||
|
||||
|
||||
// Training the neural network
|
||||
function train(nn, inputs, targets) {
|
||||
if (targets.length != inputs.length) {
|
||||
throw new Error("You dummy, targets length should be equal to inputs length.")
|
||||
}
|
||||
|
||||
// Training the neural network
|
||||
for (let i = 0; i < 50000; i++) { // Increased training iterations
|
||||
let index = Math.floor(Math.random() * 4);
|
||||
nn.train(inputs[index], targets[index]);
|
||||
}
|
||||
|
||||
// Testing the neural network
|
||||
let feeds = inputs;
|
||||
}
|
||||
|
||||
|
||||
function think(nn, feeds, strings) {
|
||||
if (strings.length != feeds[0].length) {
|
||||
throw new Error("You dummy, strings array length should be equal to a feed input length.")
|
||||
}
|
||||
feeds.forEach((item, index) => {
|
||||
let feededVal = Math.round(nn.feedforward(item))
|
||||
console.log([feededVal, item])
|
||||
|
@ -140,5 +164,12 @@ let sum = 0;
|
|||
item.forEach(num => sum += num);
|
||||
try { console.log(strings[sum - 1]) } catch {}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
train(nn, inputs, targets)
|
||||
think(nn, inputs, strings)
|
||||
|
||||
train(nn2, inputs2, targets2)
|
||||
think(nn2, inputs2, strings2)
|
||||
|
||||
|
|
Loading…
Reference in a new issue