Algorithms for robust learning, gradient flows, and diffusion generation of rare events