Generalization Bounds for Metric and Similarity Learning