Contrastive Learning from Pairwise Measurements