Code for training neural network