How unconstrained machine-learning models learn physical symmetries