A machine learning model can reproduce the swarming behaviour of locusts.