brain.js doing nothing when running the code

138 views Asked by At

So guys, I'm running some tests using brain.js, I got this code from different examples, but when I try to run it, nothing happens, there is no response. I already tried to wait few time to see if it would come up with a response, but seems to be doing nothing..

import brain from 'brain.js'

const net = new brain.recurrent.LSTM();
net.train([
    { input: "my unit-tests failed.", output: "software" },
    { input: "tried the program, but it was buggy.", output: "software" },
    { input: "i need a new power supply.", output: "hardware" },
    { input: "the drive has a 2TB capacity.", output: "hardware" },
    { input: "unit-tests", output: "software" },
    { input: "program", output: "software" },
    { input: "power supply", output: "hardware" },
    { input: "drive", output: "hardware" },
]);

console.log("output = " + net.run("drive"));

I don't think this is a problem related to the code because as I said, I saw like 3 different examples running almost the same code, just changing the data, and it is not working for me. What can be the problem?

1

There are 1 answers

0
Corwin On

Try to add config to your training.

The following code works for me just fine. I saw that the error value just get stuck round about 0.01 and it never reaches the default "errorThresh" of 0.005. Which leads to many many iterations in training.

const brain = require('brain.js');

const data = [
    { input: "my unit-tests failed.", output: "software" },
    { input: "tried the program, but it was buggy.", output: "software" },
    { input: "i need a new power supply.", output: "hardware" },
    { input: "the drive has a 2TB capacity.", output: "hardware" },
    { input: "unit-tests", output: "software" },
    { input: "program", output: "software" },
    { input: "power supply", output: "hardware" },
    { input: "drive", output: "hardware" },
];

const config = {
    log: true,
    logPeriod: 1,
    errorThresh: 0.02,
};

const net = new brain.recurrent.LSTM();
net.train(data, config);

console.log("output = " + net.run("drive"));