Learning Distances from Data with Normalizing Flows and Score Matching