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.

Unable to train recurrent.LSTM() after loading previous training fromJSON()

See original GitHub issue

A GIF or MEME to give some spice of the internet

What is wrong?

In other classes, such as NeuralNetwork(), I am able to save a trained model by using toJSON(), and load it later with fromJSON(), in order to continue training.

When I try to do this with recurrent.LSTM(), training fails with the following error:

/app/node_modules/brain.js/dist/index.js:7586
                throw new Error('Network error rate is unexpected NaN, check network configurations and try again. Most probably input format is not correct or training data is not enough. ');
                      ^

Error: Network error rate is unexpected NaN, check network configurations and try again. Most probably input format is not correct or training data is not enough. 
    at LSTM.train (/app/node_modules/brain.js/dist/index.js:7586:23)
    at file:///app/src/js/model.js:56:5
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async loadESM (node:internal/process/esm_loader:85:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)
    
Node.js v17.9.0

Where does it happen?

This is happening in Node.JS on Ubuntu 20.04.

How do we replicate the issue?

Execute this bit of code to reproduce the problem.

import brain from 'brain.js'

let net = new brain.recurrent.LSTM()

net.train([
    'doe, a deer, a female deer',
    'ray, a drop of golden sun',
], {
    iterations: 500,
    log: true,
    errorThresh: 0.01
})

let saved = net.toJSON()

net.fromJSON(saved)
net.train([
    'me, a name I call myself',
], {
    iterations: 500,
    log: true,
    errorThresh: 0.01
})

Expected behavior (i.e. solution)

I would expect training to resume from where it left off previously. In other classes, I am able to save my network to disk, and restart training with it later. I’m unable to do that with recurrent.LSTM().

This is particularly desired because recurrent.LSTM() is quite slow, and I don’t want to retrain my entire network if the training data changes.

Version information

Nodejs: 17.9.0

Brain.js: 2.0.0-beta.15

How important is this (1-5)?

Probably a 1. I’m new to AI and I’m guessing this limitation is by-design?

Other Comments

Thanks in advance for any help you can offer!

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TejasQcommented, Jul 15, 2022

+1, I’ve got this issue too.

1reaction
Dpr1815commented, Jun 1, 2022

Hello there! I have the same problem. Any news about it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

brain.js problem with importing LSTM network from json
It seems like it's an error with brain.js. I have also tried net.run() after importing the file, but it also didn't work.
Read more >
brain.js - npm
Use train() to train the network with an array of training data. The network has to be trained with all the data in...
Read more >
How to Save and Load Your Keras Deep Learning Model
Keras provides the ability to describe any model using JSON format with a to_json() function. This can be saved to a file and...
Read more >
Save and load a model using a distribution strategy
Adam(), metrics=[tf.metrics.SparseCategoricalAccuracy()]) return model ... After restoring the model, you can continue training on it, even without needing ...
Read more >
Recurrent Neural Network (RNN) Tutorial: Types, Examples ...
It learns from huge volumes of data and uses complex algorithms to train a neural net. Here is an example of how neural...
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