How to Update Neural Network Models With More Data

Deep learning neural network models used for predictive modeling may need to be updated.

This may be because the data has changed since the model was developed and deployed, or it may be the case that additional labeled data has been made available since the model was developed and it is expected that the additional data will improve the performance of the model.

It is important to experiment and evaluate with a range of different approaches when updating neural network models for new data, especially if model updating will be automated, such as on a periodic schedule.

There are many ways to update neural network models, although the two main approaches involve either using the existing model as a starting point and retraining it, or leaving the existing model unchanged and combining the predictions from the existing model with a new model.

In this tutorial, you will discover how to update deep learning neural network models in response to new data.

After completing this tutorial, you will know:

  • Neural network models may need to be updated when the underlying data changes or when new labeled data is made available.
  • How to update trained neural network models with just new data or combinations of old and new data.
  • How to create an ensemble of existing and new models trained on just new data or combinations of old and new data.

Let’s get started.

How to Update Neural Network Models With More Data

How to Update Neural Network Models With More Data
Photo by Judy Gallagher, some rights reserved.

Tutorial Overview

This tutorial is divided into three parts; they are:

  1. Updating Neural Network Models
  2. Retraining Update Strategies
    1. Update Model on New Data Only
    2. Update Model on Old and New Data
  3. Ensemble Update Strategies
    1. Ensemble Model With Model on New Data Only
    2. Ensemble Model With Model on Old and New Data

Updating Neural Network Models

Selecting and finalizing a deep learning neural network model for a predictive modeling project is just the beginning.

You can then start using the model to make predictions on new data.

One possible problem that you may encounter is that the nature of the prediction problem may change over time.

You may notice this by the fact that the effectiveness of predictions may begin to decline over time. This may be because the assumptions made and captured in the model are changing or no longer hold.

Generally, this is referred to as the problem of “concept drift” where the underlying probability distributions of variables and relationships between variables change over time, which can negatively impact the model built from the data.

For more on concept drift, see the tutorial:

Concept drift may affect your model at different times and depends specifically on the prediction problem you are solving and the model chosen to address it.

It can be helpful to monitor the performance of a model over time and use a clear drop in model performance as a trigger to make a change to your model, such as re-training it on new data.

Alternately, you may know that data in your domain changes frequently enough that a change to the model is required periodically, such as weekly, monthly, or annually.

Finally, you may operate your model for a while and accumulate additional data with known outcomes that you wish to use to update your model, with the hopes of improving predictive performance.

Importantly, you have a lot of flexibility when it comes to responding to a change to the problem or the availability of new data.

For example, you can take the trained neural network model and update the model weights using the new data. Or we might want to leave the existing model untouched and combine its predictions with a new model fit on the newly available data.

These approaches might represent two general themes in updating neural network models in response to new data, they are:

  • Retrain Update Strategies.
  • Ensemble Update Strategies.

Let’s take a closer look at each in turn.

Retraining Update Strategies

A benefit of neural network models is that their weights can be updated at any time with continued training.

When responding to changes in the underlying data or the availability of new data, there are a few different strategies to choose from when updating a neural network model, such as:

  • Continue training the model on the new data only.
  • Continue training the model on the old and new data.

We might also imagine variations on the above strategies, such as using a sample of the new data or a sample of new and old data instead of all available data, as well as possible instance-based weightings on sampled data.

We might also consider extensions of the model that freeze the layers of the existing model (e.g. so model weights cannot change during training), then add new layers with model weights that can change, grafting on extensions to the model to handle any change in the data. Perhaps this is a variation of the retraining and the ensemble approach in the next section, and we’ll leave it for now.

Nevertheless, these are the two main strategies to consider.

Let’s make these approaches concrete with a worked example.

Update Model on New Data Only

We can update the model on the new data only.

One extreme version of this approach is to not use any new data and simply re-train the model on the old data. This might be the same as “do nothing” in response to the new data. At the other extreme, a model could be fit on the new data only, discarding the old data and old model.

  • Ignore new data, do nothing.
  • Update existing model on new data.
  • Fit new model on new data, discard old model and data.

We will focus on the middle ground in this example, but it might be interesting to test all three approaches on your problem and see what works best.

