question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fromJSON does not work with LSTM

See original GitHub issue

I’m trying to use a LSTM network to just feed messages from a discord server, as a fun experiment to see what it can come up with. The problem is when I save the data using toJSON and then restoring it, it seems like the data is incompatible with what fromJSON expects.

const network = new brain.recurrent.LSTM();
const data = await getDataSomehow()

network.fromJSON(data)

getDataSomehow loads the json file, parses it and returns the object. After doing this, this error is put in console whenever run is called: image

Furthermore, when I try training with new data, if it encounters a character that was not in the original training data, it gives me Unrecognized character.

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
robertleeplummerjrcommented, Nov 13, 2018

Reproduced. Great find @felangel and everyone who worked on this. Merging now, and will have a new version out within the next 10 minutes.

1reaction
jorgelahozcommented, Nov 12, 2018

The same here, the issue appears when exportinf/importing to/from JSON. For example:

const BrainJS = require("brain.js");
var net = new BrainJS.recurrent.LSTM();
var trainOps = {
    iterations: 20000,
    errorThresh: 0.011,
    log: true,
    logPeriod: 1,
    timeout: Infinity     // the max number of milliseconds to train for --> number greater than 0
};
var data = [
    'doe, a deer, a female deer',
    'ray, a drop of golden sun',
    'me, a name I call myself',
];
net.train(data, trainOps);
var output = net.run('doe');  // ', a deer, a female deer'
console.log(output);
var json = net.toJSON();
net.fromJSON(json);
var output = net.run('doe');  // ', a deer, a female deer'
console.log(output);

Returns

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at LSTM.run (/code/node_modules/brain.js/src/recurrent/rnn.js:311:27)
Read more comments on GitHub >

github_iconTop Results From Across the Web

brain.js problem with importing LSTM network from json
After looking at your training data, it looks like rows/columns are properties in an object called 'input'. Is it possible that you need...
Read more >
Using a JSON dataset for lstm - Data Science Stack Exchange
But I have to run a json dataset where I have to add this output for each review in the json file. Can...
Read more >
Useful LSTM network example using brain.js
Problem They say every problem has a solution (not necessarily). ... create here an instance of LSTM network and call fromJSON() method.
Read more >
Save and load Keras models | TensorFlow Core
When would you use one or the other, and how do they work? ... Delete the custom-defined model class to ensure that the...
Read more >
brain.js - npm
js from npm should just work. However, if you run into problems, this mean prebuilt binaries are not able to download from github...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found