Cascade of phase transitions in the training of energy-based models