Hydrogen, the simplest and most abundant element in the Universe, develops a remarkably complex behaviour upon compression1. Since Wigner predicted the dissociation and metallization of solid hydrogen at megabar pressures almost a century ago2, several efforts have been made to explain the many unusual properties of dense hydrogen, including a rich and poorly understood solid polymorphism1,3–5, an anomalous melting line6 and the possible transition to a superconducting state7. Experiments at such extreme conditions are challenging and often lead to hard-to-interpret and controversial observations, whereas theoretical investigations are constrained by the huge computational cost of sufficiently accurate quantum mechanical calculations. Here we present a theoretical study of the phase diagram of dense hydrogen that uses machine learning to ‘learn’ potential-energy surfaces and interatomic forces from reference calculations and then predict them at low computational cost, overcoming length- and timescale limitations. We reproduce both the re-entrant melting behaviour and the polymorphism of the solid phase. Simulations using our machine-learning-based potentials provide evidence for a continuous molecular-to-atomic transition in the liquid, with no first-order transition observed above the melting line. This suggests a smooth transition between insulating and metallic layers in giant gas planets, and reconciles existing discrepancies between experiments as a manifestation of supercritical behaviour.