How machines learn to write