Skip to content

Online Learning in Keras? #1868

Closed
Closed
@ashwinnaresh

Description

@ashwinnaresh

I wanted to implement online learning for a LSTM RNN. Does keras support online learning as of now?
If not, can someone direct us to any source on how online learning can be implemented for RNN? (atleast on a conceptual level).

Activity

tboquet

tboquet commented on Mar 2, 2016

@tboquet
Contributor

When you say online learning, do you mean this?
If it's the case, you could take a look at this example.

sjayakum

sjayakum commented on Mar 3, 2016

@sjayakum

Say,

If I train a model with a training set.
Now, Can i 're-fit' [update NOT re-train] the model with new data such that model parameters are just updated and not re-initialized.

Example:
The below model is loaded after being trained with a training dataset.


model = model_from_json(open('lstm.json').read())
model.load_weights('lstm_weights.h5')

Now, when I do


model.fit(new_data_input,new_data_output,verbose=1,nb_epoch=j)

Here does the above statement retrain the model from scratch or just the model parameters get updated.

pasky

pasky commented on Mar 3, 2016

@pasky
Contributor
ashwinnaresh

ashwinnaresh commented on Mar 3, 2016

@ashwinnaresh
Author

Okay, thank you!

marcj

marcj commented on Mar 3, 2016

@marcj

The parameters are not only getting updated but also the learned from initial training will be overwritten. The more new_data_input you have, the more the old training will be overwritten and it's probable that the accuracy for those training data goes down. I guess you mean with online learning, that with every new input all total inputs ever used are added to the network instead of overwritten, but I don't think this is the case.

pasky

pasky commented on Mar 3, 2016

@pasky
Contributor

I'm not sure I follow exactly what Marc is trying to say (maybe he meant
to use "diminished" rather than "overwritten").

But it does bear to note that when you restart the fit(), any kind
of learning rate schedule your optimizer is following (e.g. SGD+decay
or adam) is restarted too! That means you may be updating your model
on a new small sample by using a huge learning rate, which might not
be okay.

Fixing this (to set the initial #iterations > 0) will require some
small changes to keras.optimizers. But I don't know if there's any
literature on what's actually the good way to fix this, because just
setting the #iterations to number of iterations ran before does not
sound right either. So perhaps the safest solution may be to just
use plain SGD with static learning rate for these followup fit()s.

ashwinnaresh

ashwinnaresh commented on Mar 4, 2016

@ashwinnaresh
Author

Yeah, I want the LSTM to learn with newer data. If it forgets what it has learnt from the older data, its fine. It needs to update itself depending on the trend in the new data.
It seems that .fit() does take care of the problem I had.
Thanks @tboquet, @pasky and @marcj

anujgupta82

anujgupta82 commented on Apr 19, 2016

@anujgupta82

@ashwin123 : I am also looking for online learning in keras. What I understand is that:
for every datapoint , you update the model. Once a data point is used, never use it again. Is that correct ?

Also from your experience, how did your model perform ?

ashwinnaresh

ashwinnaresh commented on Apr 20, 2016

@ashwinnaresh
Author

Yes, I was updating the model with a new batch of data points. The model seemed to perform well.

anujgupta82

anujgupta82 commented on Apr 22, 2016

@anujgupta82

@ashwin123
@fchollet
Is there a way to incorporate Passive-Aggresive Algorithm [Crammer06] in updating the weights for online variant ? To be honest I am not even sure If the 2 can be connected.

Looking for some good practices of building models using online deep learning

anujgupta82

anujgupta82 commented on Apr 25, 2016

@anujgupta82

I have put up a basic code for Online Deep Learning in Keras.
https://github.com/anujgupta82/DeepNets/blob/master/Online_Learnin/Online_Learning_DeepNets.ipynb
The key difference is the way training is done - refer to cell number 9 and 17 in the notebook.
In Cell 17, I take one datapoint (as if its a streaming data) and fit the model on this datapoint. Then take next datapoint so on and so forth. Further, each datapoint is considered exactly once and no more.

There is a difference in the outcome of offline and online - On test data ofline gave a 97.98 accuracy, online learning gave 93.96 accuracy.

Is this a right way to implement online learning in Keras ?
Any suggestions on what changes can I make to online accuracy closer to offline ?

toluwajosh

toluwajosh commented on Jul 11, 2016

@toluwajosh

@anujgupta82 the link you gave is broken. Can you please give another link that works. It will be highly appreciated. Thanks

BoltzmannBrain

BoltzmannBrain commented on Jul 11, 2016

@BoltzmannBrain

@ashwin123 would you be willing to share your code for this issue?

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pasky@marcj@i3v@patyork@GF-Huang

        Issue actions

          Online Learning in Keras? · Issue #1868 · keras-team/keras