Describe the training dynamics of a neural network. How do you detect and resolve vanishing or exploding gradient problems during backpropagation?