brain.js icon indicating copy to clipboard operation
brain.js copied to clipboard

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

Open Vectorrent opened this issue 2 years ago • 2 comments

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!

Vectorrent avatar Apr 17 '22 03:04 Vectorrent

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

Dpr1815 avatar Jun 01 '22 21:06 Dpr1815

+1, I've got this issue too.

TejasQ avatar Jul 15 '22 23:07 TejasQ

+1

cristianizzo avatar Sep 11 '22 01:09 cristianizzo

+1

GuiriDelNorte avatar Sep 14 '22 00:09 GuiriDelNorte

Investigating.

robertleeplummerjr avatar Sep 14 '22 14:09 robertleeplummerjr

The issue The tests - I added tests around the issue as well to prevent this from happening again.

robertleeplummerjr avatar Sep 14 '22 15:09 robertleeplummerjr

Published in version https://www.npmjs.com/package/brain.js/v/2.0.0-beta.16

robertleeplummerjr avatar Sep 14 '22 15:09 robertleeplummerjr