A key requirement for femtosecond spectroscopy measurements is to compress the laser pulse to its transform-limited duration. In particular, for few-cycle laser pulses, the compression process is time-consuming using conventional algorithms that converge statistically. Here we show that machine learning can accelerate the process of pulse compression: we have developed an adaptive neural-network algorithm to control a deformable-mirror-based pulse shaper that converges 100× faster than a standard evolutionary algorithm.