Model Solver
Last updated
Last updated
The mission of the model solver is to find the best set of parameters, that minimize the train/accuracy errors. On this chapter we will give a UML description with some piece of python/matlab code that allows you implement it yourself.
From the UML description we can infer some information about the Solver class:
It uses the training set, and has a reference to your model
Uses different type of optimizers(ex: SGD, ADAM, SGD with momentum)
Keep tracks of all the loss, accuracy during the training phase
Keep the set of parameters, that achieved best validation performance
This is the method called when you actually want to start a model training, the methods Step, Check_Accuracy are called inside the Train method:
Calculate number of iterations per epoch, based on number of epochs, train size, and batch size
Call step, for each iteration
Decay the learning rate
Calculate the validation accuracy
Cache the best parameters based on validation accuracy
Basically during the step operation the following operations are done:
Extract a batch from the training set.
Get the model loss and gradients
Perform a parameter update with one of the optimizers.
This method basically is called at the end of each epoch. Basically it uses the current set of parameters, and predict the whole validation set. The objective is at the end get the accuracy.
We mentioned during the "Step" operation that we get the model loss and gradients. This operation is implemented by the "getLoss" method. Consider the following basic model.
Also bellow we have the "softmaxloss" function including "dout", $$\frac{\partial L}{\partial X{scores}}$$
Bellow we have the "getLoss" function for the previous simple model.