8

I trained a model with Keras for text classification (supervised learning) using a training set. Let's say that there are 50.000 sentences in this training set.

During a week I collect 5.000 new sentences and I add them to the old training set.

If next week I want to train a new model with the new and bigger training set (50.000 old sentences + 5.000 new sentences), should I restart the training phase from the beginning, or can I take the old model and "update" it in some way to save some time?

erik.b
  • 107
  • 9
  • 3
    [check this post](https://stackoverflow.com/questions/42666046/loading-a-trained-keras-model-and-continue-training) . Your question is explained there. – Juanju Nov 14 '18 at 08:58

1 Answers1

1

You can save/load model/weights. Check out this tutorial by Jason Brownlee.

After you loaded the weights, you can start training with the new dataset (the 55000 samples). As the 'training' is basically just updating weights, and you loaded your trained weights, you are now 'updating' the already trained model.

Dinari
  • 2,487
  • 13
  • 28
  • 1
    Thank you for the quick reply! I tried the solution in the tutorial, and it works if the input layer (each different single word in my sentences) does not change between the first partial training set and the second full training set. I mean, if the 5000 sentences I add to my initial training set are made with words that are already present in the first 50000 sentences, then I can "update" my model. If there are some new words I have to retrain the model from scratch, because the input layer has changed, am I right? – erik.b Nov 14 '18 at 09:29
  • 2
    Assuming you use bag-of-words representation, you can load the whole model, and switch just the input layer. That way you will keep all the trained weights, apart from the first ones. You can look here for the way to do it: https://stackoverflow.com/questions/49546922/keras-replacing-input-layer – Dinari Nov 14 '18 at 10:17