Machine learning is becoming an increasingly popular method for building mathematical models from observations of natural processes. Here, the central challenge is to impart structure into the model parameterization to enforce physical relevance, yet retain a degree of generality so that a large variety of dynamics can be learned. We introduce a novel methodology, based on a data-driven extension of the classical Onsager principle, that strikes a balance between these competing aspects. We demonstrate its efficacy by learning quantitatively accurate and qualitatively faithful reduced order models of the Rayleigh-B\'enard convection equations.