0

I'm new to brain js and I'm trying to make it predict if a combination of words is a complete sentence. https://codepen.io/AtanasBobev/pen/zQzZrP?editors=0010

    const config = {
    hiddenLayers: [3]
};

const net = new brain.NeuralNetwork(config);

net.train([{input: ["Hello, I'm John Walker."], output: [1]},
           {input: ["This is on you!"], output: [1]},
           {input: ["Who are you?"], output: [1]},
             {input: ["Let's go."], output: [1]},
           {input: ["John kik"], output: [0]},
           {input: ["This is"], output: [0]}
          ]);

const output = net.run(["I'm Stil."]);  

alert(output);
//Output: NaN

I know that the data is not enough for a good prediction, but still I expect a value between 0-1 . What can the problem be?

  • Apparently, `brain.js` only understands numeric data. But it can be trained to represent each character as a neuron in the net. See [this example](https://stackoverflow.com/questions/37043598/use-brain-js-neural-network-to-do-text-analysis). – tao May 17 '19 at 18:51
  • Possible duplicate of [Use brain.js neural network to do text analysis](https://stackoverflow.com/questions/37043598/use-brain-js-neural-network-to-do-text-analysis) – tao May 17 '19 at 18:54

1 Answers1

1

This can be accomplished with Brain's LSTM function. Here's it working on your dataset (with a few more examples to train):

const net = new brain.recurrent.LSTM();

net.train([
  { input: "Hello, I'm John Walker.", output: "complete" },
  { input: "This is on you!", output: "complete" },
  { input: "John kik", output: "incomplete" },
  { input: "This is", output: "incomplete" },
  { input: "Great job.", output: "complete" },
  { input: "When I hear a", output: "incomplete" }
]);

Output:

> net.run("I'm Stil.");
"incomplete"
> net.run("Great job!")
"complete"

LSTM docs

Jake Worth
  • 5,490
  • 1
  • 25
  • 35