【发布时间】:2019-10-14 14:36:25
【问题描述】:
我正在使用 Brain js 进行文本分类。我面临的问题是训练速度非常慢。下面的代码需要 15-20 分钟才能执行。我读过一些simple projects 似乎面临同样的问题。一些作者做了一些非常有趣的事情——他们将文本转换为数字。我的问题是如何将字符串转换为数字以提高学习速度,然后呈现与我现在相同的输出?
//Simple emotion detetction
var net = new brain.recurrent.LSTM();
net.train([
{input: "Feeling good.", output: "positive"},
{input: "Overall well.", output: "positive"},
{input: "Extremely happy.", output: "positive"},
{input: "I'm feeling joyful.", output: "positve"},
{input: "She is in an outstanding mood.", output: "positive"},
{input: "He is feeling inspiration", output: "positive."},
{input: "Today will be my day.", output: "positive"},
{input: "I know that I’m winner.", output: "positive"},
{input: "Yes ,I can do it, I know I can.", output: "positive"},
{input: "Tomorrow is next chance.", output: "positve"},
{input: "Henna can do it.", output: "positive"},
{input: "I like vegetables.", output: "positive."},
{input: "I'm feeling worse than ever.", output: "negative"},
{input: "She seems a little distracted.", output: "negative"},
{input: "This behaviour is unacceptable.", output: "negative"},
{input: "Rober is feeling depressed.", output: "negative"},
{input: "They are feeling miserable.", output: "negative"},
{input: "Robert is in bad mood.", output: "negative"},
{input: "I'm feeling pity for m action.", output: "negative"}
]);
alert(net.run("I'm feeling pretty bad."));
【问题讨论】:
-
这里有一个建议,可以输出 [0] 和 [1],然后获取您的字符串,然后使用
.split("")拆分它们,然后使用.charCodeAt()将每个字符更改为其 charCode方法,然后将该数字除以 255,得到每个字符的 0 到 1 之间的数字。通过这种方式,它可能训练得更快。
标签: javascript machine-learning brain.js