Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is stop-inputstart-output? #210

Closed
LiamDobbelaere opened this issue May 16, 2018 · 6 comments
Closed

What is stop-inputstart-output? #210

LiamDobbelaere opened this issue May 16, 2018 · 6 comments

Comments

@LiamDobbelaere
Copy link

LiamDobbelaere commented May 16, 2018

What is wrong?

Output of my LSTM sometimes contains keywords stop-input and start-output.
I would expect if I ask it to run on my input that it just gives the expected output.
For instance, I expect:

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

net.train([
  { input: 'I feel great about the world!', output: 'happy' },
  { input: 'The world is a terrible place!', output: 'sad' },
]);
var output = net.run('I feel great about');

To output "happy" or "sad", but instead it outputs "he world is a terrible place!stop-inputstart-outputsad"

What is up with this output 'clutter' and why is it there? It's odd that I'd have to do string splitting to get the actual output.

@mubaidr
Copy link
Contributor

mubaidr commented May 17, 2018

Please try this:

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

net.train([
  { input: 'I feel great about the world!', output: {happy: 1} },
  { input: 'The world is a terrible place!', output: {sad: 1} },
]);
var output = net.run('I feel great about'); // sample log: {happy: 0.75, sad: 0.25}

@LiamDobbelaere
Copy link
Author

Using your exact code I'm getting "he world!stop-inputstart-output", really odd
I'm on brain.js^1.2.1, I installed it just yesterday so it can't be a version that's too old surely

@mubaidr
Copy link
Contributor

mubaidr commented May 17, 2018

Please check this: https://jsfiddle.net/mubaidr/1jwdgukf/1/

For details please refer to these discussions too:
#188

#209 (comment)
#109

@robertleeplummerjr
Copy link
Contributor

robertleeplummerjr commented May 17, 2018

The example that came up here as a possible fix is one we are working towards, ie: words in, decimal out. It doesn't yet work. The issue you are receiving which are the artifact of stop-inputstart-output is two fold: The way the existing neural network in v1 works, all characters are mapped to a single neuron. So when the neuron is activated, it tells that net a character entered into it. To get the net to do interesting things like predict what is next and stop, it needs certain factors, like telling the net: "stop receiving inputs, and just guess the output, then end" and that is what the above artifact is essentially.

It isn't perfect, and you've identified a bug that will need resolved. However, I am working on v2 which will give us some more robust tools for these scenarios. In your specific case where training is as follows:

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

net.train([
  { input: 'I feel great about the world!', output: 'happy' },
  { input: 'The world is a terrible place!', output: 'sad' },
]);

And running the net as:

var output = net.run('I feel great about');

The net is guessing he world is a terrible place!stop-inputstart-outputsad and in short is linking the whole sentence as: I feel great abouthe world is a terrible place!stop-inputstart-outputsad. If we cut out the artifact of stop-inputstart-out we arrive at I feel great abouthe world is a terrible place!sad and if we jump to the end result just after the artifact we get sad. In short I would say the net either needs more depth, more neurons, more training, or more training data, or a combination of those.

What is up with this output 'clutter' and why is it there? It's odd that I'd have to do string splitting to get the actual output.

You are right, it is clutter, and we can do a better job of ensuring it doesn't come out of the net, I may be able to dedicate some time to fixing this in the next few days.

The good news: The net is getting easier and easier to configure for situations like this in v2, including word to vector and translations.

@robertleeplummerjr
Copy link
Contributor

If you do, however, just run the net with the inputs you trained it with, you'll get:

net.run('I feel great about the world!'); // -> 'happy'
net.run('The world is a terrible place!'); // -> 'sad'

@LiamDobbelaere
Copy link
Author

Alright, thank you for your extensive response!
I understand a bit better now and I can't wait for v2.

Obviously if you run the same input you get the same output, but the most interesting part of neural nets is when they come up with new things based on older inputs. Then again, I don't know much about LSTM and I might settle with a simple feedforward NN for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants