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.

LSTM is extremely slow ( 2 hours )

See original GitHub issue

Hi. I’m trianing an LSTM network that takes 2 hours to train 1000 training data with only 2000 iterations. Why is it so very slow?

// learns if string is like a date

// get training data
const trainingData = [
    {"input":"33 minutes ago","output":"yes"},
    {"input":"20 hours ago","output":"yes"},
    {"input":"May 7 at 13:42 AM","output":"yes"},
    {"input":"Feb 21 at 8:43 AM","output":"yes"},
    {"input":"Jul 22, 2012 ","output":"yes"},
    {"input":"Apr 14, 2018 ","output":"yes"}
    // 1000 total...
]

const network = new brain.recurrent.LSTM();

// create configuration for training
const config = {
    iterations: 2000,
    log: true,
    logPeriod: 200,
    layers: [10],
    log(detail) {
        console.log(detail);
    }
};

network.train(trainingData, config);

const output = network.run('Apr 6, 2014');

console.log(`Is like a date: ${(output == 'yes') ? 'YES' : 'NO' }`);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

4reactions
tymmesydecommented, Oct 22, 2019

I didn’t pay more attention to your trainingSet in my previous answer, but I see that you are trying to train your network with dates in the form of strings. I suggest you to take a different approach by normalizing your data:

Maybe try to see what the similarities are in your data and use them in your trainingSet as inputs instead of a literal string Example: hasSpaces, hasNumber, hasStrings, hasCommas, hasYear, … (I suggest you add more of those)

Make a short script before, reviewing all your data by checking if it meets the above criteria. (e.g. if hasSpaces, then your first input value should be 1, and so on)

Then fill your trainingSet like that:

{
   input: [1, 0, 1, 1, 0], output: [0],
   input: [1, 1, 1, 1, 1], output: [1]
}

And when you want to use run, go through to same process

1reaction
ninjaferrari90commented, Jan 12, 2020

The training takes too long i.e. somewhere around 14 hours or even more… My data set is having different output for different input strings…

Is there a way i can reduce my training time? Although i am storing the trained results in JSON and using that while retrieving the output…

Using Node with brain.js version 2.0.0-alpha.11

const trainingData = [ {“input”:“How are you”,“output”:“very well”}, {“input”:“How have you been”,“output”:“very well”}, {“input”:“welcome to new york”,“output”:“thanks”}, {“input”:“welcome to our city”,“output”:“thanks”}, {“input”:“welcome to usa”,“output”:“thanks”}, {“input”:“Lets catchup today”,“output”:“ofcourse”}, {“input”:“Lets meet today”,“output”:“ofcourse”} … many more… //large data set with different responses for different scenarios… ]

const network = new brain.recurrent.LSTM();

// create configuration for training const config = { iterations: 10000, log: true, };

network.train(trainingData, config);

Read more comments on GitHub >

github_iconTop Results From Across the Web

deep learning - Why does my LSTM take so much time to train?
The main problem is that training is awfully slow : each iteration of training takes about half a day. Since training usually takes...
Read more >
Why is my LSTM in tensorflow learning so slowly and badly?
It's not only faster but it produces mostly meaningful words. This produces gibberish only.
Read more >
Why is my LSTM network taking 3 hours to train on a single ...
I have been training a LSTM network that contains 5000 samples of numerical data (each containing 100 time-steps). I am perplexed as to...
Read more >
Why is my GPU slower than CPU when training LSTM/RNN ...
1 Answer. This is mainly due to the sequential computation in the LSTM layer. Remember that LSTM requires sequential input to calculate the...
Read more >
Very slow training on GPU for LSTM NLP multiclass ...
The training step of LSTM NN consumes 15+ min just for the first epoch. It seems I made a mistake somewhere. def train_model(model,...
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