Optimizing transformations for contrastive learning in a differentiable framework