STS benchmarks (part of MTEB) score sentence pairs from 0 to 5 by human judgement. An embedding model is good if the ranking of its cosine similarities matches the human ranking, measured by Spearman correlation.
Implement:
cosine_pairs(A, B): the row-wise cosine similarity between two (n, d) arraysrankdata(x): ranks starting at 1, giving tied values the average of their ranks ([10, 20, 20, 30] → [1, 2.5, 2.5, 4])spearman(x, y): the Pearson correlation of the rankssts_score(A, B, gold): Spearman between the cosine similarities and the gold scores