预测是单词组合时的Brain js NaN是完整的句子

时间:2019-05-17 18:12:07

标签: javascript

我是大脑js的新手,我正在尝试使其预测单词组合是否是完整的句子。 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

我知道数据不足以进行良好的预测,但我仍然希望数值在0-1之间。 问题是什么?

1 个答案:

答案 0 :(得分:1)

这可以通过Brain的LSTM函数来完成。这是在您的数据集上进行的工作(还有其他一些要训练的示例):

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" }
]);

输出:

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

LSTM docs