First, we can define a synthetic binary classification dataset and split it into half, then use one portion as “old data” and another portion as “new data.”

We can then define a Multilayer Perceptron model (MLP) and fit it on the old data only.

We can then imagine saving the model and using it for some time.

Time passes, and we wish to update it on new data that has become available.

This would involve using a much smaller learning rate than normal so that we do not wash away the weights learned on the old data.

Note: you will need to discover a learning rate that is appropriate for your model and dataset that achieves better performance than simply fitting a new model from scratch.

We can then fit the model on the new data only with this smaller learning rate.

Tying this together, the complete example of updating a neural network model on new data only is listed below.

Next, let’s look at updating the model on new and old data.

Update Model on Old and New Data

We can update the model on a combination of both old and new data.

An extreme version of this approach is to discard the model and simply fit a new model on all available data, new and old. A less extreme version would be to use the existing model as a starting point and update it based on the combined dataset.

Again, it is a good idea to test both strategies and see what works well for your dataset.

We will focus on the less extreme update strategy in this case.

The synthetic dataset and model can be fit on the old dataset as before.

New data comes available and we wish to update the model on a combination of both old and new data.

First, we must use a much smaller learning rate in an attempt to use the current weights as a starting point for the search.

Note: you will need to discover a learning rate that is appropriate for your model and dataset that achieves better performance than simply fitting a new model from scratch.

We can then create a composite dataset composed of old and new data.

Finally, we can update the model on this composite dataset.

Tying this together, the complete example of updating a neural network model on both old and new data is listed below.

Next, let’s look at how to use ensemble models to respond to new data.

Ensemble Update Strategies

An ensemble is a predictive model that is composed of multiple other models.

There are many different types of ensemble models, although perhaps the simplest approach is to average the predictions from multiple different models.

For more on ensemble algorithms for deep learning neural networks, see the tutorial:

We can use an ensemble model as a strategy when responding to changes in the underlying data or availability of new data.

Mirroring the approaches in the previous section, we might consider two approaches to ensemble learning algorithms as strategies for responding to new data; they are:

  • Ensemble of existing model and new model fit on new data only.
  • Ensemble of existing model and new model fit on old and new data.

Again, we might consider variations on these approaches, such as samples of old and new data, and more than one existing or additional models included in the ensemble.

Nevertheless, these are the two main strategies to consider.

Let’s make these approaches concrete with a worked example.

Ensemble Model With Model on New Data Only

We can create an ensemble of the existing model and a new model fit on only the new data.

The expectation is that the ensemble predictions perform better or are more stable (lower variance) than using either the old model or the new model alone. This should be checked on your dataset before adopting the ensemble.

First, we can prepare the dataset and fit the old model, as we did in the previous sections.

Some time passes and new data becomes available.

We can then fit a new model on the new data, naturally discovering a model and configuration that works well or best on the new dataset only.

In this case, we’ll simply use the same model architecture and configuration as the old model.

We can then fit this new model on the new data only.

Now that we have the two models, we can make predictions with each model, and calculate the average of the predictions as the “ensemble prediction.”

Tying this together, the complete example of updating using an ensemble of the existing model and a new model fit on new data only is listed below.

Ensemble Model With Model on Old and New Data

We can create an ensemble of the existing model and a new model fit on both the old and the new data.

The expectation is that the ensemble predictions perform better or are more stable (lower variance) than using either the old model or the new model alone. This should be checked on your dataset before adopting the ensemble.

First, we can prepare the dataset and fit the old model, as we did in the previous sections.

Some time passes and new data becomes available.

We can then fit a new model on a composite of the old and new data, naturally discovering a model and configuration that works well or best on the new dataset only.

In this case, we’ll simply use the same model architecture and configuration as the old model.

We can create a composite dataset from the old and new data, then fit the new model on this dataset.

Finally, we can use both models together to make ensemble predictions.

Tying this together, the complete example of updating using an ensemble of the existing model and a new model fit on the old and new data is listed below.

Further Reading

This section provides more resources on the topic if you are looking to go deeper.

Tutorials

Summary

In this tutorial, you discovered how to update deep learning neural network models in response to new data.

Specifically, you learned:

  • Neural network models may need to be updated when the underlying data changes or when new labeled data is made available.
  • How to update trained neural network models with just new data or combinations of old and new data.
  • How to create an ensemble of existing and new models trained on just new data or combinations of old and new data.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

