feed-forward neural networks predictionswe can calculate its deviation from the actual label using the loss function-- loss loss_function(output_datalabelsto backpropagate our losspytorch provides built-in module that does the heavy lifting for computing gradients for the loss with respect to the weights we simply call the loss backward(methodand the entire backpropagation is taken care of "automatic differentiation in deep learning,explores the autograd modulewhich takes care of backpropagation in pytorchin more detail once the gradients are computedit is time to update our model weights this is done in the step optimizer step(the optimizer step is aware of the parameters that need to be updated with the gradientas we provided them while defining our optimizer calling the optimizer step(function updates the weights for the networkautomatically taking into account the hyperparameters defined within the optimizer--in our casethe learning rate we repeat this process over batches for the entire training sample the training process is repeated for multiple epochsand with each iteration we expect the losses to reduce and the weights to align in order to achieve better accuracy for predictions listing - uses different optimizers to illustrate the training process for the preceding neural network since the network was trained for toy datasetwe will plot the total losses after each epoch for different optimizersinstead of plotting the validation accuracy we can study the outputs loss across epochs for each optimization variant showcased in figure - listing - training model with various optimizers #define loss function loss_function nn bceloss(#binary crosss entropy loss num_epochs batch_size= #define model object from the class defined earlier model neuralnetwork(