![]() |
VOOZH | about |
Deep learning is ubiquitous โ whether itโs Computer Vision applications or breakthroughs in the field of Natural Language Processing, we are living in a deep learning-fueled world. Thanks to the rapid advances in technology, more and more people are able to leverage the power of deep learning. At the same time, it is a complex field and can appear daunting for newcomers.
Note: If you are more interested in learning concepts in an Audio-Visual format, We have this entire article explained in the video below. If not, you may continue reading.
One common concern for everyone in this field is- How can they improve their Deep Learning models? Are there any ways or techniques which can help them to improve their models? Well, there certainly are such techniques which you need to know if you also want to improve your model performance. And in this article, Iโm going to cover one of such techniques, which I must say is very important while building a Neural Network. This technique is called Model Checkpointing. And it majorly has two advantages-
Weโll discuss each one in detail. Letโs begin!
Letโs discuss what do we mean by โBest Modelโ and how it can be saved? Letโs say that this is the visualization of the performance of a model-
๐ Model Checkpointing - Saving the Best Model
Here the blue line represents the training loss and the orange line represents the validation loss. On the X-axis, we have the number of epochs and on the Y-axis we have the loss values. Now, while making the predictions, the weights and biases stored at the very last epoch will be used. So the model will train completely till the specified number of epochs, which is 50 in this case. And the parameters learned during the last epoch will be used in order to make the predictions.
๐ model checkpointing - epoch vs loss
But if you look closely in this particular graph, the best validation loss is around this epoch, which is epoch number 45-
Let me take the model history in order to elaborate on this a bit more. So here is the model history for a model which has been trained for 50 epochs-
๐ Model Checkpointing - 50 epochs
And you can see the epoch numbers here. Now we can see that we have the training loss, training accuracy, validation loss, and validation accuracy shown here. Letโs look at the valuation loss as highlighted here-
๐ Model Checkpointing - valuation loss
So what we generally do is we take the parameters of the model at the last epoch, which is epoch 50 here, and make the predictions. Now, in this case, we can see that the valuation loss at epoch number 50 is 0.629, whereas if you see the lowest validation loss was 0.61, which was at epoch 45.
๐ Model Checkpointing - 45 epochs
So through the model checkpointing, instead of saving the last model or the parameters of the last epoch, we are going to save the model which produces the best results. And this model is called the Best Model. So basically Model Checkpointing will help us save the best model.
Now, since it seems the best model, the second useful advantage of this technique is that in case your system breaks or fails during the training process, you will not lose much information since the model is being saved constantly. Now, we know that through model checkpointing, we can save the best model but you must be wondering, how do we do that? How do we know which model is the best model?
So to answer that in Keras, we have to define two parameters. One is โMonitorโ and the other one is โModeโ.
The first one refers to the quantity that we wish to monitor, such as validation loss or validation accuracy and โModeโ refers to the mode of that quantity. Let me explain this with an example. So letโs say we wish to monitor the validation loss in this case. While we are monitoring the validation loss, the mode will be minimum because we want to minimize the loss.
Similarly, if we are monitoring the validation accuracy, the mode will be maximum since we want the maximum accuracy for the validation set.
So after every epoch, we will monitor either the validation loss or the validation accuracy and save the model, if these values have improved from the previous model.
Now, these are the common steps that we perform while creating any deep learning model, and we setup model checkpointing at the time of Model Training-
After reading this article you should have got an intuition behind the Model Checkpointing technique which can be really helpful and can do wonders if youโre looking forward to improving your deep learning model. For the implementation of this technique, stay tuned! Iโm going to cover its implementation in the next article.
If you are looking to kick start your Data Science Journey and want every topic under one roof, your search stops here. Check out Analytics Vidhyaโs Certified AI & ML BlackBelt Plus Program
If you have any questions, let me know in the comments section!
Iโm a data lover who enjoys finding hidden patterns and turning them into useful insights. As the Manager - Content and Growth at Analytics Vidhya, I help data enthusiasts learn, share, and grow together.
Thanks for stopping by my profile - hope you found something you liked :)
GPT-4 vs. Llama 3.1 โ Which Model is Better?
Llama-3.1-Storm-8B: The 8B LLM Powerhouse Surpa...
A Comprehensive Guide to Building Agentic RAG S...
Top 10 Machine Learning Algorithms in 2026
45 Questions to Test a Data Scientist on Basics...
90+ Python Interview Questions and Answers (202...
8 Easy Ways to Access ChatGPT for Free
Prompt Engineering: Definition, Examples, Tips ...
What is LangChain?
What is Retrieval-Augmented Generation (RAG)?
Some of the math is over my head but I do understand most of the concepts.
Edit
Resend OTP
Resend OTP in 45s