Develop Deep Learning Projects with Python!

Deep Learning with Python

 What If You Could Develop A Network in Minutes

...with just a few lines of Python

Discover how in my new Ebook:
Deep Learning With Python

It covers end-to-end projects on topics like:
Multilayer PerceptronsConvolutional Nets and Recurrent Neural Nets, and more...

Finally Bring Deep Learning To
Your Own Projects

Skip the Academics. Just Results.

See What's Inside

23 Responses to How to Update Neural Network Models With More Data

  1. Jack March 5, 2021 at 6:59 pm #

    hi, Dr. Jason Brownlee

    Good example
    but i cannot see the full code in the website, because i can not move the screenshot and see the all code, can i see the all code?

    • Jason Brownlee March 6, 2021 at 5:15 am #

      Sorry, I don’t understand. Can you please elaborate?

      What do you mean, you cannot see the full code example?

    • Cpc March 6, 2021 at 6:49 am #

      Try to press and hold for a few seconds on the code box. I did that and a horizontal bar appeared. Now I can read all the code.

  2. Vidya March 8, 2021 at 1:18 pm #

    Hi Jason.

    What does kernel_initailizer = ‘he_normal’ do ? Tried understanding from tensorflow.keras website but not clear .

    Thanks so much!

  3. Vidya March 8, 2021 at 1:24 pm #

    Hi Jason .

    Thanks for the post.
    When we get new data , isn’t it always better to add to the old data and retrain ? As more the historical data , more better is the inferencing . But does it vary with case ?

    • Jason Brownlee March 8, 2021 at 1:36 pm #

      You’re welcome.

      No good general rules. It really depends on how much new data there is and how different it is.

  4. Niranjan March 12, 2021 at 11:30 pm #

    Hi Jason,

    Thanks for this post.

    I am just wondering to know that what are your thoughts on doing addition of new labels into the existing model.
    Lets say, I have Model A already trained on 10 classes and then after some time I want to add 2 more classes dataset to the existing, one option is that retrain whole model with all classes 12 and use previous weights.
    But my concern is that, do you think we can retrain on 12 classes [10 old + 2 new] without using older data or some percentage of older data and whole new dataset.?? We can use previous trained model weights.

    Thanks

    • Jason Brownlee March 13, 2021 at 5:33 am #

      It feels more like transfer learning than model updating. I’d probably cut off the output layer and fit a new output layer.

      Nevertheless, experiment and discvoer what works well for your dataset.

  5. yan April 28, 2021 at 10:06 am #

    Think you very much for this work.

  6. Mostafa Amin RIZK July 14, 2021 at 12:26 am #

    Hello,
    Is there any published research articles about this topic?

  7. ishaque July 14, 2021 at 8:38 pm #

    Hi sir, my question is that for implementing the Update Model on New Data, I need to change the input_shape of the model to train new data on the new model, so please tell me how I can change the input_shape of the existing model.

    • Jason Brownlee July 15, 2021 at 5:28 am #

      You can remove the input layer from the model and define a new input layer with the desired shape. This is easily done using the functional API and is done all the time in transfer learning (see some examples on the blog).

      • ishaque July 16, 2021 at 11:00 pm #

        could you please give me code for ” remove the input layer from the model and define a new input layer with the desired shape in functional API” I have been searching for the solution but I didn’t find a solution?

        FYI I have read the blog for functional API and that was great thank you.
        help

        • Jason Brownlee July 17, 2021 at 5:23 am #

          There are many examples of this on the blog, use the search and look at examples for feature selection on image classification datasets.

          • ishaque July 17, 2021 at 4:32 pm #

            plz, share the code for changing the input of existing I am so confused. kindly help

          • Jason Brownlee July 18, 2021 at 5:21 am #

            Sorry, I don’t have the capacity to prepare custom code for you.

  8. ww July 26, 2021 at 11:23 am #

    Hi, sir. Thanks for your post.
    Now I use NN model to forecasting time series, when I have new time series data, can i update my NN model using the new time series data?

    • Jason Brownlee July 27, 2021 at 5:04 am #

      The above tutorial shows you how to update your model.

Leave a Reply