Adding a function to train the neural network