To control the temporal profile of an electron beam to meet requirements of various advanced scientific applications, a widely-used technique is to manipulate the dispersion terms which turns out to be one-to-many problems. Due to their intrinsic one-to-many property, current popular stochastic optimization approaches on temporal shaping are not very effective, for being trapped into local optima or suggesting only one solution. Here we propose a real-time solver for one-to-many problems of temporal shaping, with the aid of a semi-supervised machine learning method, the conditional generative adversarial network (CGAN). We demonstrate that the CGAN solver can learn the one-to-many dynamics and is able to accurately and quickly predict the required dispersion terms for different custom temporal profiles. This machine learning-based solver overcomes the limitation of the stochastic optimization methods and is expected to have the potential for wide applications to one-to-many problems in other scientific fields.