Online and Batch Learning of Generalized Cosine Similarities