We apply batch optimization, a technique widely used in machine learning, to finding the laser pulses for two-qubit gates on trapped ions. We experimentally verify that the new method improves the gate’s robustness to offsets of the motional-mode frequencies.