Learning collective variables that preserve transition rates